Blame SOURCES/libvirt-qemu_hotplug-refactor-qemuDomainDetachDiskLive-and-qemuDomainDetachDiskDevice.patch

99cbc7
From dea1270caa9ade77248eb0be00a4316a9968a2d9 Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <dea1270caa9ade77248eb0be00a4316a9968a2d9@dist-git>
99cbc7
From: Laine Stump <laine@laine.org>
99cbc7
Date: Thu, 11 Apr 2019 15:14:34 -0400
99cbc7
Subject: [PATCH] qemu_hotplug: refactor qemuDomainDetachDiskLive and
99cbc7
 qemuDomainDetachDiskDevice
99cbc7
99cbc7
qemuDomainDetachDiskDevice() is only called from one place. Moving the
99cbc7
contents of the function to that place makes
99cbc7
qemuDomainDetachDiskLive() more similar to the other Detach functions
99cbc7
called by the toplevel qemuDomainDetachDevice().
99cbc7
99cbc7
The goal is to make each of the device-type-specific functions do this:
99cbc7
99cbc7
  1) find the exact device
99cbc7
  2) do any device-specific validation
99cbc7
  3) do general validation
99cbc7
  4) do device-specific shutdown (only needed for net devices)
99cbc7
  5) do the common block of code to send device_del to qemu, then
99cbc7
     optionally wait for a corresponding DEVICE_DELETED event from
99cbc7
     qemu.
99cbc7
99cbc7
with the final aim being that only items 1 & 2 will remain in each
99cbc7
device-type-specific function, while 3 & 5 (which are the same for
99cbc7
almost every type) will be de-duplicated and moved to the toplevel
99cbc7
function that calls all of these (qemuDomainDetachDeviceLive(), which
99cbc7
will also contain a callout to the one instance of (4) (netdev).
99cbc7
99cbc7
Signed-off-by: Laine Stump <laine@laine.org>
99cbc7
ACKed-by: Peter Krempa <pkrempa@redhat.com>
99cbc7
(cherry picked from commit ac442713e6aa1b1087d095796f9c35fd372a0511)
99cbc7
99cbc7
Partially-Resolves: https://bugzilla.redhat.com/1658198
99cbc7
Signed-off-by: Laine Stump <laine@redhat.com>
99cbc7
Signed-off-by: Laine Stump <laine@laine.org>
99cbc7
Message-Id: <20190411191453.24055-23-laine@redhat.com>
99cbc7
Acked-by: Michal Privoznik <mprivozn@redhat.com>
99cbc7
---
99cbc7
 src/qemu/qemu_hotplug.c | 84 ++++++++++++++++++-----------------------
99cbc7
 1 file changed, 37 insertions(+), 47 deletions(-)
99cbc7
99cbc7
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
99cbc7
index 0ae944475e..18c98c59ec 100644
99cbc7
--- a/src/qemu/qemu_hotplug.c
99cbc7
+++ b/src/qemu/qemu_hotplug.c
99cbc7
@@ -4721,47 +4721,6 @@ qemuDomainSignalDeviceRemoval(virDomainObjPtr vm,
99cbc7
 }
99cbc7
 
99cbc7
 
99cbc7
-static int
99cbc7
-qemuDomainDetachDiskDevice(virQEMUDriverPtr driver,
99cbc7
-                           virDomainObjPtr vm,
99cbc7
-                           virDomainDiskDefPtr detach,
99cbc7
-                           bool async)
99cbc7
-{
99cbc7
-    int ret = -1;
99cbc7
-
99cbc7
-    if (qemuDomainDiskBlockJobIsActive(detach))
99cbc7
-        return -1;
99cbc7
-
99cbc7
-    if (detach->bus == VIR_DOMAIN_DISK_BUS_VIRTIO &&
99cbc7
-        qemuIsMultiFunctionDevice(vm->def, &detach->info)) {
99cbc7
-        virReportError(VIR_ERR_OPERATION_FAILED,
99cbc7
-                       _("cannot hot unplug multifunction PCI device: %s"),
99cbc7
-                       detach->dst);
99cbc7
-        return -1;
99cbc7
-    }
99cbc7
-
99cbc7
-    if (!async)
99cbc7
-        qemuDomainMarkDeviceForRemoval(vm, &detach->info);
99cbc7
-
99cbc7
-    if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) {
99cbc7
-        if (virDomainObjIsActive(vm))
99cbc7
-            virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
99cbc7
-        goto cleanup;
99cbc7
-    }
99cbc7
-
99cbc7
-    if (async) {
99cbc7
-        ret = 0;
99cbc7
-    } else {
99cbc7
-        if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
99cbc7
-            ret = qemuDomainRemoveDiskDevice(driver, vm, detach);
99cbc7
-    }
99cbc7
-
99cbc7
- cleanup:
99cbc7
-    if (!async)
99cbc7
-        qemuDomainResetDeviceRemoval(vm);
99cbc7
-    return ret;
99cbc7
-}
99cbc7
-
99cbc7
 static int
