[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v5 08/12] nbd: Refactor counting of metadata contexts
From: |
Eric Blake |
Subject: |
[PATCH v5 08/12] nbd: Refactor counting of metadata contexts |
Date: |
Fri, 23 Oct 2020 13:36:48 -0500 |
Rather than open-code the count of negotiated contexts at several
sites, embed it directly into the struct.
Signed-off-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
nbd/server.c | 23 +++++++++++------------
1 file changed, 11 insertions(+), 12 deletions(-)
diff --git a/nbd/server.c b/nbd/server.c
index 05a8154975a1..27d943529409 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -106,8 +106,7 @@ static QTAILQ_HEAD(, NBDExport) exports =
QTAILQ_HEAD_INITIALIZER(exports);
* NBD_OPT_LIST_META_CONTEXT. */
typedef struct NBDExportMetaContexts {
NBDExport *exp;
- bool valid; /* means that negotiation of the option finished without
- errors */
+ size_t count; /* number of negotiated contexts */
bool base_allocation; /* export base:allocation context (block status) */
bool allocation_depth; /* export qemu:allocation-depth */
bool bitmap; /* export qemu:dirty-bitmap:<export bitmap name> */
@@ -448,7 +447,9 @@ static int nbd_negotiate_handle_list(NBDClient *client,
Error **errp)
static void nbd_check_meta_export(NBDClient *client)
{
- client->export_meta.valid &= client->exp == client->export_meta.exp;
+ if (client->exp != client->export_meta.exp) {
+ client->export_meta.count = 0;
+ }
}
/* Send a reply to NBD_OPT_EXPORT_NAME.
@@ -956,6 +957,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client,
NBDExportMetaContexts local_meta;
uint32_t nb_queries;
int i;
+ size_t count = 0;
if (!client->structured_reply) {
return nbd_opt_invalid(client, errp,
@@ -1013,6 +1015,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client,
if (ret < 0) {
return ret;
}
+ count++;
}
if (meta->allocation_depth) {
@@ -1022,6 +1025,7 @@ static int nbd_negotiate_meta_queries(NBDClient *client,
if (ret < 0) {
return ret;
}
+ count++;
}
if (meta->bitmap) {
@@ -1035,11 +1039,12 @@ static int nbd_negotiate_meta_queries(NBDClient *client,
if (ret < 0) {
return ret;
}
+ count++;
}
ret = nbd_negotiate_send_rep(client, NBD_REP_ACK, errp);
if (ret == 0) {
- meta->valid = true;
+ meta->count = count;
}
return ret;
@@ -2400,15 +2405,9 @@ static coroutine_fn int nbd_handle_request(NBDClient
*client,
return nbd_send_generic_reply(client, request->handle, -EINVAL,
"need non-zero length", errp);
}
- if (client->export_meta.valid &&
- (client->export_meta.base_allocation ||
- client->export_meta.allocation_depth ||
- client->export_meta.bitmap))
- {
+ if (client->export_meta.count) {
bool dont_fragment = request->flags & NBD_CMD_FLAG_REQ_ONE;
- int contexts_remaining = client->export_meta.base_allocation +
- client->export_meta.allocation_depth +
- client->export_meta.bitmap;
+ int contexts_remaining = client->export_meta.count;
if (client->export_meta.base_allocation) {
ret = nbd_co_send_block_status(client, request->handle,
--
2.29.0
- Re: [PATCH v5 01/12] qapi: Move GenericList to qapi/util.h, (continued)
- [PATCH v5 02/12] qapi: Make QAPI_LIST_ADD() public, Eric Blake, 2020/10/23
- [PATCH v5 03/12] nbd: Utilize QAPI_CLONE for type conversion, Eric Blake, 2020/10/23
- [PATCH v5 04/12] nbd: Add new qemu:allocation-depth metadata context, Eric Blake, 2020/10/23
- [PATCH v5 05/12] nbd: Add 'qemu-nbd -A' to expose allocation depth, Eric Blake, 2020/10/23
- [PATCH v5 06/12] nbd: Update qapi to support exporting multiple bitmaps, Eric Blake, 2020/10/23
- [PATCH v5 08/12] nbd: Refactor counting of metadata contexts,
Eric Blake <=
- [PATCH v5 07/12] nbd: Simplify qemu bitmap context name, Eric Blake, 2020/10/23
- [PATCH v5 09/12] nbd: Allow export of multiple bitmaps for one device, Eric Blake, 2020/10/23
- [PATCH v5 10/12] block: Return depth level during bdrv_is_allocated_above, Eric Blake, 2020/10/23
- [PATCH v5 11/12] nbd: Expose actual depth in qemu:allocation-depth, Eric Blake, 2020/10/23
- [PATCH v5 12/12] qapi: Use QAPI_LIST_ADD() where possible, Eric Blake, 2020/10/23