This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit e09a07369443025bccd4dea414765f7ec7ebb6f2
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 13:52:44 2019 +0300
python: Use PyBytes converter for init_lockspace API
This API was deprecated by write_lockspace but we want the
lockspace/resource name as bytes change to be uniform so we
modify it as well for sake of old use cases.
Also added stub test for argument parsing.
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 19 ++++++++++++-------
tests/python_test.py | 7 +++++++
2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 86aec94..f73c507 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -356,8 +356,9 @@ Initialize a device to be used as sanlock lockspace.");
static PyObject *
py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, max_hosts = 0, num_hosts = 0, use_aio = 1;
- const char *lockspace, *path;
+ int rv = -1, max_hosts = 0, num_hosts = 0, use_aio = 1;
+ PyObject *lockspace = NULL;
+ const char *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "path",
"offset",
@@ -367,14 +368,14 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiii", kwlist,
- &lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&s|kiii", kwlist,
+ convert_to_pybytes, &lockspace, &path, &ls.host_id_disk.offset,
&max_hosts,
&num_hosts, &use_aio)) {
- return NULL;
+ goto finally;
}
/* prepare sanlock names */
- strncpy(ls.name, lockspace, SANLK_NAME_LEN);
+ strncpy(ls.name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
/* init sanlock lockspace (gil disabled) */
@@ -384,9 +385,13 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock lockspace init failure");
- return NULL;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
}
diff --git a/tests/python_test.py b/tests/python_test.py
index f831c15..0d97cb9 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -599,7 +599,14 @@ def test_reg_event_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno():
sanlock.reg_event(name)
+
@pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
def test_end_event_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno(errno.EALREADY):
sanlock.end_event(-1, name)
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_init_lockspace_parse_args(no_sanlock_daemon, name):
+ with raises_sanlock_errno(errno.ENODEV):
+ sanlock.init_lockspace(name, "path")
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.