NBD export bitmaps
v3 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.
v3:
01: new
02: rewritten to satisfy changes in 03, drop r-b
03: - fix comments
- rewrite nbd_meta_bitmap_query() and rename it to nbd_meta_qemu_query(): parse 'qemu:dirty-bitmaps:' for LIST option to represent list of all dirty-bitmap contexts.
- trace points
- s/512/BDRV_SECTOR_SIZE/
drop TODO comment
04: s/2.13/3.0
05: new
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 (5):
nbd/server: fix trace
nbd/server: add nbd_meta_empty_or_pattern helper nbd/server: implement dirty bitmap export
qapi: new qmp command nbd-server-add-bitmap docs/interop: add nbd.txt
docs/interop/nbd.txt | 37 ++++++ qapi/block.json | 23 ++++ include/block/nbd.h | 6 + blockdev-nbd.c | 23 ++++ nbd/server.c | 322 ++++++++++++++++++++++++++++++++++++++++++++++----- MAINTAINERS | 1 + 6 files changed, 383 insertions(+), 29 deletions(-) create mode 100644 docs/interop/nbd.txt
Signature · 1 line
2.11.1
PATCH v3 1/5 nbd/server: fix trace
Return code = 1 doesn't mean that we parsed base:allocation. Move trace point to appropriate place.
--- nbd/server.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
nbd/server.c +5 -2
@@ -741,7 +741,10 @@ static int nbd_negotiate_send_meta_context(NBDClient *client,* 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. */ +* sending a reply about inconsistent lengths, or 1 on success. +* +* Note: return code = 1 doesn't mean that we've parsed "base:allocation" +* namespace. It only means that there are no errors.*/ static int nbd_meta_base_query (NBDClient *client,NBDExportMetaContexts *meta,uint32_t len,Error **errp) {
@@ -768,10 +771,10 @@ static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta, }if (strncmp (query,"allocation" , alen) ==0 ) { +trace_nbd_negotiate_meta_query_parse ("base:allocation" ); meta->base_allocation = true; } -trace_nbd_negotiate_meta_query_parse ("base:allocation" );return 1 ; }
Signature · 1 line
2.11.1
Re: [Qemu-devel] [PATCH v3 1/5] nbd/server: fix trace
Quoted 10 lines · Vladimir Sementsov-Ogievskiy
Return code = 1 doesn't mean that we parsed base:allocation. Move trace point to appropriate place.
Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>--- nbd/server.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
nbd/server.c static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta, · line 776
Quoted 6 lines
nbd/server.c +1
-0@@ -768,10 +771,10 @@ static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta, }if (strncmp (query,"allocation" , alen) ==0 ) { +trace_nbd_negotiate_meta_query_parse ("base:allocation" ); meta->base_allocation = true; }
It's probably worth tracing even when we successfully skip the request, as in:
if (strncmp...) {
trace_nbd_negotiate_meta_query_parse("base:allocation");
meta->base_allocation = true;
} else {
trace_nbd_negotiate_meta_query_skip("unrecognized request %s", query);
}Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
PATCH v3 2/5 nbd/server: add nbd_meta_empty_or_pattern helper
In reply to Vladimir Sementsov-OgievskiyAdd nbd_meta_pattern() and nbd_meta_empty_or_pattern() helpers for metadata query parsing. nbd_meta_pattern() will be reused for "qemu" namespace in following patches.
--- nbd/server.c | 82 ++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 57 insertions(+), 25 deletions(-)
nbd/server.c +57 -25
@@ -734,48 +734,79 @@ 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 strlen(@pattern) bytes, and set @match to true if they match @pattern. +* @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. * -* Note: return code = 1 doesn't mean that we've parsed "base:allocation" -* namespace. It only means that there are no errors.*/ -static int nbd_meta_base_query (NBDClient *client,NBDExportMetaContexts *meta, -uint32_t len,Error **errp) +* Note: return code = 1 doesn't mean that we've read exactly @pattern +* It only means that there are no errors. */ +static int nbd_meta_pattern (NBDClient *client,const char *pattern,bool *match, +Error **errp) {int ret; -char query[sizeof ("allocation" ) -1 ]; -size_t alen =strlen ("allocation" ); +char *query; +int len =strlen (pattern); + +assert (len); + + query =g_malloc (len); + ret =nbd_opt_read (client, query, len, errp); +if (ret <=0 ) { +g_free (query); +return ret; + } + +if (strncmp (query, pattern, len) ==0 ) { +trace_nbd_negotiate_meta_query_parse (pattern); + *match = true; + } +g_free (query); +return 1 ; +} + +/* 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. +* +* Note: return code = 1 doesn't mean that we've read exactly @pattern +* It only means that there are no errors. */ +static int nbd_meta_empty_or_pattern (NBDClient *client,const char *pattern, +uint32_t len,bool *match,Error **errp) +{if (len ==0 ) {if (client->opt ==NBD_OPT_LIST_META_CONTEXT ) { - meta->base_allocation = true; + *match = true; } -trace_nbd_negotiate_meta_query_parse ("base:" ); +trace_nbd_negotiate_meta_query_parse ("empty" );return 1 ; } -if (len != alen) { -trace_nbd_negotiate_meta_query_skip ("not base:allocation" ); +if (len !=strlen (pattern)) { +trace_nbd_negotiate_meta_query_skip ("different lengths" );return nbd_opt_skip (client, len, errp); } - ret =nbd_opt_read (client, query, len, errp); -if (ret <=0 ) { -return ret; - } - -if (strncmp (query,"allocation" , alen) ==0 ) { -trace_nbd_negotiate_meta_query_parse ("base:allocation" ); - meta->base_allocation = true; - } +return nbd_meta_pattern (client, pattern, match, errp); +} -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_empty_or_pattern (client,"allocation" , len, + &meta->base_allocation, errp); }/* nbd_negotiate_meta_query
@@ -821,6 +852,7 @@ static int nbd_negotiate_meta_query(NBDClient *client,return nbd_opt_skip (client, len, errp); } +trace_nbd_negotiate_meta_query_parse ("base:" );return nbd_meta_base_query (client, meta, len, errp); }
Signature · 1 line
2.11.1
PATCH v3 3/5 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 | 265 ++++++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 253 insertions(+), 18 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 +247 -18
349 lines not on this page · raw message
Signature · 1 line
2.11.1
Re: [Qemu-devel] [PATCH v3 3/5] nbd/server: implement dirty bitmap export
Quoted 10 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]>---
[...]
Quoted 7 lines
nbd/server.c +6
-0+/* nbd_meta_bitmap_query +* +* Handle query to 'qemu:' namespace. +* @len is the amount of text remaining to be read from the current name, after +* the 'qemu:' portion has been stripped. +*
nbd/server.c static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta, · line 837
Quoted 10 lines
nbd/server.c +10
-0+* 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_qemu_query (NBDClient *client,NBDExportMetaContexts *meta, +uint32_t len,Error **errp) +{ +bool dirty_bitmap = false; +int dirty_bitmap_len =strlen ("dirty-bitmap:" ); +int ret; + +if (!client->exp->export_bitmap) {
client->exp is not yet set here. meta->exp should be used instead (and patch should be added, to move from meta->export_name to meta->exp, I'll add it in v4)
Quoted 20 lines
nbd/server.c +20
-0+return nbd_opt_skip (client, len, errp); + } + +if (len ==0 ) { +if (client->opt ==NBD_OPT_LIST_META_CONTEXT ) { + meta->dirty_bitmap = true; + } +trace_nbd_negotiate_meta_query_parse ("empty" ); +return 1 ; + } + +if (len < dirty_bitmap_len) { +trace_nbd_negotiate_meta_query_skip ("not dirty-bitmap:" ); +return nbd_opt_skip (client, len, errp); + } + + len -= dirty_bitmap_len; + ret =nbd_meta_pattern (client,"dirty-bitmap:" , &dirty_bitmap, errp); +if (ret <=0 ) { +return ret;
nbd/server.c static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta, · line 867
Quoted 10 lines
nbd/server.c +10
-0+ } +if (!dirty_bitmap) { +trace_nbd_negotiate_meta_query_skip ("not dirty-bitmap:" ); +return nbd_opt_skip (client, len, errp); + } + +trace_nbd_negotiate_meta_query_parse ("dirty-bitmap:" ); + + return nbd_meta_empty_or_pattern( + client, client->exp->export_bitmap_context +
meta->exp
Quoted 4 lines
nbd/server.c +3
-0+ strlen("qemu:dirty_bitmap:"), len, &meta->dirty_bitmap, errp); +} +
Signature · 2 lines
Best regards, Vladimir
PATCH v3 4/5 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: 3.0 +## + { '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 v3 5/5 docs/interop: add nbd.txt
In reply to Vladimir Sementsov-OgievskiyDescribe new metadata namespace: "qemu".
--- docs/interop/nbd.txt | 37 +++++++++++++++++++++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 38 insertions(+) create mode 100644 docs/interop/nbd.txt
docs/interop/nbd.txt new file +37 -0
@@ -0,0 +1,37 @@ +Qemu supports NBD protocol, and has internal NBD client (look at +block/nbd.c), internal NBD server (look at blockdev-nbd.c) as well as +external NBD server tool - qemu-nbd.c. The common code is placed in +nbd/*. + +NBD protocol is specified here: +https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md + +This following paragraphs describe some specific properties of NBD +protocol realization in Qemu. + + += Metadata namespaces = + +Qemu supports "base:allocation" metadata context as defined in the NBD +protocol specification and defines own metadata namespace: "qemu". + + +== "qemu" namespace == + +For now, the only type of metadata context in the namespace is dirty +bitmap. All available metadata contexts have the following form: + + qemu:dirty-bitmap:<dirty-bitmap-export-name> + +Each dirty-bitmap metadata context defines the only one flag for +extents in reply for NBD_CMD_BLOCK_STATUS: + + bit 0: NBD_STATE_DIRTY, means that the extent is "dirty" + +For NBD_OPT_LIST_META_CONTEXT the following queries are supported +additionally to "qemu:dirty-bitmap:<dirty-bitmap-export-name>": + +* "qemu:" : returns list of all available metadata contexts in the + namespace. +* "qemu:dirty-bitmap:" : returns list of all available dirty-bitmap + metadata contexts.
MAINTAINERS +1 -0
@@ -1923,6 +1923,7 @@ F: nbd/ F: include/block/nbd* F: qemu-nbd.* F: blockdev-nbd.c +F: docs/interop/nbd.txt T: git git://repo.or.cz/qemu/ericb.git nbd NFS
Signature · 1 line
2.11.1