thebeanogamer / rpms / qemu-kvm

Forked from rpms/qemu-kvm 5 months ago
Clone

Blame SOURCES/kvm-block-Don-t-probe-for-unknown-backing-file-format.patch

05bba0
From a0f50f0877463e9370ffa411bd826d7c704ab9fe Mon Sep 17 00:00:00 2001
05bba0
From: Max Reitz <mreitz@redhat.com>
05bba0
Date: Sat, 13 Jun 2015 16:22:30 +0200
05bba0
Subject: [PATCH 36/42] block: Don't probe for unknown backing file format
05bba0
05bba0
Message-id: <1434212556-3927-37-git-send-email-mreitz@redhat.com>
05bba0
Patchwork-id: 66055
05bba0
O-Subject: [RHEL-7.2 qemu-kvm PATCH 36/42] block: Don't probe for unknown backing file format
05bba0
Bugzilla: 1129893
05bba0
RH-Acked-by: Jeffrey Cody <jcody@redhat.com>
05bba0
RH-Acked-by: Fam Zheng <famz@redhat.com>
05bba0
RH-Acked-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
05bba0
From: Kevin Wolf <kwolf@redhat.com>
05bba0
05bba0
BZ: 1129893
05bba0
05bba0
If a qcow2 image specifies a backing file format that doesn't correspond
05bba0
to any format driver that qemu knows, we shouldn't fall back to probing,
05bba0
but simply error out.
05bba0
05bba0
Not looking up the backing file driver in bdrv_open_backing_file(), but
05bba0
just filling in the "driver" option if it isn't there moves us closer to
05bba0
the goal of having everything in QDict options and gets us the error
05bba0
handling of bdrv_open(), which correctly refuses unknown drivers.
05bba0
05bba0
Cc: qemu-stable@nongnu.org
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
Reviewed-by: Max Reitz <mreitz@redhat.com>
05bba0
Message-id: 1416935562-7760-4-git-send-email-kwolf@redhat.com
05bba0
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
05bba0
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
05bba0
(cherry picked from commit c5f6e493bb5339d244eae5d3f21c5b6d73996739)
05bba0
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
05bba0
05bba0
Conflicts:
05bba0
	block.c
05bba0
	tests/qemu-iotests/114.out
05bba0
05bba0
Downstream is missing a check whether the driver specified by the
05bba0
"driver" option is actually valid (if it is not, it will be probed
05bba0
anyway); this check is introduced upstream by
05bba0
17b005f1d422d4581f8ce95b75d603deb081f4f3, but that commit has a couple
05bba0
of dependencies and relies on a code path that is very different from
05bba0
downstream (e.g. not bdrv_file_open() anymore). So I just introduced the
05bba0
check in this patch.
05bba0
05bba0
Also, the different code paths upstream and downstream result in the
05bba0
error message missing the "Could not open backing file:" part, which
05bba0
means that 114.out has to be fixed up.
05bba0
05bba0
Signed-off-by: Max Reitz <mreitz@redhat.com>
05bba0
---
05bba0
 block.c                    | 12 ++++++---
05bba0
 tests/qemu-iotests/114     | 61 ++++++++++++++++++++++++++++++++++++++++++++++
05bba0
 tests/qemu-iotests/114.out | 13 ++++++++++
05bba0
 tests/qemu-iotests/group   |  1 +
05bba0
 4 files changed, 83 insertions(+), 4 deletions(-)
05bba0
 create mode 100755 tests/qemu-iotests/114
05bba0
 create mode 100644 tests/qemu-iotests/114.out
