Skip to contentSkip to conversation

bitmap export over NBD

GIT PULL Applied Eric Blake 2 participants 9 messages Jun 21, 2018 – Jun 22, 2018

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

The following changes since commit 46012db666990ff2eed1d3dc199ab8006439a93b:

Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20180619' into staging (2018-06-20 09:51:30 +0100)

are available in the Git repository at:

git://repo.or.cz/qemu/ericb.git tags/pull-nbd-2018-06-20-v2

for you to fetch changes up to bc37b06a5cde24fb24c2a2cc44dd86756034ba9d:

nbd/server: introduce NBD_CMD_CACHE (2018-06-21 09:41:39 -0500)

Only sending the new patches (2, 9) and the changed patch (6, was 5/7 in v1)

----------------------------------------------------------------
nbd patches for 2018-06-20

Add experimental x-nbd-server-add-bitmap to expose a disabled bitmap over NBD, in preparation for a pull model incremental backup scheme. Also fix a corner case protocol issue with NBD_CMD_BLOCK_STATUS, and add new NBD_CMD_CACHE.

- Eric Blake: tests: Simplify .gitignore
- Eric Blake: nbd/server: Reject 0-length block status request
- Vladimir Sementsov-Ogievskiy: 0/6 NBD export bitmaps
- Vladimir Sementsov-Ogievskiy: nbd/server: introduce NBD_CMD_CACHE

----------------------------------------------------------------
Eric Blake (2):
tests: Simplify .gitignore
nbd/server: Reject 0-length block status request

Vladimir Sementsov-Ogievskiy (7):
nbd/server: fix trace
nbd/server: refactor NBDExportMetaContexts 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
nbd/server: introduce NBD_CMD_CACHE

 docs/interop/nbd.txt |  38 +++++
 qapi/block.json      |  23 +++
 include/block/nbd.h  |  11 +-
 blockdev-nbd.c       |  23 +++
 nbd/common.c         |   2 +
 nbd/server.c         | 385 ++++++++++++++++++++++++++++++++++++++++++++-------
 MAINTAINERS          |   1 +
 nbd/trace-events     |   1 +
 tests/.gitignore     |  93 +------------
 9 files changed, 433 insertions(+), 144 deletions(-)
 create mode 100644 docs/interop/nbd.txt
Signature · 1 line
2.14.4
author
#1 lore raw

[Qemu-devel] [PULL v2 2/9] nbd/server: Reject 0-length block status request

The NBD spec says that behavior is unspecified if the client requests 0 length for block status; but since the structured reply is documenting as returning a non-zero length, it's easier to just diagnose this with an EINVAL error than to figure out what to return.

Message-Id: <[email protected]>

---
 nbd/server.c | 4 ++++
 1 file changed, 4 insertions(+)
nbd/server.c +4 -0
index 9e1f2271784..493a926e063 100644
@@ -2007,6 +2007,10 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
                                       "discard failed", errp);
 
     case NBD_CMD_BLOCK_STATUS:
