This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit ade8f0b4bd3d0efa70be5b130cf9eb6eff501890
Author: Denis Chaplygin <dchaplyg(a)redhat.com>
AuthorDate: Wed Oct 17 10:40:51 2018 +0200
Added python bindings for a configurable sector size and align size.
---
python/example.py | 2 +-
python/sanlock.c | 34 +++++++++++++++++++++++++++-------
2 files changed, 28 insertions(+), 8 deletions(-)
diff --git a/python/example.py b/python/example.py
index 0e8a2f6..6878383 100644
--- a/python/example.py
+++ b/python/example.py
@@ -29,7 +29,7 @@ def main():
fd = sanlock.register()
print "Initializing '%s'" % (LOCKSPACE_NAME,)
- sanlock.write_lockspace(LOCKSPACE_NAME, disk)
+ 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)
diff --git a/python/sanlock.c b/python/sanlock.c
index 3142b2a..888a90d 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -360,7 +360,8 @@ exit_fail:
/* write_lockspace */
PyDoc_STRVAR(pydoc_write_lockspace, "\
-write_lockspace(lockspace, path, offset=0, max_hosts=0, iotimeout=0)\n\
+write_lockspace(lockspace, path, offset=0, max_hosts=0, iotimeout=0, \
+align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512)\n\
Initialize or update a device to be used as sanlock lockspace.");
static PyObject *
@@ -368,19 +369,20 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
{
int rv, max_hosts = 0;
uint32_t io_timeout = 0;
+ uint32_t align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
const char *lockspace, *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "path", "offset",
"max_hosts",
- "iotimeout", NULL};
+ "iotimeout", "align",
"sector", NULL};
/* initialize lockspace structure */
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiI", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiIII", kwlist,
&lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
- &io_timeout)) {
+ &io_timeout, &align, §or)) {
return NULL;
}
@@ -388,6 +390,10 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
strncpy(ls.name, lockspace, SANLK_NAME_LEN);
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+ /* set alignment/sector flags */
+ ls.flags |= align;
+ ls.flags |= sector;
+
/* write sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_write_lockspace(&ls, max_hosts, 0, io_timeout);
@@ -403,7 +409,8 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
/* read_lockspace */
PyDoc_STRVAR(pydoc_read_lockspace, "\
-read_lockspace(path, offset=0) -> dict\n\
+read_lockspace(path, offset=0 \
+align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512)\n -> dict\n\
Read the lockspace information from a device at a specific offset.");
static PyObject *
@@ -411,6 +418,7 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
{
int rv;
uint32_t io_timeout = 0;
+ uint32_t align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
const char *path;
struct sanlk_lockspace ls;
PyObject *ls_info = NULL, *ls_entry = NULL;
@@ -421,14 +429,18 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|k", kwlist,
- &path, &ls.host_id_disk.offset)) {
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kII", kwlist,
+ &path, &ls.host_id_disk.offset, &align, §or)) {
return NULL;
}
/* prepare sanlock names */
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
+ /* set alignment/sector flags */
+ ls.flags |= align;
+ ls.flags |= sector;
+
/* read sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_read_lockspace(&ls, 0, &io_timeout);
@@ -1632,5 +1644,13 @@ initsanlock(void)
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_REPLACE_EVENT,
"SETEV_REPLACE_EVENT");
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_ALL_HOSTS, "SETEV_ALL_HOSTS");
+ /* Sector and align size flags */
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_SECTOR512, "SANLK_RES_SECTOR512");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_SECTOR4K, "SANLK_RES_SECTOR4K");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN1M, "SANLK_RES_ALIGN1M");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN2M, "SANLK_RES_ALIGN2M");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN4M, "SANLK_RES_ALIGN4M");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN8M, "SANLK_RES_ALIGN8M");
+
#undef PYSNLK_INIT_ADD_CONSTANT
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.