05bba0
From 82023923707c148ddd91eb3ac18fc9befc4288d5 Mon Sep 17 00:00:00 2001
05bba0
From: Max Reitz <mreitz@redhat.com>
05bba0
Date: Wed, 22 Jul 2015 16:24:55 +0200
05bba0
Subject: [PATCH 3/5] block: Print its file name if backing file opening failed
05bba0
05bba0
Message-id: <1437582297-9244-2-git-send-email-mreitz@redhat.com>
05bba0
Patchwork-id: 67106
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 1/3] block: Print its file name if backing file opening failed
05bba0
Bugzilla: 1238639
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
RH-Acked-by: Kevin Wolf <kwolf@redhat.com>
05bba0
RH-Acked-by: Fam Zheng <famz@redhat.com>
05bba0
05bba0
From: Fam Zheng <famz@redhat.com>
05bba0
05bba0
If backing file doesn't exist, the error message is confusing and
05bba0
misleading:
05bba0
05bba0
    $ qemu /tmp/a.qcow2
05bba0
    qemu: could not open disk image /tmp/a.qcow2: Could not open file: No
05bba0
    such file or directory
05bba0
05bba0
But...
05bba0
05bba0
    $ ls /tmp/a.qcow2
05bba0
    /tmp/a.qcow2
05bba0
05bba0
    $ qemu-img info /tmp/a.qcow2
05bba0
    image: /tmp/a.qcow2
05bba0
    file format: qcow2
05bba0
    virtual size: 8.0G (8589934592 bytes)
05bba0
    disk size: 196K
05bba0
    cluster_size: 65536
05bba0
    backing file: /tmp/b.qcow2
05bba0
05bba0
Because...
05bba0
05bba0
    $ ls /tmp/b.qcow2
05bba0
    ls: cannot access /tmp/b.qcow2: No such file or directory
05bba0
05bba0
This is not intuitive. It's better to have the missing file's name in
05bba0
the error message. With this patch:
05bba0
05bba0
    $ qemu-io -c 'read 0 512' /tmp/a.qcow2
05bba0
    qemu-io: can't open device /tmp/a.qcow2: Could not open backing
05bba0
    file: Could not open '/stor/vm/arch.raw': No such file or directory
05bba0
    no file open, try 'help open'
05bba0
05bba0
Which is a little bit better.
05bba0
05bba0
Signed-off-by: Fam Zheng <famz@redhat.com>
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
(cherry picked from commit b04b6b6ec3a1e0ba90c2f58617286d9fc35fa372)
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
05bba0
Conflicts:
05bba0
	tests/qemu-iotests/082.out
05bba0
	tests/qemu-iotests/114.out
05bba0
05bba0
When both tests were introduced downstream
05bba0
(6b1816a687831a1622637ed10605759d9e90aa9c and
05bba0
a0f50f0877463e9370ffa411bd826d7c704ab9fe, respectively), they were
05bba0
modified from upstream because this patch had not been backported. These
05bba0
changes are now reverted.
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
---
05bba0
 block.c                    | 4 +++-
05bba0
 block/raw-posix.c          | 1 -
05bba0
 block/raw-win32.c          | 1 -
05bba0
 tests/qemu-iotests/051.out | 2 +-
05bba0
 tests/qemu-iotests/069.out | 2 +-
05bba0
 tests/qemu-iotests/082.out | 4 ++--
05bba0
 tests/qemu-iotests/114.out | 2 +-
05bba0
 7 files changed, 8 insertions(+), 8 deletions(-)
05bba0
05bba0
diff --git a/block.c b/block.c
05bba0
index e36fa2f..dedfa52 100644
05bba0
--- a/block.c
05bba0
+++ b/block.c
05bba0
@@ -1050,7 +1050,9 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
05bba0
         bdrv_unref(bs->backing_hd);
05bba0
         bs->backing_hd = NULL;
05bba0
         bs->open_flags |= BDRV_O_NO_BACKING;
05bba0
-        error_propagate(errp, local_err);
05bba0
+        error_setg(errp, "Could not open backing file: %s",
05bba0
+                   error_get_pretty(local_err));
05bba0
+        error_free(local_err);
05bba0
         return ret;
05bba0
     }
05bba0
 
05bba0
diff --git a/block/raw-posix.c b/block/raw-posix.c
05bba0
index 46b941b..72a9dc0 100644
05bba0
--- a/block/raw-posix.c
05bba0
+++ b/block/raw-posix.c
05bba0
@@ -388,7 +388,6 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
05bba0
         if (ret == -EROFS) {
05bba0
             ret = -EACCES;
05bba0
         }
