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