[libvirt] [PATCH 0/2] qemu: hotplug: Fix two issues with drives made empty by using starup policy

If a cdrom drive is emptied by 'requisite' startup policy the policy setting would not be cleared and due to a bug in qemu the cdrom image could not be changed. The first patch clears the startup policy setting and the second one fixes ejection of cdroms if --force is specified. Also I've reported the issue in qemu https://bugzilla.redhat.com/show_bug.cgi?id=1373264 Peter Krempa (2): qemu: domain: Clear startup policy for dropped removable media qemu: hotplug: Don't wait if cdrom tray is opened forcibly src/qemu/qemu_domain.c | 2 ++ src/qemu/qemu_hotplug.c | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-) -- 2.9.2

When a source image is dropped when missing due to startup policy the policy needs to be cleared since it was relevant only for the given storage source. New sources need to update it if needed. --- src/qemu/qemu_domain.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c index 7fce2fc..37b7b44 100644 --- a/src/qemu/qemu_domain.c +++ b/src/qemu/qemu_domain.c @@ -4334,6 +4334,8 @@ qemuDomainCheckRemoveOptionalDisk(virQEMUDriverPtr driver, disk->info.alias, VIR_DOMAIN_EVENT_DISK_CHANGE_MISSING_ON_START); ignore_value(virDomainDiskSetSource(disk, NULL)); + /* keeping the old startup policy would be invalid for new images */ + disk->startupPolicy = VIR_DOMAIN_STARTUP_POLICY_DEFAULT; } else { event = virDomainEventDiskChangeNewFromObj(vm, src, NULL, disk->info.alias, -- 2.9.2

Qemu always opens the tray if forced to. Skip the waiting step in such case. This also helps if qemu does not report the tray change event when opening the cdrom forcibly (the documentation says that the event will not be sent although qemu in fact does trigger it even if @force is selceted). This is a workaround for a qemu issue where qemu does not send the tray change event in some cases (after migration with empty closed locked drive) and thus renders the cdrom useless from libvirt's point of view. Partially resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1368368 --- src/qemu/qemu_hotplug.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index d13474a..48108fb 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -149,8 +149,7 @@ static int qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, virDomainObjPtr vm, virDomainDiskDefPtr disk, - const char *driveAlias, - bool force) + const char *driveAlias) { unsigned long long now; int rc; @@ -175,7 +174,7 @@ qemuHotplugWaitForTrayEject(virQEMUDriverPtr driver, /* re-issue ejection command to pop out the media */ qemuDomainObjEnterMonitor(driver, vm); - rc = qemuMonitorEjectMedia(qemuDomainGetMonitor(vm), driveAlias, force); + rc = qemuMonitorEjectMedia(qemuDomainGetMonitor(vm), driveAlias, false); if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0) return -1; @@ -238,9 +237,9 @@ qemuDomainChangeEjectableMedia(virQEMUDriverPtr driver, goto cleanup; /* If the tray is present and tray change event is supported wait for it to open. */ - if (diskPriv->tray && + if (!force && diskPriv->tray && virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_TRAY_MOVED)) { - rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias, force); + rc = qemuHotplugWaitForTrayEject(driver, vm, disk, driveAlias); if (rc < 0) goto error; } else { -- 2.9.2

On 05.09.2016 18:41, Peter Krempa wrote:
If a cdrom drive is emptied by 'requisite' startup policy the policy setting would not be cleared and due to a bug in qemu the cdrom image could not be changed.
The first patch clears the startup policy setting and the second one fixes ejection of cdroms if --force is specified.
Also I've reported the issue in qemu https://bugzilla.redhat.com/show_bug.cgi?id=1373264
Peter Krempa (2): qemu: domain: Clear startup policy for dropped removable media qemu: hotplug: Don't wait if cdrom tray is opened forcibly
src/qemu/qemu_domain.c | 2 ++ src/qemu/qemu_hotplug.c | 9 ++++----- 2 files changed, 6 insertions(+), 5 deletions(-)
ACK to both. Michal
participants (2)
-
Michal Privoznik
-
Peter Krempa