This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 5764a68b9eb0f67cece49bf19bb9b825d9cc099b
Author: Denis Chaplygin <dchaplyg(a)redhat.com>
AuthorDate: Thu Oct 25 14:35:52 2018 +0200
Add align/sector size support to the *_resource python bindings.
---
python/example.py | 2 +-
python/sanlock.c | 29 ++++++++++++++++++++---------
2 files changed, 21 insertions(+), 10 deletions(-)
diff --git a/python/example.py b/python/example.py
index 6878383..c0adf54 100644
--- a/python/example.py
+++ b/python/example.py
@@ -32,7 +32,7 @@ def main():
sanlock.write_lockspace(LOCKSPACE_NAME, disk, max_hosts=0, iotimeout=0,
align=sanlock.SANLK_RES_ALIGN1M, sector=sanlock.SANLK_RES_SECTOR512)
print "Initializing '%s' on '%s'" % (RESOURCE_NAME,
LOCKSPACE_NAME)
- sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS)
+ sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS,
align=sanlock.SANLK_RES_ALIGN1M, sector=sanlock.SANLK_RES_SECTOR512)
print "Acquiring the id '%i' on '%s'" % (HOST_ID,
LOCKSPACE_NAME)
sanlock.add_lockspace(LOCKSPACE_NAME, HOST_ID, disk)
diff --git a/python/sanlock.c b/python/sanlock.c
index 888a90d..5ddb6d4 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -423,7 +423,7 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
struct sanlk_lockspace ls;
PyObject *ls_info = NULL, *ls_entry = NULL;
- static char *kwlist[] = {"path", "offset", NULL};
+ static char *kwlist[] = {"path", "offset", "align",
"sector", NULL};
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
@@ -482,18 +482,20 @@ exit_fail:
/* read_resource */
PyDoc_STRVAR(pydoc_read_resource, "\
-read_resource(path, offset=0) -> dict\n\
+read_resource(path, offset=0, \
+align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512) -> dict\n\
Read the resource information from a device at a specific offset.");
static PyObject *
py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv, rs_len;
+ uint32_t align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
const char *path;
struct sanlk_resource *rs;
PyObject *rs_info = NULL, *rs_entry = NULL;
- static char *kwlist[] = {"path", "offset", NULL};
+ static char *kwlist[] = {"path", "offset", "align",
"sector", NULL};
/* allocate the needed memory for the resource and one disk */
rs_len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
@@ -509,14 +511,18 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject
*keywds)
rs->num_disks = 1;
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|k", kwlist,
- &path, &(rs->disks[0].offset))) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kII", kwlist,
+ &path, &(rs->disks[0].offset), &align, §or)) {
goto exit_fail;
}
/* prepare the resource disk path */
strncpy(rs->disks[0].path, path, SANLK_PATH_LEN - 1);
+ /* set alignment/sector flags */
+ rs->flags |= align;
+ rs->flags |= sector;
+
/* read sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_read_resource(rs, 0);
@@ -569,7 +575,7 @@ exit_fail:
/* write_resource */
PyDoc_STRVAR(pydoc_write_resource, "\
write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0, \
-clear=False)\n\
+clear=False, align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512)\n\
Initialize a device to be used as sanlock resource.\n\
The disks must be in the format: [(path, offset), ... ].\n\
If clear is True, the resource is cleared so subsequent read will\n\
@@ -579,18 +585,19 @@ static PyObject *
py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv, max_hosts = 0, num_hosts = 0, clear = 0;
+ uint32_t align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
const char *lockspace, *resource;
struct sanlk_resource *rs;
PyObject *disks;
uint32_t flags = 0;
static char *kwlist[] = {"lockspace", "resource",
"disks", "max_hosts",
- "num_hosts", "clear", NULL};
+ "num_hosts", "clear",
"align", "sector", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii",
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiiII",
kwlist, &lockspace, &resource, &PyList_Type, &disks,
&max_hosts,
- &num_hosts, &clear)) {
+ &num_hosts, &clear, &align, §or)) {
return NULL;
}
@@ -603,6 +610,10 @@ 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);
+ /* set alignment/sector flags */
+ rs->flags |= align;
+ rs->flags |= sector;
+
if (clear) {
flags |= SANLK_WRITE_CLEAR;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.