This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 5fa18571e8d5d0ddab20039b7859d5b7a7e8d9f0
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 15:50:19 2019 +0300
python: Use PyBytes converter for write_lockspace API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 25 +++++++++++++++----------
1 file changed, 15 insertions(+), 10 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 3d0bfb0..493608c 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -460,10 +460,11 @@ Sector can be one of (512, 4096).");
static PyObject *
py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, max_hosts = 0, sector = SECTOR_SIZE_512;
+ int rv = -1, max_hosts = 0, sector = SECTOR_SIZE_512;
long align = ALIGNMENT_1M;
uint32_t io_timeout = 0;
- const char *lockspace, *path;
+ PyObject *lockspace = NULL;
+ const char *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "path", "offset",
"max_hosts",
@@ -473,22 +474,22 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiIli", kwlist,
- &lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
- &io_timeout, &align, §or)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&s|kiIli", kwlist,
+ convert_to_pybytes, &lockspace, &path, &ls.host_id_disk.offset,
+ &max_hosts, &io_timeout, &align, §or)) {
+ 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);
/* set alignment/sector flags */
if (add_align_flag(align, &ls.flags) == -1)
- return NULL;
+ goto finally;
if (add_sector_flag(sector, &ls.flags) == -1)
- return NULL;
+ goto finally;
/* write sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -497,9 +498,13 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock lockspace write failure");
- return NULL;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.