cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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