Blame SOURCES/kvm-qemu-nbd-Add-bitmap-NAME-option.patch

7711c0
From 608c35120c7e8026232a2c2b7083648fca20144d Mon Sep 17 00:00:00 2001
7711c0
From: John Snow <jsnow@redhat.com>
7711c0
Date: Wed, 27 Mar 2019 17:22:33 +0100
7711c0
Subject: [PATCH 094/163] qemu-nbd: Add --bitmap=NAME option
7711c0
7711c0
RH-Author: John Snow <jsnow@redhat.com>
7711c0
Message-id: <20190327172308.31077-21-jsnow@redhat.com>
7711c0
Patchwork-id: 85200
7711c0
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 20/55] qemu-nbd: Add --bitmap=NAME option
7711c0
Bugzilla: 1691009
7711c0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
7711c0
RH-Acked-by: Max Reitz <mreitz@redhat.com>
7711c0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
7711c0
From: Eric Blake <eblake@redhat.com>
7711c0
7711c0
Having to fire up qemu, then use QMP commands for nbd-server-start
7711c0
and nbd-server-add, just to expose a persistent dirty bitmap, is
7711c0
rather tedious.  Make it possible to expose a dirty bitmap using
7711c0
just qemu-nbd (of course, for now this only works when qemu-nbd is
7711c0
visiting a BDS formatted as qcow2).
7711c0
7711c0
Of course, any good feature also needs unit testing, so expand
7711c0
iotest 223 to cover it.
7711c0
7711c0
Signed-off-by: Eric Blake <eblake@redhat.com>
7711c0
Message-Id: <20190111194720.15671-9-eblake@redhat.com>
7711c0
(cherry picked from commit 636192c4b6052820ea126a5287c58a8f53f3c84f)
7711c0
Signed-off-by: John Snow <jsnow@redhat.com>
7711c0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
7711c0
---
7711c0
 qemu-nbd.c                 | 10 ++++++++--
7711c0
 qemu-nbd.texi              |  4 ++++
7711c0
 tests/qemu-iotests/223     | 18 +++++++++++++++++-
7711c0
 tests/qemu-iotests/223.out | 12 +++++++++++-
7711c0
 4 files changed, 40 insertions(+), 4 deletions(-)
7711c0
7711c0
diff --git a/qemu-nbd.c b/qemu-nbd.c
7711c0
index ac4c958..0c92f62 100644
7711c0
--- a/qemu-nbd.c
7711c0
+++ b/qemu-nbd.c
7711c0
@@ -95,6 +95,7 @@ static void usage(const char *name)
7711c0
 "Exposing part of the image:\n"
7711c0
 "  -o, --offset=OFFSET       offset into the image\n"
7711c0
 "  -P, --partition=NUM       only expose partition NUM\n"
7711c0
+"  -B, --bitmap=NAME         expose a persistent dirty bitmap\n"
7711c0
 "\n"
7711c0
 "General purpose options:\n"
7711c0
 "  --object type,id=ID,...   define an object such as 'secret' for providing\n"
7711c0
@@ -509,7 +510,7 @@ int main(int argc, char **argv)
7711c0
     off_t fd_size;
7711c0
     QemuOpts *sn_opts = NULL;
7711c0
     const char *sn_id_or_name = NULL;
7711c0
-    const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:x:T:D:";
7711c0
+    const char *sopt = "hVb:o:p:rsnP:c:dvk:e:f:tl:x:T:D:B:";
7711c0
     struct option lopt[] = {
7711c0
         { "help", no_argument, NULL, 'h' },
7711c0
         { "version", no_argument, NULL, 'V' },
7711c0
@@ -519,6 +520,7 @@ int main(int argc, char **argv)
7711c0
         { "offset", required_argument, NULL, 'o' },
7711c0
         { "read-only", no_argument, NULL, 'r' },
7711c0
         { "partition", required_argument, NULL, 'P' },
7711c0
+        { "bitmap", required_argument, NULL, 'B' },
7711c0
         { "connect", required_argument, NULL, 'c' },
7711c0
         { "disconnect", no_argument, NULL, 'd' },
7711c0
         { "snapshot", no_argument, NULL, 's' },
7711c0
@@ -558,6 +560,7 @@ int main(int argc, char **argv)
7711c0
     QDict *options = NULL;
7711c0
     const char *export_name = ""; /* Default export name */
7711c0
     const char *export_description = NULL;
7711c0
+    const char *bitmap = NULL;
7711c0
     const char *tlscredsid = NULL;
7711c0
     bool imageOpts = false;
7711c0
     bool writethrough = true;
7711c0
@@ -695,6 +698,9 @@ int main(int argc, char **argv)
7711c0
                 exit(EXIT_FAILURE);
7711c0
             }
7711c0
             break;
7711c0
+        case 'B':
7711c0
+            bitmap = optarg;
7711c0
+            break;
7711c0
         case 'k':
7711c0
             sockpath = optarg;
7711c0
             if (sockpath[0] != '/') {
7711c0
@@ -1018,7 +1024,7 @@ int main(int argc, char **argv)
7711c0
     }
