[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sanlock-devel
Subject:    [PATCH v2] python: Support resource clearing
From:       Nir Soffer <nirsof () gmail ! com>
Date:       2016-12-04 10:55:13
Message-ID: 1480848913-25164-1-git-send-email-nirsof () gmail ! com
[Download RAW message or body]

From: Nir Soffer <nsoffer@redhat.com>

Add a clear kwarg to sanlock.write_resource(), using SANLK_WRITE_CLEAR
to clear the resource.

To clear a resource, you can do now:

    sanlock.write_resource("lockspace", "resource", [("/path/to/resource", 0)],
                           clear=True)

Subsequent sanlock.read_resource() calls will return the regular error
when a resource is not found.

Signed-off-by: Nir Soffer <nsoffer@redhat.com>
---
 python/sanlock.c | 22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

diff --git a/python/sanlock.c b/python/sanlock.c
index 40da92f..f2ad672 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -551,25 +551,29 @@ 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, \
+clear=False)\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 clear is True, 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;
+    int rv, max_hosts = 0, num_hosts = 0, clear = 0;
     const char *lockspace, *resource;
     struct sanlk_resource *rs;
     PyObject *disks;
+    uint32_t flags = 0;
 
     static char *kwlist[] = {"lockspace", "resource", "disks", "max_hosts",
-                                "num_hosts", NULL};
+                                "num_hosts", "clear", 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, &clear)) {
         return NULL;
     }
 
@@ -582,9 +586,13 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
     strncpy(rs->lockspace_name, lockspace, SANLK_NAME_LEN);
     strncpy(rs->name, resource, SANLK_NAME_LEN);
 
+    if (clear) {
+        flags |= SANLK_WRITE_CLEAR;
+    }
+
     /* 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) {
-- 
2.7.4
_______________________________________________
sanlock-devel mailing list -- sanlock-devel@lists.fedorahosted.org
To unsubscribe send an email to sanlock-devel-leave@lists.fedorahosted.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic