mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-02-22 11:22:23 +00:00
Add a 'nop' lock driver implementation.
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 * 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.
This commit is contained in:
parent
6a943419c5
commit
db98851c24
@ -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
|
||||
|
115
src/locking/lock_driver_nop.c
Normal file
115
src/locking/lock_driver_nop.c
Normal file
@ -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
|
||||
*
|
||||
*/
|
||||
|
||||
#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,
|
||||
};
|
30
src/locking/lock_driver_nop.h
Normal file
30
src/locking/lock_driver_nop.h
Normal file
@ -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__ */
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user