Blame SOURCES/kvm-iotests-Test-file-posix-locking-and-reopen.patch

383d26
From bc3e5687b0f29cae1b5770aee8f4625b348deea1 Mon Sep 17 00:00:00 2001
383d26
From: Max Reitz <mreitz@redhat.com>
383d26
Date: Mon, 4 Feb 2019 20:42:07 +0100
383d26
Subject: [PATCH 07/33] iotests: Test file-posix locking and reopen
383d26
383d26
RH-Author: Max Reitz <mreitz@redhat.com>
383d26
Message-id: <20190204204207.18079-8-mreitz@redhat.com>
383d26
Patchwork-id: 84226
383d26
O-Subject: [RHEL-7.7 qemu-kvm-rhev PATCH 7/7] iotests: Test file-posix locking and reopen
383d26
Bugzilla: 1551486
383d26
RH-Acked-by: John Snow <jsnow@redhat.com>
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
383d26
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Reviewed-by: Alberto Garcia <berto@igalia.com>
383d26
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
383d26
(cherry picked from commit 6d0a4a0fb5c8f10c8eb68b52cfda0082b00ae963)
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 tests/qemu-iotests/182     | 71 ++++++++++++++++++++++++++++++++++++++++++++++
383d26
 tests/qemu-iotests/182.out |  9 ++++++
383d26
 2 files changed, 80 insertions(+)
383d26
383d26
diff --git a/tests/qemu-iotests/182 b/tests/qemu-iotests/182
383d26
index 4b31592..3b7689c 100755
383d26
--- a/tests/qemu-iotests/182
383d26
+++ b/tests/qemu-iotests/182
383d26
@@ -31,6 +31,7 @@ status=1	# failure is the default!
383d26
 _cleanup()
383d26
 {
383d26
     _cleanup_test_img
383d26
+    rm -f "$TEST_IMG.overlay"
383d26
 }
383d26
 trap "_cleanup; exit \$status" 0 1 2 3 15
383d26
 
383d26
@@ -71,6 +72,76 @@ echo 'quit' | $QEMU -nographic -monitor stdio \
383d26
 
383d26
 _cleanup_qemu
383d26
 
383d26
+echo
383d26
+echo '=== Testing reopen ==='
383d26
+echo
383d26
+
383d26
+# This tests that reopening does not unshare any permissions it should
383d26
+# not unshare
383d26
+# (There was a bug where reopening shared exactly the opposite of the
383d26
+# permissions it was supposed to share)
383d26
+
383d26
+_launch_qemu
383d26
+
383d26
+_send_qemu_cmd $QEMU_HANDLE \
383d26
+    "{'execute': 'qmp_capabilities'}" \
383d26
+    'return'
383d26
+
383d26
+# Open the image without any format layer (we are not going to access
383d26
+# it, so that is fine)
383d26
+# This should keep all permissions shared.
383d26
+success_or_failure=y _send_qemu_cmd $QEMU_HANDLE \
383d26
+    "{'execute': 'blockdev-add',
383d26
+      'arguments': {
383d26
+          'node-name': 'node0',
383d26
+          'driver': 'file',
383d26
+          'filename': '$TEST_IMG',
383d26
+          'locking': 'on'
383d26
+          } }" \
383d26
+    'return' \
383d26
+    'error'
383d26
+
383d26
+# This snapshot will perform a reopen to drop R/W to RO.
383d26
+# It should still keep all permissions shared.
383d26
+success_or_failure=y _send_qemu_cmd $QEMU_HANDLE \
383d26
+    "{'execute': 'blockdev-snapshot-sync',
383d26
+      'arguments': {
383d26
+          'node-name': 'node0',
383d26
+          'snapshot-file': '$TEST_IMG.overlay',
383d26
+          'snapshot-node-name': 'node1'
383d26
+      } }" \
383d26
+    'return' \
383d26
+    'error'
383d26
+
383d26
+# Now open the same file again
383d26
+# This does not require any permissions (and does not unshare any), so
383d26
+# this will not conflict with node0.
383d26
+success_or_failure=y _send_qemu_cmd $QEMU_HANDLE \
383d26
+    "{'execute': 'blockdev-add',
383d26
+      'arguments': {
383d26
+          'node-name': 'node1',
383d26
+          'driver': 'file',
383d26
+          'filename': '$TEST_IMG',
383d26
+          'locking': 'on'
383d26
+          } }" \
383d26
+    'return' \
383d26
+    'error'
383d26
+
383d26
+# Now we attach the image to a virtio-blk device.  This device does
383d26
+# require some permissions (at least WRITE and READ_CONSISTENT), so if
383d26
+# reopening node0 unshared any (which it should not have), this will
383d26
+# fail (but it should not).
383d26
+success_or_failure=y _send_qemu_cmd $QEMU_HANDLE \
383d26
+    "{'execute': 'device_add',
383d26
+      'arguments': {
383d26
+          'driver': 'virtio-blk',
383d26
+          'drive': 'node1'
383d26
+      } }" \
383d26
+    'return' \
383d26
+    'error'
383d26
+
383d26
+_cleanup_qemu
383d26
+
383d26
 # success, all done
383d26
 echo "*** done"
383d26
 rm -f $seq.full
383d26
diff --git a/tests/qemu-iotests/182.out b/tests/qemu-iotests/182.out
383d26
index f1463c8..af501ca 100644
383d26
--- a/tests/qemu-iotests/182.out
383d26
+++ b/tests/qemu-iotests/182.out
383d26
@@ -5,4 +5,13 @@ Starting QEMU
383d26
 Starting a second QEMU using the same image should fail
383d26
 QEMU_PROG: -drive file=TEST_DIR/t.qcow2,if=none,id=drive0,file.locking=on: Failed to get "write" lock
383d26
 Is another process using the image [TEST_DIR/t.qcow2]?
383d26
+
383d26
+=== Testing reopen ===
383d26
+
383d26
+{"return": {}}
383d26
+{"return": {}}
383d26
+Formatting 'TEST_DIR/t.qcow2.overlay', fmt=qcow2 size=197120 backing_file=TEST_DIR/t.qcow2 backing_fmt=file cluster_size=65536 lazy_refcounts=off refcount_bits=16
383d26
+{"return": {}}
383d26
+{"return": {}}
383d26
+{"return": {}}
383d26
 *** done
383d26
-- 
383d26
1.8.3.1
383d26