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