python/sanlock.c | 71 +++++++++++++++++++++++++++++++++++++++----------------
1 file changed, 51 insertions(+), 20 deletions(-)
New commits:
commit b6b331352be90c9ea3c868ccb38b12668384f2d7
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Thu May 3 14:25:42 2012 +0000
python: UNUSED flag for lockspace rem
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index fdca561..bfce46c 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -360,27 +360,30 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
/* rem_lockspace */
PyDoc_STRVAR(pydoc_rem_lockspace, "\
-rem_lockspace(lockspace, host_id, path, offset=0, async=False)\n\
+rem_lockspace(lockspace, host_id, path, offset=0, async=False, unused=False)\n\
Remove a lockspace, releasing the acquired host_id. If async is True the\n\
function will return immediatly and the status can be checked using\n\
-inq_lockspace.");
+inq_lockspace. If unused is True the command will fail (EBUSY) if there is\n\
+at least one acquired resource in the lockspace (instead of automatically\n\
+release it).");
static PyObject *
py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, async = 0, flags = 0;
+ int rv, async = 0, unused = 0, flags = 0;
const char *lockspace, *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id",
"path", "offset",
- "async", NULL};
+ "async", "unused", NULL};
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|ki", kwlist,
- &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
&async)) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|kii", kwlist,
+ &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
&async,
+ &unused)) {
return NULL;
}
@@ -393,6 +396,10 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
flags |= SANLK_REM_ASYNC;
}
+ if (unused) {
+ flags |= SANLK_REM_UNUSED;
+ }
+
/* remove sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_rem_lockspace(&ls, flags);
commit c6fc4b00469a500eb6634276ccc03907bed1847b
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Thu May 3 14:25:41 2012 +0000
python: ASYNC flag for lockspace add and rem
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 9ece9da..fdca561 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -267,32 +267,41 @@ exit_fail:
/* add_lockspace */
PyDoc_STRVAR(pydoc_add_lockspace, "\
-add_lockspace(lockspace, host_id, path, offset=0)\n\
-Add a lockspace, acquiring a host_id in it.");
+add_lockspace(lockspace, host_id, path, offset=0, async=False)\n\
+Add a lockspace, acquiring a host_id in it. If async is True the function\n\
+will return immediatly and the status can be checked using inq_lockspace.");
static PyObject *
-py_add_lockspace(PyObject *self __unused, PyObject *args)
+py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv;
+ int rv, async = 0, flags = 0;
const char *lockspace, *path;
struct sanlk_lockspace ls;
+ static char *kwlist[] = {"lockspace", "host_id",
"path", "offset",
+ "async", NULL};
+
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTuple(args, "sks|k",
- &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset)) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|ki", kwlist,
+ &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
&async)) {
return NULL;
}
+ /* prepare sanlock_add_lockspace flags */
+ if (async) {
+ flags |= SANLK_ADD_ASYNC;
+ }
+
/* prepare sanlock names */
strncpy(ls.name, lockspace, SANLK_NAME_LEN);
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
/* add sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_add_lockspace(&ls, 0 );
+ rv = sanlock_add_lockspace(&ls, flags);
Py_END_ALLOW_THREADS
if (rv != 0) {
@@ -311,17 +320,19 @@ False otherwise. The special value None is returned when the daemon
is\n\
still in the process of acquiring or releasing the host_id.");
static PyObject *
-py_inq_lockspace(PyObject *self __unused, PyObject *args)
+py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv;
const char *lockspace, *path;
struct sanlk_lockspace ls;
+ static char *kwlist[] = {"lockspace", "host_id",
"path", "offset", NULL};
+
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTuple(args, "sks|k",
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|k", kwlist,
&lockspace, &ls.host_id, &path, &ls.host_id_disk.offset)) {
return NULL;
}
@@ -332,7 +343,7 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args)
/* add sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_inq_lockspace(&ls, 0 );
+ rv = sanlock_inq_lockspace(&ls, 0);
Py_END_ALLOW_THREADS
if (rv == 0) {
@@ -349,22 +360,27 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args)
/* rem_lockspace */
PyDoc_STRVAR(pydoc_rem_lockspace, "\
-rem_lockspace(lockspace, host_id, path, offset=0)\n\
-Remove a lockspace, releasing the acquired host_id.");
+rem_lockspace(lockspace, host_id, path, offset=0, async=False)\n\
+Remove a lockspace, releasing the acquired host_id. If async is True the\n\
+function will return immediatly and the status can be checked using\n\
+inq_lockspace.");
static PyObject *
-py_rem_lockspace(PyObject *self __unused, PyObject *args)
+py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv;
+ int rv, async = 0, flags = 0;
const char *lockspace, *path;
struct sanlk_lockspace ls;
+ static char *kwlist[] = {"lockspace", "host_id",
"path", "offset",
+ "async", NULL};
+
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTuple(args, "sks|k",
- &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset)) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|ki", kwlist,
+ &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
&async)) {
return NULL;
}
@@ -372,9 +388,14 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args)
strncpy(ls.name, lockspace, SANLK_NAME_LEN);
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+ /* prepare sanlock_rem_lockspace flags */
+ if (async) {
+ flags |= SANLK_REM_ASYNC;
+ }
+
/* remove sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_rem_lockspace(&ls, 0);
+ rv = sanlock_rem_lockspace(&ls, flags);
Py_END_ALLOW_THREADS
if (rv != 0) {
@@ -525,9 +546,12 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_init_lockspace},
{"init_resource", (PyCFunction) py_init_resource,
METH_VARARGS|METH_KEYWORDS, pydoc_init_resource},
- {"add_lockspace", py_add_lockspace, METH_VARARGS, pydoc_add_lockspace},
- {"inq_lockspace", py_inq_lockspace, METH_VARARGS, pydoc_inq_lockspace},
- {"rem_lockspace", py_rem_lockspace, METH_VARARGS, pydoc_rem_lockspace},
+ {"add_lockspace", (PyCFunction) py_add_lockspace,
+ METH_VARARGS|METH_KEYWORDS, pydoc_add_lockspace},
+ {"inq_lockspace", (PyCFunction) py_inq_lockspace,
+ METH_VARARGS|METH_KEYWORDS, pydoc_inq_lockspace},
+ {"rem_lockspace", (PyCFunction) py_rem_lockspace,
+ METH_VARARGS|METH_KEYWORDS, pydoc_rem_lockspace},
{"acquire", (PyCFunction) py_acquire,
METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
{"release", (PyCFunction) py_release,