Skip to contentSkip to conversation

NBD patches through 2019-09-05

GIT PULL Applied Eric Blake 2 participants 6 messages Sep 5, 2019 – Sep 9, 2019

lore
Share & tools
lore

Eric Blake

author
#0 lore raw

The following changes since commit eac2f39602e0423adf56be410c9a22c31fec9a81:

target/arm: Inline gen_bx_im into callers (2019-09-05 13:23:04 +0100)

are available in the Git repository at:

https://repo.or.cz/qemu/ericb.git tags/pull-nbd-2019-09-05-v2

for you to fetch changes up to b491dbb7f8e09ef864770c205a3b5bce6c5c1881:

nbd: Implement server use of NBD FAST_ZERO (2019-09-05 16:04:53 -0500)

v2 pull request: fix iotests 223 and 233 (only re-sending the patches that needed tweaking, per this backport-diff):
001/9:[0002] [FC] 'nbd: Advertise multi-conn for shared read-only connections' 002/9:[----] [--] 'nbd: Use g_autofree in a few places' 003/9:[0008] [FC] 'nbd: Tolerate more errors to structured reply request' 004/9:[----] [--] 'block: workaround for unaligned byte range in fallocate()' 005/9:[----] [--] 'docs: Update preferred NBD device syntax' 006/9:[0002] [FC] 'nbd: Improve per-export flag handling in server' 007/9:[----] [--] 'nbd: Prepare for NBD_CMD_FLAG_FAST_ZERO' 008/9:[----] [--] 'nbd: Implement client use of NBD FAST_ZERO' 009/9:[0004] [FC] 'nbd: Implement server use of NBD FAST_ZERO'

----------------------------------------------------------------
nbd patches for 2019-09-05

- Advertise NBD_FLAG_CAN_MULTI_CONN on readonly images
- Tolerate larger set of server error responses during handshake
- More precision on handling fallocate() failures due to alignment
- Better documentation of NBD connection URIs
- Implement new extension NBD_CMD_FLAG_FAST_ZERO to benefit qemu-img convert

----------------------------------------------------------------
Andrey Shinkevich (1):
block: workaround for unaligned byte range in fallocate()

Eric Blake (8):
nbd: Advertise multi-conn for shared read-only connections
nbd: Use g_autofree in a few places
nbd: Tolerate more errors to structured reply request
docs: Update preferred NBD device syntax
nbd: Improve per-export flag handling in server
nbd: Prepare for NBD_CMD_FLAG_FAST_ZERO
nbd: Implement client use of NBD FAST_ZERO
nbd: Implement server use of NBD FAST_ZERO

 docs/interop/nbd.txt       |  2 ++
 qemu-doc.texi              | 11 ++++--
 include/block/nbd.h        |  6 +++-
 block/io.c                 |  2 +-
 block/file-posix.c         |  7 ++++
 block/nbd.c                | 18 ++++++----
 blockdev-nbd.c             |  3 +-
 nbd/client.c               | 85 ++++++++++++++++++++++------------------------
 nbd/common.c               |  5 +++
 nbd/server.c               | 83 +++++++++++++++++++++++++-------------------
 qemu-nbd.c                 |  7 ++--
 nbd/trace-events           |  2 +-
 tests/qemu-iotests/223.out |  4 +--
 tests/qemu-iotests/233.out | 10 +++---
 14 files changed, 141 insertions(+), 104 deletions(-)
Signature · 1 line
2.21.0
author
#1 lore raw

[Qemu-devel] [PULL v2 1/9] nbd: Advertise multi-conn for shared read-only connections

The NBD specification defines NBD_FLAG_CAN_MULTI_CONN, which can be advertised when the server promises cache consistency between simultaneous clients (basically, rules that determine what FUA and flush from one client are able to guarantee for reads from another client). When we don't permit simultaneous clients (such as qemu-nbd without -e), the bit makes no sense; and for writable images, we probably have a lot more work before we can declare that actions from one client are cache-consistent with actions from another. But for read-only images, where flush isn't changing any data, we might as well advertise multi-conn support. What's more, advertisement of the bit makes it easier for clients to determine if 'qemu-nbd -e' was in use, where a second connection will succeed rather than hang until the first client goes away.

