edecca
From 47660a5a575b406cfe09ad0f7fae56a7ae429c6c Mon Sep 17 00:00:00 2001
edecca
Message-Id: <47660a5a575b406cfe09ad0f7fae56a7ae429c6c@dist-git>
edecca
From: Peter Krempa <pkrempa@redhat.com>
edecca
Date: Mon, 21 Jan 2019 18:43:13 +0100
edecca
Subject: [PATCH] qemu: command: Don't format image properties for empty -drive
edecca
MIME-Version: 1.0
edecca
Content-Type: text/plain; charset=UTF-8
edecca
Content-Transfer-Encoding: 8bit
edecca
edecca
If a -drive has no image, using image properties makes qemu whine that
edecca
they should not be used.
edecca
edecca
This patch stops formating cache/readonly/... for empty drives
edecca
for the pre-blockdev syntax. Unfortunately those parameters can't be
edecca
added later when inserting media, but on the other hand qemu will start
edecca
with an empty drive.
edecca
edecca
Since we already were able to start a VM with such config previously due
edecca
to qemu ignoring them I've opted just to skip formatting them.
edecca
Additionally with -blockdev support it will work as expected as the
edecca
image properties will be formatted when adding the image itself which is
edecca
not possible without it.
edecca
edecca
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1651457
edecca
edecca
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
edecca
(cherry picked from commit f80eae8c2ae0c62ecaa550ab6353cf871bb17d4e)
edecca
edecca
https://bugzilla.redhat.com/show_bug.cgi?id=1553255
edecca
edecca
 Conflicts:
edecca
	src/qemu/qemu_command.c
edecca
	tests/qemuxml2argvdata/disk-cdrom.args
edecca
            - context: bootindex not yet assumed, 'boot=on' code still
edecca
            present
edecca
	tests/qemuxml2argvdata/disk-cdrom.x86_64-2.12.0.args
edecca
	tests/qemuxml2argvdata/disk-cdrom.x86_64-latest.args
edecca
            - missing refactor to capability file based tests
edecca
edecca
Reviewed-by: Ján Tomko <jtomko@redhat.com>
edecca
---
edecca
 src/qemu/qemu_command.c                      | 55 ++++++++++----------
edecca
 tests/qemuxml2argvdata/disk-cdrom-empty.args |  2 +-
edecca
 tests/qemuxml2argvdata/disk-cdrom.args       |  2 +-
edecca
 3 files changed, 30 insertions(+), 29 deletions(-)
edecca
edecca
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
edecca
index c706a4b095..e153c011f6 100644
edecca
--- a/src/qemu/qemu_command.c
edecca
+++ b/src/qemu/qemu_command.c
edecca
@@ -1695,37 +1695,38 @@ qemuBuildDriveStr(virDomainDiskDefPtr disk,
edecca
         disk->bus != VIR_DOMAIN_DISK_BUS_IDE)
edecca
         virBufferAddLit(&opt, ",boot=on");
edecca
 
