thebeanogamer / rpms / qemu-kvm

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