This patch affects qemu as server in advertising the bit. We may want to consider patches to qemu as client to attempt parallel connections for higher throughput by spreading the load over those connections when a server advertises multi-conn, but for now sticking to one connection per nbd:// BDS is okay.

See also: https://bugzilla.redhat.com/1708300

Message-Id: <[email protected]> [eblake: tweak blockdev-nbd.c to not request shared when writable, fix iotest 233]

---
 docs/interop/nbd.txt       | 1 +
 include/block/nbd.h        | 2 +-
 blockdev-nbd.c             | 2 +-
 nbd/server.c               | 4 +++-
 qemu-nbd.c                 | 2 +-
 tests/qemu-iotests/223.out | 2 +-
 6 files changed, 8 insertions(+), 5 deletions(-)
docs/interop/nbd.txt +1 -0
index fc64473e02b2..6dfec7f47647 100644
@@ -53,3 +53,4 @@ the operation of that feature.
 * 2.12: NBD_CMD_BLOCK_STATUS for "base:allocation"
 * 3.0: NBD_OPT_STARTTLS with TLS Pre-Shared Keys (PSK),
 NBD_CMD_BLOCK_STATUS for "qemu:dirty-bitmap:", NBD_CMD_CACHE
+* 4.2: NBD_FLAG_CAN_MULTI_CONN for sharable read-only exports
include/block/nbd.h +1 -1
index 7b36d672f046..991fd52a5134 100644
@@ -326,7 +326,7 @@ typedef struct NBDClient NBDClient;
 
 NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
                           uint64_t size, const char *name, const char *desc,
-                          const char *bitmap, uint16_t nbdflags,
+                          const char *bitmap, uint16_t nbdflags, bool shared,
                           void (*close)(NBDExport *), bool writethrough,
                           BlockBackend *on_eject_blk, Error **errp);
 void nbd_export_close(NBDExport *exp);