+        if (!request->len) {
+            return nbd_send_generic_reply(client, request->handle, -EINVAL,
+                                          "need non-zero length", errp);
+        }
         if (client->export_meta.valid && client->export_meta.base_allocation) {
             return nbd_co_send_block_status(client, request->handle,
                                             blk_bs(exp->blk), request->from,
Signature · 1 line
2.14.4
author
#2 lore raw

[Qemu-devel] [PULL v2 9/9] nbd/server: introduce NBD_CMD_CACHE

In reply to Eric Blake

From: Vladimir Sementsov-Ogievskiy <[email protected]>

Handle nbd CACHE command. Just do read, without sending read data back. Cache mechanism should be done by exported node driver chain.

Message-Id: <[email protected]>

[eblake: fix two missing case labels in switch statements]
---
 include/block/nbd.h |  3 ++-
 nbd/common.c        |  2 ++
 nbd/server.c        | 11 +++++++----
 3 files changed, 11 insertions(+), 5 deletions(-)
include/block/nbd.h +2 -1
index 8bb9606c39b..daaeae61bf9 100644
@@ -135,6 +135,7 @@ typedef struct NBDExtent {
 #define NBD_FLAG_SEND_TRIM         (1 << 5) /* Send TRIM (discard) */
 #define NBD_FLAG_SEND_WRITE_ZEROES (1 << 6) /* Send WRITE_ZEROES */
 #define NBD_FLAG_SEND_DF           (1 << 7) /* Send DF (Do not Fragment) */
+#define NBD_FLAG_SEND_CACHE        (1 << 8) /* Send CACHE (prefetch) */
 
 /* New-style handshake (global) flags, sent from server to client, and
    control what will happen during handshake phase. */
@@ -195,7 +196,7 @@ enum {
     NBD_CMD_DISC = 2,
     NBD_CMD_FLUSH = 3,
     NBD_CMD_TRIM = 4,
-    /* 5 reserved for failed experiment NBD_CMD_CACHE */
+    NBD_CMD_CACHE = 5,
     NBD_CMD_WRITE_ZEROES = 6,
     NBD_CMD_BLOCK_STATUS = 7,
 };
nbd/common.c +2 -0
index 8c95c1d606e..41f5ed8d9fa 100644
@@ -148,6 +148,8 @@ const char *nbd_cmd_lookup(uint16_t cmd)
         return "flush";
     case NBD_CMD_TRIM:
         return "trim";
+    case NBD_CMD_CACHE:
+        return "cache";
     case NBD_CMD_WRITE_ZEROES:
         return "write zeroes";
     case NBD_CMD_BLOCK_STATUS:
nbd/server.c +7 -4
index 2c2d62c6361..274604609f4 100644
@@ -1252,7 +1252,7 @@ static coroutine_fn int nbd_negotiate(NBDClient *client, Error **errp)
     int ret;
     const uint16_t myflags = (NBD_FLAG_HAS_FLAGS | NBD_FLAG_SEND_TRIM |
                               NBD_FLAG_SEND_FLUSH | NBD_FLAG_SEND_FUA |
-                              NBD_FLAG_SEND_WRITE_ZEROES);
+                              NBD_FLAG_SEND_WRITE_ZEROES | NBD_FLAG_SEND_CACHE);
     bool oldStyle;
 
     /* Old style negotiation header, no room for options
@@ -2034,7 +2034,9 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request,
         return -EIO;
     }
 
-    if (request->type == NBD_CMD_READ || request->type == NBD_CMD_WRITE) {
+    if (request->type == NBD_CMD_READ || request->type == NBD_CMD_WRITE ||
+        request->type == NBD_CMD_CACHE)
+    {
         if (request->len > NBD_MAX_BUFFER_SIZE) {
             error_setg(errp, "len (%" PRIu32" ) is larger than max len (%u)",
                        request->len, NBD_MAX_BUFFER_SIZE);
@@ -2119,7 +2121,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
     int ret;
     NBDExport *exp = client->exp;
 
-    assert(request->type == NBD_CMD_READ);
+    assert(request->type == NBD_CMD_READ || request->type == NBD_CMD_CACHE);
 
     /* XXX: NBD Protocol only documents use of FUA with WRITE */
     if (request->flags & NBD_CMD_FLAG_FUA) {
@@ -2138,7 +2140,7 @@ static coroutine_fn int nbd_do_cmd_read(NBDClient *client, NBDRequest *request,
 
     ret = blk_pread(exp->blk, request->from + exp->dev_offset, data,
                     request->len);
-    if (ret < 0) {
+    if (ret < 0 || request->type == NBD_CMD_CACHE) {
         return nbd_send_generic_reply(client, request->handle, ret,
                                       "reading from file failed", errp);
     }
@@ -2171,6 +2173,7 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
 
     switch (request->type) {
     case NBD_CMD_READ:
+    case NBD_CMD_CACHE:
         return nbd_do_cmd_read(client, request, data, errp);
 
     case NBD_CMD_WRITE:
Signature · 1 line
2.14.4
author
#3 lore raw

[Qemu-devel] [PULL v2 6/9] nbd/server: implement dirty bitmap export

In reply to Eric Blake

From: Vladimir Sementsov-Ogievskiy <[email protected]>

Handle a new NBD meta namespace: "qemu", and corresponding queries:
"qemu:dirty-bitmap:<export bitmap name>".

With the new metadata context negotiated, BLOCK_STATUS query will reply with dirty-bitmap data, converted to extents. The new public function nbd_export_bitmap selects which bitmap to export. For now, only one bitmap may be exported.

Message-Id: <[email protected]>

[eblake: wording tweaks, minor cleanups, additional tracing]
---
 include/block/nbd.h |   8 +-
 nbd/server.c        | 278 +++++++++++++++++++++++++++++++++++++++++++++++-----
 nbd/trace-events    |   1 +
 3 files changed, 262 insertions(+), 25 deletions(-)
include/block/nbd.h +6 -2
index fcdcd545023..8bb9606c39b 100644
@@ -229,11 +229,13 @@ enum {
 #define NBD_REPLY_TYPE_ERROR         NBD_REPLY_ERR(1)
 #define NBD_REPLY_TYPE_ERROR_OFFSET  NBD_REPLY_ERR(2)
 
-/* Flags for extents (NBDExtent.flags) of NBD_REPLY_TYPE_BLOCK_STATUS,
- * for base:allocation meta context */
+/* Extent flags for base:allocation in NBD_REPLY_TYPE_BLOCK_STATUS */
 #define NBD_STATE_HOLE (1 << 0)
 #define NBD_STATE_ZERO (1 << 1)
 
+/* Extent flags for qemu:dirty-bitmap in NBD_REPLY_TYPE_BLOCK_STATUS */
+#define NBD_STATE_DIRTY (1 << 0)
+
 static inline bool nbd_reply_type_is_error(int type)
 {
     return type & (1 << 15);
@@ -315,6 +317,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 +255 -23

370 lines not on this page · raw message

nbd/trace-events +1 -0
index dee081e7758..5e1d4afe8e6 100644
@@ -64,6 +64,7 @@ nbd_co_send_simple_reply(uint64_t handle, uint32_t error, const char *errname, i
 nbd_co_send_structured_done(uint64_t handle) "Send structured reply done: handle = %" PRIu64
 nbd_co_send_structured_read(uint64_t handle, uint64_t offset, void *data, size_t size) "Send structured read data reply: handle = %" PRIu64 ", offset = %" PRIu64 ", data = %p, len = %zu"
 nbd_co_send_structured_read_hole(uint64_t handle, uint64_t offset, size_t size) "Send structured read hole reply: handle = %" PRIu64 ", offset = %" PRIu64 ", len = %zu"
+nbd_co_send_extents(uint64_t handle, unsigned int extents, uint32_t id, uint64_t length, int last) "Send block status reply: handle = %" PRIu64 ", extents = %u, context = %d (extents cover %" PRIu64 " bytes, last chunk = %d)"
 nbd_co_send_structured_error(uint64_t handle, int err, const char *errname, const char *msg) "Send structured error reply: handle = %" PRIu64 ", error = %d (%s), msg = '%s'"
 nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type, const char *name) "Decoding type: handle = %" PRIu64 ", type = %" PRIu16 " (%s)"
 nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Payload received: handle = %" PRIu64 ", len = %" PRIu32
Signature · 1 line
2.14.4
#4 lore raw
In reply to Eric Blake
Quoted 23 lines · Eric Blake

The following changes since commit 46012db666990ff2eed1d3dc199ab8006439a93b:

Merge remote-tracking branch 'remotes/cohuck/tags/s390x-20180619' into staging (2018-06-20 09:51:30 +0100)

are available in the Git repository at:

git://repo.or.cz/qemu/ericb.git tags/pull-nbd-2018-06-20-v2

for you to fetch changes up to bc37b06a5cde24fb24c2a2cc44dd86756034ba9d:

nbd/server: introduce NBD_CMD_CACHE (2018-06-21 09:41:39 -0500)

Only sending the new patches (2, 9) and the changed patch (6, was 5/7 in v1)

----------------------------------------------------------------
nbd patches for 2018-06-20

Add experimental x-nbd-server-add-bitmap to expose a disabled bitmap over NBD, in preparation for a pull model incremental backup scheme. Also fix a corner case protocol issue with NBD_CMD_BLOCK_STATUS, and add new NBD_CMD_CACHE.

Quoted 5 lines

- Eric Blake: tests: Simplify .gitignore
- Eric Blake: nbd/server: Reject 0-length block status request
- Vladimir Sementsov-Ogievskiy: 0/6 NBD export bitmaps
- Vladimir Sementsov-Ogievskiy: nbd/server: introduce NBD_CMD_CACHE

Applied, thanks.

-- PMM

#5 lore raw
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Eric Blake

----------------------------------------------------------------
nbd patches for 2018-06-20

Add experimental x-nbd-server-add-bitmap to expose a disabled bitmap over NBD, in preparation for a pull model incremental backup scheme. Also fix a corner case protocol issue with NBD_CMD_BLOCK_STATUS, and add new NBD_CMD_CACHE.

Quoted 6 lines
Quoted 5 lines

- Eric Blake: tests: Simplify .gitignore
- Eric Blake: nbd/server: Reject 0-length block status request
- Vladimir Sementsov-Ogievskiy: 0/6 NBD export bitmaps
- Vladimir Sementsov-Ogievskiy: nbd/server: introduce NBD_CMD_CACHE

Applied, thanks.

...patchew seems to be unhappy, though, eg
https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg06559.html
has an unrelated patchset failing with:

/tmp/qemu-test/src/nbd/server.c: In function 'nbd_trip':
/tmp/qemu-test/src/nbd/server.c:1980:19: error: 'end' may be used uninitialized in this function [-Werror=maybe-uninitialized]

     *length = end - offset;
               ~~~~^~~~~~~~
/tmp/qemu-test/src/nbd/server.c:1940:30: note: 'end' was declared here
     uint64_t begin = offset, end;
                              ^~~

cc1: all warnings being treated as errors

thanks
-- PMM

author
#6 lore raw
Quoted 21 lines · Peter Maydell
Quoted 9 lines · Peter Maydell
Quoted 8 lines · Eric Blake

----------------------------------------------------------------
nbd patches for 2018-06-20

Add experimental x-nbd-server-add-bitmap to expose a disabled bitmap over NBD, in preparation for a pull model incremental backup scheme. Also fix a corner case protocol issue with NBD_CMD_BLOCK_STATUS, and add new NBD_CMD_CACHE.

Quoted 6 lines
Quoted 5 lines

- Eric Blake: tests: Simplify .gitignore
- Eric Blake: nbd/server: Reject 0-length block status request
- Vladimir Sementsov-Ogievskiy: 0/6 NBD export bitmaps
- Vladimir Sementsov-Ogievskiy: nbd/server: introduce NBD_CMD_CACHE

Applied, thanks.

...patchew seems to be unhappy, though, eg
https://lists.gnu.org/archive/html/qemu-devel/2018-06/msg06559.html
has an unrelated patchset failing with:

Quoted 5 lines

/tmp/qemu-test/src/nbd/server.c: In function 'nbd_trip':
/tmp/qemu-test/src/nbd/server.c:1980:19: error: 'end' may be used uninitialized in this function [-Werror=maybe-uninitialized]

      *length = end - offset;
                ~~~~^~~~~~~~

Uurgh. It's a false positive (the compiler is complaining that the variable is uninitialized, which can only happen if the while loop is not executed; but the preconditions guarantee the loop executes at least once). The assert() that I added was enough to silence gcc 7.3.1 on my Fedora 27 system, but docker-mingw@fedora is using gcc-8.1.1-1.fc28.x86_64. This should silence things (another way to silence would be rewriting while{} into do{}while). I'll submit this as a formal patch if I can reproduce the problem/fix on docker.

nbd/server.c +2 -1
index 94137fbfe8f..2379f82d5d4 100644
@@ -1968,7 +1968,7 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitmap *bitmap, uint64_t offset,
                                       unsigned int nb_extents,
                                       bool dont_fragment)
 {
-    uint64_t begin = offset, end;
+    uint64_t begin = offset, end = offset;
     uint64_t overall_end = offset + *length;
     unsigned int i = 0;
     BdrvDirtyBitmapIter *it;
@@ -2008,6 +2008,7 @@ static unsigned int bitmap_to_extents(BdrvDirtyBitmap *bitmap, uint64_t offset,
 
     bdrv_dirty_bitmap_unlock(bitmap);
 
+    assert(offset > end);
     *length = end - offset;
     return i;
 }
Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org
#7 lore raw
Quoted 8 lines · Eric Blake

Uurgh. It's a false positive (the compiler is complaining that the variable is uninitialized, which can only happen if the while loop is not executed; but the preconditions guarantee the loop executes at least once). The assert() that I added was enough to silence gcc 7.3.1 on my Fedora 27 system, but docker-mingw@fedora is using gcc-8.1.1-1.fc28.x86_64. This should silence things (another way to silence would be rewriting while{} into do{}while). I'll submit this as a formal patch if I can reproduce the problem/fix on docker.

Huh. I had thought this was an old-gcc problem, not a new-gcc one. Might be worth submitting to the gcc folks as a regression...

thanks
-- PMM

author
#8 lore raw
Quoted 10 lines · Peter Maydell
Quoted 8 lines · Eric Blake

Uurgh. It's a false positive (the compiler is complaining that the variable is uninitialized, which can only happen if the while loop is not executed; but the preconditions guarantee the loop executes at least once). The assert() that I added was enough to silence gcc 7.3.1 on my Fedora 27 system, but docker-mingw@fedora is using gcc-8.1.1-1.fc28.x86_64. This should silence things (another way to silence would be rewriting while{} into do{}while). I'll submit this as a formal patch if I can reproduce the problem/fix on docker.

Quoted 2 lines

Huh. I had thought this was an old-gcc problem, not a new-gcc one. Might be worth submitting to the gcc folks as a regression...

Hmm, I couldn't quickly reproduce it with a direct gcc on Fedora 28; and I don't know docker well enough to know if the cross-gcc used in docker-mingw@fedora is a different version than the native gcc-8.1.1 listed in the installed packages list (the patchew output doesn't list the version of x86_64-w64-mingw32-gcc). Thus, I can't tell if it is a recent gcc regression or merely an old-gcc issue. But I can confirm that 'make docker-test-mingw@fedora' reproduced the problem without my cleanup patch, and that my cleanup patch now in master made that happy again.

Signature · 3 lines
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org