edecca
-    if (disk->src->readonly)
edecca
-        virBufferAddLit(&opt, ",readonly=on");
edecca
+    if (!virStorageSourceIsEmpty(disk->src)) {
edecca
+        if (disk->src->readonly)
edecca
+            virBufferAddLit(&opt, ",readonly=on");
edecca
 
edecca
+        if (disk->cachemode) {
edecca
+            virBufferAsprintf(&opt, ",cache=%s",
edecca
+                              qemuDiskCacheV2TypeToString(disk->cachemode));
edecca
+        }
edecca
 
edecca
-    if (disk->cachemode) {
edecca
-        virBufferAsprintf(&opt, ",cache=%s",
edecca
-                          qemuDiskCacheV2TypeToString(disk->cachemode));
edecca
+        if (disk->copy_on_read) {
edecca
+            virBufferAsprintf(&opt, ",copy-on-read=%s",
edecca
+                              virTristateSwitchTypeToString(disk->copy_on_read));
edecca
+        }
edecca
+
edecca
+        if (disk->discard) {
edecca
+            virBufferAsprintf(&opt, ",discard=%s",
edecca
+                              virDomainDiskDiscardTypeToString(disk->discard));
edecca
+        }
edecca
+
edecca
+        if (detect_zeroes) {
edecca
+            virBufferAsprintf(&opt, ",detect-zeroes=%s",
edecca
+                              virDomainDiskDetectZeroesTypeToString(detect_zeroes));
edecca
+        }
edecca
+
edecca
+        if (disk->iomode) {
edecca
+            virBufferAsprintf(&opt, ",aio=%s",
edecca
+                              virDomainDiskIoTypeToString(disk->iomode));
edecca
+        }
edecca
+
edecca
+        qemuBuildDiskThrottling(disk, &opt;;
edecca
     }
edecca
 
edecca
-    if (disk->copy_on_read) {
edecca
-        virBufferAsprintf(&opt, ",copy-on-read=%s",
edecca
-                          virTristateSwitchTypeToString(disk->copy_on_read));
edecca
-    }
edecca
-
edecca
-    if (disk->discard) {
edecca
-        virBufferAsprintf(&opt, ",discard=%s",
edecca
-                          virDomainDiskDiscardTypeToString(disk->discard));
edecca
-    }
edecca
-
edecca
-    if (detect_zeroes) {
edecca
-        virBufferAsprintf(&opt, ",detect-zeroes=%s",
edecca
-                          virDomainDiskDetectZeroesTypeToString(detect_zeroes));
edecca
-    }
edecca
-
edecca
-    if (disk->iomode) {
edecca
-        virBufferAsprintf(&opt, ",aio=%s",
edecca
-                          virDomainDiskIoTypeToString(disk->iomode));
edecca
-    }
edecca
-
edecca
-    qemuBuildDiskThrottling(disk, &opt;;
edecca
-
edecca
     if (virBufferCheckError(&opt) < 0)
edecca
         goto error;
edecca
 
edecca
diff --git a/tests/qemuxml2argvdata/disk-cdrom-empty.args b/tests/qemuxml2argvdata/disk-cdrom-empty.args
edecca
index 1cbc76ab86..b84bdda143 100644
edecca
--- a/tests/qemuxml2argvdata/disk-cdrom-empty.args
edecca
+++ b/tests/qemuxml2argvdata/disk-cdrom-empty.args
edecca
@@ -24,5 +24,5 @@ server,nowait \
edecca
 -usb \
edecca
 -drive file=/dev/HostVG/QEMUGuest1,format=raw,if=none,id=drive-ide0-0-0 \
edecca
 -device ide-drive,bus=ide.0,unit=0,drive=drive-ide0-0-0,id=ide0-0-0 \
edecca
--drive if=none,id=drive-ide0-1-0,media=cdrom,readonly=on \
edecca
+-drive if=none,id=drive-ide0-1-0,media=cdrom \
edecca
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
edecca
diff --git a/tests/qemuxml2argvdata/disk-cdrom.args b/tests/qemuxml2argvdata/disk-cdrom.args
edecca
index 547263cbd8..f519ea5236 100644
edecca
--- a/tests/qemuxml2argvdata/disk-cdrom.args
edecca
+++ b/tests/qemuxml2argvdata/disk-cdrom.args
edecca
@@ -27,5 +27,5 @@ server,nowait \
edecca
 -drive file=/root/boot.iso,format=raw,if=none,id=drive-ide0-0-1,media=cdrom,\
edecca
 readonly=on \
edecca
 -device ide-drive,bus=ide.0,unit=1,drive=drive-ide0-0-1,id=ide0-0-1 \
edecca
--drive if=none,id=drive-ide0-1-0,media=cdrom,readonly=on,cache=none \
edecca
+-drive if=none,id=drive-ide0-1-0,media=cdrom \
edecca
 -device ide-drive,bus=ide.1,unit=0,drive=drive-ide0-1-0,id=ide0-1-0
edecca
-- 
edecca
2.20.1
edecca