Refactor the functions to follow logic from qemuAddSharedDisk and
qemuRemoveSharedDisk with respect to locking driver.
Signed-off-by: John Ferlan <jferlan(a)redhat.com>
---
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 0314707..faa0b49 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -1286,13 +1286,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;
}
@@ -1382,18 +1387,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