05bba0
-        error_setg_errno(errp, -ret, "Could not open file");
05bba0
         goto fail;
05bba0
     }
05bba0
     s->fd = fd;
05bba0
diff --git a/block/raw-win32.c b/block/raw-win32.c
05bba0
index ac20370..bb6dc6a 100644
05bba0
--- a/block/raw-win32.c
05bba0
+++ b/block/raw-win32.c
05bba0
@@ -319,7 +319,6 @@ static int raw_open(BlockDriverState *bs, QDict *options, int flags,
05bba0
         } else {
05bba0
             ret = -EINVAL;
05bba0
         }
05bba0
-        error_setg_errno(errp, -ret, "Could not open file");
05bba0
         goto fail;
05bba0
     }
05bba0
 
05bba0
diff --git a/tests/qemu-iotests/051.out b/tests/qemu-iotests/051.out
05bba0
index 4fca1ca..32c94e5 100644
05bba0
--- a/tests/qemu-iotests/051.out
05bba0
+++ b/tests/qemu-iotests/051.out
05bba0
@@ -169,6 +169,6 @@ Testing: -drive file=foo:bar
05bba0
 QEMU_PROG: -drive file=foo:bar: could not open disk image foo:bar: Unknown protocol
05bba0
 
05bba0
 Testing: -drive file.filename=foo:bar
05bba0
-QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open file: No such file or directory
05bba0
+QEMU_PROG: -drive file.filename=foo:bar: could not open disk image ide0-hd0: Could not open 'foo:bar': No such file or directory
05bba0
 
05bba0
 *** done
05bba0
diff --git a/tests/qemu-iotests/069.out b/tests/qemu-iotests/069.out
05bba0
index 3648814..b48306d 100644
05bba0
--- a/tests/qemu-iotests/069.out
05bba0
+++ b/tests/qemu-iotests/069.out
05bba0
@@ -4,5 +4,5 @@ QA output created by 069
05bba0
 
05bba0
 Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=131072 
05bba0
 Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=131072 backing_file='TEST_DIR/t.IMGFMT.base' 
05bba0
-qemu-io: can't open device TEST_DIR/t.IMGFMT: Could not open file: No such file or directory
05bba0
+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
05bba0
 *** done
05bba0
diff --git a/tests/qemu-iotests/082.out b/tests/qemu-iotests/082.out
05bba0
index 8abfde7..41324d5 100644
05bba0
--- a/tests/qemu-iotests/082.out
05bba0
+++ b/tests/qemu-iotests/082.out
05bba0
@@ -326,10 +326,10 @@ preallocation    Preallocation mode (allowed values: off, metadata, falloc, full
05bba0
 lazy_refcounts   Postpone refcount updates
05bba0
 
05bba0
 Testing: convert -O qcow2 -o backing_file=TEST_DIR/t.qcow2,,help TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base
05bba0
-qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open file: No such file or directory
05bba0
+qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open backing file: Could not open 'TEST_DIR/t.qcow2,help': No such file or directory
05bba0
 
05bba0
 Testing: convert -O qcow2 -o backing_file=TEST_DIR/t.qcow2,,? TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base
05bba0
-qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open file: No such file or directory
05bba0
+qemu-img: Could not open 'TEST_DIR/t.qcow2.base': Could not open backing file: Could not open 'TEST_DIR/t.qcow2,?': No such file or directory
05bba0
 
05bba0
 Testing: convert -O qcow2 -o backing_file=TEST_DIR/t.qcow2, -o help TEST_DIR/t.qcow2 TEST_DIR/t.qcow2.base
05bba0
 qemu-img: Invalid option list: backing_file=TEST_DIR/t.qcow2,
05bba0
diff --git a/tests/qemu-iotests/114.out b/tests/qemu-iotests/114.out
05bba0
index de8f529..6c6b210 100644
05bba0
--- a/tests/qemu-iotests/114.out
05bba0
+++ b/tests/qemu-iotests/114.out
05bba0
@@ -7,7 +7,7 @@ virtual size: 64M (67108864 bytes)
05bba0
 cluster_size: 65536
05bba0
 backing file: TEST_DIR/t.IMGFMT.base
05bba0
 backing file format: foo
05bba0
-qemu-io: can't open device TEST_DIR/t.qcow2: Unknown driver 'foo'
05bba0
+qemu-io: can't open device TEST_DIR/t.qcow2: Could not open backing file: Unknown driver 'foo'
05bba0
 read 4096/4096 bytes at offset 0
05bba0
 4 KiB, X ops; XX:XX:XX.X (XXX YYY/sec and XXX ops/sec)
05bba0
 *** done
05bba0
-- 
05bba0
1.8.3.1
05bba0