Allow per-driver config file for lock manager plugins

Allow a 'configFile' parameter to be passed into the lock
drivers to provide configuration. Wire up the QEMU driver
to pass in file names '/etc/libvirt/qemu-$NAME.conf
eg qemu-sanlock.conf

* src/locking/lock_driver.h, src/locking/lock_driver_nop.c,
  src/locking/lock_driver_sanlock.c, src/locking/lock_manager.c,
  src/locking/lock_manager.h: Add configFile parameter
* src/qemu/qemu_conf.c: Pass in configuration file path to
  lock driver plugins
This commit is contained in:
Daniel P. Berrange 2011-06-13 14:30:26 +01:00
parent 25171f607c
commit 5df29ebc25
6 changed files with 17 additions and 7 deletions

View File

@ -121,6 +121,7 @@ struct _virLockManagerParam {
* Returns -1 if the requested version/flags were inadequate
*/
typedef int (*virLockDriverInit)(unsigned int version,
const char *configFile,
unsigned int flags);
/**

View File

@ -28,9 +28,10 @@
static int virLockManagerNopInit(unsigned int version,
const char *configFile,
unsigned int flags)
{
VIR_DEBUG("version=%u flags=%u", version, flags);
VIR_DEBUG("version=%u configFile=%s flags=%u", version, NULLSTR(configFile), flags);
return 0;
}

View File

@ -64,6 +64,7 @@ struct _virLockManagerSanlockPrivate {
*/
static int virLockManagerSanlockInit(unsigned int version ATTRIBUTE_UNUSED,
const char *configFile ATTRIBUTE_UNUSED,
unsigned int flags)
{
virCheckFlags(0, -1);

View File

@ -119,6 +119,7 @@ static void virLockManagerLogParams(size_t nparams,
*/
#if HAVE_DLFCN_H
virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
const char *configFile,
unsigned int flags)
{
void *handle = NULL;
@ -162,11 +163,8 @@ virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
}
}
if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, flags) < 0) {
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",
_("plugin ABI is not compatible"));
if (driver->drvInit(VIR_LOCK_MANAGER_VERSION, configFile, flags) < 0)
goto cleanup;
}
if (VIR_ALLOC(plugin) < 0) {
virReportOOMError();
@ -193,6 +191,7 @@ cleanup:
}
#else /* !HAVE_DLFCN_H */
virLockManagerPluginPtr virLockManagerPluginNew(const char *name ATTRIBUTE_UNUSED,
const char *configFile ATTRIBUTE_UNUSED,
unsigned int flags ATTRIBUTE_UNUSED)
{
virLockError(VIR_ERR_INTERNAL_ERROR, "%s",

View File

@ -29,6 +29,7 @@ typedef struct _virLockManagerPlugin virLockManagerPlugin;
typedef virLockManagerPlugin *virLockManagerPluginPtr;
virLockManagerPluginPtr virLockManagerPluginNew(const char *name,
const char *configFile,
unsigned int flags);
void virLockManagerPluginRef(virLockManagerPluginPtr plugin);
void virLockManagerPluginUnref(virLockManagerPluginPtr plugin);

View File

@ -116,7 +116,7 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
#endif
if (!(driver->lockManager =
virLockManagerPluginNew("nop", 0)))
virLockManagerPluginNew("nop", NULL, 0)))
return -1;
/* Just check the file is readable before opening it, otherwise
@ -438,10 +438,17 @@ int qemudLoadDriverConfig(struct qemud_driver *driver,
p = virConfGetValue (conf, "lock_manager");
CHECK_TYPE ("lock_manager", VIR_CONF_STRING);
if (p && p->str) {
char *lockConf;
virLockManagerPluginUnref(driver->lockManager);
if (virAsprintf(&lockConf, "%s/libvirt/qemu-%s.conf", SYSCONFDIR, p->str) < 0) {
virReportOOMError();
virConfFree(conf);
return -1;
}
if (!(driver->lockManager =
virLockManagerPluginNew(p->str, 0)))
virLockManagerPluginNew(p->str, lockConf, 0)))
VIR_ERROR(_("Failed to load lock manager %s"), p->str);
VIR_FREE(lockConf);
}
virConfFree (conf);