Blame SOURCES/kvm-iotests-Add-creation-test-to-153.patch

383d26
From e37408d4eee39e39d653ac2ce35155bed6db9a9e Mon Sep 17 00:00:00 2001
383d26
From: Max Reitz <mreitz@redhat.com>
383d26
Date: Mon, 18 Jun 2018 14:53:37 +0200
383d26
Subject: [PATCH 08/57] iotests: Add creation test to 153
383d26
383d26
RH-Author: Max Reitz <mreitz@redhat.com>
383d26
Message-id: <20180618145337.633-4-mreitz@redhat.com>
383d26
Patchwork-id: 80752
383d26
O-Subject: [RHV-7.6 qemu-kvm-rhev PATCH 3/3] iotests: Add creation test to 153
383d26
Bugzilla: 1519144
383d26
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
383d26
RH-Acked-by: Fam Zheng <famz@redhat.com>
383d26
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
383d26
This patch adds a test case to 153 which tries to overwrite an image
383d26
(using qemu-img create) while it is in use.  Without the original user
383d26
explicitly sharing the necessary permissions (writing and truncation),
383d26
this should not be allowed.
383d26
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Reviewed-by: Fam Zheng <famz@redhat.com>
383d26
Message-id: 20180509215336.31304-4-mreitz@redhat.com
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
(cherry picked from commit f45b638f9f967cdbea4e24704bd16a858ddcde03)
383d26
Signed-off-by: Max Reitz <mreitz@redhat.com>
383d26
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
383d26
---
383d26
 tests/qemu-iotests/153     | 18 ++++++++++++++++++
383d26
 tests/qemu-iotests/153.out | 13 +++++++++++++
383d26
 2 files changed, 31 insertions(+)
383d26
383d26
diff --git a/tests/qemu-iotests/153 b/tests/qemu-iotests/153
383d26
index ec508c7..673813c 100755
383d26
--- a/tests/qemu-iotests/153
383d26
+++ b/tests/qemu-iotests/153
383d26
@@ -137,6 +137,24 @@ for opts1 in "" "read-only=on" "read-only=on,force-share=on"; do
383d26
         _run_cmd $QEMU_IMG dd          $L if="${TEST_IMG}" of="${TEST_IMG}.convert" bs=512 count=1
383d26
         _run_cmd $QEMU_IMG bench       $L -c 1 "${TEST_IMG}"
383d26
         _run_cmd $QEMU_IMG bench       $L -w -c 1 "${TEST_IMG}"
383d26
+
383d26
+        # qemu-img create does not support -U
383d26
+        if [ -z "$L" ]; then
383d26
+            _run_cmd $QEMU_IMG create -f $IMGFMT "${TEST_IMG}" \
383d26
+                                      -b ${TEST_IMG}.base
383d26
+            # Read the file format.  It used to be the case that
383d26
+            # file-posix simply truncated the file, but the qcow2
383d26
+            # driver then failed to format it because it was unable
383d26
+            # to acquire the necessary WRITE permission.  However, the
383d26
+            # truncation was already wrong, and the whole process
383d26
+            # resulted in the file being completely empty and thus its
383d26
+            # format would be detected to be raw.
383d26
+            # So we read it here to see that creation either completed
383d26
+            # successfully (thus the format is qcow2) or it aborted
383d26
+            # before the file was changed at all (thus the format stays
383d26
+            # qcow2).
383d26
+            _img_info -U | grep 'file format'
383d26
+        fi
383d26
     done
383d26
     _send_qemu_cmd $h "{ 'execute': 'quit', }" ""
383d26
     echo
383d26
diff --git a/tests/qemu-iotests/153.out b/tests/qemu-iotests/153.out
383d26
index 2510762..3492ba7 100644
383d26
--- a/tests/qemu-iotests/153.out
383d26
+++ b/tests/qemu-iotests/153.out
383d26
@@ -92,6 +92,11 @@ _qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
383d26
 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
383d26
 Is another process using the image?
383d26
 
383d26
+_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
383d26
+qemu-img: TEST_DIR/t.qcow2: Failed to get "write" lock
383d26
+Is another process using the image?
383d26
+file format: IMGFMT
383d26
+
383d26
 == Running utility commands -U ==
383d26
 
383d26
 _qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
383d26
@@ -209,6 +214,11 @@ _qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
383d26
 qemu-img: Could not open 'TEST_DIR/t.qcow2': Failed to get "write" lock
383d26
 Is another process using the image?
383d26
 
383d26
+_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
383d26
+qemu-img: TEST_DIR/t.qcow2: Failed to get "write" lock
383d26
+Is another process using the image?
383d26
+file format: IMGFMT
383d26
+
383d26
 == Running utility commands -U ==
383d26
 
383d26
 _qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
383d26
@@ -309,6 +319,9 @@ _qemu_img_wrapper bench -c 1 TEST_DIR/t.qcow2
383d26
 
383d26
 _qemu_img_wrapper bench -w -c 1 TEST_DIR/t.qcow2
383d26
 
383d26
+_qemu_img_wrapper create -f qcow2 TEST_DIR/t.qcow2 -b TEST_DIR/t.qcow2.base
383d26
+file format: IMGFMT
383d26
+
383d26
 == Running utility commands -U ==
383d26
 
383d26
 _qemu_io_wrapper -U -c read 0 512 TEST_DIR/t.qcow2
383d26
-- 
383d26
1.8.3.1
383d26