mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-27 19:11:16 +00:00
lock_driver_sanlock: Avoid global driver variable whenever possible
Global variables are bad, we should avoid using them. Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
parent
ff3112f3dc
commit
78da4296a6
@ -80,7 +80,7 @@ struct _virLockManagerSanlockDriver {
|
||||
gid_t group;
|
||||
};
|
||||
|
||||
static virLockManagerSanlockDriver *driver;
|
||||
static virLockManagerSanlockDriverPtr sanlockDriver;
|
||||
|
||||
struct _virLockManagerSanlockPrivate {
|
||||
const char *vm_uri;
|
||||
@ -100,7 +100,9 @@ struct _virLockManagerSanlockPrivate {
|
||||
/*
|
||||
* sanlock plugin for the libvirt virLockManager API
|
||||
*/
|
||||
static int virLockManagerSanlockLoadConfig(const char *configFile)
|
||||
static int
|
||||
virLockManagerSanlockLoadConfig(virLockManagerSanlockDriverPtr driver,
|
||||
const char *configFile)
|
||||
{
|
||||
virConfPtr conf;
|
||||
int ret = -1;
|
||||
@ -161,7 +163,8 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
|
||||
/* How many times try adding a lockspace? */
|
||||
#define LOCKSPACE_RETRIES 10
|
||||
|
||||
static int virLockManagerSanlockSetupLockspace(void)
|
||||
static int
|
||||
virLockManagerSanlockSetupLockspace(virLockManagerSanlockDriverPtr driver)
|
||||
{
|
||||
int fd = -1;
|
||||
struct stat st;
|
||||
@ -371,16 +374,20 @@ static int virLockManagerSanlockInit(unsigned int version,
|
||||
const char *configFile,
|
||||
unsigned int flags)
|
||||
{
|
||||
virLockManagerSanlockDriverPtr driver;
|
||||
|
||||
VIR_DEBUG("version=%u configFile=%s flags=%x",
|
||||
version, NULLSTR(configFile), flags);
|
||||
virCheckFlags(0, -1);
|
||||
|
||||
if (driver)
|
||||
if (sanlockDriver)
|
||||
return 0;
|
||||
|
||||
if (VIR_ALLOC(driver) < 0)
|
||||
if (VIR_ALLOC(sanlockDriver) < 0)
|
||||
return -1;
|
||||
|
||||
driver = sanlockDriver;
|
||||
|
||||
driver->requireLeaseForDisks = true;
|
||||
driver->hostID = 0;
|
||||
driver->autoDiskLease = false;
|
||||
@ -392,7 +399,7 @@ static int virLockManagerSanlockInit(unsigned int version,
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (virLockManagerSanlockLoadConfig(configFile) < 0)
|
||||
if (virLockManagerSanlockLoadConfig(driver, configFile) < 0)
|
||||
goto error;
|
||||
|
||||
if (driver->autoDiskLease && !driver->hostID) {
|
||||
@ -402,7 +409,7 @@ static int virLockManagerSanlockInit(unsigned int version,
|
||||
}
|
||||
|
||||
if (driver->autoDiskLease) {
|
||||
if (virLockManagerSanlockSetupLockspace() < 0)
|
||||
if (virLockManagerSanlockSetupLockspace(driver) < -1)
|
||||
goto error;
|
||||
}
|
||||
|
||||
@ -415,11 +422,11 @@ static int virLockManagerSanlockInit(unsigned int version,
|
||||
|
||||
static int virLockManagerSanlockDeinit(void)
|
||||
{
|
||||
if (!driver)
|
||||
if (!sanlockDriver)
|
||||
return 0;
|
||||
|
||||
VIR_FREE(driver->autoDiskLeasePath);
|
||||
VIR_FREE(driver);
|
||||
VIR_FREE(sanlockDriver->autoDiskLeasePath);
|
||||
VIR_FREE(sanlockDriver);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -438,7 +445,7 @@ static int virLockManagerSanlockNew(virLockManagerPtr lock,
|
||||
|
||||
virCheckFlags(VIR_LOCK_MANAGER_NEW_STARTED, -1);
|
||||
|
||||
if (!driver) {
|
||||
if (!sanlockDriver) {
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
|
||||
_("Sanlock plugin is not initialized"));
|
||||
return -1;
|
||||
@ -566,11 +573,13 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
|
||||
|
||||
|
||||
static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
||||
const char *name,
|
||||
size_t nparams,
|
||||
virLockManagerParamPtr params ATTRIBUTE_UNUSED,
|
||||
bool shared)
|
||||
static int
|
||||
virLockManagerSanlockAddDisk(virLockManagerSanlockDriverPtr driver,
|
||||
virLockManagerPtr lock,
|
||||
const char *name,
|
||||
size_t nparams,
|
||||
virLockManagerParamPtr params ATTRIBUTE_UNUSED,
|
||||
bool shared)
|
||||
{
|
||||
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
||||
int ret = -1;
|
||||
@ -631,7 +640,9 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
||||
}
|
||||
|
||||
|
||||
static int virLockManagerSanlockCreateLease(struct sanlk_resource *res)
|
||||
static int
|
||||
virLockManagerSanlockCreateLease(virLockManagerSanlockDriverPtr driver,
|
||||
struct sanlk_resource *res)
|
||||
{
|
||||
int fd = -1;
|
||||
struct stat st;
|
||||
@ -719,6 +730,7 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
|
||||
virLockManagerParamPtr params,
|
||||
unsigned int flags)
|
||||
{
|
||||
virLockManagerSanlockDriverPtr driver = sanlockDriver;
|
||||
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
||||
|
||||
virCheckFlags(VIR_LOCK_MANAGER_RESOURCE_READONLY |
|
||||
@ -738,11 +750,12 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
|
||||
switch (type) {
|
||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK:
|
||||
if (driver->autoDiskLease) {
|
||||
if (virLockManagerSanlockAddDisk(lock, name, nparams, params,
|
||||
if (virLockManagerSanlockAddDisk(driver, lock, name, nparams, params,
|
||||
!!(flags & VIR_LOCK_MANAGER_RESOURCE_SHARED)) < 0)
|
||||
return -1;
|
||||
|
||||
if (virLockManagerSanlockCreateLease(priv->res_args[priv->res_count-1]) < 0)
|
||||
if (virLockManagerSanlockCreateLease(driver,
|
||||
priv->res_args[priv->res_count-1]) < 0)
|
||||
return -1;
|
||||
} else {
|
||||
if (!(flags & (VIR_LOCK_MANAGER_RESOURCE_SHARED |
|
||||
@ -868,6 +881,7 @@ static int virLockManagerSanlockAcquire(virLockManagerPtr lock,
|
||||
virDomainLockFailureAction action,
|
||||
int *fd)
|
||||
{
|
||||
virLockManagerSanlockDriverPtr driver = sanlockDriver;
|
||||
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
||||
struct sanlk_options *opt = NULL;
|
||||
struct sanlk_resource **res_args;
|
||||
|
Loading…
Reference in New Issue
Block a user