qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols
@ 2013-03-18 16:58 Stefan Hajnoczi
  2013-03-18 16:58 ` [Qemu-devel] [PATCH v2 1/2] block: fix BDRV_O_SNAPSHOT protocol detection Stefan Hajnoczi
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2013-03-18 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, rjones, Stefan Hajnoczi

Richard Jones <rjones@redhat.com> 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.

v2:
 * Rebased onto latest qemu.git/master

Stefan Hajnoczi (2):
  block: fix BDRV_O_SNAPSHOT protocol detection
  qemu-iotests: add 052 BDRV_O_SNAPSHOT test

 block.c                    |  6 +----
 tests/qemu-iotests/052     | 61 ++++++++++++++++++++++++++++++++++++++++++++++
 tests/qemu-iotests/052.out | 13 ++++++++++
 tests/qemu-iotests/group   |  1 +
 4 files changed, 76 insertions(+), 5 deletions(-)
 create mode 100755 tests/qemu-iotests/052
 create mode 100644 tests/qemu-iotests/052.out

-- 
1.8.1.4

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v2 1/2] block: fix BDRV_O_SNAPSHOT protocol detection
  2013-03-18 16:58 [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Stefan Hajnoczi
@ 2013-03-18 16:58 ` Stefan Hajnoczi
  2013-03-18 16:58 ` [Qemu-devel] [PATCH v2 2/2] qemu-iotests: add 052 BDRV_O_SNAPSHOT test Stefan Hajnoczi
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2013-03-18 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, rjones, Stefan Hajnoczi

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.

Reported-by: Richard Jones <rjones@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 block.c | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/block.c b/block.c
index 037e15e..0a062c9 100644
--- a/block.c
+++ b/block.c
@@ -830,7 +830,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
     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];
@@ -847,9 +846,6 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
         }
         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));
@@ -858,7 +854,7 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
         }
 
         /* 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)) {
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [Qemu-devel] [PATCH v2 2/2] qemu-iotests: add 052 BDRV_O_SNAPSHOT test
  2013-03-18 16:58 [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Stefan Hajnoczi
  2013-03-18 16:58 ` [Qemu-devel] [PATCH v2 1/2] block: fix BDRV_O_SNAPSHOT protocol detection Stefan Hajnoczi
@ 2013-03-18 16:58 ` Stefan Hajnoczi
  2013-03-18 17:10 ` [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Kevin Wolf
  2013-03-19  6:16 ` Michael Tokarev
  3 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2013-03-18 16:58 UTC (permalink / raw)
  To: qemu-devel; +Cc: Kevin Wolf, rjones, Stefan Hajnoczi

Check that writes to an image opened with BDRV_O_SNAPSHOT do not modify
the underlying image file.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
---
 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

diff --git a/tests/qemu-iotests/052 b/tests/qemu-iotests/052
new file mode 100755
index 0000000..14a5126
--- /dev/null
+++ b/tests/qemu-iotests/052
@@ -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
+owner=stefanha@redhat.com
+
+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
diff --git a/tests/qemu-iotests/052.out b/tests/qemu-iotests/052.out
new file mode 100644
index 0000000..8617aa2
--- /dev/null
+++ b/tests/qemu-iotests/052.out
@@ -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
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
index 1d7e4f3..73c5966 100644
--- a/tests/qemu-iotests/group
+++ b/tests/qemu-iotests/group
@@ -57,3 +57,4 @@
 048 img auto quick
 049 rw auto
 050 rw auto backing quick
+052 rw auto backing
-- 
1.8.1.4

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols
  2013-03-18 16:58 [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Stefan Hajnoczi
  2013-03-18 16:58 ` [Qemu-devel] [PATCH v2 1/2] block: fix BDRV_O_SNAPSHOT protocol detection Stefan Hajnoczi
  2013-03-18 16:58 ` [Qemu-devel] [PATCH v2 2/2] qemu-iotests: add 052 BDRV_O_SNAPSHOT test Stefan Hajnoczi
@ 2013-03-18 17:10 ` Kevin Wolf
  2013-03-19  6:16 ` Michael Tokarev
  3 siblings, 0 replies; 6+ messages in thread
From: Kevin Wolf @ 2013-03-18 17:10 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: qemu-devel, rjones

Am 18.03.2013 um 17:58 hat Stefan Hajnoczi geschrieben:
> Richard Jones <rjones@redhat.com> 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.
> 
> v2:
>  * Rebased onto latest qemu.git/master

Thanks, applied all to the block branch.

Kevin

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols
  2013-03-18 16:58 [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Stefan Hajnoczi
                   ` (2 preceding siblings ...)
  2013-03-18 17:10 ` [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Kevin Wolf
@ 2013-03-19  6:16 ` Michael Tokarev
  2013-03-19  8:48   ` Stefan Hajnoczi
  3 siblings, 1 reply; 6+ messages in thread
From: Michael Tokarev @ 2013-03-19  6:16 UTC (permalink / raw)
  To: Stefan Hajnoczi; +Cc: Kevin Wolf, qemu-devel

18.03.2013 20:58, Stefan Hajnoczi wrote:
> Richard Jones <rjones@redhat.com> reported that BDRV_O_SNAPSHOT does not work
> with NBD:

Heh.  http://permalink.gmane.org/gmane.comp.emulators.qemu/148390

(nothing's wrong with the patchset, just saying ;)

/mjt

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols
  2013-03-19  6:16 ` Michael Tokarev
@ 2013-03-19  8:48   ` Stefan Hajnoczi
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Hajnoczi @ 2013-03-19  8:48 UTC (permalink / raw)
  To: Michael Tokarev; +Cc: Kevin Wolf, qemu-devel

On Tue, Mar 19, 2013 at 10:16:41AM +0400, Michael Tokarev wrote:
> 18.03.2013 20:58, Stefan Hajnoczi wrote:
> > Richard Jones <rjones@redhat.com> reported that BDRV_O_SNAPSHOT does not work
> > with NBD:
> 
> Heh.  http://permalink.gmane.org/gmane.comp.emulators.qemu/148390
> 
> (nothing's wrong with the patchset, just saying ;)

Sorry, that wasn't intentional.  Richard included your link in his bug
report but I didn't follow it since the scope of the bug seemed clear
enough.

Stefan

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-03-19  8:48 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-18 16:58 [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Stefan Hajnoczi
2013-03-18 16:58 ` [Qemu-devel] [PATCH v2 1/2] block: fix BDRV_O_SNAPSHOT protocol detection Stefan Hajnoczi
2013-03-18 16:58 ` [Qemu-devel] [PATCH v2 2/2] qemu-iotests: add 052 BDRV_O_SNAPSHOT test Stefan Hajnoczi
2013-03-18 17:10 ` [Qemu-devel] [PATCH v2 0/2] block: fix BDRV_O_SNAPSHOT with protocols Kevin Wolf
2013-03-19  6:16 ` Michael Tokarev
2013-03-19  8:48   ` Stefan Hajnoczi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).