NBD export bitmaps
v2 cover NBD export bitmaps
Hi all.
This is a proposal and realization of new NBD meta context:
qemu. (I hope to send corresponding proposal to NBD protocol soon)
New possible queries will look like:
qemu:dirty-bitmap:<export-bitmap-name>
Mapping from export-bitmap-name to BdrvDirtyBitmap is done through qmp command nbd-server-add-bitmap. For now, only one bitmap export is allowed per NBD export, however it may be easily improved if needed (we don't have such cases for now)
Client and testing.
I wrote client code for Virtuozzo, but it turned out to be unused, actually it's used only for tests. We don't have cases, where we need to import dirty bitmap through qemu nbd-client. All this done for exporting dirty bitmaps to the third tool. So, I think, it is not worth refactoring, rebasing and merging client part upstream, if there are no real usage cases.
v2:
01 from v1 is dropped: actually, we don't need generic namespace parsing for now (especially, after moving to qemu: namespace, which has the same length as base:), lets postpone it.
01: Improve comment wording (Eric), add Eric's r-b
02: improve commit message
move NBD_STATE_DIRTY to header
add comment on NBD_MAX_BITMAP_EXTENTS
remove MAX_EXTENT_LENGTH and instead update add_extents() which
uses it
use export_bitmap_context instead of export_bitmap_name to reduce
operations on it
move from qemu-dirty-bitmap to qemu:dirty-bitmap
other way to parse namespace name
handle FLAG_DF
03: Improve specification of new qmp command (Eric)
Vladimir Sementsov-Ogievskiy (3):
nbd/server: add nbd_meta_single_query helper
nbd/server: implement dirty bitmap export
qapi: new qmp command nbd-server-add-bitmap
qapi/block.json | 23 +++++ include/block/nbd.h | 6 ++ blockdev-nbd.c | 23 +++++ nbd/server.c | 274 ++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 297 insertions(+), 29 deletions(-)
Signature · 1 line
2.11.1
PATCH v2 1/3 nbd/server: add nbd_meta_single_query helper
The helper will be reused for bitmaps namespace.
--- nbd/server.c | 40 +++++++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 13 deletions(-)
nbd/server.c +27 -13
@@ -733,44 +733,58 @@ static int nbd_negotiate_send_meta_context(NBDClient *client,return qio_channel_writev_all (client->ioc, iov,2 , errp) <0 ? -EIO :0 ; } -/* nbd_meta_base_query -* -* Handle query to 'base' namespace. For now, only base:allocation context is -* available in it. 'len' is the amount of text remaining to be read from -* the current name, after the 'base:' portion has been stripped. +/* Read @len bytes, and set @match to true if they match @pattern, or if @len +* is 0 and the client is performing _LIST_. @match is never set to false. * * Return -errno on I/O error, 0 if option was completely handled by * sending a reply about inconsistent lengths, or 1 on success. */ -static int nbd_meta_base_query (NBDClient *client,NBDExportMetaContexts *meta, -uint32_t len,Error **errp) +static int nbd_meta_single_query (NBDClient *client,const char *pattern, +uint32_t len,bool *match,Error **errp) {int ret; -char query[sizeof ("allocation" ) -1 ]; -size_t alen =strlen ("allocation" ); +char *query;if (len ==0 ) {if (client->opt ==NBD_OPT_LIST_META_CONTEXT ) { - meta->base_allocation = true; + *match = true; }return 1 ; } -if (len != alen) { +if (len !=strlen (pattern)) {return nbd_opt_skip (client, len, errp); } + query =g_malloc (len); ret =nbd_opt_read (client, query, len, errp);if (ret <=0 ) { +g_free (query);return ret; } -if (strncmp (query,"allocation" , alen) ==0 ) { - meta->base_allocation = true; +if (strncmp (query, pattern, len) ==0 ) { + *match = true; } +g_free (query);return 1 ; } +/* nbd_meta_base_query +* +* Handle query to 'base' namespace. For now, only base:allocation context is +* available in it. 'len' is the amount of text remaining to be read from +* the current name, after the 'base:' portion has been stripped. +* +* Return -errno on I/O error, 0 if option was completely handled by +* sending a reply about inconsistent lengths, or 1 on success. */ +static int nbd_meta_base_query (NBDClient *client,NBDExportMetaContexts *meta, +uint32_t len,Error **errp) +{ +return nbd_meta_single_query (client,"allocation" , len, + &meta->base_allocation, errp); +} +/* nbd_negotiate_meta_query * * Parse namespace name and call corresponding function to parse body of the
Signature · 1 line
2.11.1
PATCH v2 3/3 qapi: new qmp command nbd-server-add-bitmap
In reply to Vladimir Sementsov-Ogievskiy--- qapi/block.json | 23 +++++++++++++++++++++++ blockdev-nbd.c | 23 +++++++++++++++++++++++ 2 files changed, 46 insertions(+)
qapi/block.json +23 -0
@@ -269,6 +269,29 @@ 'data': {'name': 'str', '*mode': 'NbdServerRemoveMode'} } ## +# @nbd-server-add-bitmap: +# +# Expose a dirty bitmap associated with the selected export. The bitmap search +# starts at the device attached to the export, and includes all backing files. +# The exported bitmap is then locked until the NBD export is removed. +# +# @name: Export name. +# +# @bitmap: Bitmap name to search for. +# +# @bitmap-export-name: How the bitmap will be seen by nbd clients +# (default @bitmap) +# +# Note: the client must use NBD_OPT_SET_META_CONTEXT with a query of +# "qemu:dirty-bitmap:NAME" (where NAME matches @bitmap-export-name) to access +# the exposed bitmap. +# +# Since: 2.13 +## + { 'command': 'nbd-server-add-bitmap', + 'data': {'name': 'str', 'bitmap': 'str', '*bitmap-export-name': 'str'} } + +## # @nbd-server-stop: # # Stop QEMU's embedded NBD server, and unregister all devices previously
blockdev-nbd.c +23 -0
@@ -220,3 +220,26 @@ void qmp_nbd_server_stop(Error **errp)nbd_server_free (nbd_server); nbd_server =NULL ; } + +void qmp_nbd_server_add_bitmap (const char *name,const char *bitmap, +bool has_bitmap_export_name, +const char *bitmap_export_name, +Error **errp) +{ +NBDExport *exp; + +if (!nbd_server) { +error_setg (errp,"NBD server not running" ); +return ; + } + + exp =nbd_export_find (name); +if (exp ==NULL ) { +error_setg (errp,"Export '%s' is not found" , name); +return ; + } + +nbd_export_bitmap (exp, bitmap, + has_bitmap_export_name ? bitmap_export_name : bitmap, + errp); +}
Signature · 1 line
2.11.1
PATCH v2 2/3 nbd/server: implement dirty bitmap export
In reply to Vladimir Sementsov-OgievskiyHandle new NBD meta namespace: "qemu", and corresponding queries:
"qemu:dirty-bitmap:<export bitmap name>".
With new metadata context negotiated, BLOCK_STATUS query will reply with dirty-bitmap data, converted to extents. New public function nbd_export_bitmap selects bitmap to export. For now, only one bitmap may be exported.
--- include/block/nbd.h | 6 ++ nbd/server.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 224 insertions(+), 16 deletions(-)
include/block/nbd.h +6 -0
@@ -234,6 +234,10 @@ enum {#define NBD_STATE_HOLE (1 << 0)#define NBD_STATE_ZERO (1 << 1) +/* Flags for extents (NBDExtent.flags) of NBD_REPLY_TYPE_BLOCK_STATUS, +* for qemu:dirty-bitmap:* meta contexts */ +#define NBD_STATE_DIRTY (1 << 0) +static inline bool nbd_reply_type_is_error (int type) {return type & (1 <<15 );
@@ -315,6 +319,8 @@ void nbd_client_put(NBDClient *client);void nbd_server_start (SocketAddress *addr,const char *tls_creds,Error **errp); +void nbd_export_bitmap (NBDExport *exp,const char *bitmap, +const char *bitmap_export_name,Error **errp);/* nbd_read * Reads @size bytes from @ioc. Returns 0 on success.
nbd/server.c +218 -16
317 lines not on this page · raw message
Signature · 1 line
2.11.1
Re: [Qemu-devel] [PATCH v2 2/3] nbd/server: implement dirty bitmap export
Quoted 16 lines · Vladimir Sementsov-Ogievskiy
Handle new NBD meta namespace: "qemu", and corresponding queries:
"qemu:dirty-bitmap:<export bitmap name>".With new metadata context negotiated,
BLOCK_STATUSquery will reply with dirty-bitmap data, converted to extents. New public functionnbd_export_bitmapselects bitmap to export. For now, only one bitmap may be exported.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- include/block/nbd.h | 6 ++ nbd/server.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 224 insertions(+), 16 deletions(-)
Quoted 3 lines
+/*
nbd_meta_bitmap_query
+ *
+ * Handle query to 'qemu-dirty-bitmap' namespace.
Stale comment
Quoted 2 lines
+ * 'len' is the amount of text remaining to be read from the current name, after
+ * the 'qemu-dirty-bitmap:' portion has been stripped.
and again
nbd/server.c static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta, · line 815
Quoted 13 lines
+ *
+ * Return -errno on I/O error, 0 if option was completely handled by
+ * sending a reply about inconsistent lengths, or 1 on success. */nbd/server.c +10
-0+static int nbd_meta_bitmap_query (NBDClient *client,NBDExportMetaContexts *meta, +uint32_t len,Error **errp) +{ +if (!client->exp->export_bitmap) { +return nbd_opt_skip (client, len, errp); + } + +return nbd_meta_single_query ( + client, client->exp->export_bitmap_context +strlen ("qemu:" ), len, + &meta->dirty_bitmap, errp);
Wait, so client->exp->export_bitmap_context is stored WITH the "qemu:" prefix as part of the name?
During _LIST, you are allowing a query of "qemu:" to list all qemu-specific contexts (namely, qemu:dirty-bitmap:<export-name>); but should we also make it work that if you do "qemu:dirty-bitmap:", you get a list of just dirty-bitmap contexts even if "qemu:" has added other contexts in the meantime?
Quoted 4 lines
nbd/server.c +0
-0@@ -1800,6 +1851,94 @@ static int nbd_co_send_block_status(NBDClient *client, uint64_t handle,return nbd_co_send_extents (client, handle, &extent,1 , context_id, errp); }
nbd/server.c static int nbd_co_send_block_status(NBDClient *client, uint64_t handle, · line 1863
Quoted 10 lines
nbd/server.c +10
-0+/* Set several extents, describing region of given @length with given @flags. +* Do not set more than @nb_extents, return number of set extents. +*/ +static unsigned add_extents (NBDExtent *extents,unsigned nb_extents, +uint64_t length,uint32_t flags) +{ +unsigned i =0 ; +uint32_t max_extent =QEMU_ALIGN_DOWN (INT32_MAX ,512 ); +/* TODO: should be somehow in agreement with blocksize of OPT_GO, +* and this should be documented in NBD proto. */
nbd.git commit 218c446 documented that descriptor lengths MUST be an integer multiple of minimum block size; as for maximum, I see no reason why BLOCK_STATUS can't report larger extents than what NBD_CMD_READ can do. Do we need further doc tweaks to nbd.git?
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Re: [Qemu-devel] [PATCH v2 2/3] nbd/server: implement dirty bitmap export
Quoted 41 lines · Eric Blake
Quoted 15 lines · Vladimir Sementsov-Ogievskiy
Handle new NBD meta namespace: "qemu", and corresponding queries:
"qemu:dirty-bitmap:<export bitmap name>".With new metadata context negotiated,
BLOCK_STATUSquery will reply with dirty-bitmap data, converted to extents. New public functionnbd_export_bitmapselects bitmap to export. For now, only one bitmap may be exported.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- include/block/nbd.h | 6 ++ nbd/server.c | 234 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 224 insertions(+), 16 deletions(-)Quoted 3 lines
+/*
nbd_meta_bitmap_query
+ *
+ * Handle query to 'qemu-dirty-bitmap' namespace.Stale comment
Quoted 2 lines
+ * 'len' is the amount of text remaining to be read from the current name, after
+ * the 'qemu-dirty-bitmap:' portion has been stripped.and again
nbd/server.c static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta, · line 815
Quoted 13 lines
+ *
+ * Return -errno on I/O error, 0 if option was completely handled by
+ * sending a reply about inconsistent lengths, or 1 on success. */nbd/server.c +10
-0+static int nbd_meta_bitmap_query (NBDClient *client,NBDExportMetaContexts *meta, +uint32_t len,Error **errp) +{ +if (!client->exp->export_bitmap) { +return nbd_opt_skip (client, len, errp); + } + +return nbd_meta_single_query ( + client, client->exp->export_bitmap_context +strlen ("qemu:" ), len, + &meta->dirty_bitmap, errp);Wait, so
client->exp->export_bitmap_contextis stored WITH the "qemu:" prefix as part of the name?
Quoted 5 lines
During
_LIST, you are allowing a query of "qemu:" to list all qemu-specific contexts (namely, qemu:dirty-bitmap:<export-name>); but should we also make it work that if you do "qemu:dirty-bitmap:", you get a list of just dirty-bitmap contexts even if "qemu:" has added other contexts in the meantime?
reasonable.
Quoted 5 lines
Quoted 5 lines
nbd/server.c +0
-0@@ -1800,6 +1851,94 @@ static int nbd_co_send_block_status(NBDClient *client, uint64_t handle,return nbd_co_send_extents (client, handle, &extent,1 , context_id, errp); }
Quoted 15 lines
nbd/server.c static int nbd_co_send_block_status(NBDClient *client, uint64_t handle, · line 1863
Quoted 10 lines
nbd/server.c +10
-0+/* Set several extents, describing region of given @length with given @flags. +* Do not set more than @nb_extents, return number of set extents. +*/ +static unsigned add_extents (NBDExtent *extents,unsigned nb_extents, +uint64_t length,uint32_t flags) +{ +unsigned i =0 ; +uint32_t max_extent =QEMU_ALIGN_DOWN (INT32_MAX ,512 ); +/* TODO: should be somehow in agreement with blocksize of OPT_GO, +* and this should be documented in NBD proto. */ nbd.git commit 218c446 documented that descriptor lengths MUST be an integer multiple of minimum block size; as for maximum, I see no reason why
BLOCK_STATUScan't report larger extents than whatNBD_CMD_READcan do. Do we need further doc tweaks to nbd.git?
ok, missed it.
Signature · 2 lines
Best regards, Vladimir
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Hi all.
This is a proposal and realization of new NBD meta context:
qemu. (I hope to send corresponding proposal to NBD protocol soon)New possible queries will look like:
qemu:dirty-bitmap:<export-bitmap-name>
Quoted 5 lines
qapi/block.json | 23 +++++ include/block/nbd.h | 6 ++ blockdev-nbd.c | 23 +++++ nbd/server.c | 274 ++++++++++++++++++++++++++++++++++++++++++++++------ 4 files changed, 297 insertions(+), 29 deletions(-)
We need something in docs/interop/ that documents the qemu: namespace within NBD, so that the upstream NBD spec can point to our document as a reference for other clients to be aware of what semantics we are exporting.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org