cryptospore / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone

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

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