Blame SOURCES/kvm-qemu-iotests-Test-qemu-img-bitmap-commit-exit-code-o.patch

97168e
From 7c6faae20638f58681df223e0ca44e0a6cb60d2d Mon Sep 17 00:00:00 2001
97168e
From: Kevin Wolf <kwolf@redhat.com>
97168e
Date: Thu, 12 Jan 2023 20:14:54 +0100
97168e
Subject: [PATCH 4/4] qemu-iotests: Test qemu-img bitmap/commit exit code on
97168e
 error
97168e
97168e
RH-Author: Kevin Wolf <kwolf@redhat.com>
97168e
RH-MergeRequest: 251: qemu-img: Fix exit code for errors closing the image
97168e
RH-Bugzilla: 2147617
97168e
RH-Acked-by: Hanna Czenczek <hreitz@redhat.com>
97168e
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
97168e
RH-Acked-by: Stefano Garzarella <sgarzare@redhat.com>
97168e
RH-Commit: [4/4] fb2f9de98ddd2ee1d745119e4f15272ef44e0aae
97168e
97168e
This tests that when an error happens while writing back bitmaps to the
97168e
image file in qcow2_inactivate(), 'qemu-img bitmap/commit' actually
97168e
return an error value in their exit code instead of making the operation
97168e
look successful to scripts.
97168e
97168e
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
97168e
Message-Id: <20230112191454.169353-5-kwolf@redhat.com>
97168e
Reviewed-by: Hanna Czenczek <hreitz@redhat.com>
97168e
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
97168e
(cherry picked from commit 07a4e1f8e5418f36424cd57d5d061b090a238c65)
97168e
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
97168e
---
97168e
 .../qemu-iotests/tests/qemu-img-close-errors  | 96 +++++++++++++++++++
97168e
 .../tests/qemu-img-close-errors.out           | 23 +++++
97168e
 2 files changed, 119 insertions(+)
97168e
 create mode 100755 tests/qemu-iotests/tests/qemu-img-close-errors
97168e
 create mode 100644 tests/qemu-iotests/tests/qemu-img-close-errors.out
