[libvirt] [PATCH RFC 8/8] add qemu cache mutex

Michal Privoznik mprivozn at redhat.com
Mon Mar 12 13:00:19 UTC 2012


On 11.03.2012 19:56, Lee Schermerhorn wrote:
> 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 };

This is not allowed in our code as we build with win32 threads which
initialize mutexes completely different. Why do you want to initialize
it here anyway ...
> +
>  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);
> +}
> +

if you have created this function?
>  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,
> 
> --
> libvir-list mailing list
> libvir-list at redhat.com
> https://www.redhat.com/mailman/listinfo/libvir-list




More information about the libvir-list mailing list