blockdev-nbd.c +1 -1
index c621686131fd..1fcfdb0997c6 100644
@@ -188,7 +188,7 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
     }
 
     exp = nbd_export_new(bs, 0, len, name, NULL, bitmap,
-                         writable ? 0 : NBD_FLAG_READ_ONLY,
+                         writable ? 0 : NBD_FLAG_READ_ONLY, !writable,
                          NULL, false, on_eject_blk, errp);
     if (!exp) {
         return;
nbd/server.c +3 -1
index f55ccf8edfde..0fb41c6c50ea 100644
@@ -1461,7 +1461,7 @@ static void nbd_eject_notifier(Notifier *n, void *data)
 
 NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
                           uint64_t size, const char *name, const char *desc,
-                          const char *bitmap, uint16_t nbdflags,
+                          const char *bitmap, uint16_t nbdflags, bool shared,
                           void (*close)(NBDExport *), bool writethrough,
                           BlockBackend *on_eject_blk, Error **errp)
 {
@@ -1487,6 +1487,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
     perm = BLK_PERM_CONSISTENT_READ;
     if ((nbdflags & NBD_FLAG_READ_ONLY) == 0) {
         perm |= BLK_PERM_WRITE;
+    } else if (shared) {
+        nbdflags |= NBD_FLAG_CAN_MULTI_CONN;
     }
     blk = blk_new(bdrv_get_aio_context(bs), perm,
                   BLK_PERM_CONSISTENT_READ | BLK_PERM_WRITE_UNCHANGED |
qemu-nbd.c +1 -1
index 83b6c32d73aa..2403ef3d0f9f 100644
@@ -1173,7 +1173,7 @@ int main(int argc, char **argv)
     }
 
     export = nbd_export_new(bs, dev_offset, fd_size, export_name,
-                            export_description, bitmap, nbdflags,
+                            export_description, bitmap, nbdflags, shared > 1,
                             nbd_export_closed, writethrough, NULL,
                             &error_fatal);
 
tests/qemu-iotests/223.out +1 -1
index d5201b2356a3..2bca28ae72f9 100644
@@ -40,7 +40,7 @@ exports available: 0
 exports available: 2
  export: 'n'
   size:  4194304
-  flags: 0x4ef ( readonly flush fua trim zeroes df cache )
+  flags: 0x5ef ( readonly flush fua trim zeroes df multi cache )
   min block: 1
   opt block: 4096
   max block: 33554432
Signature · 1 line
2.21.0
author
#2 lore raw

[Qemu-devel] [PULL v2 3/9] nbd: Tolerate more errors to structured reply request

In reply to Eric Blake

A server may have a reason to reject a request for structured replies, beyond just not recognizing them as a valid request; similarly, it may have a reason for rejecting a request for a meta context. It doesn't hurt us to continue talking to such a server; otherwise 'qemu-nbd --list' of such a server fails to display all available details about the export.

Encountered when temporarily tweaking nbdkit to reply with NBD_REP_ERR_POLICY. Present since structured reply support was first added (commit d795299b reused starttls handling, but starttls is different in that we can't fall back to other behavior on any error).

Note that for an unencrypted client trying to connect to a server that requires encryption, this defers the point of failure to when we finally execute a strict command (such as NBD_OPT_GO or NBD_OPT_LIST), now that the intermediate NBD_OPT_STRUCTURED_REPLY does not diagnose NBD_REP_ERR_TLS_REQD as fatal; but as the protocol eventually gets us to a command where we can't continue onwards, the changed error message doesn't cause any security concerns.

Message-Id: <[email protected]>

[eblake: fix iotest 233]
---
 nbd/client.c               | 63 ++++++++++++++++++++------------------
 nbd/trace-events           |  2 +-
 tests/qemu-iotests/233.out |  8 ++---
 3 files changed, 38 insertions(+), 35 deletions(-)
nbd/client.c +33 -30
index a9d8d32feff7..b9dc829175f9 100644
@@ -1,5 +1,5 @@
 /*
- *  Copyright (C) 2016-2018 Red Hat, Inc.
+ *  Copyright (C) 2016-2019 Red Hat, Inc.
  *  Copyright (C) 2005  Anthony Liguori <[email protected]>
  *
  *  Network Block Device Client Side
@@ -142,17 +142,18 @@ static int nbd_receive_option_reply(QIOChannel *ioc, uint32_t opt,
     return 0;
 }
 
-/* If reply represents success, return 1 without further action.
- * If reply represents an error, consume the optional payload of
- * the packet on ioc.  Then return 0 for unsupported (so the client
- * can fall back to other approaches), or -1 with errp set for other
- * errors.
+/*
+ * If reply represents success, return 1 without further action.  If
+ * reply represents an error, consume the optional payload of the
+ * packet on ioc.  Then return 0 for unsupported (so the client can
+ * fall back to other approaches), where @strict determines if only
+ * ERR_UNSUP or all errors fit that category, or -1 with errp set for
+ * other errors.
  */
 static int nbd_handle_reply_err(QIOChannel *ioc, NBDOptionReply *reply,
-                                Error **errp)
+                                bool strict, Error **errp)
 {
-    char *msg = NULL;
-    int result = -1;
+    g_autofree char *msg = NULL;
 
     if (!(reply->type & (1 << 31))) {
         return 1;
@@ -163,26 +164,28 @@ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOptionReply *reply,
             error_setg(errp, "server error %" PRIu32
                        " (%s) message is too long",
                        reply->type, nbd_rep_lookup(reply->type));
-            goto cleanup;
+            goto err;
         }
         msg = g_malloc(reply->length + 1);
         if (nbd_read(ioc, msg, reply->length, NULL, errp) < 0) {
             error_prepend(errp, "Failed to read option error %" PRIu32
                           " (%s) message: ",
                           reply->type, nbd_rep_lookup(reply->type));
-            goto cleanup;
+            goto err;
         }
         msg[reply->length] = '\0';
         trace_nbd_server_error_msg(reply->type,
                                    nbd_reply_type_lookup(reply->type), msg);
     }
 
+    if (reply->type == NBD_REP_ERR_UNSUP || !strict) {
+        trace_nbd_reply_err_ignored(reply->option,
+                                    nbd_opt_lookup(reply->option),
+                                    reply->type, nbd_rep_lookup(reply->type));
+        return 0;
+    }
+
     switch (reply->type) {
-    case NBD_REP_ERR_UNSUP:
-        trace_nbd_reply_err_unsup(reply->option, nbd_opt_lookup(reply->option));
-        result = 0;
-        goto cleanup;
-
     case NBD_REP_ERR_POLICY:
         error_setg(errp, "Denied by server for option %" PRIu32 " (%s)",
                    reply->option, nbd_opt_lookup(reply->option));
@@ -227,12 +230,9 @@ static int nbd_handle_reply_err(QIOChannel *ioc, NBDOptionReply *reply,
         error_append_hint(errp, "server reported: %s\n", msg);
     }
 
- cleanup:
-    g_free(msg);
-    if (result < 0) {
-        nbd_send_opt_abort(ioc);
-    }
-    return result;
+ err:
+    nbd_send_opt_abort(ioc);
+    return -1;
 }
 
 /* nbd_receive_list:
@@ -257,7 +257,7 @@ static int nbd_receive_list(QIOChannel *ioc, char **name, char **description,
     if (nbd_receive_option_reply(ioc, NBD_OPT_LIST, &reply, errp) < 0) {
         return -1;
     }
-    error = nbd_handle_reply_err(ioc, &reply, errp);
+    error = nbd_handle_reply_err(ioc, &reply, true, errp);
     if (error <= 0) {
         return error;
     }
@@ -363,7 +363,7 @@ static int nbd_opt_info_or_go(QIOChannel *ioc, uint32_t opt,
         if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {
             return -1;
         }
-        error = nbd_handle_reply_err(ioc, &reply, errp);
+        error = nbd_handle_reply_err(ioc, &reply, true, errp);
         if (error <= 0) {
             return error;
         }
@@ -538,12 +538,15 @@ static int nbd_receive_query_exports(QIOChannel *ioc,
     }
 }
 
-/* nbd_request_simple_option: Send an option request, and parse the reply
+/*
+ * nbd_request_simple_option: Send an option request, and parse the reply.
+ * @strict controls whether ERR_UNSUP or all errors produce 0 status.
  * return 1 for successful negotiation,
  *        0 if operation is unsupported,
  *        -1 with errp set for any other error
  */
-static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)
+static int nbd_request_simple_option(QIOChannel *ioc, int opt, bool strict,
+                                     Error **errp)
 {
     NBDOptionReply reply;
     int error;
@@ -555,7 +558,7 @@ static int nbd_request_simple_option(QIOChannel *ioc, int opt, Error **errp)
     if (nbd_receive_option_reply(ioc, opt, &reply, errp) < 0) {
         return -1;
     }
-    error = nbd_handle_reply_err(ioc, &reply, errp);
+    error = nbd_handle_reply_err(ioc, &reply, strict, errp);
     if (error <= 0) {
         return error;
     }
@@ -587,7 +590,7 @@ static QIOChannel *nbd_receive_starttls(QIOChannel *ioc,
     QIOChannelTLS *tioc;
     struct NBDTLSHandshakeData data = { 0 };
 
-    ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, errp);
+    ret = nbd_request_simple_option(ioc, NBD_OPT_STARTTLS, true, errp);
     if (ret <= 0) {
         if (ret == 0) {
             error_setg(errp, "Server don't support STARTTLS option");
@@ -687,7 +690,7 @@ static int nbd_receive_one_meta_context(QIOChannel *ioc,
         return -1;
     }
 
-    ret = nbd_handle_reply_err(ioc, &reply, errp);
+    ret = nbd_handle_reply_err(ioc, &reply, false, errp);
     if (ret <= 0) {
         return ret;
     }
@@ -943,7 +946,7 @@ static int nbd_start_negotiate(AioContext *aio_context, QIOChannel *ioc,
             if (structured_reply) {
                 result = nbd_request_simple_option(ioc,
                                                    NBD_OPT_STRUCTURED_REPLY,
-                                                   errp);
+                                                   false, errp);
                 if (result < 0) {
                     return -EINVAL;
                 }
nbd/trace-events +1 -1
index 7ab6b3788cb2..f6cde967903a 100644
@@ -4,7 +4,7 @@
 nbd_send_option_request(uint32_t opt, const char *name, uint32_t len) "Sending option request %" PRIu32" (%s), len %" PRIu32
 nbd_receive_option_reply(uint32_t option, const char *optname, uint32_t type, const char *typename, uint32_t length) "Received option reply %" PRIu32" (%s), type %" PRIu32" (%s), len %" PRIu32
 nbd_server_error_msg(uint32_t err, const char *type, const char *msg) "server reported error 0x%" PRIx32 " (%s) with additional message: %s"
-nbd_reply_err_unsup(uint32_t option, const char *name) "server doesn't understand request %" PRIu32 " (%s), attempting fallback"
+nbd_reply_err_ignored(uint32_t option, const char *name, uint32_t reply, const char *reply_name) "server failed request %" PRIu32 " (%s) with error 0x%" PRIx32 " (%s), attempting fallback"
 nbd_receive_list(const char *name, const char *desc) "export list includes '%s', description '%s'"
 nbd_opt_info_go_start(const char *opt, const char *name) "Attempting %s for export '%s'"
 nbd_opt_info_go_success(const char *opt) "Export is ready after %s request"
tests/qemu-iotests/233.out +4 -4
index 9b46284ab0de..a3ecc4eb5ccf 100644
@@ -20,10 +20,10 @@ qemu-nbd: Denied by server for option 5 (starttls)
 server reported: TLS not configured
 
 == check plain client to TLS server fails ==
-qemu-img: Could not open 'nbd://localhost:PORT': TLS negotiation required before option 8 (structured reply)
-server reported: Option 0x8 not permitted before TLS
-qemu-nbd: TLS negotiation required before option 8 (structured reply)
-server reported: Option 0x8 not permitted before TLS
+qemu-img: Could not open 'nbd://localhost:PORT': TLS negotiation required before option 7 (go)
+server reported: Option 0x7 not permitted before TLS
+qemu-nbd: TLS negotiation required before option 3 (list)
+server reported: Option 0x3 not permitted before TLS
 
 == check TLS works ==
 image: nbd://127.0.0.1:PORT
Signature · 1 line
2.21.0
author
#3 lore raw

[Qemu-devel] [PULL v2 6/9] nbd: Improve per-export flag handling in server

In reply to Eric Blake

When creating a read-only image, we are still advertising support for TRIM and WRITE_ZEROES to the client, even though the client should not be issuing those commands. But seeing this requires looking across multiple functions:

All callers to nbd_export_new() passed a single flag based solely on whether the export allows writes. Later, we then pass a constant set of flags to nbd_negotiate_options() (namely, the set of flags which we always support, at least for writable images), which is then further dynamically modified with NBD_FLAG_SEND_DF based on client requests for structured options. Finally, when processing NBD_OPT_EXPORT_NAME or NBD_OPT_EXPORT_GO we bitwise-or the original caller's flag with the runtime set of flags we've built up over several functions.

Let's refactor things to instead compute a baseline of flags as soon as possible which gets shared between multiple clients, in nbd_export_new(), and changing the signature for the callers to pass in a simpler bool rather than having to figure out flags. We can then get rid of the 'myflags' parameter to various functions, and instead refer to client for everything we need (we still have to perform a bitwise-OR for NBD_FLAG_SEND_DF during NBD_OPT_EXPORT_NAME and NBD_OPT_EXPORT_GO, but it's easier to see what is being computed). This lets us quit advertising senseless flags for read-only images, as well as making the next patch for exposing FAST_ZERO support easier to write.

Message-Id: <[email protected]>

[eblake: improve commit message, update iotest 223]
---
 include/block/nbd.h        |  2 +-
 blockdev-nbd.c             |  3 +-
 nbd/server.c               | 62 +++++++++++++++++++++-----------------
 qemu-nbd.c                 |  6 ++--
 tests/qemu-iotests/223.out |  2 +-
 5 files changed, 40 insertions(+), 35 deletions(-)
include/block/nbd.h +1 -1
index 991fd52a5134..2c87b42dfd48 100644
@@ -326,7 +326,7 @@ typedef struct NBDClient NBDClient;
 
 NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
                           uint64_t size, const char *name, const char *desc,
-                          const char *bitmap, uint16_t nbdflags, bool shared,
+                          const char *bitmap, bool readonly, bool shared,
                           void (*close)(NBDExport *), bool writethrough,
                           BlockBackend *on_eject_blk, Error **errp);
 void nbd_export_close(NBDExport *exp);
blockdev-nbd.c +1 -2
index 1fcfdb0997c6..213f226ac1c4 100644
@@ -187,8 +187,7 @@ void qmp_nbd_server_add(const char *device, bool has_name, const char *name,
         writable = false;
     }
 
-    exp = nbd_export_new(bs, 0, len, name, NULL, bitmap,
-                         writable ? 0 : NBD_FLAG_READ_ONLY, !writable,
+    exp = nbd_export_new(bs, 0, len, name, NULL, bitmap, !writable, !writable,
                          NULL, false, on_eject_blk, errp);
     if (!exp) {
         return;
nbd/server.c +34 -28

165 lines not on this page · raw message

qemu-nbd.c +3 -3
index 2403ef3d0f9f..ae841150760e 100644
@@ -600,7 +600,7 @@ int main(int argc, char **argv)
     BlockBackend *blk;
     BlockDriverState *bs;
     uint64_t dev_offset = 0;
-    uint16_t nbdflags = 0;
+    bool readonly = false;
     bool disconnect = false;
     const char *bindto = NULL;
     const char *port = NULL;
@@ -782,7 +782,7 @@ int main(int argc, char **argv)
             }
             /* fall through */
         case 'r':
-            nbdflags |= NBD_FLAG_READ_ONLY;
+            readonly = true;
             flags &= ~BDRV_O_RDWR;
             break;
         case 'P':
@@ -1173,7 +1173,7 @@ int main(int argc, char **argv)
     }
 
     export = nbd_export_new(bs, dev_offset, fd_size, export_name,
-                            export_description, bitmap, nbdflags, shared > 1,
+                            export_description, bitmap, readonly, shared > 1,
                             nbd_export_closed, writethrough, NULL,
                             &error_fatal);
 
tests/qemu-iotests/223.out +1 -1
index 2bca28ae72f9..2db0dc991a27 100644
@@ -40,7 +40,7 @@ exports available: 0
 exports available: 2
  export: 'n'
   size:  4194304
-  flags: 0x5ef ( readonly flush fua trim zeroes df multi cache )
+  flags: 0x58f ( readonly flush fua df multi cache )
   min block: 1
   opt block: 4096
   max block: 33554432
Signature · 1 line
2.21.0
author
#4 lore raw

[Qemu-devel] [PULL v2 9/9] nbd: Implement server use of NBD FAST_ZERO

In reply to Eric Blake

The server side is fairly straightforward: we can always advertise support for detection of fast zero, and implement it by mapping the request to the block layer BDRV_REQ_NO_FALLBACK.

Message-Id: <[email protected]>

[eblake: update iotests 223, 233]
---
 nbd/server.c               | 8 ++++++--
 tests/qemu-iotests/223.out | 2 +-
 tests/qemu-iotests/233.out | 2 +-
 3 files changed, 8 insertions(+), 4 deletions(-)
nbd/server.c +6 -2
index 4992148de1c4..28c3c8be854c 100644
@@ -1513,7 +1513,8 @@ NBDExport *nbd_export_new(BlockDriverState *bs, uint64_t dev_offset,
             exp->nbdflags |= NBD_FLAG_CAN_MULTI_CONN;
         }
     } else {
-        exp->nbdflags |= NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_WRITE_ZEROES;
+        exp->nbdflags |= (NBD_FLAG_SEND_TRIM | NBD_FLAG_SEND_WRITE_ZEROES |
+                          NBD_FLAG_SEND_FAST_ZERO);
     }
     assert(size <= INT64_MAX - dev_offset);
     exp->size = QEMU_ALIGN_DOWN(size, BDRV_SECTOR_SIZE);
@@ -2166,7 +2167,7 @@ static int nbd_co_receive_request(NBDRequestData *req, NBDRequest *request,
     if (request->type == NBD_CMD_READ && client->structured_reply) {
         valid_flags |= NBD_CMD_FLAG_DF;
     } else if (request->type == NBD_CMD_WRITE_ZEROES) {
-        valid_flags |= NBD_CMD_FLAG_NO_HOLE;
+        valid_flags |= NBD_CMD_FLAG_NO_HOLE | NBD_CMD_FLAG_FAST_ZERO;
     } else if (request->type == NBD_CMD_BLOCK_STATUS) {
         valid_flags |= NBD_CMD_FLAG_REQ_ONE;
     }
@@ -2305,6 +2306,9 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
         if (!(request->flags & NBD_CMD_FLAG_NO_HOLE)) {
             flags |= BDRV_REQ_MAY_UNMAP;
         }
+        if (request->flags & NBD_CMD_FLAG_FAST_ZERO) {
+            flags |= BDRV_REQ_NO_FALLBACK;
+        }
         ret = blk_pwrite_zeroes(exp->blk, request->from + exp->dev_offset,
                                 request->len, flags);
         return nbd_send_generic_reply(client, request->handle, ret,
tests/qemu-iotests/223.out +1 -1
index 2db0dc991a27..5d00398c11cb 100644
@@ -49,7 +49,7 @@ exports available: 2
    qemu:dirty-bitmap:b
  export: 'n2'
   size:  4194304
-  flags: 0x4ed ( flush fua trim zeroes df cache )
+  flags: 0xced ( flush fua trim zeroes df cache fast-zero )
   min block: 1
   opt block: 4096
   max block: 33554432
tests/qemu-iotests/233.out +1 -1
index a3ecc4eb5ccf..24321efa113b 100644
@@ -37,7 +37,7 @@ disk size: unavailable
 exports available: 1
  export: ''
   size:  67108864
-  flags: 0x4ed ( flush fua trim zeroes df cache )
+  flags: 0xced ( flush fua trim zeroes df cache fast-zero )
   min block: 1
   opt block: 4096
   max block: 33554432
Signature · 1 line
2.21.0
#5 lore raw
In reply to Eric Blake
Quoted 38 lines · Eric Blake

The following changes since commit eac2f39602e0423adf56be410c9a22c31fec9a81:

target/arm: Inline gen_bx_im into callers (2019-09-05 13:23:04 +0100)

are available in the Git repository at:

https://repo.or.cz/qemu/ericb.git tags/pull-nbd-2019-09-05-v2

for you to fetch changes up to b491dbb7f8e09ef864770c205a3b5bce6c5c1881:

nbd: Implement server use of NBD FAST_ZERO (2019-09-05 16:04:53 -0500)

v2 pull request: fix iotests 223 and 233 (only re-sending the patches that needed tweaking, per this backport-diff):
001/9:[0002] [FC] 'nbd: Advertise multi-conn for shared read-only connections' 002/9:[----] [--] 'nbd: Use g_autofree in a few places' 003/9:[0008] [FC] 'nbd: Tolerate more errors to structured reply request' 004/9:[----] [--] 'block: workaround for unaligned byte range in fallocate()' 005/9:[----] [--] 'docs: Update preferred NBD device syntax' 006/9:[0002] [FC] 'nbd: Improve per-export flag handling in server' 007/9:[----] [--] 'nbd: Prepare for NBD_CMD_FLAG_FAST_ZERO' 008/9:[----] [--] 'nbd: Implement client use of NBD FAST_ZERO' 009/9:[0004] [FC] 'nbd: Implement server use of NBD FAST_ZERO'

----------------------------------------------------------------
nbd patches for 2019-09-05

- Advertise NBD_FLAG_CAN_MULTI_CONN on readonly images
- Tolerate larger set of server error responses during handshake
- More precision on handling fallocate() failures due to alignment
- Better documentation of NBD connection URIs
- Implement new extension NBD_CMD_FLAG_FAST_ZERO to benefit qemu-img convert

----------------------------------------------------------------
Andrey Shinkevich (1):
block: workaround for unaligned byte range in fallocate()

Quoted 10 lines

Eric Blake (8):
nbd: Advertise multi-conn for shared read-only connections
nbd: Use g_autofree in a few places
nbd: Tolerate more errors to structured reply request
docs: Update preferred NBD device syntax
nbd: Improve per-export flag handling in server
nbd: Prepare for NBD_CMD_FLAG_FAST_ZERO
nbd: Implement client use of NBD FAST_ZERO
nbd: Implement server use of NBD FAST_ZERO

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.2
for any user-visible changes.

-- PMM