block: fix BDRV_O_SNAPSHOT with protocols
cover block: fix BDRV_O_SNAPSHOT with protocols
Richard Jones <[email protected]> reported that BDRV_O_SNAPSHOT does not work with NBD:
/usr/bin/qemu-system-x86_64 \
[...]
-device virtio-scsi-pci,id=scsi \
-drive file=nbd:localhost:61930,snapshot=on,format=raw,id=hd0,if=none \
-device scsi-hd,drive=hd0 \
[...]gives the error:
qemu-system-x86_64: -drive file=nbd:localhost:61930,snapshot=on,format=raw,id=hd0,if=none: could not open disk image nbd:localhost:61930: No such file or directory
This series fixes the issue and adds a regression test, qemu-iotests 052. Run the test like this:
$ QEMU_PROG=... PATH=... ./check -nbd 052
If Patch 1 is not applied, the test case fails. Note that the test case is also useful with -raw or other formats.
Stefan Hajnoczi (2):
block: fix BDRV_O_SNAPSHOT protocol detection
qemu-iotests: add 052 BDRV_O_SNAPSHOT test
block.c | 9 +++---- tests/qemu-iotests/052 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/052.out | 13 ++++++++++ tests/qemu-iotests/group | 1 + 4 files changed, 78 insertions(+), 6 deletions(-) create mode 100755 tests/qemu-iotests/052 create mode 100644 tests/qemu-iotests/052.out
Signature · 1 line
1.8.1.4
PATCH 1/2 block: fix BDRV_O_SNAPSHOT protocol detection
realpath(3) is used to get an absolute path to the image file when creating a -drive snapshot=on temporary qcow2. This does not work for protocols since their filenames ("proto:foo:...") do not correspond to file system paths.
Commit 7c96d46ec245d73fd76726588409f9abe4bd5dc1 ("Let snapshot work with protocols") skipped realpath(3) for protocols. Later on the "raw" format was introduced and broke the check.
Use path_has_protocol(filename) to decide if this image uses a protocol or a filename.
--- block.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
block.c +3 -6
@@ -812,7 +812,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags,if (flags &BDRV_O_SNAPSHOT ) {BlockDriverState *bs1;int64_t total_size; -int is_protocol =0 ;BlockDriver *bdrv_qcow2;QEMUOptionParameter *options;char backing_filename[PATH_MAX ];
@@ -829,9 +828,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, } total_size =bdrv_getlength (bs1) &BDRV_SECTOR_MASK ; -if (bs1->drv && bs1->drv->protocol_name) - is_protocol =1 ; -bdrv_delete (bs1); ret =get_tmp_filename (tmp_filename,sizeof (tmp_filename));
@@ -840,11 +836,12 @@ int bdrv_open(BlockDriverState *bs, const char *filename, int flags, }/* Real path is meaningless for protocols */ -if (is_protocol) +if (path_has_protocol (filename)) {snprintf (backing_filename,sizeof (backing_filename),"%s" , filename); -else if (!realpath (filename, backing_filename)) + }else if (!realpath (filename, backing_filename)) {return -errno; + } bdrv_qcow2 =bdrv_find_format ("qcow2" ); options =parse_option_parameters ("" , bdrv_qcow2->create_options,NULL );
Signature · 1 line
1.8.1.4
PATCH 2/2 qemu-iotests: add 052 BDRV_O_SNAPSHOT test
In reply to Stefan HajnocziCheck that writes to an image opened with BDRV_O_SNAPSHOT do not modify the underlying image file.
--- tests/qemu-iotests/052 | 61 ++++++++++++++++++++++++++++++++++++++++++++++ tests/qemu-iotests/052.out | 13 ++++++++++ tests/qemu-iotests/group | 1 + 3 files changed, 75 insertions(+) create mode 100755 tests/qemu-iotests/052 create mode 100644 tests/qemu-iotests/052.out
tests/qemu-iotests/052 new file +61 -0
@@ -0,0 +1,61 @@ +#!/bin/bash +# +# Test bdrv_read/bdrv_write using BDRV_O_SNAPSHOT +# +# Copyright (C) 2013 Red Hat, Inc. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# + +# creator [email protected] + +seq=`basename $0` +echo "QA output created by $seq" + +here=`pwd` +tmp=/tmp/$$ +status=1 # failure is the default! + +_cleanup() +{ + _cleanup_test_img +} +trap "_cleanup; exit \$status" 0 1 2 3 15 + +# get standard environment, filters and checks +. ./common.rc +. ./common.filter + +_supported_fmt generic +_supported_proto generic +_supported_os Linux + + +size=128M +_make_test_img $size + +echo +echo "== reading whole image ==" +$QEMU_IO -s -c "read 0 $size" $TEST_IMG | _filter_qemu_io + +echo +echo "== writing whole image does not modify image ==" +$QEMU_IO -s -c "write -P 0xa 0 $size" $TEST_IMG | _filter_qemu_io +$QEMU_IO -c "read -P 0 0 $size" $TEST_IMG | _filter_qemu_io + +# success, all done +echo "*** done" +rm -f $seq.full +status=0
tests/qemu-iotests/052.out new file +13 -0
@@ -0,0 +1,13 @@ +QA output created by 052 +Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=134217728 + +== reading whole image == +read 134217728/134217728 bytes at offset 0 +128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) + +== writing whole image does not modify image == +wrote 134217728/134217728 bytes at offset 0 +128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +read 134217728/134217728 bytes at offset 0 +128 MiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec) +*** done
tests/qemu-iotests/group +1 -0
@@ -56,3 +56,4 @@ 047 rw auto 048 img auto quick 049 rw auto +052 rw auto backing
Signature · 1 line
1.8.1.4