99cbc7
 qemuFindDisk(virDomainDefPtr def, const char *dst)
99cbc7
 {
99cbc7
@@ -4783,6 +4742,7 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver,
99cbc7
 {
99cbc7
     virDomainDiskDefPtr disk;
99cbc7
     int idx;
99cbc7
+    int ret = -1;
99cbc7
 
99cbc7
     if ((idx = qemuFindDisk(vm->def, dev->data.disk->dst)) < 0) {
99cbc7
         virReportError(VIR_ERR_OPERATION_FAILED,
99cbc7
@@ -4799,7 +4759,7 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver,
99cbc7
         case VIR_DOMAIN_DISK_BUS_VIRTIO:
99cbc7
         case VIR_DOMAIN_DISK_BUS_USB:
99cbc7
         case VIR_DOMAIN_DISK_BUS_SCSI:
99cbc7
-            return qemuDomainDetachDiskDevice(driver, vm, disk, async);
99cbc7
+            break;
99cbc7
 
99cbc7
         case VIR_DOMAIN_DISK_BUS_IDE:
99cbc7
         case VIR_DOMAIN_DISK_BUS_FDC:
99cbc7
@@ -4809,12 +4769,12 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver,
99cbc7
         case VIR_DOMAIN_DISK_BUS_SD:
99cbc7
             virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
99cbc7
                            _("This type of disk cannot be hot unplugged"));
99cbc7
-            break;
99cbc7
+            return -1;
99cbc7
 
99cbc7
         case VIR_DOMAIN_DISK_BUS_LAST:
99cbc7
         default:
99cbc7
             virReportEnumRangeError(virDomainDiskBus, disk->bus);
99cbc7
-            break;
99cbc7
+            return -1;
99cbc7
         }
99cbc7
         break;
99cbc7
 
99cbc7
@@ -4823,15 +4783,45 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver,
99cbc7
         virReportError(VIR_ERR_OPERATION_UNSUPPORTED,
99cbc7
                        _("disk device type '%s' cannot be detached"),
99cbc7
                        virDomainDiskDeviceTypeToString(disk->device));
99cbc7
-        break;
99cbc7
+        return -1;
99cbc7
 
99cbc7
     case VIR_DOMAIN_DISK_DEVICE_LAST:
99cbc7
     default:
99cbc7
         virReportEnumRangeError(virDomainDiskDevice, disk->device);
99cbc7
-        break;
99cbc7
+        return -1;
99cbc7
     }
99cbc7
 
99cbc7
-    return -1;
99cbc7
+    if (qemuDomainDiskBlockJobIsActive(disk))
99cbc7
+        return -1;
99cbc7
+
99cbc7
+    if (disk->bus == VIR_DOMAIN_DISK_BUS_VIRTIO &&
99cbc7
+        qemuIsMultiFunctionDevice(vm->def, &disk->info)) {
99cbc7
+        virReportError(VIR_ERR_OPERATION_FAILED,
99cbc7
+                       _("cannot hot unplug multifunction PCI device: %s"),
99cbc7
+                       disk->dst);
99cbc7
+        return -1;
99cbc7
+    }
99cbc7
+
99cbc7
+    if (!async)
99cbc7
+        qemuDomainMarkDeviceForRemoval(vm, &disk->info);
99cbc7
+
99cbc7
+    if (qemuDomainDeleteDevice(vm, disk->info.alias) < 0) {
99cbc7
+        if (virDomainObjIsActive(vm))
99cbc7
+            virDomainAuditDisk(vm, disk->src, NULL, "detach", false);
99cbc7
+        goto cleanup;
99cbc7
+    }
99cbc7
+
99cbc7
+    if (async) {
99cbc7
+        ret = 0;
99cbc7
+    } else {
99cbc7
+        if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
99cbc7
+            ret = qemuDomainRemoveDiskDevice(driver, vm, disk);
99cbc7
+    }
99cbc7
+
99cbc7
+ cleanup:
99cbc7
+    if (!async)
99cbc7
+        qemuDomainResetDeviceRemoval(vm);
99cbc7
+    return ret;
99cbc7
 }
99cbc7
 
99cbc7
 
99cbc7
-- 
99cbc7
2.21.0
99cbc7