From f2457f033f4cd55280628f1033f648d2497d30d0 Mon Sep 17 00:00:00 2001 From: Benny Zlotnik Date: Jan 26 2021 16:05:48 +0000 Subject: python: add lvb flag to sanlock.acquire The flag will allow to acquire a resource with the SANLK_ACQUIRE_LVB flag, allowing the user to write or read data from LVB space. Signed-off-by: Benny Zlotnik --- diff --git a/python/sanlock.c b/python/sanlock.c index 7c50aba..d26e618 100644 --- a/python/sanlock.c +++ b/python/sanlock.c @@ -1082,28 +1082,31 @@ finally: /* acquire */ PyDoc_STRVAR(pydoc_acquire, "\ acquire(lockspace, resource, disks \ -[, slkfd=fd, pid=owner, shared=False, version=None])\n\ +[, slkfd=fd, pid=owner, shared=False, version=None, lvb=False])\n\ Acquire a resource lease for the current process (using the slkfd argument\n\ to specify the sanlock file descriptor) or for an other process (using the\n\ pid argument). If shared is True the resource will be acquired in the shared\n\ mode. The version is the version of the lease that must be acquired or fail.\n\ -The disks must be in the format: [(path, offset), ... ]\n"); +The disks must be in the format: [(path, offset), ... ]\n\ +If lvb is True the resource will be acquired with the LVB flag enabled\n\ +to allow access to LVB data.\n"); static PyObject * py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds) { - int rv = -1, sanlockfd = -1, pid = -1, shared = 0; + int rv = -1, sanlockfd = -1, pid = -1, shared = 0, lvb = 0; + uint32_t flags = 0; PyObject *lockspace = NULL, *resource = NULL; struct sanlk_resource *res = NULL; PyObject *disks, *version = Py_None; static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd", - "pid", "shared", "version", NULL}; + "pid", "shared", "lvb", "version", NULL}; /* parse python tuple */ - if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iiiO", kwlist, + if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iiiiO", kwlist, convert_to_pybytes, &lockspace, convert_to_pybytes, &resource, - &PyList_Type, &disks, &sanlockfd, &pid, &shared, &version)) { + &PyList_Type, &disks, &sanlockfd, &pid, &shared, &lvb, &version)) { goto finally; } @@ -1127,6 +1130,10 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds) res->flags |= SANLK_RES_SHARED; } + if (lvb) { + flags |= SANLK_ACQUIRE_LVB; + } + /* prepare the resource version */ if (version != Py_None) { res->flags |= SANLK_RES_LVER; @@ -1139,7 +1146,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds) /* acquire sanlock resource (gil disabled) */ Py_BEGIN_ALLOW_THREADS - rv = sanlock_acquire(sanlockfd, pid, 0, 1, &res, 0); + rv = sanlock_acquire(sanlockfd, pid, flags, 1, &res, 0); Py_END_ALLOW_THREADS if (rv != 0) {