commit b8012ce9312f00947c5ca7250a7a96534c85835f Author: David Weber Date: Mon May 14 09:53:02 2012 +0000 sanlock: fix locking for readonly devices Add ignore param for readonly and shared disk in sanlock diff --git a/src/locking/libvirt_sanlock.aug b/src/locking/libvirt_sanlock.aug index 5f5f8a1..d65b002 100644 --- a/src/locking/libvirt_sanlock.aug +++ b/src/locking/libvirt_sanlock.aug @@ -21,6 +21,7 @@ module Libvirt_sanlock = | bool_entry "auto_disk_leases" | int_entry "host_id" | bool_entry "require_lease_for_disks" + | bool_entry "ignore_readonly_and_shared_disks" let comment = [ label "#comment" . del /#[ \t]*/ "# " . store /([^ \t\n][^\n]*)?/ . del /\n/ "\n" ] let empty = [ label "#empty" . eol ] diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index d344d6a..146aefd 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -1,7 +1,7 @@ /* * lock_driver_sanlock.c: A lock driver for Sanlock * - * Copyright (C) 2010-2011 Red Hat, Inc. + * Copyright (C) 2010-2012 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 @@ -65,6 +65,7 @@ struct _virLockManagerSanlockDriver { bool requireLeaseForDisks; int hostID; bool autoDiskLease; + bool ignoreReadonlyShared; char *autoDiskLeasePath; }; @@ -114,6 +115,10 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) CHECK_TYPE("auto_disk_leases", VIR_CONF_LONG); 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"); CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING); if (p && p->str) { @@ -625,6 +630,12 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock, return -1; } + if ((flags & (VIR_LOCK_MANAGER_RESOURCE_READONLY | + VIR_LOCK_MANAGER_RESOURCE_SHARED)) && + driver->ignoreReadonlyShared) { + return 0; + } + if (flags & VIR_LOCK_MANAGER_RESOURCE_READONLY) { virLockError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", _("Readonly leases are not supported")); diff --git a/src/locking/sanlock.conf b/src/locking/sanlock.conf index efc35ee..19ab2b3 100644 --- a/src/locking/sanlock.conf +++ b/src/locking/sanlock.conf @@ -52,3 +52,10 @@ # to enabled, otherwise it defaults to disabled. # #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 commit acbd4965c44c4dbc676dfe89aff970052e376073 Author: Daniel P. Berrange Date: Thu Jun 21 15:34:46 2012 +0100 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 diff --git a/src/locking/lock_driver_sanlock.c b/src/locking/lock_driver_sanlock.c index 146aefd..16941c9 100644 --- a/src/locking/lock_driver_sanlock.c +++ b/src/locking/lock_driver_sanlock.c @@ -65,7 +65,6 @@ struct _virLockManagerSanlockDriver { bool requireLeaseForDisks; int hostID; bool autoDiskLease; - bool ignoreReadonlyShared; char *autoDiskLeasePath; }; @@ -115,10 +114,6 @@ static int virLockManagerSanlockLoadConfig(const char *configFile) CHECK_TYPE("auto_disk_leases", VIR_CONF_LONG); 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"); CHECK_TYPE("disk_lease_dir", VIR_CONF_STRING); if (p && p->str) { @@ -428,7 +423,8 @@ static int virLockManagerSanlockDiskLeaseName(const char *path, static int virLockManagerSanlockAddLease(virLockManagerPtr lock, const char *name, size_t nparams, - virLockManagerParamPtr params) + virLockManagerParamPtr params, + bool shared) { virLockManagerSanlockPrivatePtr priv = lock->privateData; int ret = -1; @@ -440,6 +436,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock, goto cleanup; } + res->flags = shared ? SANLK_RES_SHARED : 0; res->num_disks = 1; if (!virStrcpy(res->name, name, SANLK_NAME_LEN)) { virLockError(VIR_ERR_INTERNAL_ERROR, @@ -485,7 +482,8 @@ cleanup: static int virLockManagerSanlockAddDisk(virLockManagerPtr lock, const char *name, size_t nparams, - virLockManagerParamPtr params ATTRIBUTE_UNUSED) + virLockManagerParamPtr params ATTRIBUTE_UNUSED, + bool shared) { virLockManagerSanlockPrivatePtr priv = lock->privateData; int ret = -1; @@ -503,6 +501,7 @@ static int virLockManagerSanlockAddDisk(virLockManagerPtr lock, goto cleanup; } + res->flags = shared ? SANLK_RES_SHARED : 0; res->num_disks = 1; if (virLockManagerSanlockDiskLeaseName(name, res->name, SANLK_NAME_LEN) < 0) goto cleanup; @@ -630,27 +629,15 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock, return -1; } - if ((flags & (VIR_LOCK_MANAGER_RESOURCE_READONLY | - VIR_LOCK_MANAGER_RESOURCE_SHARED)) && - driver->ignoreReadonlyShared) { - 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; - } + /* Treat R/O resources as a no-op lock request */ + if (flags & VIR_LOCK_MANAGER_RESOURCE_READONLY) + return 0; switch (type) { case VIR_LOCK_MANAGER_RESOURCE_TYPE_DISK: 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; if (virLockManagerSanlockCreateLease(priv->res_args[priv->res_count-1]) < 0) @@ -664,7 +651,8 @@ static int virLockManagerSanlockAddResource(virLockManagerPtr lock, break; 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; break; diff --git a/src/locking/sanlock.conf b/src/locking/sanlock.conf index 19ab2b3..efc35ee 100644 --- a/src/locking/sanlock.conf +++ b/src/locking/sanlock.conf @@ -52,10 +52,3 @@ # to enabled, otherwise it defaults to disabled. # #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