[PATCH 3/4] Pass virQEMUDriverPtr into APIs managed shared disk list

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

 



From: "Daniel P. Berrange" <berrange@xxxxxxxxxx>

Currently the APIs for managing the shared disk list take
a virHashTablePtr as the primary argument. This is bad
because it requires the caller to deal with locking of
the QEMU driver. Switch the APIs to take the full
virQEMUDriverPtr instance

Signed-off-by: Daniel P. Berrange <berrange@xxxxxxxxxx>
---
 src/qemu/qemu_conf.c    | 51 +++++++++++++++++++++++--------------------------
 src/qemu/qemu_conf.h    |  4 ++--
 src/qemu/qemu_driver.c  |  6 +++---
 src/qemu/qemu_process.c | 10 +++++-----
 src/qemu/qemu_process.h |  2 +-
 5 files changed, 35 insertions(+), 38 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 574d2cb..2bd1931 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -825,65 +825,62 @@ qemuGetSharedDiskKey(const char *disk_path)
  * add a new entry.
  */
 int
-qemuAddSharedDisk(virHashTablePtr sharedDisks,
+qemuAddSharedDisk(virQEMUDriverPtr driver,
                   const char *disk_path)
 {
     size_t *ref = NULL;
     char *key = NULL;
+    int ret = -1;
 
     if (!(key = qemuGetSharedDiskKey(disk_path)))
-        return -1;
+        goto cleanup;
 
-    if ((ref = virHashLookup(sharedDisks, key))) {
-        if (virHashUpdateEntry(sharedDisks, key, ++ref) < 0) {
-             VIR_FREE(key);
-             return -1;
-        }
+    if ((ref = virHashLookup(driver->sharedDisks, key))) {
+        if (virHashUpdateEntry(driver->sharedDisks, key, ++ref) < 0)
+             goto cleanup;
     } else {
-        if (virHashAddEntry(sharedDisks, key, (void *)0x1)) {
-            VIR_FREE(key);
-            return -1;
-        }
+        if (virHashAddEntry(driver->sharedDisks, key, (void *)0x1))
+            goto cleanup;
     }
 
+    ret = 0;
+cleanup:
     VIR_FREE(key);
-    return 0;
+    return ret;
 }
 
 /* Decrease the ref count if the entry already exists, otherwise
  * remove the entry.
  */
 int
-qemuRemoveSharedDisk(virHashTablePtr sharedDisks,
+qemuRemoveSharedDisk(virQEMUDriverPtr driver,
                      const char *disk_path)
 {
     size_t *ref = NULL;
     char *key = NULL;
+    int ret = -1;
 
     if (!(key = qemuGetSharedDiskKey(disk_path)))
-        return -1;
+        goto cleanup;
 
-    if (!(ref = virHashLookup(sharedDisks, key))) {
-        VIR_FREE(key);
-        return -1;
-    }
+    if (!(ref = virHashLookup(driver->sharedDisks, key)))
+        goto cleanup;
 
     if (ref != (void *)0x1) {
-        if (virHashUpdateEntry(sharedDisks, key, --ref) < 0) {
-             VIR_FREE(key);
-             return -1;
-        }
+        if (virHashUpdateEntry(driver->sharedDisks, key, --ref) < 0)
+            goto cleanup;
     } else {
-        if (virHashRemoveEntry(sharedDisks, key) < 0) {
-            VIR_FREE(key);
-            return -1;
-        }
+        if (virHashRemoveEntry(driver->sharedDisks, key) < 0)
+            goto cleanup;
     }
 
+    ret = 0;
+cleanup:
     VIR_FREE(key);
-    return 0;
+    return ret;
 }
 
+
 int qemuDriverAllocateID(virQEMUDriverPtr driver)
 {
     return virAtomicIntInc(&driver->nextvmid);
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index f0a3da1..09eacce 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -275,11 +275,11 @@ qemuDriverCloseCallback qemuDriverCloseCallbackGet(virQEMUDriverPtr driver,
 void qemuDriverCloseCallbackRunAll(virQEMUDriverPtr driver,
                                    virConnectPtr conn);
 
-int qemuAddSharedDisk(virHashTablePtr sharedDisks,
+int qemuAddSharedDisk(virQEMUDriverPtr driver,
                       const char *disk_path)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 
-int qemuRemoveSharedDisk(virHashTablePtr sharedDisks,
+int qemuRemoveSharedDisk(virQEMUDriverPtr driver,
                          const char *disk_path)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
 char * qemuGetSharedDiskKey(const char *disk_path)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index e94227e..fdefdef 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5830,7 +5830,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
 
     if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
         disk->shared &&
-        (qemuCheckSharedDisk(driver->sharedDisks, disk) < 0))
+        (qemuCheckSharedDisk(driver, disk) < 0))
         goto end;
 
     if (qemuDomainDetermineDiskChain(driver, disk, false) < 0)
@@ -5886,7 +5886,7 @@ qemuDomainAttachDeviceDiskLive(virConnectPtr conn,
 
     if (ret == 0) {
         if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK && disk->shared) {
-            if (qemuAddSharedDisk(driver->sharedDisks, disk->src) < 0)
+            if (qemuAddSharedDisk(driver, disk->src) < 0)
                 VIR_WARN("Failed to add disk '%s' to shared disk table",
                          disk->src);
         }
@@ -6013,7 +6013,7 @@ qemuDomainDetachDeviceDiskLive(virQEMUDriverPtr driver,
     if (ret == 0 &&
         disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK &&
         disk->shared) {
-        if (qemuRemoveSharedDisk(driver->sharedDisks, disk->src) < 0)
+        if (qemuRemoveSharedDisk(driver, disk->src) < 0)
              VIR_WARN("Failed to remove disk '%s' from shared disk table",
                       disk->src);
     }
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index abbee5e..9759332 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -3557,7 +3557,7 @@ qemuSetUnprivSGIO(virDomainDiskDefPtr disk)
  * Returns 0 if no conflicts, otherwise returns -1.
  */
 int
-qemuCheckSharedDisk(virHashTablePtr sharedDisks,
+qemuCheckSharedDisk(virQEMUDriverPtr driver,
                     virDomainDiskDefPtr disk)
 {
     int val;
@@ -3571,7 +3571,7 @@ qemuCheckSharedDisk(virHashTablePtr sharedDisks,
     /* It can't be conflict if no other domain is
      * is sharing it.
      */
-    if (!(ref = virHashLookup(sharedDisks, key)))
+    if (!(ref = virHashLookup(driver->sharedDisks, key)))
         goto cleanup;
 
     if (ref == (void *)0x1)
@@ -3953,10 +3953,10 @@ int qemuProcessStart(virConnectPtr conn,
 #endif
 
         if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK && disk->shared) {
-            if (qemuAddSharedDisk(driver->sharedDisks, disk->src) < 0)
+            if (qemuAddSharedDisk(driver, disk->src) < 0)
                 goto cleanup;
 
-            if (qemuCheckSharedDisk(driver->sharedDisks, disk) < 0)
+            if (qemuCheckSharedDisk(driver, disk) < 0)
                 goto cleanup;
         }
 
@@ -4368,7 +4368,7 @@ void qemuProcessStop(virQEMUDriverPtr driver,
         virDomainDiskDefPtr disk = vm->def->disks[i];
 
         if (disk->type == VIR_DOMAIN_DISK_TYPE_BLOCK && disk->shared) {
-            ignore_value(qemuRemoveSharedDisk(driver->sharedDisks, disk->src));
+            ignore_value(qemuRemoveSharedDisk(driver, disk->src));
         }
     }
 
diff --git a/src/qemu/qemu_process.h b/src/qemu/qemu_process.h
index 2dc8041..cbdab24 100644
--- a/src/qemu/qemu_process.h
+++ b/src/qemu/qemu_process.h
@@ -100,7 +100,7 @@ virBitmapPtr qemuPrepareCpumap(virQEMUDriverPtr driver,
                                virBitmapPtr nodemask);
 int qemuSetUnprivSGIO(virDomainDiskDefPtr disk);
 
-int qemuCheckSharedDisk(virHashTablePtr sharedDisks,
+int qemuCheckSharedDisk(virQEMUDriverPtr driver,
                         virDomainDiskDefPtr disk);
 
 #endif /* __QEMU_PROCESS_H__ */
-- 
1.8.1

--
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]