[PATCH 09/14] qemu: conf: rename qemuCheckSharedDevice to qemuCheckSharedDisk

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

 



The qemuCheckSharedDevice function is operating only on disk devices.
Rename it and change the arguments to reflect that and refactor some
logic for more readability.
---
 src/qemu/qemu_conf.c | 89 ++++++++++++++++++++++------------------------------
 1 file changed, 38 insertions(+), 51 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 79f8df8..5efabfb 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -814,82 +814,68 @@ qemuGetSharedDeviceKey(const char *device_path)
  * Returns 0 if no conflicts, otherwise returns -1.
  */
 static int
-qemuCheckSharedDevice(virHashTablePtr sharedDevices,
-                      virDomainDeviceDefPtr dev)
+qemuCheckSharedDisk(virHashTablePtr sharedDevices,
+                    virDomainDiskDefPtr disk)
 {
-    virDomainDiskDefPtr disk = NULL;
     char *sysfs_path = NULL;
     char *key = NULL;
     int val;
-    int ret = 0;
-    const char *src;
-
-    if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
-        disk = dev->data.disk;
+    int ret = -1;

-        /* The only conflicts between shared disk we care about now
-         * is sgio setting, which is only valid for device='lun'.
-         */
-        if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
-            return 0;
-    } else {
+    if (disk->device != VIR_DOMAIN_DISK_DEVICE_LUN)
         return 0;
-    }
-
-    src = virDomainDiskGetSource(disk);
-    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(src, NULL))) {
-        ret = -1;
-        goto cleanup;
-    }

-    /* It can't be conflict if unpriv_sgio is not supported
-     * by kernel.
-     */
-    if (!virFileExists(sysfs_path))
+    if (!(sysfs_path = virGetUnprivSGIOSysfsPath(disk->src->path, NULL)))
         goto cleanup;

-    if (!(key = qemuGetSharedDeviceKey(src))) {
-        ret = -1;
+    /* It can't be conflict if unpriv_sgio is not supported by kernel. */
+    if (!virFileExists(sysfs_path)) {
+        ret = 0;
         goto cleanup;
     }

-    /* It can't be conflict if no other domain is
-     * is sharing it.
-     */
-    if (!(virHashLookup(sharedDevices, key)))
+    if (!(key = qemuGetSharedDeviceKey(disk->src->path)))
         goto cleanup;

-    if (virGetDeviceUnprivSGIO(src, NULL, &val) < 0) {
-        ret = -1;
+    /* It can't be conflict if no other domain is sharing it. */
+    if (!(virHashLookup(sharedDevices, key))) {
+        ret = 0;
         goto cleanup;
     }

-    if ((val == 0 &&
-         (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
-          disk->sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
-        (val == 1 &&
-         disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))
+    if (virGetDeviceUnprivSGIO(disk->src->path, NULL, &val) < 0)
         goto cleanup;

-    if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
-                         "with other active domains"),
-                       disk->src->srcpool->pool,
-                       disk->src->srcpool->volume);
-    } else {
-        virReportError(VIR_ERR_OPERATION_INVALID,
-                       _("sgio of shared disk '%s' conflicts with other "
-                         "active domains"), src);
+    if (!((val == 0 &&
+           (disk->sgio == VIR_DOMAIN_DEVICE_SGIO_FILTERED ||
+            disk->sgio == VIR_DOMAIN_DEVICE_SGIO_DEFAULT)) ||
+          (val == 1 &&
+           disk->sgio == VIR_DOMAIN_DEVICE_SGIO_UNFILTERED))) {
+
+        if (virDomainDiskGetType(disk) == VIR_STORAGE_TYPE_VOLUME) {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("sgio of shared disk 'pool=%s' 'volume=%s' conflicts "
+                             "with other active domains"),
+                           disk->src->srcpool->pool,
+                           disk->src->srcpool->volume);
+        } else {
+            virReportError(VIR_ERR_OPERATION_INVALID,
+                           _("sgio of shared disk '%s' conflicts with other "
+                             "active domains"), disk->src->path);
+        }
+
+        goto cleanup;
     }

-    ret = -1;
+    ret = 0;
+
  cleanup:
     VIR_FREE(sysfs_path);
     VIR_FREE(key);
     return ret;
 }

+
 bool
 qemuSharedDeviceEntryDomainExists(qemuSharedDeviceEntryPtr entry,
                                   const char *name,
@@ -1007,10 +993,11 @@ qemuAddSharedDevice(virQEMUDriverPtr driver,
     }

     qemuDriverLock(driver);
-    if (qemuCheckSharedDevice(driver->sharedDevices, dev) < 0)
-        goto cleanup;

     if (dev->type == VIR_DOMAIN_DEVICE_DISK) {
+        if (qemuCheckSharedDisk(driver->sharedDevices, disk) < 0)
+            goto cleanup;
+
         if (!(key = qemuGetSharedDeviceKey(virDomainDiskGetSource(disk))))
             goto cleanup;
     } else {
-- 
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]