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

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