init.d/sanlock | 2 ++
python/sanlock.c | 30 +++++++++++++++++++++---------
src/delta_lease.c | 6 ++++++
src/sanlock_internal.h | 4 ++++
4 files changed, 33 insertions(+), 9 deletions(-)
New commits:
commit 9e299a36cca6d07205ecd43b18ebca773396f727
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Mon Dec 19 16:32:43 2011 +0000
python: acquire leases for other processes
The python binding was lacking the support for acquiring leases on
behalf of other processes.
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 9c1bfa0..79b7e2d 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -343,21 +343,26 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args)
/* acquire */
PyDoc_STRVAR(pydoc_acquire, "\
-acquire(fd, lockspace, resource, disks)\n\
-Acquire a resource lease for the current process.\n\
-The disks must be in the format: [(path, offset), ... ]");
+acquire(lockspace, resource, disks [, slkfd=fd, pid=owner])\n\
+Acquire a resource lease for the current process (using the slkfd argument\n\
+to specify the sanlock file descriptor) or for an other process (using the\n\
+pid argument).\n\
+The disks must be in the format: [(path, offset), ... ]\n");
static PyObject *
-py_acquire(PyObject *self __unused, PyObject *args)
+py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, sanlockfd;
+ int rv, sanlockfd = -1, pid = -1;
const char *lockspace, *resource;
struct sanlk_resource *res;
PyObject *disks;
+ static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd",
+ "pid", NULL};
+
/* parse python tuple */
- if (!PyArg_ParseTuple(args, "issO!",
- &sanlockfd, &lockspace, &resource, &PyList_Type, &disks)) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii", kwlist,
+ &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid)) {
return NULL;
}
@@ -366,13 +371,19 @@ py_acquire(PyObject *self __unused, PyObject *args)
return NULL;
}
+ /* check if any of the slkfd or pid parameters was given */
+ if (sanlockfd == -1 && pid == -1) {
+ __set_exception(EINVAL, "Invalid slkfd and pid values");
+ return NULL;
+ }
+
/* prepare sanlock names */
strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
strncpy(res->name, resource, SANLK_NAME_LEN);
/* acquire sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_acquire(sanlockfd, -1, 0, 1, &res, 0);
+ rv = sanlock_acquire(sanlockfd, pid, 0, 1, &res, 0);
Py_END_ALLOW_THREADS
if (rv != 0) {
@@ -462,7 +473,8 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_init_resource},
{"add_lockspace", py_add_lockspace, METH_VARARGS, pydoc_add_lockspace},
{"rem_lockspace", py_rem_lockspace, METH_VARARGS, pydoc_rem_lockspace},
- {"acquire", py_acquire, METH_VARARGS, pydoc_acquire},
+ {"acquire", (PyCFunction) py_acquire,
+ METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
{"release", py_release, METH_VARARGS, pydoc_release},
{NULL, NULL, 0, NULL}
};
commit 4cdb754d208ac108fa3a65cb463ad8eed42a0f46
Author: David Teigland <teigland(a)redhat.com>
Date: Mon Dec 19 12:07:10 2011 -0600
sanlock: quick host_id reacquire
when we were the last owner.
Also use sanlock uid/gid in init script.
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/init.d/sanlock b/init.d/sanlock
index 74df2c9..b2682ef 100644
--- a/init.d/sanlock
+++ b/init.d/sanlock
@@ -25,6 +25,8 @@ prog="sanlock"
lockfile="/var/run/$prog/$prog.pid"
exec="/usr/sbin/$prog"
+SANLOCKOPTS="-U sanlock -G sanlock"
+
[ -f /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
start() {
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 53cbd5e..64bc123 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -211,6 +211,12 @@ int delta_lease_acquire(struct task *task,
if (leader.timestamp == LEASE_FREE)
goto write_new;
+ if (!strncmp(leader.resource_name, our_host_name, NAME_ID_SIZE)) {
+ log_space(sp, "delta_acquire %llu fast reacquire",
+ (unsigned long long)host_id);
+ goto write_new;
+ }
+
/* we need to ensure that a host_id cannot be acquired and released
* sooner than host_dead_seconds because the change in host_id
* ownership affects the host_id "liveness" determination used by paxos
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 46e2b36..567b704 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -429,6 +429,10 @@ struct space {
* 3. ios can't be reliably canceled and never really time out; an io is only
* really dead when the machine is dead/reset or storage access is cut off.
* The delta lease algorithm expects real io timeouts.
+ *
+ * So, the delay is really meant to represent the time until we are certain a
+ * host is safely gone and will no longer write, and for sanlock that means
+ * until the watchdog has reset it.
*/
#define HOSTID_AIO_CB_SIZE 4