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

List:       sanlock-devel
Subject:    [PATCH 5/5] python: add support to read resource owners
From:       Federico Simoncelli <fsimonce () redhat ! com>
Date:       2013-06-14 16:15:40
Message-ID: 1371226540-16748-5-git-send-email-fsimonce () redhat ! com
[Download RAW message or body]

Signed-off-by: Federico Simoncelli <fsimonce@redhat.com>
---
 python/example.py |    3 ++
 python/sanlock.c  |   54 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 0 deletions(-)

diff --git a/python/example.py b/python/example.py
index f3cd414..14e81a8 100644
--- a/python/example.py
+++ b/python/example.py
@@ -49,6 +49,9 @@ def main():
                 print "Lockspace '%s' hosts: " % LOCKSPACE_NAME, hosts_list
                 break
             time.sleep(5)
+        print "Resource '%s' owners: " % RESOURCE_NAME, \
+            sanlock.read_resource_owners(
+                LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS)
         print "Releasing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME)
         sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd)
     except Exception as e:
diff --git a/python/sanlock.c b/python/sanlock.c
index c1067ae..b62b8bc 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1091,6 +1091,58 @@ exit_fail:
     return NULL;
 }
 
+/* read_resource_owners */
+PyDoc_STRVAR(pydoc_read_resource_owners, "\
+read_resource_owners(lockspace, resource, disks) -> list\n\
+Returns the list of hosts owning a resource, the list is not filtered and\n\
+it might contain hosts that are currently failing or dead. The hosts are\n\
+returned in the same format used by get_hosts.\n\
+The disks must be in the format: [(path, offset), ... ]");
+
+static PyObject *
+py_read_resource_owners(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+    int rv, hss_count = 0;
+    const char *lockspace, *resource;
+    struct sanlk_resource *res = NULL;
+    struct sanlk_host *hss = NULL;
+    PyObject *disks, *ls_list = NULL;
+
+    static char *kwlist[] = {"lockspace", "resource", "disks", NULL};
+
+    /* parse python tuple */
+    if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!", kwlist,
+        &lockspace, &resource, &PyList_Type, &disks)) {
+        return NULL;
+    }
+
+    /* parse and check sanlock resource */
+    if (__parse_resource(disks, &res) < 0) {
+        return NULL;
+    }
+
+    /* prepare sanlock names */
+    strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
+    strncpy(res->name, resource, SANLK_NAME_LEN);
+
+    /* read resource owners (gil disabled) */
+    Py_BEGIN_ALLOW_THREADS
+    rv = sanlock_read_resource_owners(res, 0, &hss, &hss_count);
+    Py_END_ALLOW_THREADS
+
+    if (rv != 0) {
+        __set_exception(rv, "Unable to read resource owners");
+        goto exit_fail;
+    }
+
+    ls_list = __hosts_to_list(hss, hss_count);
+
+exit_fail:
+    if (res) free(res);
+    if (hss) free(hss);
+    return ls_list;
+}
+
 /* killpath */
 PyDoc_STRVAR(pydoc_killpath, "\
 killpath(path, args [, slkfd=fd])\n\
@@ -1217,6 +1269,8 @@ sanlock_methods[] = {
                         METH_VARARGS|METH_KEYWORDS, pydoc_get_lockspaces},
     {"get_hosts", (PyCFunction) py_get_hosts,
                         METH_VARARGS|METH_KEYWORDS, pydoc_get_hosts},
+    {"read_resource_owners", (PyCFunction) py_read_resource_owners,
+                METH_VARARGS|METH_KEYWORDS, pydoc_read_resource_owners},
     {"acquire", (PyCFunction) py_acquire,
                 METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
     {"release", (PyCFunction) py_release,
-- 
1.7.1

_______________________________________________
sanlock-devel mailing list
sanlock-devel@lists.fedorahosted.org
https://lists.fedorahosted.org/mailman/listinfo/sanlock-devel

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

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