[checking through my old branches] On Wed, Apr 08, 2026 at 11:03:31AM +0300, Vladimir Sementsov-Ogievskiy wrote: > On 08.04.26 05:16, Eric Blake wrote: > > qemu-nbd already has the ability to wrap a read-write layer on top of > > the export of a read-only image (-s) and the ability to export an > > internal snapshot rather than the main image in a qcow2 file (-l > > SNAPID). But it gave a confusing error message when trying to mix the > > two, because the snapshot overlay created first no longer has access > > to the internal snapshots of the image being wrapped. > > > > WIth a bit of finesse, this useful scenario is now supported. > > > > https://gitlab.com/qemu-project/qemu/-/work_items/159 > > > > Signed-off-by: Eric Blake <[email protected]> > > Reviewed-by: Vladimir Sementsov-Ogievskiy <[email protected]> > > Some optional suggestions below: > > > + > > +echo > > +echo "=== Main image in snapshot mode ===" > > +echo > > + > > +nbd_server_start_unix_socket -s -f qcow2 "$TEST_IMG" > > +$QEMU_IO -c 'r -P 2 3M 1M' -c 'w -P 3 3M 1M' -f raw \ > > Maybe, add read command after write, to check write correctness. [*]
Good idea. > > > + nbd:unix:$nbd_unix_socket | _filter_qemu_io > > +nbd_server_stop > > + > > +echo > > +echo "=== Read-only snapshot access ===" > > +echo > > + > > +nbd_server_start_unix_socket -l snap -f qcow2 "$TEST_IMG" > > +$QEMU_IO -r -c 'r -P 1 3M 1M' -f raw \ > > Suggest, add write command, to check that it fails. qemu-io rejects attempts to do -c 'w ...' on a read-only connection, but it is a good idea to prove that qemu-io won't connect read-write to a read-only server. I'm queueing this patch with the following squashed in. diff --git i/tests/qemu-iotests/tests/qemu-nbd-snapshots w/tests/qemu-iotests/tests/qemu-nbd-snapshots index de405e43720..5bc7a1a5d23 100755 --- i/tests/qemu-iotests/tests/qemu-nbd-snapshots +++ w/tests/qemu-iotests/tests/qemu-nbd-snapshots @@ -45,7 +45,7 @@ echo "=== Main image in snapshot mode ===" echo nbd_server_start_unix_socket -s -f qcow2 "$TEST_IMG" -$QEMU_IO -c 'r -P 2 3M 1M' -c 'w -P 3 3M 1M' -f raw \ +$QEMU_IO -c 'r -P 2 3M 1M' -c 'w -P 3 3M 1M' -c 'r -P 3 3M 1M' -f raw \ nbd:unix:$nbd_unix_socket | _filter_qemu_io nbd_server_stop @@ -56,6 +56,9 @@ echo nbd_server_start_unix_socket -l snap -f qcow2 "$TEST_IMG" $QEMU_IO -r -c 'r -P 1 3M 1M' -f raw \ nbd:unix:$nbd_unix_socket | _filter_qemu_io +$QEMU_IO -c 'r -P 1 3M 1M' -f raw \ + nbd:unix:$nbd_unix_socket 2>&1 | _filter_qemu_io | _filter_testdir + nbd_server_stop echo @@ -63,7 +66,7 @@ echo "=== Combine -s and -l for read-write internal snapshot access ===" echo nbd_server_start_unix_socket -s -l snap -f qcow2 "$TEST_IMG" -$QEMU_IO -c 'r -P 1 3M 1M' -c 'w -P 3 3M 1M' -f raw \ +$QEMU_IO -c 'r -P 1 3M 1M' -c 'w -P 3 3M 1M' -c 'r -P 3 3M 1M' -f raw \ nbd:unix:$nbd_unix_socket | _filter_qemu_io nbd_server_stop diff --git i/tests/qemu-iotests/tests/qemu-nbd-snapshots.out w/tests/qemu-iotests/tests/qemu-nbd-snapshots.out index 6bce9d90253..47289c30f1d 100644 --- i/tests/qemu-iotests/tests/qemu-nbd-snapshots.out +++ w/tests/qemu-iotests/tests/qemu-nbd-snapshots.out @@ -14,11 +14,14 @@ read 1048576/1048576 bytes at offset 3145728 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 1048576/1048576 bytes at offset 3145728 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) === Read-only snapshot access === read 1048576/1048576 bytes at offset 3145728 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +qemu-io: can't open device nbd:unix:SOCK_DIR/qemu-nbd.sock: Could not open image: Permission denied === Combine -s and -l for read-write internal snapshot access === @@ -26,6 +29,8 @@ read 1048576/1048576 bytes at offset 3145728 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) wrote 1048576/1048576 bytes at offset 3145728 1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 1048576/1048576 bytes at offset 3145728 +1 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) === Check that original image is unchanged === -- Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
