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