Blame SOURCES/kvm-nbd-server-implement-dirty-bitmap-export.patch

1bdc94
From 59e211a4d669b8950a66bba63e7ae4e58cee648f Mon Sep 17 00:00:00 2001
1bdc94
From: John Snow <jsnow@redhat.com>
1bdc94
Date: Wed, 18 Jul 2018 22:55:03 +0200
1bdc94
Subject: [PATCH 78/89] nbd/server: implement dirty bitmap export
1bdc94
1bdc94
RH-Author: John Snow <jsnow@redhat.com>
1bdc94
Message-id: <20180718225511.14878-28-jsnow@redhat.com>
1bdc94
Patchwork-id: 81412
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 27/35] nbd/server: implement dirty bitmap export
1bdc94
Bugzilla: 1207657
1bdc94
RH-Acked-by: Eric Blake <eblake@redhat.com>
1bdc94
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
1bdc94
RH-Acked-by: Fam Zheng <famz@redhat.com>
1bdc94
1bdc94
From: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1bdc94
1bdc94
Handle a new NBD meta namespace: "qemu", and corresponding queries:
1bdc94
"qemu:dirty-bitmap:<export bitmap name>".
1bdc94
1bdc94
With the new metadata context negotiated, BLOCK_STATUS query will reply
1bdc94
with dirty-bitmap data, converted to extents. The new public function
1bdc94
nbd_export_bitmap selects which bitmap to export. For now, only one bitmap
1bdc94
may be exported.
1bdc94
1bdc94
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
1bdc94
Message-Id: <20180609151758.17343-5-vsementsov@virtuozzo.com>
1bdc94
Reviewed-by: Eric Blake <eblake@redhat.com>
1bdc94
[eblake: wording tweaks, minor cleanups, additional tracing]
1bdc94
Signed-off-by: Eric Blake <eblake@redhat.com>
1bdc94
(cherry picked from commit 3d068aff16d6dbf066328977c5152847a62f2a0a)
1bdc94
Signed-off-by: John Snow <jsnow@redhat.com>
1bdc94
1bdc94
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
1bdc94
---
1bdc94
 include/block/nbd.h |   8 +-
1bdc94
 nbd/server.c        | 278 +++++++++++++++++++++++++++++++++++++++++++++++-----
1bdc94
 nbd/trace-events    |   1 +
1bdc94
 3 files changed, 262 insertions(+), 25 deletions(-)
