For consistency the request actions are renamed to:
SANLK_REQ_SIGKILL: sigkill the process holding the resource lease. SANLK_REQ_RELEASE: gracefully release the lease sending SIGUSR1 to the process holding the resource lease.
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- src/resource.c | 4 ++-- src/sanlock.8 | 4 ++-- src/sanlock_resource.h | 14 ++++++++++---- 3 files changed, 14 insertions(+), 8 deletions(-)
diff --git a/src/resource.c b/src/resource.c index 2a60a16..6c02107 100644 --- a/src/resource.c +++ b/src/resource.c @@ -856,11 +856,11 @@ static void do_request(struct token *tt, int pid, uint32_t force_mode)
memset(&hm, 0, sizeof(hm));
- if (force_mode == SANLK_REQ_KILL_PID) { + if (force_mode == SANLK_REQ_SIGKILL) { hm.type = HELPER_MSG_KILLPID; hm.pid = pid; hm.sig = (flags & R_RESTRICT_SIGKILL) ? SIGTERM : SIGKILL; - } else if (force_mode == SANLK_REQ_SIGUSR1) { + } else if (force_mode == SANLK_REQ_RELEASE) { hm.type = HELPER_MSG_KILLPID; hm.pid = pid; hm.sig = SIGUSR1; diff --git a/src/sanlock.8 b/src/sanlock.8 index a23e54a..ea188f6 100644 --- a/src/sanlock.8 +++ b/src/sanlock.8 @@ -515,12 +515,12 @@ set in A's bitmap for request_finish_seconds.) \fIforce_mode\fP determines the action the resource lease owner should take:
-\fB1\fP (KILL_PID): kill the process holding the resource lease. When the +\fB1\fP (SIGKILL): kill the process holding the resource lease. When the process has exited, the resource lease will be released, and can then be acquired by anyone. The kill signal is SIGKILL (or SIGTERM if SIGKILL is restricted.)
-\fB2\fP (SIGUSR1): send SIGUSR1 to the process holding the resource lease. +\fB2\fP (RELEASE): send SIGUSR1 to the process holding the resource lease.
\fB3\fP (KILLPATH): run the program configured by sanlock_killpath against the process holding the resource lease. diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h index f68fc3e..4969b65 100644 --- a/src/sanlock_resource.h +++ b/src/sanlock_resource.h @@ -33,15 +33,21 @@
/* * request force_mode - * SANLK_REQ_KILL_PID: send SIGKILL to pid holding the resource, or - * SIGTERM if SIGKILL is restricted - * SANLK_REQ_SIGUSR1: send SIGUSR1 to pid holding the resource + * SANLK_REQ_SIGKILL: send SIGKILL to pid holding the resource, or + * SIGTERM if SIGKILL is restricted + * SANLK_REQ_RELEASE: send SIGUSR1 to pid holding the resource * SANLK_REQ_KILLPATH: run configured killpath against the pid */
+#define SANLK_REQ_SIGKILL 0x00000001 +#define SANLK_REQ_RELEASE 0x00000002 +#define SANLK_REQ_KILLPATH 0x00000003 + +/* + * kept for backward compatibility + */ #define SANLK_REQ_KILL_PID 0x00000001 #define SANLK_REQ_SIGUSR1 0x00000002 -#define SANLK_REQ_KILLPATH 0x00000003
int sanlock_register(void);
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- python/sanlock.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index 750157f..c5999d3 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -689,9 +689,9 @@ PyDoc_STRVAR(pydoc_get_lockspaces, "\ get_lockspaces() -> dict\n\ Return the list of lockspaces currently managed by sanlock. The reported\n\ flag indicates whether the lockspace is acquired (0) or in transition.\n\ -The possible transition values are SANLK_LSF_ADD if the lockspace is in\n\ -the process of being acquired, and SANLK_LSF_REM if it's in the process\n\ -of being released.\n"); +The possible transition values are LSFLAG_ADD if the lockspace is in the\n\ +process of being acquired, and LSFLAG_REM if it's in the process of being\n\ +released.\n");
static PyObject * py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds) @@ -1081,13 +1081,13 @@ initsanlock(void) }
if ((sk_constant = PyInt_FromLong(SANLK_LSF_ADD)) != NULL) { - if (PyModule_AddObject(py_module, "SANLK_LSF_ADD", sk_constant)) { + if (PyModule_AddObject(py_module, "LSFLAG_ADD", sk_constant)) { Py_DECREF(sk_constant); } }
if ((sk_constant = PyInt_FromLong(SANLK_LSF_REM)) != NULL) { - if (PyModule_AddObject(py_module, "SANLK_LSF_REM", sk_constant)) { + if (PyModule_AddObject(py_module, "LSFLAG_REM", sk_constant)) { Py_DECREF(sk_constant); } }
The init_lockspace/resource commands have been obsoleted, the new ones are write_lockspace/resource.
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- python/example.py | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/python/example.py b/python/example.py index ef1c957..28b5180 100644 --- a/python/example.py +++ b/python/example.py @@ -19,10 +19,10 @@ def main(): fd = sanlock.register()
print "Initializing '%s'" % (LOCKSPACE_NAME,) - sanlock.init_lockspace(LOCKSPACE_NAME, disk) + sanlock.write_lockspace(LOCKSPACE_NAME, disk)
print "Initializing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME) - sanlock.init_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS) + sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS)
print "Acquiring the id '%i' on '%s'" % (HOST_ID, LOCKSPACE_NAME) sanlock.add_lockspace(LOCKSPACE_NAME, HOST_ID, disk)
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- python/example.py | 3 ++- python/sanlock.c | 19 +++++++++++++------ 2 files changed, 15 insertions(+), 7 deletions(-)
diff --git a/python/example.py b/python/example.py index 28b5180..354579e 100644 --- a/python/example.py +++ b/python/example.py @@ -29,7 +29,8 @@ def main():
try: print "Acquiring '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME) - sanlock.acquire(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd) + sanlock.acquire(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd, + version=0) print "Releasing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME) sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd) finally: diff --git a/python/sanlock.c b/python/sanlock.c index c5999d3..79bc8d2 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -779,28 +779,29 @@ exit_fail:
/* acquire */ PyDoc_STRVAR(pydoc_acquire, "\ -acquire(lockspace, resource, disks [, slkfd=fd, pid=owner, shared=False])\n\ +acquire(lockspace, resource, disks \ +[, slkfd=fd, pid=owner, shared=False, version=0])\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). If shared is True the resource will be acquired in the shared\n\ -mode.\n\ +mode. The version is the version of the lease that must be acquired or fail.\n\ The disks must be in the format: [(path, offset), ... ]\n");
static PyObject * py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv, sanlockfd = -1, pid = -1, shared = 0; + int rv, sanlockfd = -1, pid = -1, shared = 0, version = 0; const char *lockspace, *resource; struct sanlk_resource *res; PyObject *disks;
static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd", - "pid", "shared", NULL}; + "pid", "shared", "version", NULL};
/* parse python tuple */ - if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiii", kwlist, &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid, - &shared)) { + &shared, &version)) { return NULL; }
@@ -824,6 +825,12 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds) res->flags |= SANLK_RES_SHARED; }
+ /* prepare the resource version */ + if (version) { + res->flags |= SANLK_RES_LVER; + res->lver = version; + } + /* acquire sanlock resource (gil disabled) */ Py_BEGIN_ALLOW_THREADS rv = sanlock_acquire(sanlockfd, pid, 0, 1, &res, 0);
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- python/sanlock.c | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index 79bc8d2..e1e0397 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -461,6 +461,14 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds) if (rv != 0) goto exit_fail;
+ /* fill the dictionary information: version */ + if ((rs_entry = PyInt_FromLong(rs->lver)) == NULL) + goto exit_fail; + rv = PyDict_SetItemString(rs_info, "version", rs_entry); + Py_DECREF(rs_entry); + if (rv != 0) + goto exit_fail; + /* success */ free(rs); return rs_info;
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- python/sanlock.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 72 insertions(+), 0 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index e1e0397..7954690 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -907,6 +907,64 @@ exit_fail: return NULL; }
+/* request */ +PyDoc_STRVAR(pydoc_request, "\ +request(lockspace, resource, disks [, action=REQ_RELEASE, version=0])\n\ +Request the owner of a resource to do something specified by action.\n\ +The possible values for action are: REQ_RELEASE to request a graceful\n\ +release of the resource and REQ_SIGKILL to sigkill the owner of the\n\ +resource (forcible release).\n\ +The disks must be in the format: [(path, offset), ... ]"); +static PyObject * +py_request(PyObject *self __unused, PyObject *args, PyObject *keywds) +{ + int rv, action = SANLK_REQ_RELEASE, version = 0; + const char *lockspace, *resource; + struct sanlk_resource *res; + PyObject *disks; + + static char *kwlist[] = {"lockspace", "resource", "disks", "action", + "version", NULL}; + + /* parse python tuple */ + if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii", kwlist, + &lockspace, &resource, &PyList_Type, &disks, &action, &version)) { + return NULL; + } + + /* parse and check sanlock resource */ + if (__parse_resource(disks, &res) < 0) { + return NULL; + } + + /* prepare sanlock names */ + strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN); + strncpy(res->name, resource, SANLK_NAME_LEN); + + /* prepare the resource version */ + if (version) { + res->flags |= SANLK_RES_LVER; + res->lver = version; + } + + /* request sanlock resource (gil disabled) */ + Py_BEGIN_ALLOW_THREADS + rv = sanlock_request(0, action, res); + Py_END_ALLOW_THREADS + + if (rv != 0) { + __set_exception(rv, "Sanlock request not submitted"); + goto exit_fail; + } + + free(res); + Py_RETURN_NONE; + +exit_fail: + free(res); + return NULL; +} + /* killpath */ PyDoc_STRVAR(pydoc_killpath, "\ killpath(path, args [, slkfd=fd])\n\ @@ -1035,6 +1093,8 @@ sanlock_methods[] = { METH_VARARGS|METH_KEYWORDS, pydoc_acquire}, {"release", (PyCFunction) py_release, METH_VARARGS|METH_KEYWORDS, pydoc_release}, + {"request", (PyCFunction) py_request, + METH_VARARGS|METH_KEYWORDS, pydoc_request}, {"killpath", (PyCFunction) py_killpath, METH_VARARGS|METH_KEYWORDS, pydoc_killpath}, {NULL, NULL, 0, NULL} @@ -1106,4 +1166,16 @@ initsanlock(void) Py_DECREF(sk_constant); } } + + if ((sk_constant = PyInt_FromLong(SANLK_REQ_SIGKILL)) != NULL) { + if (PyModule_AddObject(py_module, "REQ_SIGKILL", sk_constant)) { + Py_DECREF(sk_constant); + } + } + + if ((sk_constant = PyInt_FromLong(SANLK_REQ_RELEASE)) != NULL) { + if (PyModule_AddObject(py_module, "REQ_RELEASE", sk_constant)) { + Py_DECREF(sk_constant); + } + } }
sanlock-devel@lists.fedorahosted.org