Add a mutex for access to the qemu emulator cache. Not clear that
this is actually needed -- driver should be locked across calls [?].
The patch can be dropped if not needed.
---
src/qemu/qemu_capabilities.c | 18 +++++++++++++++++-
src/qemu/qemu_capabilities.h | 2 ++
src/qemu/qemu_driver.c | 3 +++
3 files changed, 22 insertions(+), 1 deletion(-)
Index: libvirt-0.9.10/src/qemu/qemu_capabilities.c
===================================================================
--- libvirt-0.9.10.orig/src/qemu/qemu_capabilities.c
+++ libvirt-0.9.10/src/qemu/qemu_capabilities.c
@@ -27,6 +27,7 @@
#include "memory.h"
#include "logging.h"
#include "virterror_internal.h"
+#include "threads.h"
#include "util.h"
#include "virfile.h"
#include "nodeinfo.h"
@@ -180,6 +181,11 @@ enum qemuCapsProbes {
QEMU_PROBE_SIZE
};
+/*
+ * Use static initializer for tests
+ */
+static virMutex qemuEmulatorCacheMutex = { PTHREAD_MUTEX_INITIALIZER };
+
typedef struct _qemuEmulatorCache qemuEmulatorCache;
typedef qemuEmulatorCache* qemuEmulatorCachePtr;
struct _qemuEmulatorCache {
@@ -206,9 +212,17 @@ qemuEmulatorCachedInfoGet(enum qemuCapsP
const char *binary,
const char *arch);
+int
+qemuCapsCacheInit(void)
+{
+ return virMutexInit(&qemuEmulatorCacheMutex);
+}
+
static void
qemuEmulatorCachedInfoRelease(qemuEmulatorCachePtr emulator ATTRIBUTE_UNUSED)
-{ }
+{
+ virMutexUnlock(&qemuEmulatorCacheMutex);
+}
/* Feature flags for the architecture info */
static const struct qemu_feature_flags const arch_info_i686_flags [] = {
@@ -1769,6 +1783,8 @@ qemuEmulatorCachedInfoGet(enum qemuCapsP
bool alreadyCached;
int i;
+ virMutexLock(&qemuEmulatorCacheMutex);
+
if (stat(binary, &st) != 0) {
char ebuf[1024];
VIR_INFO("Failed to stat emulator %s : %s",
Index: libvirt-0.9.10/src/qemu/qemu_driver.c
===================================================================
--- libvirt-0.9.10.orig/src/qemu/qemu_driver.c
+++ libvirt-0.9.10/src/qemu/qemu_driver.c
@@ -585,6 +585,9 @@ qemudStartup(int privileged) {
if (qemuSecurityInit(qemu_driver) < 0)
goto error;
+ if (qemuCapsCacheInit() < 0)
+ goto error;
+
if ((qemu_driver->caps = qemuCreateCapabilities(NULL,
qemu_driver)) == NULL)
goto error;
Index: libvirt-0.9.10/src/qemu/qemu_capabilities.h
===================================================================
--- libvirt-0.9.10.orig/src/qemu/qemu_capabilities.h
+++ libvirt-0.9.10/src/qemu/qemu_capabilities.h
@@ -139,6 +139,8 @@ void qemuCapsClear(virBitmapPtr caps,
bool qemuCapsGet(virBitmapPtr caps,
enum qemuCapsFlags flag);
+int qemuCapsCacheInit(void);
+
virCapsPtr qemuCapsInit(virCapsPtr old_caps);
int qemuCapsProbeMachineTypes(const char *binary,