From: Nir Soffer <nsoffer(a)redhat.com>
Add the missing flags kwarg to sanlock.write_resource(), and the new
sanlock.WRITE_CLEAR constant.
To clear a resource, you can do now:
sanlock.write_resource("lockspace", "resource", [("/path/to/resource", 0)],
flags=sanlock.WRITE_CLEAR)
Subsequent sanlock.read_resource() calls will return the regular error
when a resource is not found.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 40da92f..af89d17 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -551,25 +551,28 @@ exit_fail:
/* write_resource */
PyDoc_STRVAR(pydoc_write_resource, "\
-write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0)\n\
+write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0, flags=0)\n\
Initialize a device to be used as sanlock resource.\n\
-The disks must be in the format: [(path, offset), ... ]");
+The disks must be in the format: [(path, offset), ... ].\n\
+If WRITE_CLEAR flag is used, the resource is cleared so subsequent read will\n\
+return an error.");
static PyObject *
py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv, max_hosts = 0, num_hosts = 0;
+ uint32_t flags = 0;
const char *lockspace, *resource;
struct sanlk_resource *rs;
PyObject *disks;
static char *kwlist[] = {"lockspace", "resource", "disks", "max_hosts",
- "num_hosts", NULL};
+ "num_hosts", "flags", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii",
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiI",
kwlist, &lockspace, &resource, &PyList_Type, &disks, &max_hosts,
- &num_hosts)) {
+ &num_hosts, &flags)) {
return NULL;
}
@@ -584,7 +587,7 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* init sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_write_resource(rs, max_hosts, num_hosts, 0);
+ rv = sanlock_write_resource(rs, max_hosts, num_hosts, flags);
Py_END_ALLOW_THREADS
if (rv != 0) {
@@ -1605,6 +1608,9 @@ initsanlock(void)
PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_FORCE, "REQ_FORCE");
PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_GRACEFUL, "REQ_GRACEFUL");
+ /* resource write flags */
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_WRITE_CLEAR, "WRITE_CLEAR");
+
/* hosts list flags */
PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_FREE, "HOST_FREE");
PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_LIVE, "HOST_LIVE");
--
2.7.4