[PATCH 11/14] qemu: conf: Split up qemuRemoveSharedDevice into per-device-type functions

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Removing a shared device needs special steps for disks and hostdevs.
Instead of having one function dealing this split the code into two
separate functions that can be used with better granularity.
---
 src/qemu/qemu_conf.c | 117 +++++++++++++++++++++++++++++++--------------------
 1 file changed, 71 insertions(+), 46 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 7af3c5c..f6a3b8d 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1088,64 +1088,65 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
         return 0;
 }

-/* qemuRemoveSharedDevice:
- * @driver: Pointer to qemu driver struct
- * @device: The device def
- * @name: The domain name
- *
- * Decrease ref count and remove the domain name from the list which
- * records all the domains that use the shared device if ref is not
- * 1, otherwise remove the entry.
- */
-int
-qemuRemoveSharedDevice(virQEMUDriverPtr driver,
-                       virDomainDeviceDefPtr dev,
-                       const char *name)
+
+static int
+qemuRemoveSharedDisk(virQEMUDriverPtr driver,
+                     virDomainDiskDefPtr disk,
+                     const char *name)
 {
-    virDomainDiskDefPtr disk = NULL;
-    virDomainHostdevDefPtr hostdev = NULL;
     char *key = NULL;
-    char *dev_name = NULL;
-    char *dev_path = NULL;
     int ret = -1;

-    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
-        disk = dev->data.disk;
+    if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src))
+        return 0;

-        if (!disk->src->shared || !virDomainDiskSourceIsBlockType(disk->src))
-            return 0;
-    } else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV) {
-        hostdev = dev->data.hostdev;
+    qemuDriverLock(driver);

-        if (!hostdev->shareable ||
-            !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
-              hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
-            return 0;
-    } else {
+    if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
+        goto cleanup;
+
+    if (qemuSharedDeviceEntryRemove(driver, key, name) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    qemuDriverUnlock(driver);
+    VIR_FREE(key);
+    return ret;
+}
+
+
+static int
+qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
+                        virDomainHostdevDefPtr hostdev,
+                        const char *name)
+{
+    virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
+    virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
+    char *key = NULL;
+    char *dev_name = NULL;
+    char *dev_path = NULL;
+    int ret = -1;
+
+    if (!hostdev->shareable ||
+        !(hostdev->mode == VIR_DOMAIN_HOSTDEV_MODE_SUBSYS &&
+          hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI))
         return 0;
-    }

     qemuDriverLock(driver);

-    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
-        if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
-            goto cleanup;
-    } else {
-        virDomainHostdevSubsysSCSIPtr scsisrc = &hostdev->source.subsys.u.scsi;
-        virDomainHostdevSubsysSCSIHostPtr scsihostsrc = &scsisrc->u.host;
-        if (!(dev_name = virSCSIDeviceGetDevName(NULL,
-                                                 scsihostsrc->adapter,
-                                                 scsihostsrc->bus,
-                                                 scsihostsrc->target,
-                                                 scsihostsrc->unit)))
-            goto cleanup;
+    if (!(dev_name = virSCSIDeviceGetDevName(NULL,
+                                             scsihostsrc->adapter,
+                                             scsihostsrc->bus,
+                                             scsihostsrc->target,
+                                             scsihostsrc->unit)))
+        goto cleanup;

-        if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0)
-            goto cleanup;
+    if (virAsprintf(&dev_path, "/dev/%s", dev_name) < 0)
+        goto cleanup;

-        if (!(key = qemuGetSharedDeviceKey(dev_path)))
-            goto cleanup;
-    }
+    if (!(key = qemuGetSharedDeviceKey(dev_path)))
+        goto cleanup;

     if (qemuSharedDeviceEntryRemove(driver, key, name) < 0)
         goto cleanup;
@@ -1159,6 +1160,30 @@ qemuRemoveSharedDevice(virQEMUDriverPtr driver,
     return ret;
 }

+
+/* qemuRemoveSharedDevice:
+ * @driver: Pointer to qemu driver struct
+ * @device: The device def
+ * @name: The domain name
+ *
+ * Decrease ref count and remove the domain name from the list which
+ * records all the domains that use the shared device if ref is not
+ * 1, otherwise remove the entry.
+ */
+int
+qemuRemoveSharedDevice(virQEMUDriverPtr driver,
+                       virDomainDeviceDefPtr dev,
+                       const char *name)
+{
+    if (dev->type == VIR_DOMAIN_DEVICE_DISK)
+        return qemuRemoveSharedDisk(driver, dev->data.disk, name);
+    else if (dev->type == VIR_DOMAIN_DEVICE_HOSTDEV)
+        return qemuRemoveSharedHostdev(driver, dev->data.hostdev, name);
+    else
+        return 0;
+}
+
+
 int
 qemuSetUnprivSGIO(virDomainDeviceDefPtr dev)
 {
-- 
2.0.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]