All of lore.kernel.org
 help / color / mirror / Atom feed
From: Kevin Wolf <kwolf@redhat.com>
To: qemu-block@nongnu.org
Cc: kwolf@redhat.com, stefanha@redhat.com, afaria@redhat.com,
	qemu-devel@nongnu.org
Subject: [PATCH 2/2] iotests: Add loop-accept-ro-dev test
Date: Wed, 28 Oct 2026 18:10:57 +0100	[thread overview]
Message-ID: <20261028171057.139326-3-kwolf@redhat.com> (raw)
In-Reply-To: <20261028171057.139326-1-kwolf@redhat.com>

Add a test for the accept-read-only-device option of host_device.

Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
 tests/qemu-iotests/tests/loop-accept-ro-dev   | 87 +++++++++++++++++++
 .../qemu-iotests/tests/loop-accept-ro-dev.out | 19 ++++
 2 files changed, 106 insertions(+)
 create mode 100755 tests/qemu-iotests/tests/loop-accept-ro-dev
 create mode 100644 tests/qemu-iotests/tests/loop-accept-ro-dev.out

diff --git a/tests/qemu-iotests/tests/loop-accept-ro-dev b/tests/qemu-iotests/tests/loop-accept-ro-dev
new file mode 100755
index 00000000000..83ca67a0cf0
--- /dev/null
+++ b/tests/qemu-iotests/tests/loop-accept-ro-dev
@@ -0,0 +1,87 @@
+#!/usr/bin/env bash
+# group: quick
+#
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Copyright Red Hat, Inc.
+#
+# Test the accept-read-only-device option on a loop device
+
+seq="$(basename $0)"
+echo "QA output created by $seq"
+
+status=1	# failure is the default!
+
+_cleanup() {
+    if [ -n "$loopdev" ]; then
+        sudo losetup --detach "$loopdev"
+    fi
+
+    _cleanup_test_img
+}
+
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+# get standard environment, filters and checks
+cd ..
+. ./common.rc
+. ./common.filter
+
+_supported_fmt raw
+_supported_proto file
+_supported_os Linux
+
+do_run_qemu()
+{
+    echo Testing: "$@"
+    $QEMU -nographic -qmp stdio -nodefaults "$@"
+    echo
+}
+
+run_qemu()
+{
+    echo -e '{"execute":"qmp_capabilities"}\n{"execute":"quit"}' |
+    do_run_qemu "$@" 2>&1 | _filter_testdir | _filter_qemu | _filter_qmp |
+        _filter_generated_node_ids | _filter_imgfmt |
+        _filter_actual_image_size | _filter_img_info
+}
+
+if ! sudo -n losetup &>/dev/null; then
+    _notrun "sudo losetup not available"
+fi
+
+if ! command -v blockdev >/dev/null 2>&1; then
+    _notrun "blockdev tool not available"
+fi
+
+echo
+echo "=== Start QEMU on a loop device after blockdev --setro ==="
+echo
+
+_make_test_img -f $IMGFMT 1M
+
+loopdev=$(sudo losetup --find --show "$TEST_IMG")
+if [ -z "$loopdev" ]; then
+    _fail
+fi
+
+sudo blockdev --setro "$loopdev"
+sudo chmod a+rw "$loopdev"
+
+run_qemu \
+    -blockdev host_device,node-name=disk,filename="$loopdev" \
+    -device virtio-blk,drive=disk
+
+run_qemu \
+    -blockdev host_device,node-name=disk,filename="$loopdev",accept-read-only-device=off \
+    -device virtio-blk,drive=disk
+
+run_qemu \
+    -blockdev host_device,node-name=disk,filename="$loopdev",accept-read-only-device=on \
+    -device virtio-blk,drive=disk
+
+# success, all done
+echo
+echo '*** done'
+rm -f $seq.full
+status=0
diff --git a/tests/qemu-iotests/tests/loop-accept-ro-dev.out b/tests/qemu-iotests/tests/loop-accept-ro-dev.out
new file mode 100644
index 00000000000..dbf3de9fdf6
--- /dev/null
+++ b/tests/qemu-iotests/tests/loop-accept-ro-dev.out
@@ -0,0 +1,19 @@
+QA output created by loop-accept-ro-dev
+
+=== Start QEMU on a loop device after blockdev --setro ===
+
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=1048576
+Testing: -blockdev host_device,node-name=disk,filename=/dev/loop1 -device virtio-blk,drive=disk
+QEMU_PROG: -blockdev host_device,node-name=disk,filename=/dev/loop1: The device is not writable: Permission denied
+
+Testing: -blockdev host_device,node-name=disk,filename=/dev/loop1,accept-read-only-device=off -device virtio-blk,drive=disk
+QEMU_PROG: -blockdev host_device,node-name=disk,filename=/dev/loop1,accept-read-only-device=off: The device is not writable: Permission denied
+
+Testing: -blockdev host_device,node-name=disk,filename=/dev/loop1,accept-read-only-device=on -device virtio-blk,drive=disk
+QMP_VERSION
+{"return": {}}
+{"timestamp": {"seconds":  TIMESTAMP, "microseconds":  TIMESTAMP}, "event": "SHUTDOWN", "data": {"guest": false, "reason": "host-qmp-quit"}}
+{"return": {}}
+
+
+*** done
-- 
2.56.0



  parent reply	other threads:[~2026-10-28 17:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 17:10 [PATCH 0/2] file-posix: Add 'accept-read-only-device' option Kevin Wolf
2026-10-28 17:10 ` [PATCH 1/2] " Kevin Wolf
2026-10-28 17:54   ` Eric Blake
2026-10-28 17:10 ` Kevin Wolf [this message]
2026-10-28 18:10   ` [PATCH 2/2] iotests: Add loop-accept-ro-dev test Eric Blake
2026-10-29 16:42     ` Kevin Wolf
2026-10-28 19:49 ` [PATCH 0/2] file-posix: Add 'accept-read-only-device' option Stefan Hajnoczi

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261028171057.139326-3-kwolf@redhat.com \
    --to=kwolf@redhat.com \
    --cc=afaria@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.