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

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