New SANLK_INQ_WAIT for sanlock_inq_lockspace().
When the SANLK_INQ_WAIT flag is used the command will block and wait for the ongoing procedure (add_lockspace/rem_lockspace) to complete before before returning the status.
sanlock_inq_lockspace() still returns:
0 lockspace exists and is not being added or removed -EINPROGRESS add or rem is in progress, when the flag SANLK_INQ_WAIT is not used -ENOENT no lockspace with matching name and disk location is found
Signed-off-by: Federico Simoncelli fsimonce@redhat.com --- python/sanlock.c | 25 +++++++++++++++++-------- src/cmd.c | 15 ++++++++++++--- src/sanlock_admin.h | 3 +++ 3 files changed, 32 insertions(+), 11 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c index bfce46c..d953c90 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -314,36 +314,45 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* inq_lockspace */ PyDoc_STRVAR(pydoc_inq_lockspace, "\ -inq_lockspace(lockspace, host_id, path, offset=0)\n\ +inq_lockspace(lockspace, host_id, path, offset=0, wait=False)\n\ Return True if the sanlock daemon currently owns the host_id in lockspace,\n\ False otherwise. The special value None is returned when the daemon is\n\ -still in the process of acquiring or releasing the host_id."); +still in the process of acquiring or releasing the host_id. If the wait\n\ +flag is set to True the function will block until the host_id is either\n\ +acquired or released.");
static PyObject * py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv; + int rv, waitrs = 0, flags = 0; const char *lockspace, *path; struct sanlk_lockspace ls;
- static char *kwlist[] = {"lockspace", "host_id", "path", "offset", NULL}; + static char *kwlist[] = {"lockspace", "host_id", "path", "offset", + "wait", NULL};
/* initialize lockspace structure */ memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */ - if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|k", kwlist, - &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, + &waitrs)) { return NULL; }
+ /* prepare sanlock_inq_lockspace flags */ + if (waitrs) { + flags |= SANLK_INQ_WAIT; + } + /* 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_inq_lockspace(&ls, 0); + rv = sanlock_inq_lockspace(&ls, flags); Py_END_ALLOW_THREADS
if (rv == 0) { @@ -362,7 +371,7 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds) PyDoc_STRVAR(pydoc_rem_lockspace, "\ 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\ +function will return immediately and the status can be checked using\n\ 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)."); diff --git a/src/cmd.c b/src/cmd.c index 6417df0..de82ff7 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -891,6 +891,7 @@ static void cmd_add_lockspace(struct cmd_args *ca) static void cmd_inq_lockspace(struct cmd_args *ca) { struct sanlk_lockspace lockspace; + int waitrs = ca->header.cmd_flags & SANLK_INQ_WAIT; int fd, rv, result;
fd = client[ca->ci_in].fd; @@ -903,13 +904,21 @@ static void cmd_inq_lockspace(struct cmd_args *ca) goto reply; }
- log_debug("cmd_inq_lockspace %d,%d %.48s:%llu:%s:%llu", + log_debug("cmd_inq_lockspace %d,%d %.48s:%llu:%s:%llu flags %x", ca->ci_in, fd, lockspace.name, (unsigned long long)lockspace.host_id, lockspace.host_id_disk.path, - (unsigned long long)lockspace.host_id_disk.offset); + (unsigned long long)lockspace.host_id_disk.offset, + ca->header.cmd_flags); + + while (1) { + result = inq_lockspace(&lockspace); + if ((result != -EINPROGRESS) || !(waitrs)) { + break; + } + sleep(1); + }
- result = inq_lockspace(&lockspace); reply: log_debug("cmd_inq_lockspace %d,%d done %d", ca->ci_in, fd, result);
diff --git a/src/sanlock_admin.h b/src/sanlock_admin.h index c5a3a0f..5134faa 100644 --- a/src/sanlock_admin.h +++ b/src/sanlock_admin.h @@ -17,6 +17,9 @@ #define SANLK_REM_ASYNC 0x00000001 #define SANLK_REM_UNUSED 0x00000002
+/* inq flags */ +#define SANLK_INQ_WAIT 0x00000001 + /* * add_lockspace returns: * 0: the lockspace has been added successfully
sanlock-devel@lists.fedorahosted.org