.gitignore | 3
python/sanlock.c | 181 +++++++++++++++++++++++++++++++++++++++++--------
src/client.c | 2
src/sanlock_resource.h | 2
4 files changed, 159 insertions(+), 29 deletions(-)
New commits:
commit fc4e74c9e01ae4fa454818d58de64e23f5cf7e2d
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Feb 15 07:58:31 2013 -0500
python: add get_lockspaces
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index c0c0276..750157f 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -684,6 +684,99 @@ 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_count;
+ struct sanlk_lockspace *lss = NULL;
+ PyObject *ls_list = NULL, *ls_entry = NULL, *ls_value = NULL;
+
+ /* get all the lockspaces (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_get_lockspaces(&lss, &lss_count, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv < 0) {
+ __set_exception(rv, "Sanlock get lockspace failure");
+ goto exit_fail;
+ }
+
+ /* 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 +1014,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 +1063,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 +1079,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);
+ }
+ }
}
commit 87265bc3095803dd79695bf1b3339ef5fe51d2f3
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Feb 15 07:58:30 2013 -0500
python: fix multiple issues reported by cpychecker
* mark __set_exception and __parse_resource for cpychecker
(as functions that set exceptions)
* fix const char* warnings
* fix PyArg_ParseTupleAndKeywords format issues
* fix a refcount of ls_entry in py_write_lockspace
* fix refcounts in initexception
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 92e1396..c0c0276 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -16,13 +16,30 @@
#define __unused __attribute__ ((unused))
#endif
+#ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE
+#define __sets_exception \
+ __attribute__((cpychecker_sets_exception))
+#else
+#define __sets_exception
+#endif
+
+#ifdef WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE
+#define __neg_sets_exception \
+ __attribute__((cpychecker_negative_result_sets_exception))
+#else
+#define __neg_sets_exception
+#endif
+
+/* Functions prototypes */
+static void __set_exception(int en, char *msg) __sets_exception;
+static int __parse_resource(PyObject *obj, struct sanlk_resource **res_ret) __neg_sets_exception;
+
/* Sanlock module */
PyDoc_STRVAR(pydoc_sanlock, "\
Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.\n\
This copyrighted material is made available to anyone wishing to use,\n\
modify, copy, or redistribute it subject to the terms and conditions\n\
of the GNU General Public License v2 or (at your option) any later version.");
-PyObject *py_module;
/* Sanlock exception */
static PyObject *py_exception;
@@ -30,7 +47,7 @@ static PyObject *py_exception;
static void
__set_exception(int en, char *msg)
{
- char *err_name;
+ const char *err_name;
PyObject *exc_tuple;
if (en < 0 && en > -200) {
@@ -241,7 +258,7 @@ py_init_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) != 0) {
+ if (__parse_resource(disks, &res) < 0) {
return NULL;
}
@@ -287,7 +304,7 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiiI", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiI", kwlist,
&lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
&io_timeout)) {
return NULL;
@@ -363,8 +380,8 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* 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);
+ Py_DECREF(ls_entry);
if (rv != 0)
goto exit_fail;
@@ -473,14 +490,14 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
"num_hosts", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii",
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii",
kwlist, &lockspace, &resource, &PyList_Type, &disks, &max_hosts,
&num_hosts)) {
return NULL;
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &rs) != 0) {
+ if (__parse_resource(disks, &rs) < 0) {
return NULL;
}
@@ -701,7 +718,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) != 0) {
+ if (__parse_resource(disks, &res) < 0) {
return NULL;
}
@@ -756,7 +773,7 @@ py_release(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) != 0) {
+ if (__parse_resource(disks, &res) < 0) {
return NULL;
}
@@ -794,7 +811,8 @@ static PyObject *
py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv, i, j, n, num_args, sanlockfd = -1;
- char *p, *path, kpargs[SANLK_HELPER_ARGS_LEN];
+ char kpargs[SANLK_HELPER_ARGS_LEN];
+ const char *p, *path;
PyObject *argslist, *item;
static char *kwlist[] = {"path", "args", "slkfd", NULL};
@@ -917,51 +935,53 @@ sanlock_exception = {
"errno", (PyCFunction) py_exception_errno, METH_O, pydoc_errno
};
-static void
+static PyObject *
initexception(void)
{
int rv;
- PyObject *dict, *func, *meth;
+ PyObject *dict, *func, *meth, *excp = NULL;
- dict = PyDict_New();
+ if ((dict = PyDict_New()) == NULL)
+ goto exit_fail;
- if (dict == NULL)
- return;
+ if ((func = PyCFunction_New(&sanlock_exception, NULL)) == NULL)
+ goto exit_fail;
- func = PyCFunction_New(&sanlock_exception, NULL);
meth = PyObject_CallFunction((PyObject *) &PyProperty_Type, "O", func);
Py_DECREF(func);
-
if (meth == NULL)
- return;
+ goto exit_fail;
rv = PyDict_SetItemString(dict, sanlock_exception.ml_name, meth);
Py_DECREF(meth);
-
if (rv < 0)
- return;
+ goto exit_fail;
+
+ excp = PyErr_NewException("sanlock.SanlockException", NULL, dict);
- py_exception = PyErr_NewException("sanlock.SanlockException", NULL, dict);
- Py_DECREF(dict);
+exit_fail:
+ Py_XDECREF(dict);
+
+ return excp;
}
PyMODINIT_FUNC
initsanlock(void)
{
+ PyObject *py_module;
py_module = Py_InitModule4("sanlock",
sanlock_methods, pydoc_sanlock, NULL, PYTHON_API_VERSION);
- /* Python's module loader doesn't support clean recovery from errors */
if (py_module == NULL)
return;
- /* Initializing sanlock exception */
- initexception();
+ py_exception = initexception();
if (py_exception == NULL)
return;
- Py_INCREF(py_exception);
- PyModule_AddObject(py_module, "SanlockException", py_exception);
+ if (PyModule_AddObject(py_module, "SanlockException", py_exception) == 0) {
+ Py_INCREF(py_exception);
+ }
}
diff --git a/src/client.c b/src/client.c
index 5c78354..1cb81ee 100644
--- a/src/client.c
+++ b/src/client.c
@@ -549,7 +549,7 @@ int sanlock_restrict(int sock, uint32_t flags)
return rv;
}
-int sanlock_killpath(int sock, uint32_t flags, char *path, char *args)
+int sanlock_killpath(int sock, uint32_t flags, const char *path, char *args)
{
char path_max[SANLK_HELPER_PATH_LEN];
char args_max[SANLK_HELPER_ARGS_LEN];
diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h
index 5215797..cf2a798 100644
--- a/src/sanlock_resource.h
+++ b/src/sanlock_resource.h
@@ -45,7 +45,7 @@ int sanlock_register(void);
int sanlock_restrict(int sock, uint32_t flags);
-int sanlock_killpath(int sock, uint32_t flags, char *path, char *args);
+int sanlock_killpath(int sock, uint32_t flags, const char *path, char *args);
int sanlock_acquire(int sock, int pid, uint32_t flags, int res_count,
struct sanlk_resource *res_args[],
commit c7cac4eb108f1399bc3c6d0b36f1aabb78b62e74
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Feb 15 07:58:29 2013 -0500
misc: add wdmd to gitignore
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
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