]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: hotplug: Properly clean up drive backend if frontend hotplug fails
authorPeter Krempa <pkrempa@redhat.com>
Fri, 11 Sep 2015 15:34:18 +0000 (17:34 +0200)
committerCole Robinson <crobinso@redhat.com>
Tue, 22 Sep 2015 00:18:05 +0000 (20:18 -0400)
Commit 8125113c added code that should remove the disk backend if the
fronted hotplug failed for any reason. The code had a bug though as it
used the disk string for unplug rather than the backend alias. Fix the
code by pre-creating an alias string and using it instead of the disk
string. In cases where qemu does not support QEMU_CAPS_DEVICE, we ignore
the unplug of the backend since we can't really create an alias in that
case.

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1262399
(cherry picked from commit 64c6695f1ad72f0a99faace5deb1caf7effa2275)

src/qemu/qemu_hotplug.c

index e71a204bfd5c902e8c03e912d7fe2d456a383af3..64a9e206d05813a2362688bd30919d009504362d 100644 (file)
@@ -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;