Blame SOURCES/kvm-iotests-New-test-223-for-exporting-dirty-bitmap-over.patch

1bdc94
From a213535d2d03296c7b2f31845160757dbb959ca6 Mon Sep 17 00:00:00 2001
1bdc94
From: John Snow <jsnow@redhat.com>
1bdc94
Date: Tue, 24 Jul 2018 13:06:13 +0200
1bdc94
Subject: [PATCH 86/89] iotests: New test 223 for exporting dirty bitmap over
1bdc94
 NBD
1bdc94
1bdc94
RH-Author: John Snow <jsnow@redhat.com>
1bdc94
Message-id: <20180718225511.14878-36-jsnow@redhat.com>
1bdc94
Patchwork-id: 81424
1bdc94
O-Subject: [RHEL-7.6 qemu-kvm-rhev PATCH 35/35] iotests: New test 223 for exporting dirty bitmap over NBD
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: Eric Blake <eblake@redhat.com>
1bdc94
1bdc94
Although this test is NOT a full test of image fleecing (as it
1bdc94
intentionally uses just a single block device directly exported
1bdc94
over NBD, rather than trying to set up a blockdev-backup job with
1bdc94
multiple BDS involved), it DOES prove that qemu as a server is
1bdc94
able to properly expose a dirty bitmap over NBD.
1bdc94
1bdc94
When coupled with image fleecing, it is then possible for a
1bdc94
third-party client to do an incremental backup by using
1bdc94
qemu-img map with the x-dirty-bitmap option to learn which parts
1bdc94
of the file are dirty (perhaps confusingly, they are the portions
1bdc94
mapped as "data":false - which is part of the reason this is
1bdc94
still in the x- experimental namespace), along with another
1bdc94
normal client (perhaps 'qemu-nbd -c' to expose the server over
1bdc94
/dev/nbd0 and then just use normal I/O on that block device) to
1bdc94
read the dirty sections.
1bdc94
1bdc94
Signed-off-by: Eric Blake <eblake@redhat.com>
1bdc94
Message-Id: <20180702191458.28741-3-eblake@redhat.com>
1bdc94
Tested-by: John Snow <jsnow@redhat.com>
1bdc94
Reviewed-by: John Snow <jsnow@redhat.com>
1bdc94
(cherry picked from commit a1532a225a183c9fa60b9c1e8ac8a00c7771f64d)
1bdc94
Signed-off-by: John Snow <jsnow@redhat.com>
1bdc94
---
1bdc94
 tests/qemu-iotests/223     | 138 +++++++++++++++++++++++++++++++++++++++++++++
1bdc94
 tests/qemu-iotests/223.out |  49 ++++++++++++++++
1bdc94
 tests/qemu-iotests/group   |   1 +
1bdc94
 3 files changed, 188 insertions(+)
1bdc94
 create mode 100644 tests/qemu-iotests/223
1bdc94
 create mode 100644 tests/qemu-iotests/223.out
