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

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