thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-Print-its-file-name-if-backing-file-opening-fa.patch

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