1bdc94
1bdc94
diff --git a/tests/qemu-iotests/223 b/tests/qemu-iotests/223
1bdc94
new file mode 100644
1bdc94
index 0000000..b63b7a4
1bdc94
--- /dev/null
1bdc94
+++ b/tests/qemu-iotests/223
1bdc94
@@ -0,0 +1,138 @@
1bdc94
+#!/bin/bash
1bdc94
+#
1bdc94
+# Test reading dirty bitmap over NBD
1bdc94
+#
1bdc94
+# Copyright (C) 2018 Red Hat, Inc.
1bdc94
+#
1bdc94
+# This program is free software; you can redistribute it and/or modify
1bdc94
+# it under the terms of the GNU General Public License as published by
1bdc94
+# the Free Software Foundation; either version 2 of the License, or
1bdc94
+# (at your option) any later version.
1bdc94
+#
1bdc94
+# This program is distributed in the hope that it will be useful,
1bdc94
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1bdc94
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1bdc94
+# GNU General Public License for more details.
1bdc94
+#
1bdc94
+# You should have received a copy of the GNU General Public License
1bdc94
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
1bdc94
+#
1bdc94
+
1bdc94
+seq="$(basename $0)"
1bdc94
+echo "QA output created by $seq"
1bdc94
+
1bdc94
+here="$PWD"
1bdc94
+status=1 # failure is the default!
1bdc94
+
1bdc94
+_cleanup()
1bdc94
+{
1bdc94
+    _cleanup_test_img
1bdc94
+    _cleanup_qemu
1bdc94
+    rm -f "$TEST_DIR/nbd"
1bdc94
+}
1bdc94
+trap "_cleanup; exit \$status" 0 1 2 3 15
1bdc94
+
1bdc94
+# get standard environment, filters and checks
1bdc94
+. ./common.rc
1bdc94
+. ./common.filter
1bdc94
+. ./common.qemu
1bdc94
+
1bdc94
+_supported_fmt qcow2
1bdc94
+_supported_proto file # uses NBD as well
1bdc94
+_supported_os Linux
1bdc94
+
1bdc94
+function do_run_qemu()
1bdc94
+{
1bdc94
+    echo Testing: "$@"
1bdc94
+    $QEMU -nographic -qmp stdio -serial none "$@"
1bdc94
+    echo
1bdc94
+}
1bdc94
+
1bdc94
+function run_qemu()
1bdc94
+{
1bdc94
+    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qmp \
1bdc94
+                          | _filter_qemu | _filter_imgfmt \
1bdc94
+                          | _filter_actual_image_size
1bdc94
+}
1bdc94
+
1bdc94
+echo
1bdc94
+echo "=== Create partially sparse image, then add dirty bitmap ==="
1bdc94
+echo
1bdc94
+
1bdc94
+_make_test_img 4M
1bdc94
+$QEMU_IO -c 'w -P 0x11 1M 2M' "$TEST_IMG" | _filter_qemu_io
1bdc94
+run_qemu <
1bdc94
+{ "execute": "qmp_capabilities" }
1bdc94
+{ "execute": "blockdev-add",
1bdc94
+  "arguments": {
1bdc94
+    "driver": "$IMGFMT",
1bdc94
+    "node-name": "n",
1bdc94
+    "file": {
1bdc94
+      "driver": "file",
1bdc94
+      "filename": "$TEST_IMG"
1bdc94
+    }
1bdc94
+  }
1bdc94
+}
1bdc94
+{ "execute": "block-dirty-bitmap-add",
1bdc94
+  "arguments": {
1bdc94
+    "node": "n",
1bdc94
+    "name": "b",
1bdc94
+    "persistent": true
1bdc94
+  }
1bdc94
+}
1bdc94
+{ "execute": "quit" }
1bdc94
+EOF
1bdc94
+
1bdc94
+echo
1bdc94
+echo "=== Write part of the file under active bitmap ==="
1bdc94
+echo
1bdc94
+
1bdc94
+$QEMU_IO -c 'w -P 0x22 2M 2M' "$TEST_IMG" | _filter_qemu_io
1bdc94
+
1bdc94
+echo
1bdc94
+echo "=== End dirty bitmap, and start serving image over NBD ==="
1bdc94
+echo
1bdc94
+
1bdc94
+_launch_qemu 2> >(_filter_nbd)
1bdc94
+
1bdc94
+silent=
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"qmp_capabilities"}' "return"
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"blockdev-add",
1bdc94
+  "arguments":{"driver":"qcow2", "node-name":"n",
1bdc94
+    "file":{"driver":"file", "filename":"'"$TEST_IMG"'"}}}' "return"
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-block-dirty-bitmap-disable",
1bdc94
+  "arguments":{"node":"n", "name":"b"}}' "return"
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-start",
1bdc94
+  "arguments":{"addr":{"type":"unix",
1bdc94
+    "data":{"path":"'"$TEST_DIR/nbd"'"}}}}' "return"
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-add",
1bdc94
+  "arguments":{"device":"n"}}' "return"
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"x-nbd-server-add-bitmap",
1bdc94
+  "arguments":{"name":"n", "bitmap":"b"}}' "return"
1bdc94
+
1bdc94
+echo
1bdc94
+echo "=== Contrast normal status with dirty-bitmap status ==="
1bdc94
+echo
1bdc94
+
1bdc94
+QEMU_IO_OPTIONS=$QEMU_IO_OPTIONS_NO_FMT
1bdc94
+IMG="driver=nbd,export=n,server.type=unix,server.path=$TEST_DIR/nbd"
1bdc94
+$QEMU_IO -r -c 'r -P 0 0 1m' -c 'r -P 0x11 1m 1m' \
1bdc94
+  -c 'r -P 0x22 2m 2m' --image-opts "$IMG" | _filter_qemu_io
1bdc94
+$QEMU_IMG map --output=json --image-opts \
1bdc94
+  "$IMG" | _filter_qemu_img_map
1bdc94
+$QEMU_IMG map --output=json --image-opts \
1bdc94
+  "$IMG,x-dirty-bitmap=qemu:dirty-bitmap:b" | _filter_qemu_img_map
1bdc94
+
1bdc94
+echo
1bdc94
+echo "=== End NBD server ==="
1bdc94
+echo
1bdc94
+
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-remove",
1bdc94
+  "arguments":{"name":"n"}}' "return"
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"nbd-server-stop"}' "return"
1bdc94
+_send_qemu_cmd $QEMU_HANDLE '{"execute":"quit"}' "return"
1bdc94
+
1bdc94
+# success, all done
1bdc94
+echo '*** done'
1bdc94
+rm -f $seq.full
1bdc94
+status=0
1bdc94
diff --git a/tests/qemu-iotests/223.out b/tests/qemu-iotests/223.out
1bdc94
new file mode 100644
1bdc94
index 0000000..33021c8
1bdc94
--- /dev/null
1bdc94
+++ b/tests/qemu-iotests/223.out
1bdc94
@@ -0,0 +1,49 @@
1bdc94
+QA output created by 223
1bdc94
+
1bdc94
+=== Create partially sparse image, then add dirty bitmap ===
1bdc94
+
1bdc94
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=4194304
1bdc94
+wrote 2097152/2097152 bytes at offset 1048576
1bdc94
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
1bdc94
+Testing:
1bdc94
+QMP_VERSION
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false}}
1bdc94
+
1bdc94
+
1bdc94
+=== Write part of the file under active bitmap ===
1bdc94
+
1bdc94
+wrote 2097152/2097152 bytes at offset 2097152
1bdc94
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
1bdc94
+
1bdc94
+=== End dirty bitmap, and start serving image over NBD ===
1bdc94
+
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+
1bdc94
+=== Contrast normal status with dirty-bitmap status ===
1bdc94
+
1bdc94
+read 1048576/1048576 bytes at offset 0
1bdc94
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
1bdc94
+read 1048576/1048576 bytes at offset 1048576
1bdc94
+1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
1bdc94
+read 2097152/2097152 bytes at offset 2097152
1bdc94
+2 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
1bdc94
+[{ "start": 0, "length": 1048576, "depth": 0, "zero": true, "data": false},
1bdc94
+{ "start": 1048576, "length": 3145728, "depth": 0, "zero": false, "data": true}]
1bdc94
+[{ "start": 0, "length": 2097152, "depth": 0, "zero": false, "data": true},
1bdc94
+{ "start": 2097152, "length": 2097152, "depth": 0, "zero": false, "data": false}]
1bdc94
+
1bdc94
+=== End NBD server ===
1bdc94
+
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+{"return": {}}
1bdc94
+*** done
1bdc94
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
1bdc94
index be55905..401258f 100644
1bdc94
--- a/tests/qemu-iotests/group
1bdc94
+++ b/tests/qemu-iotests/group
1bdc94
@@ -219,4 +219,5 @@
1bdc94
 218 rw auto quick
1bdc94
 219 rw auto
1bdc94
 222 rw auto quick
1bdc94
+223 rw auto quick
1bdc94
 226 auto quick
1bdc94
-- 
1bdc94
1.8.3.1
1bdc94