[PATCHv2] python: add get_lockspaces
by Federico Simoncelli
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
python/sanlock.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 116 insertions(+), 1 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index c0c0276..190518a 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -684,6 +684,107 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_RETURN_NONE;
}
+/* get_lockspaces */
+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");
+
+static PyObject *
+py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, i, lss_size = 0, lss_count;
+ struct sanlk_lockspace *lss = NULL;
+ PyObject *ls_list = NULL, *ls_entry = NULL, *ls_value = NULL;
+
+ while (1) {
+ /* get all the lockspaces (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_get_lockspaces(lss, lss_size, &lss_count, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv == 0)
+ break;
+
+ if (rv != -ENOBUFS) {
+ __set_exception(rv, "Sanlock get lockspace failure");
+ goto exit_fail;
+ }
+
+ lss_size = (lss_count * sizeof(struct sanlk_lockspace));
+ lss = realloc(lss, lss_size);
+ }
+
+ /* prepare the dictionary holding the information */
+ if ((ls_list = PyList_New(0)) == NULL)
+ goto exit_fail;
+
+ for (i = 0; i < lss_count; i++) {
+ if ((ls_entry = PyDict_New()) == NULL)
+ goto exit_fail;
+
+ /* fill the dictionary information: lockspace */
+ if ((ls_value = PyString_FromString(lss[i].name)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "lockspace", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: host_id */
+ if ((ls_value = PyInt_FromLong(lss[i].host_id)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "host_id", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: path */
+ if ((ls_value = PyString_FromString(lss[i].host_id_disk.path)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "path", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: offset */
+ if ((ls_value = PyInt_FromLong(lss[i].host_id_disk.offset)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "offset", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: flags */
+ if ((ls_value = PyInt_FromLong(lss[i].flags)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "flags", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ if (PyList_Append(ls_list, ls_entry) != 0)
+ goto exit_fail;
+
+ Py_DECREF(ls_entry);
+ }
+
+ /* success */
+ free(lss);
+ return ls_list;
+
+ /* failure */
+exit_fail:
+ if (lss) free(lss);
+ Py_XDECREF(ls_entry);
+ Py_XDECREF(ls_list);
+ return NULL;
+}
+
+
/* acquire */
PyDoc_STRVAR(pydoc_acquire, "\
acquire(lockspace, resource, disks [, slkfd=fd, pid=owner, shared=False])\n\
@@ -921,6 +1022,8 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_inq_lockspace},
{"rem_lockspace", (PyCFunction) py_rem_lockspace,
METH_VARARGS|METH_KEYWORDS, pydoc_rem_lockspace},
+ {"get_lockspaces", (PyCFunction) py_get_lockspaces,
+ METH_VARARGS|METH_KEYWORDS, pydoc_get_lockspaces},
{"acquire", (PyCFunction) py_acquire,
METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
{"release", (PyCFunction) py_release,
@@ -968,7 +1071,7 @@ exit_fail:
PyMODINIT_FUNC
initsanlock(void)
{
- PyObject *py_module;
+ PyObject *py_module, *sk_constant;
py_module = Py_InitModule4("sanlock",
sanlock_methods, pydoc_sanlock, NULL, PYTHON_API_VERSION);
@@ -984,4 +1087,16 @@ initsanlock(void)
if (PyModule_AddObject(py_module, "SanlockException", py_exception) == 0) {
Py_INCREF(py_exception);
}
+
+ if ((sk_constant = PyInt_FromLong(SANLK_LSF_ADD)) != NULL) {
+ if (PyModule_AddObject(py_module, "SANLK_LSF_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)) {
+ Py_DECREF(sk_constant);
+ }
+ }
}
--
1.7.1
11 years, 2 months
[PATCH 1/3] misc: add wdmd to gitignore
by Federico Simoncelli
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
.gitignore | 3 +++
1 files changed, 3 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
index 74a57d8..05f923a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,9 @@
*.co
.vimdir
cscope.*
+wdmd/libwdmd.so*
+wdmd/wdmd
+wdmd/wdmd_client
src/libsanlock.so*
src/libsanlock_client.so*
src/sanlock
--
1.7.1
11 years, 3 months
wdmd/Makefile wdmd/main.c
by David Teigland
wdmd/Makefile | 2 +-
wdmd/main.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
New commits:
commit 478582b58f8ff203bc9513c4387e07d34d16fe66
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Mon Dec 10 17:33:58 2012 +0100
wdmd: fix miscellaneous build warnings
Fixed warnings:
* wdmd: _FORTIFY_SOURCE requires compiling with optimization (-O)
* wdmd: initialization discards ‘const’ qualifier from pointer target type
* ignoring return value of ‘write’
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/wdmd/Makefile b/wdmd/Makefile
index de6b035..bf871c5 100644
--- a/wdmd/Makefile
+++ b/wdmd/Makefile
@@ -21,7 +21,7 @@ LIB_SOURCE = client.c wdmd_sock.c
TEST_SOURCE = wdmd_client.c
-CFLAGS += -D_GNU_SOURCE -g \
+CFLAGS += -D_GNU_SOURCE -g -O2 \
-Wall \
-Wformat \
-Wformat-security \
diff --git a/wdmd/main.c b/wdmd/main.c
index d1666b9..126524c 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -63,8 +63,8 @@ static int shm_fd;
static int allow_scripts;
static int kill_script_sec;
-static char *scripts_dir = (char *)"/etc/wdmd.d";
-static char *watchdog_path = "/dev/watchdog";
+static const char *scripts_dir = "/etc/wdmd.d";
+static const char *watchdog_path = "/dev/watchdog";
struct script_status {
uint64_t start;
@@ -1309,7 +1309,7 @@ static void print_debug_and_exit(void)
if (rv < 0)
exit(1);
- write(STDOUT_FILENO, debug_buf, strlen(debug_buf));
+ rv = write(STDOUT_FILENO, debug_buf, strlen(debug_buf));
exit(0);
}
11 years, 3 months
[PATCH] wdmd: fix miscellaneous build warnings
by Federico Simoncelli
Fixed warnings:
* wdmd: _FORTIFY_SOURCE requires compiling with optimization (-O)
* wdmd: initialization discards ‘const’ qualifier from pointer target type
* ignoring return value of ‘write’
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
wdmd/Makefile | 2 +-
wdmd/main.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/wdmd/Makefile b/wdmd/Makefile
index de6b035..bf871c5 100644
--- a/wdmd/Makefile
+++ b/wdmd/Makefile
@@ -21,7 +21,7 @@ LIB_SOURCE = client.c wdmd_sock.c
TEST_SOURCE = wdmd_client.c
-CFLAGS += -D_GNU_SOURCE -g \
+CFLAGS += -D_GNU_SOURCE -g -O2 \
-Wall \
-Wformat \
-Wformat-security \
diff --git a/wdmd/main.c b/wdmd/main.c
index d1666b9..126524c 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -63,8 +63,8 @@ static int shm_fd;
static int allow_scripts;
static int kill_script_sec;
-static char *scripts_dir = (char *)"/etc/wdmd.d";
-static char *watchdog_path = "/dev/watchdog";
+static const char *scripts_dir = "/etc/wdmd.d";
+static const char *watchdog_path = "/dev/watchdog";
struct script_status {
uint64_t start;
@@ -1309,7 +1309,7 @@ static void print_debug_and_exit(void)
if (rv < 0)
exit(1);
- write(STDOUT_FILENO, debug_buf, strlen(debug_buf));
+ rv = write(STDOUT_FILENO, debug_buf, strlen(debug_buf));
exit(0);
}
--
1.7.11.7
11 years, 3 months
src/client.c src/cmd.c src/lockspace.c src/lockspace.h src/main.c src/sanlock.8 src/sanlock_admin.h src/sanlock_internal.h src/sanlock_sock.h
by David Teigland
src/client.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++
src/cmd.c | 24 +++++++++++++++---
src/lockspace.c | 47 +++++++++++++++++++++++++++++++++++
src/lockspace.h | 1
src/main.c | 56 +++++++++++++++++++++++++++++++++++++++++-
src/sanlock.8 | 8 +++++-
src/sanlock_admin.h | 18 +++++++++++++
src/sanlock_internal.h | 1
src/sanlock_sock.h | 1
9 files changed, 216 insertions(+), 5 deletions(-)
New commits:
commit 5ea36dff88fa2eddb66c81985f0ab3cc34c74b1a
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Nov 28 14:46:00 2012 -0600
sanlock: new get_lockspaces api
returns a copy of all lockspaces from the daemon
in an array of sanlk_lockspace structs.
example and test by new command,
sanlock gets
s lockspace1:1:/dev/vg/leases1:0
s lockspace0:1:/dev/vg/leases0:0 ADD
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/client.c b/src/client.c
index ae73226..5b4d81b 100644
--- a/src/client.c
+++ b/src/client.c
@@ -163,6 +163,71 @@ int sanlock_rem_lockspace(struct sanlk_lockspace *ls, uint32_t flags)
return cmd_lockspace(SM_CMD_REM_LOCKSPACE, ls, flags, 0);
}
+int sanlock_get_lockspaces(struct sanlk_lockspace *lss, int lss_size,
+ int *lss_count, uint32_t flags)
+{
+ struct sanlk_lockspace *ls;
+ struct sm_header h;
+ int rv, fd, i, ret, recv_count;
+
+ rv = connect_socket(&fd);
+ if (rv < 0)
+ return rv;
+
+ rv = send_header(fd, SM_CMD_GET_LOCKSPACES, flags, 0, 0, 0);
+ if (rv < 0)
+ goto out;
+
+ /* receive result and ls structs */
+
+ memset(&h, 0, sizeof(struct sm_header));
+
+ rv = recv(fd, &h, sizeof(h), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ if (rv != sizeof(h)) {
+ rv = -1;
+ goto out;
+ }
+
+ /* -ENOSPC means that the daemon's send buffer ran out of space */
+
+ rv = (int)h.data;
+ if (rv < 0 && rv != -ENOSPC)
+ goto out;
+
+ *lss_count = h.data2;
+ recv_count = h.data2;
+
+ if (recv_count * sizeof(struct sanlk_lockspace) > lss_size) {
+ recv_count = lss_size / sizeof(struct sanlk_lockspace);
+ rv = -ENOBUFS;
+ }
+
+ ls = lss;
+
+ for (i = 0; i < recv_count; i++) {
+ ret = recv(fd, ls, sizeof(struct sanlk_lockspace), MSG_WAITALL);
+ if (ret < 0) {
+ rv = -errno;
+ goto out;
+ }
+
+ if (ret != sizeof(struct sanlk_lockspace)) {
+ rv = -1;
+ goto out;
+ }
+
+ ls++;
+ }
+ out:
+ close(fd);
+ return rv;
+}
+
int sanlock_align(struct sanlk_disk *disk)
{
int rv, fd;
diff --git a/src/cmd.c b/src/cmd.c
index 18b9db0..6f9310f 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1896,18 +1896,32 @@ static void cmd_host_status(int fd, struct sm_header *h_recv)
free(status);
}
-static char send_log_dump[LOG_DUMP_SIZE];
+static char send_data_buf[LOG_DUMP_SIZE];
static void cmd_log_dump(int fd, struct sm_header *h_recv)
{
int len;
- copy_log_dump(send_log_dump, &len);
+ copy_log_dump(send_data_buf, &len);
h_recv->data = len;
send(fd, h_recv, sizeof(struct sm_header), MSG_NOSIGNAL);
- send(fd, send_log_dump, len, MSG_NOSIGNAL);
+ send(fd, send_data_buf, len, MSG_NOSIGNAL);
+}
+
+static void cmd_get_lockspaces(int fd, struct sm_header *h_recv)
+{
+ int count, len, rv;
+
+ rv = get_lockspaces(send_data_buf, &len, &count, LOG_DUMP_SIZE);
+
+ h_recv->length = sizeof(struct sm_header) + len;
+ h_recv->data = rv;
+ h_recv->data2 = count;
+
+ send(fd, h_recv, sizeof(struct sm_header), MSG_NOSIGNAL);
+ send(fd, send_data_buf, len, MSG_NOSIGNAL);
}
static void cmd_restrict(int ci, int fd, struct sm_header *h_recv)
@@ -1982,6 +1996,10 @@ void call_cmd_daemon(int ci, struct sm_header *h_recv, int client_maxi)
strcpy(client[ci].owner_name, "log_dump");
cmd_log_dump(fd, h_recv);
break;
+ case SM_CMD_GET_LOCKSPACES:
+ strcpy(client[ci].owner_name, "get_lockspaces");
+ cmd_get_lockspaces(fd, h_recv);
+ break;
};
if (auto_close)
diff --git a/src/lockspace.c b/src/lockspace.c
index 8e05fa5..2940549 100644
--- a/src/lockspace.c
+++ b/src/lockspace.c
@@ -24,6 +24,7 @@
#include <sys/un.h>
#include "sanlock_internal.h"
+#include "sanlock_admin.h"
#include "sanlock_sock.h"
#include "diskio.h"
#include "log.h"
@@ -859,6 +860,52 @@ int rem_lockspace_wait(struct sanlk_lockspace *ls, unsigned int space_id)
return 0;
}
+int get_lockspaces(char *buf, int *len, int *count, int maxlen)
+{
+ struct sanlk_lockspace *ls;
+ struct space *sp;
+ struct list_head *heads[] = {&spaces, &spaces_rem, &spaces_add};
+ int i, rv, sp_count = 0;
+
+ rv = 0;
+ *len = 0;
+ *count = 0;
+ ls = (struct sanlk_lockspace *)buf;
+
+ pthread_mutex_lock(&spaces_mutex);
+ for (i = 0; i < 3; i++) {
+ list_for_each_entry(sp, heads[i], list) {
+ sp_count++;
+
+ if (*len + sizeof(struct sanlk_lockspace) > maxlen) {
+ rv = -ENOSPC;
+ continue;
+ }
+
+ memcpy(ls->name, sp->space_name, NAME_ID_SIZE);
+ memcpy(&ls->host_id_disk, &sp->host_id_disk, sizeof(struct sync_disk));
+ ls->host_id_disk.pad1 = 0;
+ ls->host_id_disk.pad2 = 0;
+ ls->host_id = sp->host_id;
+ ls->flags = 0;
+
+ if (i == 1)
+ ls->flags |= SANLK_LSF_REM;
+ else if (i == 2)
+ ls->flags |= SANLK_LSF_ADD;
+
+ *len += sizeof(struct sanlk_lockspace);
+
+ ls++;
+ }
+ }
+ pthread_mutex_unlock(&spaces_mutex);
+
+ *count = sp_count;
+
+ return rv;
+}
+
/*
* we call stop_host_id() when all pids are gone and we're in a safe state, so
* it's safe to unlink the watchdog right away here. We want to sp the unlink
diff --git a/src/lockspace.h b/src/lockspace.h
index dc1099d..47ce5ba 100644
--- a/src/lockspace.h
+++ b/src/lockspace.h
@@ -25,5 +25,6 @@ int inq_lockspace(struct sanlk_lockspace *ls);
int rem_lockspace_start(struct sanlk_lockspace *ls, unsigned int *space_id);
int rem_lockspace_wait(struct sanlk_lockspace *ls, unsigned int space_id);
void free_lockspaces(int wait);
+int get_lockspaces(char *buf, int *len, int *count, int maxlen);
#endif
diff --git a/src/main.c b/src/main.c
index 37b20db..0291e22 100644
--- a/src/main.c
+++ b/src/main.c
@@ -54,6 +54,8 @@
#include "helper.h"
#include "timeouts.h"
+#define ONEMB 1048576
+
#define SIGRUNPATH 100 /* anything that's not SIGTERM/SIGKILL */
struct thread_pool {
@@ -1148,6 +1150,7 @@ static void process_connection(int ci)
case SM_CMD_STATUS:
case SM_CMD_HOST_STATUS:
case SM_CMD_LOG_DUMP:
+ case SM_CMD_GET_LOCKSPACES:
call_cmd_daemon(ci, &h, client_maxi);
break;
case SM_CMD_ADD_LOCKSPACE:
@@ -1777,6 +1780,7 @@ static void print_usage(void)
printf("\n");
printf("sanlock client <action> [options]\n");
printf("sanlock client status [-D] [-o p|s]\n");
+ printf("sanlock client gets\n");
printf("sanlock client host_status -s LOCKSPACE [-D]\n");
printf("sanlock client log_dump\n");
printf("sanlock client shutdown [-f 0|1]\n");
@@ -1879,6 +1883,8 @@ static int read_command_line(int argc, char *argv[])
com.action = ACT_STATUS;
else if (!strcmp(act, "host_status"))
com.action = ACT_HOST_STATUS;
+ else if (!strcmp(act, "gets"))
+ com.action = ACT_GETS;
else if (!strcmp(act, "log_dump"))
com.action = ACT_LOG_DUMP;
else if (!strcmp(act, "shutdown"))
@@ -2119,14 +2125,33 @@ static int read_command_line(int argc, char *argv[])
return 0;
}
+/* only used by do_client */
+static char *lsf_to_str(uint32_t flags)
+{
+ static char lsf_str[16];
+
+ memset(lsf_str, 0, 16);
+
+ if (flags & SANLK_LSF_ADD)
+ strcat(lsf_str, "ADD ");
+
+ if (flags & SANLK_LSF_REM)
+ strcat(lsf_str, "REM ");
+
+ return lsf_str;
+}
+
static int do_client(void)
{
struct sanlk_resource **res_args = NULL;
struct sanlk_resource *res;
+ struct sanlk_lockspace *ls;
char *res_state = NULL;
char *res_str = NULL;
+ char *buf;
uint32_t io_timeout = 0;
- int i, fd, rv = 0;
+ int i, fd, count;
+ int rv = 0;
if (com.action == ACT_COMMAND || com.action == ACT_ACQUIRE) {
if (com.num_hosts) {
@@ -2147,6 +2172,35 @@ static int do_client(void)
rv = sanlock_host_status(com.debug, com.lockspace.name);
break;
+ case ACT_GETS:
+ buf = malloc(ONEMB);
+ if (!buf)
+ break;
+ memset(buf, 0, ONEMB);
+ ls = (struct sanlk_lockspace *)buf;
+
+ rv = sanlock_get_lockspaces(ls, ONEMB, &count, 0);
+ if (rv < 0)
+ log_tool("gets error %d", rv);
+
+ if (rv < 0 && rv != -ENOBUFS && rv != -ENOSPC) {
+ free(buf);
+ break;
+ }
+
+ for (i = 0; i < count; i++) {
+ log_tool("s %.48s:%llu:%s:%llu %s",
+ ls->name,
+ (unsigned long long)ls->host_id,
+ ls->host_id_disk.path,
+ (unsigned long long)ls->host_id_disk.offset,
+ !ls->flags ? "" : lsf_to_str(ls->flags));
+ ls++;
+ }
+
+ free(buf);
+ break;
+
case ACT_LOG_DUMP:
rv = sanlock_log_dump(LOG_DUMP_SIZE);
break;
diff --git a/src/sanlock.8 b/src/sanlock.8
index 59ef392..dca5db8 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -248,7 +248,7 @@ use async i/o
.B sanlock client status
-Print processes, lockspaces, and resources being manged by the sanlock
+Print processes, lockspaces, and resources being managed by the sanlock
daemon. Add -D to show extra internal daemon status for debugging.
Add -o p to show resources by pid, or -o s to show resources by lockspace.
@@ -258,6 +258,12 @@ Print state of host_id delta leases read during the last renewal.
State of all lockspaces is shown (use -s to select one).
Add -D to show extra internal daemon status for debugging.
+.B sanlock client gets
+
+Print lockspaces being managed by the sanlock daemon. The LOCKSPACE
+string will be followed by ADD or REM if the lockspace is currently being
+added or removed.
+
.B sanlock client log_dump
Print the sanlock daemon internal debug log.
diff --git a/src/sanlock_admin.h b/src/sanlock_admin.h
index 14b1e7a..dadd034 100644
--- a/src/sanlock_admin.h
+++ b/src/sanlock_admin.h
@@ -20,6 +20,10 @@
/* inq flags */
#define SANLK_INQ_WAIT 0x00000001
+/* sanlk_lockspace.flags returned by get */
+#define SANLK_LSF_ADD 0x00000001
+#define SANLK_LSF_REM 0x00000002
+
/*
* add_lockspace returns:
* 0: the lockspace has been added successfully
@@ -59,6 +63,20 @@ int sanlock_inq_lockspace(struct sanlk_lockspace *ls, uint32_t flags);
int sanlock_rem_lockspace(struct sanlk_lockspace *ls, uint32_t flags);
/*
+ * get_lockspace returns:
+ * 0: all lockspaces copied out, lss_count set to number
+ * -ENOSPC: sanlock internal buffer ran out of space
+ * (lss_count set to number that would have been copied)
+ * -ENOBUFS: lss_size too small
+ * (lss_count set to number that would have been copied)
+ *
+ * sanlk_lockspace.flags set to SANLK_LSF_
+ */
+
+int sanlock_get_lockspaces(struct sanlk_lockspace *lss, int lss_size,
+ int *lss_count, uint32_t flags);
+
+/*
* Returns the alignment in bytes required by sanlock_init()
* (1MB for disks with 512 sectors, 8MB for disks with 4096 sectors)
*/
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 414ceb8..6deef0e 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -312,6 +312,7 @@ enum {
ACT_CLIENT_READ,
ACT_CLIENT_ALIGN,
ACT_EXAMINE,
+ ACT_GETS,
};
EXTERN int external_shutdown;
diff --git a/src/sanlock_sock.h b/src/sanlock_sock.h
index fbabbb2..bbffa7d 100644
--- a/src/sanlock_sock.h
+++ b/src/sanlock_sock.h
@@ -39,6 +39,7 @@ enum {
SM_CMD_WRITE_RESOURCE = 19,
SM_CMD_READ_LOCKSPACE = 20,
SM_CMD_READ_RESOURCE = 21,
+ SM_CMD_GET_LOCKSPACES = 22,
};
struct sm_header {
11 years, 3 months
2 commits - python/sanlock.c
by David Teigland
python/sanlock.c | 249 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 249 insertions(+)
New commits:
commit 2a1bc7aeff0113c314826d37a7bb3cac710bf745
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Nov 30 12:22:02 2012 -0500
python: add read lockspace and resource
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 2fc34ca..92e1396 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -310,6 +310,151 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_RETURN_NONE;
}
+/* read_lockspace */
+PyDoc_STRVAR(pydoc_read_lockspace, "\
+read_lockspace(path, offset=0) -> dict\n\
+Read the lockspace information from a device at a specific offset.");
+
+static PyObject *
+py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv;
+ uint32_t io_timeout = 0;
+ const char *path;
+ struct sanlk_lockspace ls;
+ PyObject *ls_info = NULL, *ls_entry = NULL;
+
+ static char *kwlist[] = {"path", "offset", NULL};
+
+ /* initialize lockspace structure */
+ memset(&ls, 0, sizeof(struct sanlk_lockspace));
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|k", kwlist,
+ &path, &ls.host_id_disk.offset)) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+
+ /* read sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_read_lockspace(&ls, 0, &io_timeout);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Sanlock lockspace read failure");
+ return NULL;
+ }
+
+ /* prepare the dictionary holding the information */
+ if ((ls_info = PyDict_New()) == NULL)
+ goto exit_fail;
+
+ /* fill the dictionary information: lockspace */
+ if ((ls_entry = PyString_FromString(ls.name)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_info, "lockspace", ls_entry);
+ Py_DECREF(ls_entry);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: iotimeout */
+ if ((ls_entry = PyInt_FromLong(io_timeout)) == NULL)
+ goto exit_fail;
+ Py_DECREF(ls_entry);
+ rv = PyDict_SetItemString(ls_info, "iotimeout", ls_entry);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* success */
+ return ls_info;
+
+ /* failure */
+exit_fail:
+ Py_XDECREF(ls_info);
+ return NULL;
+}
+
+/* read_resource */
+PyDoc_STRVAR(pydoc_read_resource, "\
+read_resource(path, offset=0) -> dict\n\
+Read the resource information from a device at a specific offset.");
+
+static PyObject *
+py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, rs_len;
+ const char *path;
+ struct sanlk_resource *rs;
+ PyObject *rs_info = NULL, *rs_entry = NULL;
+
+ static char *kwlist[] = {"path", "offset", NULL};
+
+ /* allocate the needed memory for the resource and one disk */
+ rs_len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
+ rs = malloc(rs_len);
+
+ if (rs == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ /* initialize resource and disk structures */
+ memset(rs, 0, rs_len);
+ rs->num_disks = 1;
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|k", kwlist,
+ &path, &(rs->disks[0].offset))) {
+ goto exit_fail;
+ }
+
+ /* prepare the resource disk path */
+ strncpy(rs->disks[0].path, path, SANLK_PATH_LEN - 1);
+
+ /* read sanlock resource (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_read_resource(rs, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Sanlock resource read failure");
+ goto exit_fail;
+ }
+
+ /* prepare the dictionary holding the information */
+ if ((rs_info = PyDict_New()) == NULL)
+ goto exit_fail;
+
+ /* fill the dictionary information: lockspace */
+ if ((rs_entry = PyString_FromString(rs->lockspace_name)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(rs_info, "lockspace", rs_entry);
+ Py_DECREF(rs_entry);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: resource */
+ if ((rs_entry = PyString_FromString(rs->name)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(rs_info, "resource", rs_entry);
+ Py_DECREF(rs_entry);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* success */
+ free(rs);
+ return rs_info;
+
+ /* failure */
+exit_fail:
+ free(rs);
+ Py_XDECREF(rs_info);
+ return NULL;
+}
+
/* write_resource */
PyDoc_STRVAR(pydoc_write_resource, "\
write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0)\n\
@@ -748,6 +893,10 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_write_lockspace},
{"write_resource", (PyCFunction) py_write_resource,
METH_VARARGS|METH_KEYWORDS, pydoc_write_resource},
+ {"read_lockspace", (PyCFunction) py_read_lockspace,
+ METH_VARARGS|METH_KEYWORDS, pydoc_read_lockspace},
+ {"read_resource", (PyCFunction) py_read_resource,
+ METH_VARARGS|METH_KEYWORDS, pydoc_read_resource},
{"add_lockspace", (PyCFunction) py_add_lockspace,
METH_VARARGS|METH_KEYWORDS, pydoc_add_lockspace},
{"inq_lockspace", (PyCFunction) py_inq_lockspace,
commit 35bf5036c86f51a53a103d2ea61f8c42dcfe93ef
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Thu Dec 6 09:20:16 2012 -0500
python: add write lockspace and resource
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index c57909a..2fc34ca 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -174,6 +174,7 @@ py_get_alignment(PyObject *self __unused, PyObject *args)
PyDoc_STRVAR(pydoc_init_lockspace, "\
init_lockspace(lockspace, path, offset=0, max_hosts=0, num_hosts=0, \
use_aio=True)\n\
+*DEPRECATED* use write_lockspace instead.\n\
Initialize a device to be used as sanlock lockspace.");
static PyObject *
@@ -217,6 +218,7 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
PyDoc_STRVAR(pydoc_init_resource, "\
init_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0, \
use_aio=True)\n\
+*DEPRECATED* use write_resource instead.\n\
Initialize a device to be used as sanlock resource.\n\
The disks must be in the format: [(path, offset), ... ]");
@@ -265,6 +267,100 @@ exit_fail:
return NULL;
}
+/* write_lockspace */
+PyDoc_STRVAR(pydoc_write_lockspace, "\
+write_lockspace(lockspace, path, offset=0, max_hosts=0, iotimeout=0)\n\
+Initialize or update a device to be used as sanlock lockspace.");
+
+static PyObject *
+py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, max_hosts = 0;
+ uint32_t io_timeout = 0;
+ const char *lockspace, *path;
+ struct sanlk_lockspace ls;
+
+ static char *kwlist[] = {"lockspace", "path", "offset", "max_hosts",
+ "iotimeout", NULL};
+
+ /* initialize lockspace structure */
+ memset(&ls, 0, sizeof(struct sanlk_lockspace));
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiiI", kwlist,
+ &lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
+ &io_timeout)) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(ls.name, lockspace, SANLK_NAME_LEN);
+ strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+
+ /* write sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_write_lockspace(&ls, max_hosts, 0, io_timeout);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Sanlock lockspace write failure");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+/* write_resource */
+PyDoc_STRVAR(pydoc_write_resource, "\
+write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0)\n\
+Initialize a device to be used as sanlock resource.\n\
+The disks must be in the format: [(path, offset), ... ]");
+
+static PyObject *
+py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, max_hosts = 0, num_hosts = 0;
+ const char *lockspace, *resource;
+ struct sanlk_resource *rs;
+ PyObject *disks;
+
+ static char *kwlist[] = {"lockspace", "resource", "disks", "max_hosts",
+ "num_hosts", NULL};
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii",
+ kwlist, &lockspace, &resource, &PyList_Type, &disks, &max_hosts,
+ &num_hosts)) {
+ return NULL;
+ }
+
+ /* parse and check sanlock resource */
+ if (__parse_resource(disks, &rs) != 0) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(rs->lockspace_name, lockspace, SANLK_NAME_LEN);
+ strncpy(rs->name, resource, SANLK_NAME_LEN);
+
+ /* init sanlock resource (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_write_resource(rs, max_hosts, num_hosts, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Sanlock resource write failure");
+ goto exit_fail;
+ }
+
+ free(rs);
+ Py_RETURN_NONE;
+
+exit_fail:
+ free(rs);
+ return NULL;
+}
+
/* add_lockspace */
PyDoc_STRVAR(pydoc_add_lockspace, "\
add_lockspace(lockspace, host_id, path, offset=0, iotimeout=0, async=False)\n\
@@ -648,6 +744,10 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_init_lockspace},
{"init_resource", (PyCFunction) py_init_resource,
METH_VARARGS|METH_KEYWORDS, pydoc_init_resource},
+ {"write_lockspace", (PyCFunction) py_write_lockspace,
+ METH_VARARGS|METH_KEYWORDS, pydoc_write_lockspace},
+ {"write_resource", (PyCFunction) py_write_resource,
+ METH_VARARGS|METH_KEYWORDS, pydoc_write_resource},
{"add_lockspace", (PyCFunction) py_add_lockspace,
METH_VARARGS|METH_KEYWORDS, pydoc_add_lockspace},
{"inq_lockspace", (PyCFunction) py_inq_lockspace,
11 years, 3 months
[PATCHv2] python: add write lockspace and resource
by Federico Simoncelli
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
---
python/sanlock.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 100 insertions(+), 0 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index c57909a..2fc34ca 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -174,6 +174,7 @@ py_get_alignment(PyObject *self __unused, PyObject *args)
PyDoc_STRVAR(pydoc_init_lockspace, "\
init_lockspace(lockspace, path, offset=0, max_hosts=0, num_hosts=0, \
use_aio=True)\n\
+*DEPRECATED* use write_lockspace instead.\n\
Initialize a device to be used as sanlock lockspace.");
static PyObject *
@@ -217,6 +218,7 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
PyDoc_STRVAR(pydoc_init_resource, "\
init_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0, \
use_aio=True)\n\
+*DEPRECATED* use write_resource instead.\n\
Initialize a device to be used as sanlock resource.\n\
The disks must be in the format: [(path, offset), ... ]");
@@ -265,6 +267,100 @@ exit_fail:
return NULL;
}
+/* write_lockspace */
+PyDoc_STRVAR(pydoc_write_lockspace, "\
+write_lockspace(lockspace, path, offset=0, max_hosts=0, iotimeout=0)\n\
+Initialize or update a device to be used as sanlock lockspace.");
+
+static PyObject *
+py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, max_hosts = 0;
+ uint32_t io_timeout = 0;
+ const char *lockspace, *path;
+ struct sanlk_lockspace ls;
+
+ static char *kwlist[] = {"lockspace", "path", "offset", "max_hosts",
+ "iotimeout", NULL};
+
+ /* initialize lockspace structure */
+ memset(&ls, 0, sizeof(struct sanlk_lockspace));
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiiI", kwlist,
+ &lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
+ &io_timeout)) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(ls.name, lockspace, SANLK_NAME_LEN);
+ strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+
+ /* write sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_write_lockspace(&ls, max_hosts, 0, io_timeout);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Sanlock lockspace write failure");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+/* write_resource */
+PyDoc_STRVAR(pydoc_write_resource, "\
+write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0)\n\
+Initialize a device to be used as sanlock resource.\n\
+The disks must be in the format: [(path, offset), ... ]");
+
+static PyObject *
+py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, max_hosts = 0, num_hosts = 0;
+ const char *lockspace, *resource;
+ struct sanlk_resource *rs;
+ PyObject *disks;
+
+ static char *kwlist[] = {"lockspace", "resource", "disks", "max_hosts",
+ "num_hosts", NULL};
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii",
+ kwlist, &lockspace, &resource, &PyList_Type, &disks, &max_hosts,
+ &num_hosts)) {
+ return NULL;
+ }
+
+ /* parse and check sanlock resource */
+ if (__parse_resource(disks, &rs) != 0) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(rs->lockspace_name, lockspace, SANLK_NAME_LEN);
+ strncpy(rs->name, resource, SANLK_NAME_LEN);
+
+ /* init sanlock resource (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_write_resource(rs, max_hosts, num_hosts, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Sanlock resource write failure");
+ goto exit_fail;
+ }
+
+ free(rs);
+ Py_RETURN_NONE;
+
+exit_fail:
+ free(rs);
+ return NULL;
+}
+
/* add_lockspace */
PyDoc_STRVAR(pydoc_add_lockspace, "\
add_lockspace(lockspace, host_id, path, offset=0, iotimeout=0, async=False)\n\
@@ -648,6 +744,10 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_init_lockspace},
{"init_resource", (PyCFunction) py_init_resource,
METH_VARARGS|METH_KEYWORDS, pydoc_init_resource},
+ {"write_lockspace", (PyCFunction) py_write_lockspace,
+ METH_VARARGS|METH_KEYWORDS, pydoc_write_lockspace},
+ {"write_resource", (PyCFunction) py_write_resource,
+ METH_VARARGS|METH_KEYWORDS, pydoc_write_resource},
{"add_lockspace", (PyCFunction) py_add_lockspace,
METH_VARARGS|METH_KEYWORDS, pydoc_add_lockspace},
{"inq_lockspace", (PyCFunction) py_inq_lockspace,
--
1.7.1
11 years, 3 months