05bba0
05bba0
diff --git a/block.c b/block.c
05bba0
index fa6e192..e36fa2f 100644
05bba0
--- a/block.c
05bba0
+++ b/block.c
05bba0
@@ -1010,7 +1010,6 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
05bba0
 {
05bba0
     char backing_filename[PATH_MAX];
05bba0
     int back_flags, ret;
05bba0
-    BlockDriver *back_drv = NULL;
05bba0
     Error *local_err = NULL;
05bba0
 
05bba0
     if (bs->backing_hd != NULL) {
05bba0
@@ -1036,8 +1035,8 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
05bba0
 
05bba0
     bs->backing_hd = bdrv_new("", &error_abort);
05bba0
 
05bba0
-    if (bs->backing_format[0] != '\0') {
05bba0
-        back_drv = bdrv_find_format(bs->backing_format);
05bba0
+    if (bs->backing_format[0] != '\0' && !qdict_haskey(options, "driver")) {
05bba0
+        qdict_put(options, "driver", qstring_from_str(bs->backing_format));
05bba0
     }
05bba0
 
05bba0
     /* backing files always opened read-only */
05bba0
@@ -1046,7 +1045,7 @@ int bdrv_open_backing_file(BlockDriverState *bs, QDict *options, Error **errp)
05bba0
 
05bba0
     ret = bdrv_open(bs->backing_hd,
05bba0
                     *backing_filename ? backing_filename : NULL, options,
05bba0
-                    back_flags, back_drv, &local_err);
05bba0
+                    back_flags, NULL, &local_err);
05bba0
     if (ret < 0) {
05bba0
         bdrv_unref(bs->backing_hd);
05bba0
         bs->backing_hd = NULL;
05bba0
@@ -1244,6 +1243,11 @@ int bdrv_open(BlockDriverState *bs, const char *filename, QDict *options,
05bba0
     if (drvname) {
05bba0
         drv = bdrv_find_format(drvname);
05bba0
         qdict_del(options, "driver");
05bba0
+        if (!drv) {
05bba0
+            error_setg(errp, "Unknown driver '%s'", drvname);
05bba0
+            ret = -EINVAL;
05bba0
+            goto unlink_and_fail;
05bba0
+        }
05bba0
     }
05bba0
 
05bba0
     if (!drv) {
05bba0
diff --git a/tests/qemu-iotests/114 b/tests/qemu-iotests/114
05bba0
new file mode 100755
05bba0
index 0000000..d02e7ff
05bba0
--- /dev/null
05bba0
+++ b/tests/qemu-iotests/114
05bba0
@@ -0,0 +1,61 @@
05bba0
+#!/bin/bash
05bba0
+#
05bba0
+# Test invalid backing file format in qcow2 images
05bba0
+#
05bba0
+# Copyright (C) 2014 Red Hat, Inc.
05bba0
+#
05bba0
+# This program is free software; you can redistribute it and/or modify
05bba0
+# it under the terms of the GNU General Public License as published by
05bba0
+# the Free Software Foundation; either version 2 of the License, or
05bba0
+# (at your option) any later version.
05bba0
+#
05bba0
+# This program is distributed in the hope that it will be useful,
05bba0
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
05bba0
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
05bba0
+# GNU General Public License for more details.
05bba0
+#
05bba0
+# You should have received a copy of the GNU General Public License
05bba0
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
05bba0
+#
05bba0
+
05bba0
+# creator
05bba0
+owner=kwolf@redhat.com
05bba0
+
05bba0
+seq="$(basename $0)"
05bba0
+echo "QA output created by $seq"
05bba0
+
05bba0
+here="$PWD"
05bba0
+tmp=/tmp/$$
05bba0
+status=1	# failure is the default!
05bba0
+
05bba0
+_cleanup()
05bba0
+{
05bba0
+	_cleanup_test_img
05bba0
+}
05bba0
+trap "_cleanup; exit \$status" 0 1 2 3 15
05bba0
+
05bba0
+# get standard environment, filters and checks
05bba0
+. ./common.rc
05bba0
+. ./common.filter
05bba0
+
05bba0
+_supported_fmt qcow2
05bba0
+_supported_proto generic
05bba0
+_supported_os Linux
05bba0
+
05bba0
+
05bba0
+TEST_IMG="$TEST_IMG.base" _make_test_img 64M
05bba0
+_make_test_img -b "$TEST_IMG.base" 64M
05bba0
+
05bba0
+# Set an invalid backing file format
05bba0
+$PYTHON qcow2.py "$TEST_IMG" add-header-ext 0xE2792ACA "foo"
05bba0
+_img_info
05bba0
+
05bba0
+# Try opening the image. Should fail (and not probe) in the first case, but
05bba0
+# overriding the backing file format should be possible.
05bba0
+$QEMU_IO -c "open $TEST_IMG" -c "read 0 4k" 2>&1 | _filter_qemu_io | _filter_testdir
05bba0
+$QEMU_IO -c "open -o backing.driver=$IMGFMT $TEST_IMG" -c "read 0 4k" | _filter_qemu_io
05bba0
+
05bba0
+# success, all done
05bba0
+echo '*** done'
05bba0
+rm -f $seq.full
05bba0
+status=0
05bba0
diff --git a/tests/qemu-iotests/114.out b/tests/qemu-iotests/114.out
05bba0
new file mode 100644
05bba0
index 0000000..de8f529
05bba0
--- /dev/null
05bba0
+++ b/tests/qemu-iotests/114.out
05bba0
@@ -0,0 +1,13 @@
05bba0
+QA output created by 114
05bba0
+Formatting 'TEST_DIR/t.IMGFMT.base', fmt=IMGFMT size=67108864 
05bba0
+Formatting 'TEST_DIR/t.IMGFMT', fmt=IMGFMT size=67108864 backing_file='TEST_DIR/t.IMGFMT.base' 
05bba0
+image: TEST_DIR/t.IMGFMT
05bba0
+file format: IMGFMT
05bba0
+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
+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
diff --git a/tests/qemu-iotests/group b/tests/qemu-iotests/group
05bba0
index 695ab02..5867cf7 100644
05bba0
--- a/tests/qemu-iotests/group
05bba0
+++ b/tests/qemu-iotests/group
05bba0
@@ -88,3 +88,4 @@
05bba0
 105 rw auto quick
05bba0
 107 rw auto quick
05bba0
 108 rw auto quick
05bba0
+114 rw auto quick
05bba0
-- 
05bba0
1.8.3.1
05bba0