python/sanlock.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
src/client.c | 5 +++++
src/cmd.c | 33 +++++++++++++++++++++++++++++++++
src/lockspace.c | 28 ++++++++++++++++++++++++++++
src/lockspace.h | 1 +
src/main.c | 10 ++++++++++
src/sanlock.8 | 4 ++++
src/sanlock_admin.h | 8 ++++++++
src/sanlock_internal.h | 1 +
src/sanlock_sock.h | 1 +
10 files changed, 136 insertions(+)
New commits:
commit ec69d6a166a54bd8989d94107f201551cbff024f
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Jan 4 15:07:37 2012 +0000
python: add the inq_lockspace command binding
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 79b7e2d..9f60e3d 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -303,6 +303,50 @@ py_add_lockspace(PyObject *self __unused, PyObject *args)
Py_RETURN_NONE;
}
+/* inq_lockspace */
+PyDoc_STRVAR(pydoc_inq_lockspace, "\
+inq_lockspace(lockspace, host_id, path, offset=0)\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.");
+
+static PyObject *
+py_inq_lockspace(PyObject *self __unused, PyObject *args)
+{
+ int rv;
+ const char *lockspace, *path;
+ struct sanlk_lockspace ls;
+
+ /* 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)) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(ls.name, lockspace, SANLK_NAME_LEN);
+ strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN);
+
+ /* add sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_inq_lockspace(&ls, 0 );
+ Py_END_ALLOW_THREADS
+
+ if (rv == 0) {
+ Py_RETURN_TRUE;
+ } else if (rv == -ENOENT) {
+ Py_RETURN_FALSE;
+ } else if (rv == -EINPROGRESS) {
+ Py_RETURN_NONE;
+ }
+
+ __set_exception(rv, "Sanlock lockspace inquire failure");
+ return NULL;
+}
+
/* rem_lockspace */
PyDoc_STRVAR(pydoc_rem_lockspace, "\
rem_lockspace(lockspace, host_id, path, offset=0)\n\
@@ -472,6 +516,7 @@ sanlock_methods[] = {
{"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},
{"acquire", (PyCFunction) py_acquire,
METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
commit 9b0462743206f6bafc648b055a8c4091ee7a5554
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Jan 4 15:07:36 2012 +0000
sanlock: implement the inq_lockspace command
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/src/client.c b/src/client.c
index ea25832..9c2a485 100644
--- a/src/client.c
+++ b/src/client.c
@@ -145,6 +145,11 @@ int sanlock_add_lockspace(struct sanlk_lockspace *ls, uint32_t flags)
return cmd_lockspace(SM_CMD_ADD_LOCKSPACE, ls, flags);
}
+int sanlock_inq_lockspace(struct sanlk_lockspace *ls, uint32_t flags)
+{
+ return cmd_lockspace(SM_CMD_INQ_LOCKSPACE, ls, flags);
+}
+
int sanlock_rem_lockspace(struct sanlk_lockspace *ls, uint32_t flags)
{
return cmd_lockspace(SM_CMD_REM_LOCKSPACE, ls, flags);
diff --git a/src/cmd.c b/src/cmd.c
index 97c4eba..bba9719 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -883,6 +883,35 @@ static void cmd_add_lockspace(struct cmd_args *ca)
client_resume(ca->ci_in);
}
+static void cmd_inq_lockspace(struct cmd_args *ca)
+{
+ struct sanlk_lockspace lockspace;
+ int fd, rv, result;
+
+ fd = client[ca->ci_in].fd;
+
+ rv = recv(fd, &lockspace, sizeof(struct sanlk_lockspace), MSG_WAITALL);
+ if (rv != sizeof(struct sanlk_lockspace)) {
+ log_error("cmd_inq_lockspace %d,%d recv %d %d",
+ ca->ci_in, fd, rv, errno);
+ result = -ENOTCONN;
+ goto reply;
+ }
+
+ log_debug("cmd_inq_lockspace %d,%d %.48s:%llu:%s:%llu",
+ 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);
+
+ result = inq_lockspace(&lockspace);
+ reply:
+ log_debug("cmd_inq_lockspace %d,%d done %d", ca->ci_in, fd, result);
+
+ send_result(fd, &ca->header, result);
+ client_resume(ca->ci_in);
+}
+
/*
* TODO: rem_lockspace works like a renewal failure would, and abandons
* resource leases (tokens) without releasing them. Unlike the renewal
@@ -1146,6 +1175,10 @@ void call_cmd_thread(struct task *task, struct cmd_args *ca)
strcpy(client[ca->ci_in].owner_name, "add_lockspace");
cmd_add_lockspace(ca);
break;
+ case SM_CMD_INQ_LOCKSPACE:
+ strcpy(client[ca->ci_in].owner_name, "inq_lockspace");
+ cmd_inq_lockspace(ca);
+ break;
case SM_CMD_REM_LOCKSPACE:
strcpy(client[ca->ci_in].owner_name, "rem_lockspace");
cmd_rem_lockspace(ca);
diff --git a/src/lockspace.c b/src/lockspace.c
index 2537b01..f4e51bd 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -701,6 +701,34 @@ int add_lockspace(struct sanlk_lockspace *ls)
return rv;
}
+int inq_lockspace(struct sanlk_lockspace *ls)
+{
+ int rv;
+ struct space *sp;
+
+ pthread_mutex_lock(&spaces_mutex);
+
+ sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id,
+ &spaces, NULL, NULL);
+
+ if (sp) {
+ rv = 0;
+ goto out;
+ } else {
+ rv = -ENOENT;
+ }
+
+ sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id,
+ &spaces_add, &spaces_rem, NULL);
+
+ if (sp)
+ rv = -EINPROGRESS;
+
+ out:
+ pthread_mutex_unlock(&spaces_mutex);
+ return rv;
+}
+
int rem_lockspace(struct sanlk_lockspace *ls)
{
struct space *sp, *sp2;
diff --git a/src/lockspace.h b/src/lockspace.h
index 00dbcf7..463809a 100644
--- a/src/lockspace.h
+++ b/src/lockspace.h
@@ -19,6 +19,7 @@ int test_id_bit(int host_id, char *bitmap);
int check_our_lease(struct task *task, struct space *sp, int *check_all, char *check_buf);
void check_other_leases(struct task *task, struct space *sp, char *buf);
int add_lockspace(struct sanlk_lockspace *ls);
+int inq_lockspace(struct sanlk_lockspace *ls);
int rem_lockspace(struct sanlk_lockspace *ls);
void free_lockspaces(int wait);
diff --git a/src/main.c b/src/main.c
index e2d0c0b..1efe3fb 100644
--- a/src/main.c
+++ b/src/main.c
@@ -994,6 +994,7 @@ static void process_connection(int ci)
call_cmd_daemon(ci, &h, client_maxi);
break;
case SM_CMD_ADD_LOCKSPACE:
+ case SM_CMD_INQ_LOCKSPACE:
case SM_CMD_REM_LOCKSPACE:
case SM_CMD_REQUEST:
case SM_CMD_EXAMINE_RESOURCE:
@@ -1366,6 +1367,7 @@ static void print_usage(void)
printf("sanlock client init -s LOCKSPACE | -r RESOURCE\n");
printf("sanlock client align -s LOCKSPACE\n");
printf("sanlock client add_lockspace -s LOCKSPACE\n");
+ printf("sanlock client inq_lockspace -s LOCKSPACE\n");
printf("sanlock client rem_lockspace -s LOCKSPACE\n");
printf("sanlock client command -r RESOURCE -c <path> <args>\n");
printf("sanlock client acquire -r RESOURCE -p <pid>\n");
@@ -1466,6 +1468,8 @@ static int read_command_line(int argc, char *argv[])
com.action = ACT_SHUTDOWN;
else if (!strcmp(act, "add_lockspace"))
com.action = ACT_ADD_LOCKSPACE;
+ else if (!strcmp(act, "inq_lockspace"))
+ com.action = ACT_INQ_LOCKSPACE;
else if (!strcmp(act, "rem_lockspace"))
com.action = ACT_REM_LOCKSPACE;
else if (!strcmp(act, "command"))
@@ -1749,6 +1753,12 @@ static int do_client(void)
log_tool("add_lockspace done %d", rv);
break;
+ case ACT_INQ_LOCKSPACE:
+ log_tool("inq_lockspace");
+ rv = sanlock_inq_lockspace(&com.lockspace, 0);
+ log_tool("inq_lockspace done %d", rv);
+ break;
+
case ACT_REM_LOCKSPACE:
log_tool("rem_lockspace");
rv = sanlock_rem_lockspace(&com.lockspace, 0);
diff --git a/src/sanlock.8 b/src/sanlock.8
index 891ab86..0136fe9 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -281,6 +281,10 @@ path. Only path is used from the LOCKSPACE argument.
Tell the sanlock daemon to acquire the specified host_id in the lockspace.
This will allow resources to be acquired in the lockspace.
+.BR "sanlock client inq_lockspace -s" " LOCKSPACE"
+
+Ask to the sanlock daemon weather the lockspace is acquired or not.
+
.BR "sanlock client rem_lockspace -s" " LOCKSPACE"
Tell the sanlock daemon to release the specified host_id in the lockspace.
diff --git a/src/sanlock_admin.h b/src/sanlock_admin.h
index 802beee..0f5e452 100644
--- a/src/sanlock_admin.h
+++ b/src/sanlock_admin.h
@@ -22,6 +22,14 @@
int sanlock_add_lockspace(struct sanlk_lockspace *ls, uint32_t flags);
/*
+ * inq_lockspace returns:
+ * 0: the lockspace exists and is currently held
+ * -ENOENT: lockspace not found
+ */
+
+int sanlock_inq_lockspace(struct sanlk_lockspace *ls, uint32_t flags);
+
+/*
* rem_lockspace returns:
* 0: the lockspace has been removed successfully
* -EINPROGRESS: the lockspace is already in the process of being removed
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 567b704..0fc35b9 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -550,6 +550,7 @@ enum {
ACT_LOG_DUMP,
ACT_SHUTDOWN,
ACT_ADD_LOCKSPACE,
+ ACT_INQ_LOCKSPACE,
ACT_REM_LOCKSPACE,
ACT_COMMAND,
ACT_ACQUIRE,
diff --git a/src/sanlock_sock.h b/src/sanlock_sock.h
index 8279bd4..b9001c4 100644
--- a/src/sanlock_sock.h
+++ b/src/sanlock_sock.h
@@ -35,6 +35,7 @@ enum {
SM_CMD_EXAMINE_LOCKSPACE = 15,
SM_CMD_EXAMINE_RESOURCE = 16,
SM_CMD_HOST_STATUS = 17,
+ SM_CMD_INQ_LOCKSPACE = 18,
};
struct sm_header {