mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-22 12:35:17 +00:00
Add support for shared sanlock leases
A sanlock lease can be marked as shared (rather than exclusive) using SANLK_RES_SHARED flag. This adds support for that flag and ensures that in auto disk mode, any shared disks use shared leases. This also makes any read-only disks be completely ignored. These changes remove the need for the option ignore_readonly_and_shared_disks so that is removed Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
This commit is contained in:
parent
3b1ddec1ef
commit
acbd4965c4
@ -65,7 +65,6 @@ struct _virLockManagerSanlockDriver {
|
|||||||
bool requireLeaseForDisks;
|
bool requireLeaseForDisks;
|
||||||
int hostID;
|
int hostID;
|
||||||
bool autoDiskLease;
|
bool autoDiskLease;
|
||||||
bool ignoreReadonlyShared;
|
|
||||||
char *autoDiskLeasePath;
|
char *autoDiskLeasePath;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -115,10 +114,6 @@ static int virLockManagerSanlockLoadConfig(const char *configFile)
|
|||||||
CHECK_TYPE("auto_disk_leases", VIR_CONF_LONG);
|
CHECK_TYPE("auto_disk_leases", VIR_CONF_LONG);
|
||||||
if (p) driver->autoDiskLease = p->l;
|
if (p) driver->autoDiskLease = p->l;
|
||||||
|
|
||||||
p = virConfGetValue(conf, "ignore_readonly_and_shared_disks");
|
|
||||||
CHECK_TYPE("ignore_readonly_and_shared_disks", VIR_CONF_LONG);
|
|
||||||
if (p) driver->ignoreReadonlyShared = p->l;
|
|
||||||
|
|
||||||
p = virConfGetValue(conf, "disk_lease_dir");
|
p = virConfGetValue(conf, "disk_lease_dir");
|
||||||
CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING);
|
CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING);
|
||||||
if (p && p->str) {
|
if (p && p->str) {
|
||||||
@ -428,7 +423,8 @@ static int virLockManagerSanlockDiskLeaseName(const char *path,
|
|||||||
static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||||
const char *name,
|
const char *name,
|
||||||
size_t nparams,
|
size_t nparams,
|
||||||
virLockManagerParamPtr params)
|
virLockManagerParamPtr params,
|
||||||
|
bool shared)
|
||||||
{
|
{
|
||||||
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -440,6 +436,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res->flags = shared ? SANLK_RES_SHARED : 0;
|
||||||
res->num_disks = 1;
|
res->num_disks = 1;
|
||||||
if (!virStrcpy(res->name, name, SANLK_NAME_LEN)) {
|
if (!virStrcpy(res->name, name, SANLK_NAME_LEN)) {
|
||||||
virLockError(VIR_ERR_INTERNAL_ERROR,
|
virLockError(VIR_ERR_INTERNAL_ERROR,
|
||||||
@ -485,7 +482,8 @@ cleanup:
|
|||||||
static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
||||||
const char *name,
|
const char *name,
|
||||||
size_t nparams,
|
size_t nparams,
|
||||||
virLockManagerParamPtr params ATTRIBUTE_UNUSED)
|
virLockManagerParamPtr params ATTRIBUTE_UNUSED,
|
||||||
|
bool shared)
|
||||||
{
|
{
|
||||||
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
@ -503,6 +501,7 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock,
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
res->flags = shared ? SANLK_RES_SHARED : 0;
|
||||||
res->num_disks = 1;
|
res->num_disks = 1;
|
||||||
if (virLockManagerSanlockDiskLeaseName(name, res->name, SANLK_NAME_LEN) < 0)
|
if (virLockManagerSanlockDiskLeaseName(name, res->name, SANLK_NAME_LEN) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
@ -630,27 +629,15 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((flags & (VIR_LOCK_MANAGER_RESOURCE_READONLY |
|
/* Treat R/O resources as a no-op lock request */
|
||||||
VIR_LOCK_MANAGER_RESOURCE_SHARED)) &&
|
if (flags & VIR_LOCK_MANAGER_RESOURCE_READONLY)
|
||||||
driver->ignoreReadonlyShared) {
|
return 0;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (flags & VIR_LOCK_MANAGER_RESOURCE_READONLY) {
|
|
||||||
virLockError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("Readonly leases are not supported"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
if (flags & VIR_LOCK_MANAGER_RESOURCE_SHARED) {
|
|
||||||
virLockError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
|
|
||||||
_("Shareable leases are not supported"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK:
|
case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK:
|
||||||
if (driver->autoDiskLease) {
|
if (driver->autoDiskLease) {
|
||||||
if (virLockManagerSanlockAddDisk(lock, name, nparams, params) < 0)
|
if (virLockManagerSanlockAddDisk(lock, name, nparams, params,
|
||||||
|
!!(flags & VIR_LOCK_MANAGER_RESOURCE_SHARED)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (virLockManagerSanlockCreateLease(priv->res_args[priv->res_count-1]) < 0)
|
if (virLockManagerSanlockCreateLease(priv->res_args[priv->res_count-1]) < 0)
|
||||||
@ -664,7 +651,8 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE:
|
case VIR_LOCK_MANAGER_RESOURCE_TYPE_LEASE:
|
||||||
if (virLockManagerSanlockAddLease(lock, name, nparams, params) < 0)
|
if (virLockManagerSanlockAddLease(lock, name, nparams, params,
|
||||||
|
!!(flags & VIR_LOCK_MANAGER_RESOURCE_SHARED)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -52,10 +52,3 @@
|
|||||||
# to enabled, otherwise it defaults to disabled.
|
# to enabled, otherwise it defaults to disabled.
|
||||||
#
|
#
|
||||||
#require_lease_for_disks = 1
|
#require_lease_for_disks = 1
|
||||||
|
|
||||||
#
|
|
||||||
# Enable this flag to have sanlock ignore readonly and shared disks.
|
|
||||||
# If disabled, then this rejects attempts to share resources until
|
|
||||||
# sanlock gains support for shared locks.
|
|
||||||
#
|
|
||||||
#ignore_readonly_and_shared_disks = 1
|
|
||||||
|
@ -6,4 +6,3 @@ module Test_libvirt_sanlock =
|
|||||||
{ "disk_lease_dir" = "/var/lib/libvirt/sanlock" }
|
{ "disk_lease_dir" = "/var/lib/libvirt/sanlock" }
|
||||||
{ "host_id" = "1" }
|
{ "host_id" = "1" }
|
||||||
{ "require_lease_for_disks" = "1" }
|
{ "require_lease_for_disks" = "1" }
|
||||||
{ "ignore_readonly_and_shared_disks" = "1" }
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user