7711c0
 
7711c0
     export = nbd_export_new(bs, dev_offset, fd_size, export_name,
7711c0
-                            export_description, NULL, nbdflags,
7711c0
+                            export_description, bitmap, nbdflags,
7711c0
                             nbd_export_closed, writethrough, NULL,
7711c0
                             &error_fatal);
7711c0
 
7711c0
diff --git a/qemu-nbd.texi b/qemu-nbd.texi
7711c0
index 9a84e81..96b1546 100644
7711c0
--- a/qemu-nbd.texi
7711c0
+++ b/qemu-nbd.texi
7711c0
@@ -45,6 +45,10 @@ auto-detecting
7711c0
 Export the disk as read-only
7711c0
 @item -P, --partition=@var{num}
7711c0
 Only expose partition @var{num}
7711c0
+@item -B, --bitmap=@var{name}
7711c0
+If @var{filename} has a qcow2 persistent bitmap @var{name}, expose
7711c0
+that bitmap via the ``qemu:dirty-bitmap:@var{name}'' context
7711c0
+accessible through NBD_OPT_SET_META_CONTEXT.
7711c0
 @item -s, --snapshot
7711c0
 Use @var{filename} as an external snapshot, create a temporary
7711c0
 file with backing_file=@var{filename}, redirect the write to
7711c0
diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223
7711c0
index 0bcc98a..773892d 100755
7711c0
--- a/tests/qemu-iotests/223
7711c0
+++ b/tests/qemu-iotests/223
7711c0
@@ -25,6 +25,7 @@ status=1 # failure is the default!
7711c0
 
7711c0
 _cleanup()
7711c0
 {
7711c0
+    nbd_server_stop
7711c0
     _cleanup_test_img
7711c0
     _cleanup_qemu
7711c0
     rm -f "$TEST_DIR/nbd"
7711c0
@@ -35,6 +36,7 @@ trap "_cleanup; exit \$status" 0 1 2 3 15
7711c0
 . ./common.rc
7711c0
 . ./common.filter
7711c0
 . ./common.qemu
7711c0
+. ./common.nbd
7711c0
 
7711c0
 _supported_fmt qcow2
7711c0
 _supported_proto file # uses NBD as well
7711c0
@@ -163,7 +165,7 @@ $QEMU_IMG map --output=json --image-opts \
7711c0
   "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
7711c0
 
7711c0
 echo
7711c0
-echo "=== End NBD server ==="
7711c0
+echo "=== End qemu NBD server ==="
7711c0
 echo
7711c0
 
7711c0
 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
7711c0
@@ -176,6 +178,20 @@ _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
7711c0
 _send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "error" # Again
7711c0
 _send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
7711c0
 
7711c0
+echo
7711c0
+echo "=== Use qemu-nbd as server ==="
7711c0
+echo
7711c0
+
7711c0
+nbd_server_start_unix_socket -r -f $IMGFMT -B b "$TEST_IMG"
7711c0
+IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
7711c0
+$QEMU_IMG map --output=json --image-opts \
7711c0
+  "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
7711c0
+
7711c0
+nbd_server_start_unix_socket -f $IMGFMT -B b2 "$TEST_IMG"
7711c0
+IMG="driver=nbd,server.type=unix,server.path=$nbd_unix_socket"
7711c0
+$QEMU_IMG map --output=json --image-opts \
7711c0
+  "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b2" | _filter_qemu_img_map
7711c0
+
7711c0
 # success, all done
7711c0
 echo '*** done'
7711c0
 rm -f $seq.full
7711c0
diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out
7711c0
index a0c2dec..4012bb0 100644
7711c0
--- a/tests/qemu-iotests/223.out
7711c0
+++ b/tests/qemu-iotests/223.out
7711c0
@@ -61,7 +61,7 @@ read 2097152/2097152 bytes at offset 2097152
7711c0
 { "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": true},
7711c0
 { "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
7711c0
 
7711c0
-=== End NBD server ===
7711c0
+=== End qemu NBD server ===
7711c0
 
7711c0
 {"return": {}}
7711c0
 {"return": {}}
7711c0
@@ -69,4 +69,14 @@ read 2097152/2097152 bytes at offset 2097152
7711c0
 {"return": {}}
7711c0
 {"error": {"class": "GenericError", "desc": "NBD server not running"}}
7711c0
 {"return": {}}
7711c0
+
7711c0
+=== Use qemu-nbd as server ===
7711c0
+
7711c0
+[{ "start": 0, "length": 65536, "depth": 0, "zero": false, "data": false},
7711c0
+{ "start": 65536, "length": 2031616, "depth": 0, "zero": false, "data": true},
7711c0
+{ "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
7711c0
+[{ "start": 0, "length": 512, "depth": 0, "zero": false, "data": true},
7711c0
+{ "start": 512, "length": 512, "depth": 0, "zero": false, "data": false},
7711c0
+{ "start": 1024, "length": 2096128, "depth": 0, "zero": false, "data": true},
7711c0
+{ "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
7711c0
 *** done
7711c0
-- 
7711c0
1.8.3.1
7711c0