]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
qemu: Fix failure path in disk hotplug
authorJiri Denemark <jdenemar@redhat.com>
Thu, 20 Sep 2012 20:28:35 +0000 (22:28 +0200)
committerJiri Denemark <jdenemar@redhat.com>
Fri, 21 Sep 2012 10:23:01 +0000 (12:23 +0200)
Disk hotplug is a two phase action: qemuMonitorAddDrive followed by
qemuMonitorAddDevice. When the first part succeeds but the second one
fails, we need to rollback the drive addition.

src/qemu/qemu_hotplug.c

index 4cd83fdf3f0543f86132e34d4a3099b282694048..bcf3081a07d7e87ad684d1c61cab92025a765177 100644 (file)
@@ -252,10 +252,16 @@ int qemuDomainAttachPciDiskDevice(virConnectPtr conn,
         if (ret == 0) {
             ret = qemuMonitorAddDevice(priv->mon, devstr);
             if (ret < 0) {
-                VIR_WARN("qemuMonitorAddDevice failed on %s (%s)",
-                         drivestr, devstr);
-                /* XXX should call 'drive_del' on error but this does not
-                   exist yet */
+                virErrorPtr orig_err = virSaveLastError();
+                if (qemuMonitorDriveDel(priv->mon, drivestr) < 0) {
+                    VIR_WARN("Unable to remove drive %s (%s) after failed "
+                             "qemuMonitorAddDevice",
+                             drivestr, devstr);
+                }
+                if (orig_err) {
+                    virSetError(orig_err);
+                    virFreeError(orig_err);
+                }
             }
         }
     } else {