A number of driver API methods which acquire the driver mutex
only ever used the driver object in a read-only fashion. All
these uses are converted to call qemuDriverLockRO() allowing
for greater concurrency.
* src/qemu/qemu_conf.h: s/Mutex/RWLock/
* src/qemu/qemu_driver.c: Add a qemuDriverLockRO() method and use
it anywhere that doesn't require a write lock on the driver
---
src/qemu/qemu_conf.h | 2 +-
src/qemu/qemu_driver.c | 100 +++++++++++++++++++++++++++--------------------
2 files changed, 58 insertions(+), 44 deletions(-)
diff --git a/src/qemu/qemu_conf.h b/src/qemu/qemu_conf.h
index f9a970f..a6e68f8 100644
--- a/src/qemu/qemu_conf.h
+++ b/src/qemu/qemu_conf.h
@@ -75,7 +75,7 @@ enum qemud_cmd_flags {
/* Main driver state */
struct qemud_driver {
- virMutex lock;
+ virRWLock lock;
int privileged;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index f977247..fc6cc53 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -78,13 +78,19 @@
static int qemudShutdown(void);
+/* Obtains a full write lock */
static void qemuDriverLock(struct qemud_driver *driver)
{
- virMutexLock(&driver->lock);
+ virRWLockWrite(&driver->lock);
+}
+/* Obtains a read-only lock */
+static void qemuDriverLockRO(struct qemud_driver *driver)
+{
+ virRWLockRead(&driver->lock);
}
static void qemuDriverUnlock(struct qemud_driver *driver)
{
- virMutexUnlock(&driver->lock);
+ virRWLockUnlock(&driver->lock);
}
static void qemuDomainEventFlush(int timer, void *opaque);
@@ -431,8 +437,8 @@ qemudStartup(int privileged) {
if (VIR_ALLOC(qemu_driver) < 0)
return -1;
- if (virMutexInit(&qemu_driver->lock) < 0) {
- VIR_ERROR("%s", _("cannot initialize mutex"));
+ if (virRWLockInit(&qemu_driver->lock) < 0) {
+ VIR_ERROR("%s", _("cannot initialize rwlock"));
VIR_FREE(qemu_driver);
return -1;
}
@@ -743,7 +749,7 @@ qemudShutdown(void) {
virCgroupFree(&qemu_driver->cgroup);
qemuDriverUnlock(qemu_driver);
- virMutexDestroy(&qemu_driver->lock);
+ virRWLockDestroy(&qemu_driver->lock);
VIR_FREE(qemu_driver);
return 0;
@@ -2262,7 +2268,7 @@ qemudDispatchVMEvent(int watch, int fd, int events, void *opaque) {
* the VM must be running. Nowhere is allowed to remove
* a domain while it is running, so it is safe to not
* lock the driver here... */
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
virDomainObjLock(vm);
qemuDriverUnlock(driver);
@@ -2523,7 +2529,7 @@ static virDomainPtr qemudDomainLookupByID(virConnectPtr conn,
virDomainObjPtr vm;
virDomainPtr dom = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByID(&driver->domains, id);
qemuDriverUnlock(driver);
@@ -2548,7 +2554,7 @@ static virDomainPtr qemudDomainLookupByUUID(virConnectPtr conn,
virDomainObjPtr vm;
virDomainPtr dom = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, uuid);
qemuDriverUnlock(driver);
@@ -2575,7 +2581,7 @@ static virDomainPtr qemudDomainLookupByName(virConnectPtr conn,
virDomainObjPtr vm;
virDomainPtr dom = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByName(&driver->domains, name);
qemuDriverUnlock(driver);
@@ -2629,7 +2635,7 @@ static int qemudListDomains(virConnectPtr conn, int *ids, int nids)
{
struct qemud_driver *driver = conn->privateData;
int n;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
n = virDomainObjListGetActiveIDs(&driver->domains, ids, nids);
qemuDriverUnlock(driver);
@@ -2640,7 +2646,7 @@ static int qemudNumDomains(virConnectPtr conn) {
struct qemud_driver *driver = conn->privateData;
int n;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
n = virDomainObjListNumOfDomains(&driver->domains, 1);
qemuDriverUnlock(driver);
@@ -2734,7 +2740,7 @@ static int qemudDomainSuspend(virDomainPtr dom) {
int ret = -1;
virDomainEventPtr event = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
@@ -2764,7 +2770,9 @@ static int qemudDomainSuspend(virDomainPtr dom) {
cleanup:
if (vm)
virDomainObjUnlock(vm);
+ qemuDriverUnlock(driver);
+ qemuDriverLock(driver);
if (event)
qemuDomainEventQueue(driver, event);
qemuDriverUnlock(driver);
@@ -2778,7 +2786,7 @@ static int qemudDomainResume(virDomainPtr dom) {
int ret = -1;
virDomainEventPtr event = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
@@ -2812,6 +2820,8 @@ static int qemudDomainResume(virDomainPtr dom) {
cleanup:
if (vm)
virDomainObjUnlock(vm);
+ qemuDriverUnlock(driver);
+ qemuDriverLock(driver);
if (event)
qemuDomainEventQueue(driver, event);
qemuDriverUnlock(driver);
@@ -2824,7 +2834,7 @@ static int qemudDomainShutdown(virDomainPtr dom) {
virDomainObjPtr vm;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -2901,7 +2911,7 @@ static char *qemudDomainGetOSType(virDomainPtr dom) {
virDomainObjPtr vm;
char *type = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
if (!vm) {
@@ -2927,7 +2937,7 @@ static unsigned long qemudDomainGetMaxMemory(virDomainPtr dom) {
virDomainObjPtr vm;
unsigned long ret = 0;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -2952,7 +2962,7 @@ static int qemudDomainSetMaxMemory(virDomainPtr dom, unsigned long
newmax) {
virDomainObjPtr vm;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -2985,7 +2995,7 @@ static int qemudDomainSetMemory(virDomainPtr dom, unsigned long
newmem) {
virDomainObjPtr vm;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
if (!vm) {
@@ -3032,7 +3042,7 @@ static int qemudDomainGetInfo(virDomainPtr dom,
int err;
unsigned long balloon;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
if (!vm) {
@@ -3260,7 +3270,7 @@ static int qemudDomainCoreDump(virDomainPtr dom,
NULL,
};
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -3317,7 +3327,7 @@ static int qemudDomainSetVcpus(virDomainPtr dom, unsigned int
nvcpus) {
int ret = -1;
const char *type;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -3378,7 +3388,7 @@ qemudDomainPinVcpu(virDomainPtr dom,
virNodeInfo nodeinfo;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -3447,7 +3457,7 @@ qemudDomainGetVcpus(virDomainPtr dom,
int i, v, maxcpu;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -3536,7 +3546,7 @@ static int qemudDomainGetMaxVcpus(virDomainPtr dom) {
const char *type;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -3570,7 +3580,7 @@ static int qemudDomainGetSecurityLabel(virDomainPtr dom,
virSecurityLabelPtr sec
const char *type;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
memset(seclabel, 0, sizeof(*seclabel));
@@ -3630,7 +3640,7 @@ static int qemudNodeGetSecurityModel(virConnectPtr conn,
char *p;
int ret = 0;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
if (!driver->securityDriver) {
memset(secmodel, 0, sizeof (*secmodel));
goto cleanup;
@@ -3846,7 +3856,7 @@ static char *qemudDomainDumpXML(virDomainPtr dom,
unsigned long balloon;
int err;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -3894,7 +3904,7 @@ static char *qemuDomainXMLFromNative(virConnectPtr conn,
goto cleanup;
}
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
def = qemuParseCommandLineString(conn, driver->caps, config);
qemuDriverUnlock(driver);
if (!def)
@@ -3924,7 +3934,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
char *ret = NULL;
int i;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
if (STRNEQ(format, QEMU_CONFIG_FORMAT_ARGV)) {
qemudReportError(conn, NULL, NULL, VIR_ERR_INVALID_ARG,
@@ -4041,7 +4051,7 @@ static int qemudListDefinedDomains(virConnectPtr conn,
struct qemud_driver *driver = conn->privateData;
int n;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
n = virDomainObjListGetInactiveNames(&driver->domains, names, nnames);
qemuDriverUnlock(driver);
return n;
@@ -4051,7 +4061,7 @@ static int qemudNumDefinedDomains(virConnectPtr conn) {
struct qemud_driver *driver = conn->privateData;
int n;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
n = virDomainObjListNumOfDomains(&driver->domains, 0);
qemuDriverUnlock(driver);
@@ -4065,7 +4075,7 @@ static int qemudDomainStart(virDomainPtr dom) {
int ret = -1;
virDomainEventPtr event = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
@@ -4085,6 +4095,8 @@ static int qemudDomainStart(virDomainPtr dom) {
cleanup:
if (vm)
virDomainObjUnlock(vm);
+ qemuDriverUnlock(driver);
+ qemuDriverLock(driver);
if (event)
qemuDomainEventQueue(driver, event);
qemuDriverUnlock(driver);
@@ -5154,7 +5166,7 @@ static int qemudDomainGetAutostart(virDomainPtr dom,
virDomainObjPtr vm;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -5182,7 +5194,7 @@ static int qemudDomainSetAutostart(virDomainPtr dom,
char *configFile = NULL, *autostartLink = NULL;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
@@ -5252,7 +5264,7 @@ static char *qemuGetSchedulerType(virDomainPtr dom,
struct qemud_driver *driver = dom->conn->privateData;
char *ret = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
__FUNCTION__);
@@ -5281,7 +5293,7 @@ static int qemuSetSchedulerParameters(virDomainPtr dom,
virDomainObjPtr vm = NULL;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
__FUNCTION__);
@@ -5346,7 +5358,7 @@ static int qemuGetSchedulerParameters(virDomainPtr dom,
int ret = -1;
int rc;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
if (!qemuCgroupControllerActive(driver, VIR_CGROUP_CONTROLLER_CPU)) {
qemudReportError(dom->conn, dom, NULL, VIR_ERR_NO_SUPPORT,
__FUNCTION__);
@@ -5413,7 +5425,7 @@ qemudDomainBlockStats (virDomainPtr dom,
virDomainObjPtr vm;
virDomainDiskDefPtr disk = NULL;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
if (!vm) {
@@ -5474,7 +5486,7 @@ qemudDomainInterfaceStats (virDomainPtr dom,
int i;
int ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -5534,7 +5546,7 @@ qemudDomainBlockPeek (virDomainPtr dom,
virDomainObjPtr vm;
int fd = -1, ret = -1, i;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -5607,7 +5619,7 @@ qemudDomainMemoryPeek (virDomainPtr dom,
char *tmp = NULL;
int fd = -1, ret = -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
qemuDriverUnlock(driver);
@@ -6762,7 +6774,7 @@ qemudDomainMigratePerform (virDomainPtr dom,
int ret = -1;
int paused = 0;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
vm = virDomainFindByUUID(&driver->domains, dom->uuid);
if (!vm) {
char uuidstr[VIR_UUID_STRING_BUFLEN];
@@ -6834,6 +6846,8 @@ cleanup:
if (vm)
virDomainObjUnlock(vm);
+ qemuDriverUnlock(driver);
+ qemuDriverLock(driver);
if (event)
qemuDomainEventQueue(driver, event);
qemuDriverUnlock(driver);
@@ -7041,7 +7055,7 @@ qemudNodeDeviceReset (virNodeDevicePtr dev)
if (!pci)
return -1;
- qemuDriverLock(driver);
+ qemuDriverLockRO(driver);
if (pciResetDevice(dev->conn, pci, driver->activePciHostdevs) < 0)
goto out;
--
1.6.2.5