[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH 04/10] Add a 'nop' lock driver implementation.



On Thu, May 19, 2011 at 07:24:19AM -0400, Daniel P. Berrange wrote:
> To allow hypervisor drivers to assume that a lock driver impl
> will be guaranteed to exist, provide a 'nop' impl that is
> compiled into the library

  Also has to good property of being usable as a template for new
  ones...

> * src/Makefile.am: Add nop driver
> * src/locking/lock_driver_nop.c, src/locking/lock_driver_nop.h:
>   Nop lock driver implementation
> * src/locking/lock_manager.c: Enable direct access of 'nop'
>   driver, instead of dlopen()ing it.
> ---
>  src/Makefile.am               |    4 +-
>  src/locking/lock_driver_nop.c |  115 +++++++++++++++++++++++++++++++++++++++++
>  src/locking/lock_driver_nop.h |   30 +++++++++++
>  src/locking/lock_manager.c    |   53 ++++++++++---------
>  4 files changed, 177 insertions(+), 25 deletions(-)
>  create mode 100644 src/locking/lock_driver_nop.c
>  create mode 100644 src/locking/lock_driver_nop.h
> 
> diff --git a/src/Makefile.am b/src/Makefile.am
> index a27838b..96e2edf 100644
> --- a/src/Makefile.am
> +++ b/src/Makefile.am
> @@ -94,7 +94,9 @@ DRIVER_SOURCES =						\
>  		fdstream.c fdstream.h                 \
>  		$(NODE_INFO_SOURCES)				\
>  		libvirt.c libvirt_internal.h			\
> -		locking/lock_manager.c locking/lock_manager.h
> +		locking/lock_manager.c locking/lock_manager.h   \
> +		locking/lock_driver.h 				\
> +		locking/lock_driver_nop.h locking/lock_driver_nop.c
>  
>  
>  # XML configuration format handling sources
> diff --git a/src/locking/lock_driver_nop.c b/src/locking/lock_driver_nop.c
> new file mode 100644
> index 0000000..5ebbd8d
> --- /dev/null
> +++ b/src/locking/lock_driver_nop.c
> @@ -0,0 +1,115 @@
> +/*
> + * lock_driver_nop.c: A lock driver which locks nothing
> + *
> + * Copyright (C) 2010-2011 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *

 * Author: Daniel P. Berrange <berrange redhat com>

> + */
> +
> +#include <config.h>
> +
> +#include "lock_driver_nop.h"
> +#include "memory.h"
> +#include "logging.h"
> +#include "uuid.h"
> +
> +
> +static int virLockManagerNopInit(unsigned int version,
> +                                 unsigned int flags)
> +{
> +    VIR_DEBUG("version=%u flags=%u", version, flags);
> +
> +    return 0;
> +}
> +
> +static int virLockManagerNopDeinit(void)
> +{
> +    VIR_DEBUG(" ");
> +
> +    return 0;
> +}
> +
> +
> +static int virLockManagerNopNew(virLockManagerPtr lock ATTRIBUTE_UNUSED,
> +                                unsigned int type ATTRIBUTE_UNUSED,
> +                                size_t nparams ATTRIBUTE_UNUSED,
> +                                virLockManagerParamPtr params ATTRIBUTE_UNUSED,
> +                                unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +    return 0;
> +}
> +
> +static int virLockManagerNopAddResource(virLockManagerPtr lock ATTRIBUTE_UNUSED,
> +                                        unsigned int type ATTRIBUTE_UNUSED,
> +                                        const char *name ATTRIBUTE_UNUSED,
> +                                        size_t nparams ATTRIBUTE_UNUSED,
> +                                        virLockManagerParamPtr params ATTRIBUTE_UNUSED,
> +                                        unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +
> +    return 0;
> +}
> +
> +
> +static int virLockManagerNopAcquire(virLockManagerPtr lock ATTRIBUTE_UNUSED,
> +                                    const char *state ATTRIBUTE_UNUSED,
> +                                    unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +
> +    return 0;
> +}
> +
> +static int virLockManagerNopRelease(virLockManagerPtr lock ATTRIBUTE_UNUSED,
> +                                    char **state,
> +                                    unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +    *state = NULL;
> +
> +    return 0;
> +}
> +
> +static int virLockManagerNopInquire(virLockManagerPtr lock ATTRIBUTE_UNUSED,
> +                                    char **state,
> +                                    unsigned int flags ATTRIBUTE_UNUSED)
> +{
> +
> +    *state = NULL;
> +
> +    return 0;
> +}
> +
> +static void virLockManagerNopFree(virLockManagerPtr lock ATTRIBUTE_UNUSED)
> +{
> +}
> +
> +virLockDriver virLockDriverNop =
> +{
> +    .version = VIR_LOCK_MANAGER_VERSION,
> +    .flags = 0,
> +
> +    .drvInit = virLockManagerNopInit,
> +    .drvDeinit = virLockManagerNopDeinit,
> +
> +    .drvNew = virLockManagerNopNew,
> +    .drvFree = virLockManagerNopFree,
> +
> +    .drvAddResource = virLockManagerNopAddResource,
> +
> +    .drvAcquire = virLockManagerNopAcquire,
> +    .drvRelease = virLockManagerNopRelease,
> +
> +    .drvInquire = virLockManagerNopInquire,
> +};
> diff --git a/src/locking/lock_driver_nop.h b/src/locking/lock_driver_nop.h
> new file mode 100644
> index 0000000..4be5377
> --- /dev/null
> +++ b/src/locking/lock_driver_nop.h
> @@ -0,0 +1,30 @@
> +/*
> + * lock_driver_nop.h: A lock driver which locks nothing
> + *
> + * Copyright (C) 2010-2011 Red Hat, Inc.
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * This library is distributed in the hope that it will be useful,
> + * but WITHOUT ANY WARRANTY; without even the implied warranty of
> + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
> + * Lesser General Public License for more details.
> + *
> + * You should have received a copy of the GNU Lesser General Public
> + * License along with this library; if not, write to the Free Software
> + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
> + *
> + */
> +
> +#ifndef __VIR_LOCK_DRIVER_NOP_H__
> +# define __VIR_LOCK_DRIVER_NOP_H__
> +
> +# include "lock_driver.h"
> +
> +extern virLockDriver virLockDriverNop;
> +
> +
> +#endif /* __VIR_LOCK_DRIVER_NOP_H__ */
> diff --git a/src/locking/lock_manager.c b/src/locking/lock_manager.c
> index cb96091..6197fd4 100644
> --- a/src/locking/lock_manager.c
> +++ b/src/locking/lock_manager.c
> @@ -22,6 +22,7 @@
>  #include <config.h>
>  
>  #include "lock_manager.h"
> +#include "lock_driver_nop.h"
>  #include "virterror_internal.h"
>  #include "logging.h"
>  #include "util.h"
> @@ -123,35 +124,39 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
>      const char *moddir = getenv("LIBVIRT_LOCK_MANAGER_PLUGIN_DIR");
>      char *modfile = NULL;
>  
> -    if (moddir == NULL)
> -        moddir = DEFAULT_LOCK_MANAGER_PLUGIN_DIR;
> +    if (STREQ(name, "nop")) {
> +        driver = &virLockDriverNop;
> +    } else {
> +        if (moddir == NULL)
> +            moddir = DEFAULT_LOCK_MANAGER_PLUGIN_DIR;
>  
> -    VIR_DEBUG("Module load %s from %s", name, moddir);
> +        VIR_DEBUG("Module load %s from %s", name, moddir);
>  
> -    if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0) {
> -        virReportOOMError();
> -        return NULL;
> -    }
> +        if (virAsprintf(&modfile, "%s/%s.so", moddir, name) < 0) {
> +            virReportOOMError();
> +            return NULL;
> +        }
>  
> -    if (access(modfile, R_OK) < 0) {
> -        virReportSystemError(errno,
> -                             _("Plugin %s not accessible"),
> -                             modfile);
> -        goto cleanup;
> -    }
> +        if (access(modfile, R_OK) < 0) {
> +            virReportSystemError(errno,
> +                                 _("Plugin %s not accessible"),
> +                                 modfile);
> +            goto cleanup;
> +        }
>  
> -    handle = dlopen(modfile, RTLD_NOW | RTLD_LOCAL);
> -    if (!handle) {
> -        virLockError(VIR_ERR_SYSTEM_ERROR,
> -                     _("Failed to load plugin %s: %s"),
> -                     modfile, dlerror());
> -        goto cleanup;
> -    }
> +        handle = dlopen(modfile, RTLD_NOW | RTLD_LOCAL);
> +        if (!handle) {
> +            virLockError(VIR_ERR_SYSTEM_ERROR,
> +                         _("Failed to load plugin %s: %s"),
> +                         modfile, dlerror());
> +            goto cleanup;
> +        }
>  
> -    if (!(driver = dlsym(handle, "virLockDriverImpl"))) {
> -        virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
> -                     _("Missing plugin initialization symbol 'virLockDriverImpl'"));
> -        goto cleanup;
> +        if (!(driver = dlsym(handle, "virLockDriverImpl"))) {
> +            virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
> +                         _("Missing plugin initialization symbol 'virLockDriverImpl'"));
> +            goto cleanup;
> +        }
>      }
>  
>      if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, flags) < 0) {

  ACK,

Daniel

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]