thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

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

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