render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
7a3408
From 8819ee8472dce467407ad40b4a60eb16d16aef66 Mon Sep 17 00:00:00 2001
7a3408
Message-Id: <8819ee8472dce467407ad40b4a60eb16d16aef66@dist-git>
7a3408
From: Peter Krempa <pkrempa@redhat.com>
7a3408
Date: Mon, 14 Sep 2015 09:50:40 +0200
7a3408
Subject: [PATCH] qemu: hotplug: Properly clean up drive backend if frontend
7a3408
 hotplug fails
7a3408
7a3408
Commit 8125113c added code that should remove the disk backend if the
7a3408
fronted hotplug failed for any reason. The code had a bug though as it
7a3408
used the disk string for unplug rather than the backend alias. Fix the
7a3408
code by pre-creating an alias string and using it instead of the disk
7a3408
string. In cases where qemu does not support QEMU_CAPS_DEVICE, we ignore
7a3408
the unplug of the backend since we can't really create an alias in that
7a3408
case.
7a3408
7a3408
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1262399
7a3408
(cherry picked from commit 64c6695f1ad72f0a99faace5deb1caf7effa2275)
7a3408
7a3408
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
7a3408
---
7a3408
 src/qemu/qemu_hotplug.c | 10 ++++++++--
7a3408
 1 file changed, 8 insertions(+), 2 deletions(-)
7a3408
7a3408
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
7a3408
index cfb071b..31c56ae 100644
7a3408
--- a/src/qemu/qemu_hotplug.c
7a3408
+++ b/src/qemu/qemu_hotplug.c
7a3408
@@ -321,6 +321,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
7a3408
     qemuDomainObjPrivatePtr priv = vm->privateData;
7a3408
     char *devstr = NULL;
7a3408
     char *drivestr = NULL;
7a3408
+    char *drivealias = NULL;
7a3408
     bool releaseaddr = false;
7a3408
     virQEMUDriverConfigPtr cfg = virQEMUDriverGetConfig(driver);
7a3408
     const char *src = virDomainDiskGetSource(disk);
7a3408
@@ -365,6 +366,9 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
7a3408
         if (!(drivestr = qemuBuildDriveStr(conn, disk, false, priv->qemuCaps)))
7a3408
             goto error;
7a3408
 
7a3408
+        if (!(drivealias = qemuDeviceDriveHostAlias(disk, priv->qemuCaps)))
7a3408
+            goto error;
7a3408
+
7a3408
         if (!(devstr = qemuBuildDriveDevStr(vm->def, disk, 0, priv->qemuCaps)))
7a3408
             goto error;
7a3408
     }
7a3408
@@ -379,10 +383,11 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
7a3408
             ret = qemuMonitorAddDevice(priv->mon, devstr);
7a3408
             if (ret < 0) {
7a3408
                 virErrorPtr orig_err = virSaveLastError();
7a3408
-                if (qemuMonitorDriveDel(priv->mon, drivestr) < 0) {
7a3408
+                if (!drivealias ||
7a3408
+                    qemuMonitorDriveDel(priv->mon, drivealias) < 0) {
7a3408
                     VIR_WARN("Unable to remove drive %s (%s) after failed "
7a3408
                              "qemuMonitorAddDevice",
7a3408
-                             drivestr, devstr);
7a3408
+                             NULLSTR(drivealias), drivestr);
7a3408
                 }
7a3408
                 if (orig_err) {
7a3408
                     virSetError(orig_err);
7a3408
@@ -415,6 +420,7 @@ qemuDomainAttachVirtioDiskDevice(virConnectPtr conn,
7a3408
  cleanup:
7a3408
     VIR_FREE(devstr);
7a3408
     VIR_FREE(drivestr);
7a3408
+    VIR_FREE(drivealias);
7a3408
     virObjectUnref(cfg);
7a3408
     return ret;
7a3408
 
7a3408
-- 
7a3408
2.5.2
7a3408