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