]> git.proxmox.com Git - qemu.git/commitdiff
block: Print its file name if backing file opening failed
authorFam Zheng <famz@redhat.com>
Fri, 8 Nov 2013 03:26:49 +0000 (11:26 +0800)
committerKevin Wolf <kwolf@redhat.com>
Thu, 14 Nov 2013 12:09:06 +0000 (13:09 +0100)
If backing file doesn't exist, the error message is confusing and
misleading:

    $ qemu /tmp/a.qcow2
    qemu: could not open disk image /tmp/a.qcow2: Could not open file: No
    such file or directory

But...

    $ ls /tmp/a.qcow2
    /tmp/a.qcow2

    $ qemu-img info /tmp/a.qcow2
    image: /tmp/a.qcow2
    file format: qcow2
    virtual size: 8.0G (8589934592 bytes)
    disk size: 196K
    cluster_size: 65536
    backing file: /tmp/b.qcow2

Because...

    $ ls /tmp/b.qcow2
    ls: cannot access /tmp/b.qcow2: No such file or directory

This is not intuitive. It's better to have the missing file's name in
the error message. With this patch:

    $ qemu-io -c 'read 0 512' /tmp/a.qcow2
    qemu-io: can't open device /tmp/a.qcow2: Could not open backing
    file: Could not open '/stor/vm/arch.raw': No such file or directory
    no file open, try 'help open'

Which is a little bit better.

Signed-off-by: Fam Zheng <famz@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block.c
block/raw-posix.c
block/raw-win32.c
tests/qemu-iotests/051.out
tests/qemu-iotests/069.out

diff --git a/block.c b/block.c
index 6d5c80475c2b3d80f1e4641c802d2a820c06724b..38078f7cd548dda2dc34b611cb0d13a124145811 100644 (file)
--- a/block.c
+++ b/block.c
@@ -1009,7 +1009,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
         bdrv_unref(bs->backing_hd);
         bs->backing_hd = NULL;
         bs->open_flags |= BDRV_O_NO_BACKING;
-        error_propagate(errp, local_err);
+        error_setg(errp, "Could not open backing file: %s",
+                   error_get_pretty(local_err));
+        error_free(local_err);
         return ret;
     }
     pstrcpy(bs->backing_file, sizeof(bs->backing_file),
index ace5d962e8eb77206b69b898e7f87e748676a688..f836c8e745c4c37631ca50c11b98e3ecadc1708d 100644 (file)
@@ -310,7 +310,6 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
         if (ret == -EROFS) {
             ret = -EACCES;
         }
-        error_setg_errno(errp, -ret, "Could not open file");
         goto fail;
     }
     s->fd = fd;
index 2741e4de10b9989ca916bfe90357680c2f4fbf54..2bad5a39b4f7f5ccf78596bfb0fc5bac9911280c 100644 (file)
@@ -280,7 +280,6 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
         } else {
             ret = -EINVAL;
         }
-        error_setg_errno(errp, -ret, "Could not open file");
         goto fail;
     }
 
index 15deef6dc391811dcb105ecc4c3a16c381d93449..d351935383096bac2c82827038a95e2f0c18de74 100644 (file)
@@ -226,6 +226,6 @@ Testing: -drive file=foo:bar
 QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown protocol
 
 Testing: -drive file.filename=foo:bar
-QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open file: No such file or directory
+QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open 'foo:bar': No such file or directory
 
 *** done
index 364881429cc4670552eb86ab01208da65d8e0adf..b48306d5ab844cc4bdff55015ff0ba731d80172a 100644 (file)
@@ -4,5 +4,5 @@ QA output created by 069
 
 Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=131072 
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072 backing_file='TEST_DIR/t.IMGFMT.base' 
-qemu-io: can't open device TEST_DIR/t.IMGFMT: Could not open file: No such file or directory
+qemu-io: can't open device TEST_DIR/t.IMGFMT: Could not open backing file: Could not open 'TEST_DIR/t.IMGFMT.base': No such file or directory
 *** done