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

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