Commit 409ef9eb authored by Peter Maydell's avatar Peter Maydell
Browse files

Merge remote-tracking branch 'remotes/ericb/tags/pull-nbd-2018-06-20-v2' into staging



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

# gpg: Signature made Thu 21 Jun 2018 15:53:55 BST
# gpg:                using RSA key A7A16B4A2527436A
# gpg: Good signature from "Eric Blake <eblake@redhat.com>"
# gpg:                 aka "Eric Blake (Free Software Programmer) <ebb9@byu.net>"
# gpg:                 aka "[jpeg image of size 6874]"
# Primary key fingerprint: 71C2 CC22 B1C4 6029 27D2  F3AA A7A1 6B4A 2527 436A

* remotes/ericb/tags/pull-nbd-2018-06-20-v2:
  nbd/server: introduce NBD_CMD_CACHE
  docs/interop: add nbd.txt
  qapi: new qmp command nbd-server-add-bitmap
  nbd/server: implement dirty bitmap export
  nbd/server: add nbd_meta_empty_or_pattern helper
  nbd/server: refactor NBDExportMetaContexts
  nbd/server: fix trace
  nbd/server: Reject 0-length block status request
  tests: Simplify .gitignore

Signed-off-by: default avatarPeter Maydell <peter.maydell@linaro.org>
parents 33836a73 bc37b06a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -1972,6 +1972,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
+23 −0
Original line number Diff line number Diff line
@@ -220,3 +220,26 @@ void qmp_nbd_server_stop(Error **errp)
    nbd_server_free(nbd_server);
    nbd_server = NULL;
}

void qmp_x_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);
}

docs/interop/nbd.txt

0 → 100644
+38 −0
Original line number Diff line number Diff line
Qemu supports the NBD protocol, and has an internal NBD client (see
block/nbd.c), an internal NBD server (see blockdev-nbd.c), and an
external NBD server tool (see qemu-nbd.c). The common code is placed
in nbd/*.

The NBD protocol is specified here:
https://github.com/NetworkBlockDevice/nbd/blob/master/doc/proto.md

The following paragraphs describe some specific properties of NBD
protocol realization in Qemu.

= Metadata namespaces =

Qemu supports the "base:allocation" metadata context as defined in the
NBD protocol specification, and also defines an additional metadata
namespace "qemu".


== "qemu" namespace ==

The "qemu" namespace currently contains only one type of context,
related to exposing the contents of a dirty bitmap alongside the
associated disk contents.  That context has the following form:

    qemu:dirty-bitmap:<dirty-bitmap-export-name>

Each dirty-bitmap metadata context defines 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
in addition 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.
+8 −3
Original line number Diff line number Diff line
@@ -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,
};
@@ -229,11 +230,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 +318,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.
+2 −0
Original line number Diff line number Diff line
@@ -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:
Loading