thebeanogamer / rpms / qemu-kvm

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