97168e
97168e
diff --git a/tests/qemu-iotests/tests/qemu-img-close-errors b/tests/qemu-iotests/tests/qemu-img-close-errors
97168e
new file mode 100755
97168e
index 0000000000..50bfb6cfa2
97168e
--- /dev/null
97168e
+++ b/tests/qemu-iotests/tests/qemu-img-close-errors
97168e
@@ -0,0 +1,96 @@
97168e
+#!/usr/bin/env bash
97168e
+# group: rw auto quick
97168e
+#
97168e
+# Check that errors while closing the image, in particular writing back dirty
97168e
+# bitmaps, is correctly reported with a failing qemu-img exit code.
97168e
+#
97168e
+# Copyright (C) 2023 Red Hat, Inc.
97168e
+#
97168e
+# This program is free software; you can redistribute it and/or modify
97168e
+# it under the terms of the GNU General Public License as published by
97168e
+# the Free Software Foundation; either version 2 of the License, or
97168e
+# (at your option) any later version.
97168e
+#
97168e
+# This program is distributed in the hope that it will be useful,
97168e
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
97168e
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
97168e
+# GNU General Public License for more details.
97168e
+#
97168e
+# You should have received a copy of the GNU General Public License
97168e
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
97168e
+#
97168e
+
97168e
+# creator
97168e
+owner=kwolf@redhat.com
97168e
+
97168e
+seq="$(basename $0)"
97168e
+echo "QA output created by $seq"
97168e
+
97168e
+status=1	# failure is the default!
97168e
+
97168e
+_cleanup()
97168e
+{
97168e
+    _cleanup_test_img
97168e
+}
97168e
+trap "_cleanup; exit \$status" 0 1 2 3 15
97168e
+
97168e
+# get standard environment, filters and checks
97168e
+cd ..
97168e
+. ./common.rc
97168e
+. ./common.filter
97168e
+
97168e
+_supported_fmt qcow2
97168e
+_supported_proto file
97168e
+_supported_os Linux
97168e
+
97168e
+size=1G
97168e
+
97168e
+# The error we are going to use is ENOSPC. Depending on how many bitmaps we
97168e
+# create in the backing file (and therefore increase the used up space), we get
97168e
+# failures in different places. With a low number, only merging the bitmap
97168e
+# fails, whereas with a higher number, already 'qemu-img commit' fails.
97168e
+for max_bitmap in 6 7; do
97168e
+    echo
97168e
+    echo "=== Test with $max_bitmap bitmaps ==="
97168e
+
97168e
+    TEST_IMG="$TEST_IMG.base" _make_test_img -q $size
97168e
+    for i in $(seq 1 $max_bitmap); do
97168e
+        $QEMU_IMG bitmap --add "$TEST_IMG.base" "stale-bitmap-$i"
97168e
+    done
97168e
+
97168e
+    # Simulate a block device of 128 MB by resizing the image file accordingly
97168e
+    # and then enforcing the size with the raw driver
97168e
+    $QEMU_IO -f raw -c "truncate 128M" "$TEST_IMG.base"
97168e
+    BASE_JSON='json:{
97168e
+        "driver": "qcow2",
97168e
+        "file": {
97168e
+            "driver": "raw",
97168e
+            "size": 134217728,
97168e
+            "file": {
97168e
+                "driver": "file",
97168e
+                "filename":"'"$TEST_IMG.base"'"
97168e
+            }
97168e
+        }
97168e
+    }'
97168e
+
97168e
+    _make_test_img -q -b "$BASE_JSON" -F $IMGFMT
97168e
+    $QEMU_IMG bitmap --add "$TEST_IMG" "good-bitmap"
97168e
+
97168e
+    $QEMU_IO -c 'write 0 126m' "$TEST_IMG" | _filter_qemu_io
97168e
+
97168e
+    $QEMU_IMG commit -d "$TEST_IMG" 2>&1 | _filter_generated_node_ids
97168e
+    echo "qemu-img commit exit code: ${PIPESTATUS[0]}"
97168e
+
97168e
+    $QEMU_IMG bitmap --add "$BASE_JSON" "good-bitmap"
97168e
+    echo "qemu-img bitmap --add exit code: $?"
97168e
+
97168e
+    $QEMU_IMG bitmap --merge "good-bitmap" -b "$TEST_IMG" "$BASE_JSON" \
97168e
+        "good-bitmap" 2>&1 | _filter_generated_node_ids
97168e
+    echo "qemu-img bitmap --merge exit code:  ${PIPESTATUS[0]}"
97168e
+done
97168e
+
97168e
+# success, all done
97168e
+echo "*** done"
97168e
+rm -f $seq.full
97168e
+status=0
97168e
+
97168e
diff --git a/tests/qemu-iotests/tests/qemu-img-close-errors.out b/tests/qemu-iotests/tests/qemu-img-close-errors.out
97168e
new file mode 100644
97168e
index 0000000000..1bfe88f176
97168e
--- /dev/null
97168e
+++ b/tests/qemu-iotests/tests/qemu-img-close-errors.out
97168e
@@ -0,0 +1,23 @@
97168e
+QA output created by qemu-img-close-errors
97168e
+
97168e
+=== Test with 6 bitmaps ===
97168e
+wrote 132120576/132120576 bytes at offset 0
97168e
+126 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
97168e
+Image committed.
97168e
+qemu-img commit exit code: 0
97168e
+qemu-img bitmap --add exit code: 0
97168e
+qemu-img: Lost persistent bitmaps during inactivation of node 'NODE_NAME': Failed to write bitmap 'good-bitmap' to file: No space left on device
97168e
+qemu-img: Error while closing the image: Invalid argument
97168e
+qemu-img: Lost persistent bitmaps during inactivation of node 'NODE_NAME': Failed to write bitmap 'good-bitmap' to file: No space left on device
97168e
+qemu-img bitmap --merge exit code:  1
97168e
+
97168e
+=== Test with 7 bitmaps ===
97168e
+wrote 132120576/132120576 bytes at offset 0
97168e
+126 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
97168e
+qemu-img: Lost persistent bitmaps during inactivation of node 'NODE_NAME': Failed to write bitmap 'stale-bitmap-7' to file: No space left on device
97168e
+qemu-img: Lost persistent bitmaps during inactivation of node 'NODE_NAME': Failed to write bitmap 'stale-bitmap-7' to file: No space left on device
97168e
+qemu-img: Error while closing the image: Invalid argument
97168e
+qemu-img commit exit code: 1
97168e
+qemu-img bitmap --add exit code: 0
97168e
+qemu-img bitmap --merge exit code:  0
97168e
+*** done
97168e
-- 
97168e
2.37.3
97168e