[PATCH v2 05/10] qemu: Refactor qemuAddSharedHostdev and qemuRemoveSharedHostdev

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

 



Refactor the functions to follow logic from qemuAddSharedDisk and
qemuRemoveSharedDisk with respect to locking driver.

Signed-off-by: John Ferlan <jferlan@xxxxxxxxxx>
---
 src/qemu/qemu_conf.c | 27 ++++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index eb0b34f..8afbddc 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1291,13 +1291,18 @@ qemuAddSharedHostdev(virQEMUDriverPtr driver,
     if (!qemuIsSharedHostdev(hostdev))
         return 0;
 
+    qemuDriverLock(driver);
+
     if (!(key = qemuGetSharedHostdevKey(hostdev)))
-        return -1;
+        goto cleanup;
 
-    qemuDriverLock(driver);
-    ret = qemuSharedDeviceEntryInsert(driver, key, name);
-    qemuDriverUnlock(driver);
+    if (qemuSharedDeviceEntryInsert(driver, key, name) < 0)
+        goto cleanup;
+
+    ret = 0;
 
+ cleanup:
+    qemuDriverUnlock(driver);
     VIR_FREE(key);
     return ret;
 }
@@ -1387,18 +1392,22 @@ qemuRemoveSharedHostdev(virQEMUDriverPtr driver,
                         const char *name)
 {
     char *key = NULL;
-    int ret;
+    int ret = -1;
 
     if (!qemuIsSharedHostdev(hostdev))
         return 0;
 
+    qemuDriverLock(driver);
+
     if (!(key = qemuGetSharedHostdevKey(hostdev)))
-        return -1;
+        goto cleanup;
 
-    qemuDriverLock(driver);
-    ret = qemuSharedDeviceEntryRemove(driver, key, name);
-    qemuDriverUnlock(driver);
+    if (qemuSharedDeviceEntryRemove(driver, key, name) < 0)
+        goto cleanup;
 
+    ret = 0;
+ cleanup:
+    qemuDriverUnlock(driver);
     VIR_FREE(key);
     return ret;
 }
-- 
2.1.0

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