1bdc94
1bdc94
diff --git a/include/block/nbd.h b/include/block/nbd.h
1bdc94
index fcdcd54..8bb9606 100644
1bdc94
--- a/include/block/nbd.h
1bdc94
+++ b/include/block/nbd.h
1bdc94
@@ -229,11 +229,13 @@ enum {
1bdc94
 #define NBD_REPLY_TYPE_ERROR         NBD_REPLY_ERR(1)
1bdc94
 #define NBD_REPLY_TYPE_ERROR_OFFSET  NBD_REPLY_ERR(2)
1bdc94
 
1bdc94
-/* Flags for extents (NBDExtent.flags) of NBD_REPLY_TYPE_BLOCK_STATUS,
1bdc94
- * for base:allocation meta context */
1bdc94
+/* Extent flags for base:allocation in NBD_REPLY_TYPE_BLOCK_STATUS */
1bdc94
 #define NBD_STATE_HOLE (1 << 0)
1bdc94
 #define NBD_STATE_ZERO (1 << 1)
1bdc94
 
1bdc94
+/* Extent flags for qemu:dirty-bitmap in NBD_REPLY_TYPE_BLOCK_STATUS */
1bdc94
+#define NBD_STATE_DIRTY (1 << 0)
1bdc94
+
1bdc94
 static inline bool nbd_reply_type_is_error(int type)
1bdc94
 {
1bdc94
     return type & (1 << 15);
1bdc94
@@ -315,6 +317,8 @@ void nbd_client_put(NBDClient *client);
1bdc94
 void nbd_server_start(SocketAddress *addr, const char *tls_creds,
1bdc94
                       Error **errp);
1bdc94
 
1bdc94
+void nbd_export_bitmap(NBDExport *exp, const char *bitmap,
1bdc94
+                       const char *bitmap_export_name, Error **errp);
1bdc94
 
1bdc94
 /* nbd_read
1bdc94
  * Reads @size bytes from @ioc. Returns 0 on success.
1bdc94
diff --git a/nbd/server.c b/nbd/server.c
1bdc94
index 9171cd4..2c2d62c 100644
1bdc94
--- a/nbd/server.c
1bdc94
+++ b/nbd/server.c
1bdc94
@@ -23,6 +23,13 @@
1bdc94
 #include "nbd-internal.h"
1bdc94
 
1bdc94
 #define NBD_META_ID_BASE_ALLOCATION 0
1bdc94
+#define NBD_META_ID_DIRTY_BITMAP 1
1bdc94
+
1bdc94
+/* NBD_MAX_BITMAP_EXTENTS: 1 mb of extents data. An empirical
1bdc94
+ * constant. If an increase is needed, note that the NBD protocol
1bdc94
+ * recommends no larger than 32 mb, so that the client won't consider
1bdc94
+ * the reply as a denial of service attack. */
1bdc94
+#define NBD_MAX_BITMAP_EXTENTS (0x100000 / 8)
1bdc94
 
1bdc94
 static int system_errno_to_nbd_errno(int err)
1bdc94
 {
1bdc94
@@ -80,6 +87,9 @@ struct NBDExport {
1bdc94
 
1bdc94
     BlockBackend *eject_notifier_blk;
1bdc94
     Notifier eject_notifier;
1bdc94
+
1bdc94
+    BdrvDirtyBitmap *export_bitmap;
1bdc94
+    char *export_bitmap_context;
1bdc94
 };
1bdc94
 
1bdc94
 static QTAILQ_HEAD(, NBDExport) exports = QTAILQ_HEAD_INITIALIZER(exports);
1bdc94
@@ -92,6 +102,7 @@ typedef struct NBDExportMetaContexts {
1bdc94
     bool valid; /* means that negotiation of the option finished without
1bdc94
                    errors */
1bdc94
     bool base_allocation; /* export base:allocation context (block status) */
1bdc94
+    bool bitmap; /* export qemu:dirty-bitmap:<export bitmap name> */
1bdc94
 } NBDExportMetaContexts;
1bdc94
 
1bdc94
 struct NBDClient {
1bdc94
@@ -814,6 +825,56 @@ static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta,
1bdc94
                                      &meta->base_allocation, errp);
1bdc94
 }
1bdc94
 
1bdc94
+/* nbd_meta_bitmap_query
1bdc94
+ *
1bdc94
+ * Handle query to 'qemu:' namespace.
1bdc94
+ * @len is the amount of text remaining to be read from the current name, after
1bdc94
+ * the 'qemu:' portion has been stripped.
1bdc94
+ *
1bdc94
+ * Return -errno on I/O error, 0 if option was completely handled by
1bdc94
+ * sending a reply about inconsistent lengths, or 1 on success. */
1bdc94
+static int nbd_meta_qemu_query(NBDClient *client, NBDExportMetaContexts *meta,
1bdc94
+                               uint32_t len, Error **errp)
1bdc94
+{
1bdc94
+    bool dirty_bitmap = false;
1bdc94
+    size_t dirty_bitmap_len = strlen("dirty-bitmap:");
1bdc94
+    int ret;
1bdc94
+
1bdc94
+    if (!meta->exp->export_bitmap) {
1bdc94
+        trace_nbd_negotiate_meta_query_skip("no dirty-bitmap exported");
1bdc94
+        return nbd_opt_skip(client, len, errp);
1bdc94
+    }
1bdc94
+
1bdc94
+    if (len == 0) {
1bdc94
+        if (client->opt == NBD_OPT_LIST_META_CONTEXT) {
1bdc94
+            meta->bitmap = true;
1bdc94
+        }
1bdc94
+        trace_nbd_negotiate_meta_query_parse("empty");
1bdc94
+        return 1;
1bdc94
+    }
1bdc94
+
1bdc94
+    if (len < dirty_bitmap_len) {
1bdc94
+        trace_nbd_negotiate_meta_query_skip("not dirty-bitmap:");
1bdc94
+        return nbd_opt_skip(client, len, errp);
1bdc94
+    }
1bdc94
+
1bdc94
+    len -= dirty_bitmap_len;
1bdc94
+    ret = nbd_meta_pattern(client, "dirty-bitmap:", &dirty_bitmap, errp);
1bdc94
+    if (ret <= 0) {
1bdc94
+        return ret;
1bdc94
+    }
1bdc94
+    if (!dirty_bitmap) {
1bdc94
+        trace_nbd_negotiate_meta_query_skip("not dirty-bitmap:");
1bdc94
+        return nbd_opt_skip(client, len, errp);
1bdc94
+    }
1bdc94
+
1bdc94
+    trace_nbd_negotiate_meta_query_parse("dirty-bitmap:");
1bdc94
+
1bdc94
+    return nbd_meta_empty_or_pattern(
1bdc94
+            client, meta->exp->export_bitmap_context +
1bdc94
+            strlen("qemu:dirty_bitmap:"), len, &meta->bitmap, errp);
1bdc94
+}
1bdc94
+
1bdc94
 /* nbd_negotiate_meta_query
1bdc94
  *
1bdc94
  * Parse namespace name and call corresponding function to parse body of the
1bdc94
@@ -829,9 +890,14 @@ static int nbd_meta_base_query(NBDClient *client, NBDExportMetaContexts *meta,
1bdc94
 static int nbd_negotiate_meta_query(NBDClient *client,
1bdc94
                                     NBDExportMetaContexts *meta, Error **errp)
1bdc94
 {
1bdc94
+    /*
1bdc94
+     * Both 'qemu' and 'base' namespaces have length = 5 including a
1bdc94
+     * colon. If another length namespace is later introduced, this
1bdc94
+     * should certainly be refactored.
1bdc94
+     */
1bdc94
     int ret;
1bdc94
-    char query[sizeof("base:") - 1];
1bdc94
-    size_t baselen = strlen("base:");
1bdc94
+    size_t ns_len = 5;
1bdc94
+    char ns[5];
1bdc94
     uint32_t len;
1bdc94
 
1bdc94
     ret = nbd_opt_read(client, &len, sizeof(len), errp);
1bdc94
@@ -840,25 +906,27 @@ static int nbd_negotiate_meta_query(NBDClient *client,
1bdc94
     }
1bdc94
     cpu_to_be32s(&len;;
1bdc94
 
1bdc94
-    /* The only supported namespace for now is 'base'. So query should start
1bdc94
-     * with 'base:'. Otherwise, we can ignore it and skip the remainder. */
1bdc94
-    if (len < baselen) {
1bdc94
+    if (len < ns_len) {
1bdc94
         trace_nbd_negotiate_meta_query_skip("length too short");
1bdc94
         return nbd_opt_skip(client, len, errp);
1bdc94
     }
1bdc94
 
1bdc94
-    len -= baselen;
1bdc94
-    ret = nbd_opt_read(client, query, baselen, errp);
1bdc94
+    len -= ns_len;
1bdc94
+    ret = nbd_opt_read(client, ns, ns_len, errp);
1bdc94
     if (ret <= 0) {
1bdc94
         return ret;
1bdc94
     }
1bdc94
-    if (strncmp(query, "base:", baselen) != 0) {
1bdc94
-        trace_nbd_negotiate_meta_query_skip("not for base: namespace");
1bdc94
-        return nbd_opt_skip(client, len, errp);
1bdc94
+
1bdc94
+    if (!strncmp(ns, "base:", ns_len)) {
1bdc94
+        trace_nbd_negotiate_meta_query_parse("base:");
1bdc94
+        return nbd_meta_base_query(client, meta, len, errp);
1bdc94
+    } else if (!strncmp(ns, "qemu:", ns_len)) {
1bdc94
+        trace_nbd_negotiate_meta_query_parse("qemu:");
1bdc94
+        return nbd_meta_qemu_query(client, meta, len, errp);
1bdc94
     }
1bdc94
 
1bdc94
-    trace_nbd_negotiate_meta_query_parse("base:");
1bdc94
-    return nbd_meta_base_query(client, meta, len, errp);
1bdc94
+    trace_nbd_negotiate_meta_query_skip("unknown namespace");
1bdc94
+    return nbd_opt_skip(client, len, errp);
1bdc94
 }
1bdc94
 
1bdc94
 /* nbd_negotiate_meta_queries
1bdc94
@@ -928,6 +996,16 @@ static int nbd_negotiate_meta_queries(NBDClient *client,
1bdc94
         }
1bdc94
     }
1bdc94
 
1bdc94
+    if (meta->bitmap) {
1bdc94
+        ret = nbd_negotiate_send_meta_context(client,
1bdc94
+                                              meta->exp->export_bitmap_context,
1bdc94
+                                              NBD_META_ID_DIRTY_BITMAP,
1bdc94
+                                              errp);
1bdc94
+        if (ret < 0) {
1bdc94
+            return ret;
1bdc94
+        }
1bdc94
+    }
1bdc94
+
1bdc94
     ret = nbd_negotiate_send_rep(client, NBD_REP_ACK, errp);
1bdc94
     if (ret == 0) {
1bdc94
         meta->valid = true;
1bdc94
@@ -1556,6 +1634,11 @@ void nbd_export_put(NBDExport *exp)
1bdc94
             exp->blk = NULL;
1bdc94
         }
1bdc94
 
1bdc94
+        if (exp->export_bitmap) {
1bdc94
+            bdrv_dirty_bitmap_set_qmp_locked(exp->export_bitmap, false);
1bdc94
+            g_free(exp->export_bitmap_context);
1bdc94
+        }
1bdc94
+
1bdc94
         g_free(exp);
1bdc94
     }
1bdc94
 }
1bdc94
@@ -1797,9 +1880,15 @@ static int blockstatus_to_extent_be(BlockDriverState *bs, uint64_t offset,
1bdc94
 }
1bdc94
 
1bdc94
 /* nbd_co_send_extents
1bdc94
- * @extents should be in big-endian */
1bdc94
+ *
1bdc94
+ * @length is only for tracing purposes (and may be smaller or larger
1bdc94
+ * than the client's original request). @last controls whether
1bdc94
+ * NBD_REPLY_FLAG_DONE is sent. @extents should already be in
1bdc94
+ * big-endian format.
1bdc94
+ */
1bdc94
 static int nbd_co_send_extents(NBDClient *client, uint64_t handle,
1bdc94
-                               NBDExtent *extents, unsigned nb_extents,
1bdc94
+                               NBDExtent *extents, unsigned int nb_extents,
1bdc94
+                               uint64_t length, bool last,
1bdc94
                                uint32_t context_id, Error **errp)
1bdc94
 {
1bdc94
     NBDStructuredMeta chunk;
1bdc94
@@ -1809,7 +1898,9 @@ static int nbd_co_send_extents(NBDClient *client, uint64_t handle,
1bdc94
         {.iov_base = extents, .iov_len = nb_extents * sizeof(extents[0])}
1bdc94
     };
1bdc94
 
1bdc94
-    set_be_chunk(&chunk.h, NBD_REPLY_FLAG_DONE, NBD_REPLY_TYPE_BLOCK_STATUS,
1bdc94
+    trace_nbd_co_send_extents(handle, nb_extents, context_id, length, last);
1bdc94
+    set_be_chunk(&chunk.h, last ? NBD_REPLY_FLAG_DONE : 0,
1bdc94
+                 NBD_REPLY_TYPE_BLOCK_STATUS,
1bdc94
                  handle, sizeof(chunk) - sizeof(chunk.h) + iov[1].iov_len);
1bdc94
     stl_be_p(&chunk.context_id, context_id);
1bdc94
 
1bdc94
@@ -1819,8 +1910,8 @@ static int nbd_co_send_extents(NBDClient *client, uint64_t handle,
1bdc94
 /* Get block status from the exported device and send it to the client */
1bdc94
 static int nbd_co_send_block_status(NBDClient *client, uint64_t handle,
1bdc94
                                     BlockDriverState *bs, uint64_t offset,
1bdc94
-                                    uint64_t length, uint32_t context_id,
1bdc94
-                                    Error **errp)
1bdc94
+                                    uint64_t length, bool last,
1bdc94
+                                    uint32_t context_id, Error **errp)
1bdc94
 {
1bdc94
     int ret;
1bdc94
     NBDExtent extent;
1bdc94
@@ -1831,7 +1922,84 @@ static int nbd_co_send_block_status(NBDClient *client, uint64_t handle,
1bdc94
                 client, handle, -ret, "can't get block status", errp);
1bdc94
     }
1bdc94
 
1bdc94
-    return nbd_co_send_extents(client, handle, &extent, 1, context_id, errp);
1bdc94
+    return nbd_co_send_extents(client, handle, &extent, 1, length, last,
1bdc94
+                               context_id, errp);
1bdc94
+}
1bdc94
+
1bdc94
+/*
1bdc94
+ * Populate @extents from a dirty bitmap. Unless @dont_fragment, the
1bdc94
+ * final extent may exceed the original @length. Store in @length the
1bdc94
+ * byte length encoded (which may be smaller or larger than the
1bdc94
+ * original), and return the number of extents used.
1bdc94
+ */
1bdc94
+static unsigned int bitmap_to_extents(BdrvDirtyBitmap *bitmap, uint64_t offset,
1bdc94
+                                      uint64_t *length, NBDExtent *extents,
1bdc94
+                                      unsigned int nb_extents,
1bdc94
+                                      bool dont_fragment)
1bdc94
+{
1bdc94
+    uint64_t begin = offset, end;
1bdc94
+    uint64_t overall_end = offset + *length;
1bdc94
+    unsigned int i = 0;
1bdc94
+    BdrvDirtyBitmapIter *it;
1bdc94
+    bool dirty;
1bdc94
+
1bdc94
+    bdrv_dirty_bitmap_lock(bitmap);
1bdc94
+
1bdc94
+    it = bdrv_dirty_iter_new(bitmap);
1bdc94
+    dirty = bdrv_get_dirty_locked(NULL, bitmap, offset);
1bdc94
+
1bdc94
+    assert(begin < overall_end && nb_extents);
1bdc94
+    while (begin < overall_end && i < nb_extents) {
1bdc94
+        if (dirty) {
1bdc94
+            end = bdrv_dirty_bitmap_next_zero(bitmap, begin);
1bdc94
+        } else {
1bdc94
+            bdrv_set_dirty_iter(it, begin);
1bdc94
+            end = bdrv_dirty_iter_next(it);
1bdc94
+        }
1bdc94
+        if (end == -1 || end - begin > UINT32_MAX) {
1bdc94
+            /* Cap to an aligned value < 4G beyond begin. */
1bdc94
+            end = MIN(bdrv_dirty_bitmap_size(bitmap),
1bdc94
+                      begin + UINT32_MAX + 1 -
1bdc94
+                      bdrv_dirty_bitmap_granularity(bitmap));
1bdc94
+        }
1bdc94
+        if (dont_fragment && end > overall_end) {
1bdc94
+            end = overall_end;
1bdc94
+        }
1bdc94
+
1bdc94
+        extents[i].length = cpu_to_be32(end - begin);
1bdc94
+        extents[i].flags = cpu_to_be32(dirty ? NBD_STATE_DIRTY : 0);
1bdc94
+        i++;
1bdc94
+        begin = end;
1bdc94
+        dirty = !dirty;
1bdc94
+    }
1bdc94
+
1bdc94
+    bdrv_dirty_iter_free(it);
1bdc94
+
1bdc94
+    bdrv_dirty_bitmap_unlock(bitmap);
1bdc94
+
1bdc94
+    *length = end - offset;
1bdc94
+    return i;
1bdc94
+}
1bdc94
+
1bdc94
+static int nbd_co_send_bitmap(NBDClient *client, uint64_t handle,
1bdc94
+                              BdrvDirtyBitmap *bitmap, uint64_t offset,
1bdc94
+                              uint32_t length, bool dont_fragment, bool last,
1bdc94
+                              uint32_t context_id, Error **errp)
1bdc94
+{
1bdc94
+    int ret;
1bdc94
+    unsigned int nb_extents = dont_fragment ? 1 : NBD_MAX_BITMAP_EXTENTS;
1bdc94
+    NBDExtent *extents = g_new(NBDExtent, nb_extents);
1bdc94
+    uint64_t final_length = length;
1bdc94
+
1bdc94
+    nb_extents = bitmap_to_extents(bitmap, offset, &final_length, extents,
1bdc94
+                                   nb_extents, dont_fragment);
1bdc94
+
1bdc94
+    ret = nbd_co_send_extents(client, handle, extents, nb_extents,
1bdc94
+                              final_length, last, context_id, errp);
1bdc94
+
1bdc94
+    g_free(extents);
1bdc94
+
1bdc94
+    return ret;
1bdc94
 }
1bdc94
 
1bdc94
 /* nbd_co_receive_request
1bdc94
@@ -2051,11 +2219,34 @@ static coroutine_fn int nbd_handle_request(NBDClient *client,
1bdc94
             return nbd_send_generic_reply(client, request->handle, -EINVAL,
1bdc94
                                           "need non-zero length", errp);
1bdc94
         }
1bdc94
-        if (client->export_meta.valid && client->export_meta.base_allocation) {
1bdc94
-            return nbd_co_send_block_status(client, request->handle,
1bdc94
-                                            blk_bs(exp->blk), request->from,
1bdc94
-                                            request->len,
1bdc94
-                                            NBD_META_ID_BASE_ALLOCATION, errp);
1bdc94
+        if (client->export_meta.valid &&
1bdc94
+            (client->export_meta.base_allocation ||
1bdc94
+             client->export_meta.bitmap))
1bdc94
+        {
1bdc94
+            if (client->export_meta.base_allocation) {
1bdc94
+                ret = nbd_co_send_block_status(client, request->handle,
1bdc94
+                                               blk_bs(exp->blk), request->from,
1bdc94
+                                               request->len,
1bdc94
+                                               !client->export_meta.bitmap,
1bdc94
+                                               NBD_META_ID_BASE_ALLOCATION,
1bdc94
+                                               errp);
1bdc94
+                if (ret < 0) {
1bdc94
+                    return ret;
1bdc94
+                }
1bdc94
+            }
1bdc94
+
1bdc94
+            if (client->export_meta.bitmap) {
1bdc94
+                ret = nbd_co_send_bitmap(client, request->handle,
1bdc94
+                                         client->exp->export_bitmap,
1bdc94
+                                         request->from, request->len,
1bdc94
+                                         request->flags & NBD_CMD_FLAG_REQ_ONE,
1bdc94
+                                         true, NBD_META_ID_DIRTY_BITMAP, errp);
1bdc94
+                if (ret < 0) {
1bdc94
+                    return ret;
1bdc94
+                }
1bdc94
+            }
1bdc94
+
1bdc94
+            return ret;
1bdc94
         } else {
1bdc94
             return nbd_send_generic_reply(client, request->handle, -EINVAL,
1bdc94
                                           "CMD_BLOCK_STATUS not negotiated",
1bdc94
@@ -2207,3 +2398,44 @@ void nbd_client_new(NBDExport *exp,
1bdc94
     co = qemu_coroutine_create(nbd_co_client_start, client);
1bdc94
     qemu_coroutine_enter(co);
1bdc94
 }
1bdc94
+
1bdc94
+void nbd_export_bitmap(NBDExport *exp, const char *bitmap,
1bdc94
+                       const char *bitmap_export_name, Error **errp)
1bdc94
+{
1bdc94
+    BdrvDirtyBitmap *bm = NULL;
1bdc94
+    BlockDriverState *bs = blk_bs(exp->blk);
1bdc94
+
1bdc94
+    if (exp->export_bitmap) {
1bdc94
+        error_setg(errp, "Export bitmap is already set");
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    while (true) {
1bdc94
+        bm = bdrv_find_dirty_bitmap(bs, bitmap);
1bdc94
+        if (bm != NULL || bs->backing == NULL) {
1bdc94
+            break;
1bdc94
+        }
1bdc94
+
1bdc94
+        bs = bs->backing->bs;
1bdc94
+    }
1bdc94
+
1bdc94
+    if (bm == NULL) {
1bdc94
+        error_setg(errp, "Bitmap '%s' is not found", bitmap);
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    if (bdrv_dirty_bitmap_enabled(bm)) {
1bdc94
+        error_setg(errp, "Bitmap '%s' is enabled", bitmap);
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    if (bdrv_dirty_bitmap_qmp_locked(bm)) {
1bdc94
+        error_setg(errp, "Bitmap '%s' is locked", bitmap);
1bdc94
+        return;
1bdc94
+    }
1bdc94
+
1bdc94
+    bdrv_dirty_bitmap_set_qmp_locked(bm, true);
1bdc94
+    exp->export_bitmap = bm;
1bdc94
+    exp->export_bitmap_context =
1bdc94
+            g_strdup_printf("qemu:dirty-bitmap:%s", bitmap_export_name);
1bdc94
+}
1bdc94
diff --git a/nbd/trace-events b/nbd/trace-events
1bdc94
index dee081e..5e1d4af 100644
1bdc94
--- a/nbd/trace-events
1bdc94
+++ b/nbd/trace-events
1bdc94
@@ -64,6 +64,7 @@ nbd_co_send_simple_reply(uint64_t handle, uint32_t error, const char *errname, i
1bdc94
 nbd_co_send_structured_done(uint64_t handle) "Send structured reply done: handle = %" PRIu64
1bdc94
 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"
1bdc94
 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"
1bdc94
+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)"
1bdc94
 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'"
1bdc94
 nbd_co_receive_request_decode_type(uint64_t handle, uint16_t type, const char *name) "Decoding type: handle = %" PRIu64 ", type = %" PRIu16 " (%s)"
1bdc94
 nbd_co_receive_request_payload_received(uint64_t handle, uint32_t len) "Payload received: handle = %" PRIu64 ", len = %" PRIu32
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94