diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index e71a204bfd5c902e8c03e912d7fe2d456a383af3..64a9e206d05813a2362688bd30919d009504362d 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -321,6 +321,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, qemuDomainObjPrivatePtr priv = vm->privateData; char *devstr = NULL; char *drivestr = NULL; + char *drivealias = NULL; bool releaseaddr = false; virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver); const char *src = virDomainDiskGetSource(disk); @@ -361,6 +362,9 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, if (!(drivestr = qemuBuildDriveStr(conn, disk, false, priv->qemuCaps))) goto error; + if (!(drivealias = qemuDeviceDriveHostAlias(disk, priv->qemuCaps))) + goto error; + if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps))) goto error; } @@ -375,10 +379,11 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, ret = qemuMonitorAddDevice(priv->mon, devstr); if (ret < 0) { virErrorPtr orig_err = virSaveLastError(); - if (qemuMonitorDriveDel(priv->mon, drivestr) < 0) { + if (!drivealias || + qemuMonitorDriveDel(priv->mon, drivealias) < 0) { VIR_WARN("Unable to remove drive %s (%s) after failed " "qemuMonitorAddDevice", - drivestr, devstr); + NULLSTR(drivealias), drivestr); } if (orig_err) { virSetError(orig_err); @@ -411,6 +416,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn, cleanup: VIR_FREE(devstr); VIR_FREE(drivestr); + VIR_FREE(drivealias); virObjectUnref(cfg); return ret;