[sanlock] 13/18: python: Use PyBytes converter for resource owner
request API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit e24d87a6501e2d93575ebda902b56fd9a68e1747
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 17:25:26 2019 +0300
python: Use PyBytes converter for resource owner request API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace/resource name.
---
python/sanlock.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index b43d635..0964671 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1159,28 +1159,29 @@ The disks must be in the format: [(path, offset), ... ]");
static PyObject *
py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, action = SANLK_REQ_GRACEFUL, flags = 0;
- const char *lockspace, *resource;
- struct sanlk_resource *res;
+ int rv = -1, action = SANLK_REQ_GRACEFUL, flags = 0;
+ PyObject *lockspace = NULL, *resource = NULL;
+ struct sanlk_resource *res = NULL;
PyObject *disks, *version = Py_None;
static char *kwlist[] = {"lockspace", "resource", "disks", "action",
"version", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iO", kwlist,
- &lockspace, &resource, &PyList_Type, &disks, &action, &version)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iO", kwlist,
+ convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks, &action, &version)) {
+ goto finally;
}
/* parse and check sanlock resource */
if (__parse_resource(disks, &res) < 0) {
- return NULL;
+ goto finally;
}
/* prepare sanlock names */
- strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
- strncpy(res->name, resource, SANLK_NAME_LEN);
+ strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
+ strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
/* prepare the resource version */
if (version == Py_None) {
@@ -1190,7 +1191,7 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
res->lver = pyinteger_as_unsigned_long_long_mask(version);
if (res->lver == (uint64_t)-1) {
__set_exception(EINVAL, "Unable to convert the version value");
- goto exit_fail;
+ goto finally;
}
}
@@ -1201,15 +1202,16 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock request not submitted");
- goto exit_fail;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
free(res);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
-
-exit_fail:
- free(res);
- return NULL;
}
/* read_resource_owners */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 12/18: python: Use PyBytes converter for resource release
API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 520b21849bff16c7bff3a0be8e6816549ce56242
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 17:04:56 2019 +0300
python: Use PyBytes converter for resource release API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace/resource name.
---
python/sanlock.c | 30 ++++++++++++++++--------------
1 file changed, 16 insertions(+), 14 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 7bdbd69..b43d635 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1103,28 +1103,29 @@ The disks must be in the format: [(path, offset), ... ]");
static PyObject *
py_release(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, sanlockfd = -1, pid = -1;
- const char *lockspace, *resource;
- struct sanlk_resource *res;
+ int rv = -1, sanlockfd = -1, pid = -1;
+ PyObject *lockspace = NULL, *resource = NULL;
+ struct sanlk_resource *res = NULL;
PyObject *disks;
static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd",
"pid", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|ii", kwlist,
- &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|ii", kwlist,
+ convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks, &sanlockfd, &pid)) {
+ goto finally;
}
/* parse and check sanlock resource */
if (__parse_resource(disks, &res) < 0) {
- return NULL;
+ goto finally;
}
/* prepare sanlock names */
- strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
- strncpy(res->name, resource, SANLK_NAME_LEN);
+ strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
+ strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
/* release sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -1133,15 +1134,16 @@ py_release(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock resource not released");
- goto exit_fail;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
free(res);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
-
-exit_fail:
- free(res);
- return NULL;
}
/* request */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 11/18: python: Use PyBytes converter for resource acquire
API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 9934ce6b5d65ba10a4e0797de3040da0c1c53713
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 16:59:18 2019 +0300
python: Use PyBytes converter for resource acquire API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace/resource name.
---
python/sanlock.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index c7518c6..7bdbd69 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1030,35 +1030,35 @@ The disks must be in the format: [(path, offset), ... ]\n");
static PyObject *
py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, sanlockfd = -1, pid = -1, shared = 0;
- const char *lockspace, *resource;
- struct sanlk_resource *res;
+ int rv = -1, sanlockfd = -1, pid = -1, shared = 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};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiiO", kwlist,
- &lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid,
- &shared, &version)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iiiO", kwlist,
+ convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks, &sanlockfd, &pid, &shared, &version)) {
+ goto finally;
}
/* check if any of the slkfd or pid parameters was given */
if (sanlockfd == -1 && pid == -1) {
__set_exception(EINVAL, "Invalid slkfd and pid values");
- return NULL;
+ goto finally;
}
/* parse and check sanlock resource */
if (__parse_resource(disks, &res) < 0) {
- return NULL;
+ goto finally;
}
/* prepare sanlock names */
- strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
- strncpy(res->name, resource, SANLK_NAME_LEN);
+ strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
+ strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
/* prepare sanlock flags */
if (shared) {
@@ -1071,7 +1071,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
res->lver = pyinteger_as_unsigned_long_long_mask(version);
if (res->lver == (uint64_t)-1) {
__set_exception(EINVAL, "Unable to convert the version value");
- goto exit_fail;
+ goto finally;
}
}
@@ -1082,15 +1082,16 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock resource not acquired");
- goto exit_fail;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
free(res);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
-
-exit_fail:
- free(res);
- return NULL;
}
/* release */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 10/18: python: Use PyBytes converter for get_hosts API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 0c58dd3b3cd4d73b756093e291c745ea99ffd12c
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 16:49:43 2019 +0300
python: Use PyBytes converter for get_hosts API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 21 ++++++++++++---------
1 file changed, 12 insertions(+), 9 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 28146df..c7518c6 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -983,34 +983,37 @@ timestamp and the io_timeout.\n");
static PyObject *
py_get_hosts(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, hss_count = 0;
+ int rv = -1, hss_count = 0;
uint64_t host_id = 0;
- const char *lockspace = NULL;
+ PyObject *lockspace = NULL;
struct sanlk_host *hss = NULL;
PyObject *ls_list = NULL;
static char *kwlist[] = {"lockspace", "host_id", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|k", kwlist,
- &lockspace, &host_id)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|k", kwlist,
+ convert_to_pybytes, &lockspace, &host_id)) {
+ goto finally;
}
/* get all the lockspaces (gil disabled) */
Py_BEGIN_ALLOW_THREADS
- rv = sanlock_get_hosts(lockspace, host_id, &hss, &hss_count, 0);
+ rv = sanlock_get_hosts(PyBytes_AsString(lockspace), host_id, &hss, &hss_count, 0);
Py_END_ALLOW_THREADS
if (rv < 0) {
__set_exception(rv, "Sanlock get hosts failure");
- goto exit_fail;
+ goto finally;
}
ls_list = __hosts_to_list(hss, hss_count);
-exit_fail:
- if (hss) free(hss);
+finally:
+ Py_XDECREF(lockspace);
+ free(hss);
+ if (rv < 0)
+ return NULL;
return ls_list;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 09/18: python: Use PyBytes converter for rem_lockspace API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 0a130d251ee01ae1c062a92a534d008216c8c619
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 16:42:04 2019 +0300
python: Use PyBytes converter for rem_lockspace API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 1fdb143..28146df 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -855,8 +855,9 @@ successful termination these leases will be released.");
static PyObject *
py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, async = 0, unused = 0, flags = 0;
- const char *lockspace, *path;
+ int rv = -1, async = 0, unused = 0, flags = 0;
+ PyObject *lockspace = NULL;
+ const char *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
@@ -866,14 +867,14 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|kii", kwlist,
- &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset, &async,
- &unused)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&ks|kii", kwlist,
+ convert_to_pybytes, &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
+ &async, &unused)) {
+ 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);
/* prepare sanlock_rem_lockspace flags */
@@ -892,9 +893,13 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock lockspace remove 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.
4 years, 10 months
[sanlock] 08/18: python: Use PyBytes converter for inq_lockspace API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 271e2aab022955d30980fbe5eb83d435454647b1
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 16:37:16 2019 +0300
python: Use PyBytes converter for inq_lockspace API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index fca9c80..1fdb143 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -32,6 +32,8 @@
#define MODULE_NAME "sanlock"
+#define BIND_ERROR -1000
+
/* Functions prototypes */
static void __set_exception(int en, char *msg) __sets_exception;
static int __parse_resource(PyObject *obj, struct sanlk_resource **res_ret) __neg_sets_exception;
@@ -791,8 +793,9 @@ acquired or released.");
static PyObject *
py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, waitrs = 0, flags = 0;
- const char *lockspace, *path;
+ int rv = BIND_ERROR, waitrs = 0, flags = 0;
+ PyObject *lockspace = NULL;
+ const char *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
@@ -802,10 +805,10 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|ki", kwlist,
- &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&ks|ki", kwlist,
+ convert_to_pybytes, &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
&waitrs)) {
- return NULL;
+ goto finally;
}
/* prepare sanlock_inq_lockspace flags */
@@ -814,7 +817,7 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* 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);
/* add sanlock lockspace (gil disabled) */
@@ -822,7 +825,12 @@ py_inq_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
rv = sanlock_inq_lockspace(&ls, flags);
Py_END_ALLOW_THREADS
- if (rv == 0) {
+finally:
+ Py_XDECREF(lockspace);
+
+ if (rv == BIND_ERROR) {
+ return NULL;
+ } else if (rv == 0) {
Py_RETURN_TRUE;
} else if (rv == -ENOENT) {
Py_RETURN_FALSE;
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 07/18: python: Use PyBytes converter for add_lockspace API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 75017ecc557fc689cbb90effdcb735a423e7e152
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 16:27:58 2019 +0300
python: Use PyBytes converter for add_lockspace API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace name.
---
python/sanlock.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index ad99436..fca9c80 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -734,9 +734,10 @@ overriding the default value (see the sanlock daemon parameter -o).");
static PyObject *
py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, async = 0, flags = 0;
+ int rv = -1, async = 0, flags = 0;
uint32_t iotimeout = 0;
- const char *lockspace, *path;
+ PyObject *lockspace = NULL;
+ const char *path;
struct sanlk_lockspace ls;
static char *kwlist[] = {"lockspace", "host_id", "path", "offset",
@@ -746,10 +747,10 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "sks|kIi", kwlist,
- &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset, &iotimeout,
- &async)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&ks|kIi", kwlist,
+ convert_to_pybytes, &lockspace, &ls.host_id, &path, &ls.host_id_disk.offset,
+ &iotimeout, &async)) {
+ goto finally;
}
/* prepare sanlock_add_lockspace flags */
@@ -758,7 +759,7 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* 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);
/* add sanlock lockspace (gil disabled) */
@@ -768,9 +769,13 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock lockspace add 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.
4 years, 10 months
[sanlock] 06/18: python: Use PyBytes converter for write_resource
API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 0dc46487e367610ad249ffb665b6ae8ffb19f468
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 16:20:07 2019 +0300
python: Use PyBytes converter for write_resource API
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace/resource name.
---
python/sanlock.c | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 493608c..ad99436 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -667,10 +667,10 @@ Sector can be one of (512, 4096).");
static PyObject *
py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, max_hosts = 0, num_hosts = 0, clear = 0, sector = SECTOR_SIZE_512;
+ int rv = -1, max_hosts = 0, num_hosts = 0, clear = 0, sector = SECTOR_SIZE_512;
long align = ALIGNMENT_1M;
- const char *lockspace, *resource;
- struct sanlk_resource *rs;
+ PyObject *lockspace = NULL, *resource = NULL;
+ struct sanlk_resource *rs = NULL;
PyObject *disks;
uint32_t flags = 0;
@@ -678,27 +678,27 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
"num_hosts", "clear", "align", "sector", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiili",
- kwlist, &lockspace, &resource, &PyList_Type, &disks, &max_hosts,
- &num_hosts, &clear, &align, §or)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iiili",
+ kwlist, convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks, &max_hosts, &num_hosts, &clear, &align, §or)) {
+ goto finally;
}
/* parse and check sanlock resource */
if (__parse_resource(disks, &rs) < 0) {
- return NULL;
+ goto finally;
}
/* prepare sanlock names */
- strncpy(rs->lockspace_name, lockspace, SANLK_NAME_LEN);
- strncpy(rs->name, resource, SANLK_NAME_LEN);
+ strncpy(rs->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
+ strncpy(rs->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
/* set alignment/sector flags */
if (add_align_flag(align, &rs->flags) == -1)
- goto exit_fail;
+ goto finally;
if (add_sector_flag(sector, &rs->flags) == -1)
- goto exit_fail;
+ goto finally;
if (clear) {
flags |= SANLK_WRITE_CLEAR;
@@ -711,15 +711,16 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock resource write failure");
- goto exit_fail;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
free(rs);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
-
-exit_fail:
- free(rs);
- return NULL;
}
/* add_lockspace */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 05/18: python: Use PyBytes converter for write_lockspace
API
by pagure@pagure.io
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.
4 years, 10 months
[sanlock] 04/18: python: Use PyBytes converter for init_resource API
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
nsoffer pushed a commit to branch master
in repository sanlock.
commit 89698171cf5555244f42851e2dd529cb848fb393
Author: Amit Bawer <abawer(a)redhat.com>
AuthorDate: Sun Jun 2 14:56:05 2019 +0300
python: Use PyBytes converter for init_resource API
This API was deprecated by write_resource 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 arguments parsing.
Implications:
- Py2 : no difference
- Py3 : if used, only accept bytes for lockspace/resource name.
---
python/sanlock.c | 31 ++++++++++++++++---------------
tests/python_test.py | 9 +++++++++
2 files changed, 25 insertions(+), 15 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index f73c507..3d0bfb0 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -406,29 +406,29 @@ The disks must be in the format: [(path, offset), ... ]");
static PyObject *
py_init_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, max_hosts = 0, num_hosts = 0, use_aio = 1;
- const char *lockspace, *resource;
- struct sanlk_resource *res;
+ int rv = -1, max_hosts = 0, num_hosts = 0, use_aio = 1;
+ PyObject *lockspace = NULL, *resource = NULL;
+ struct sanlk_resource *res = NULL;
PyObject *disks;
static char *kwlist[] = {"lockspace", "resource", "disks", "max_hosts",
"num_hosts", "use_aio", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iii",
- kwlist, &lockspace, &resource, &PyList_Type, &disks, &max_hosts,
- &num_hosts, &use_aio)) {
- return NULL;
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&O&O!|iii",
+ kwlist, convert_to_pybytes, &lockspace, convert_to_pybytes, &resource,
+ &PyList_Type, &disks, &max_hosts, &num_hosts, &use_aio)) {
+ goto finally;
}
/* parse and check sanlock resource */
if (__parse_resource(disks, &res) < 0) {
- return NULL;
+ goto finally;
}
/* prepare sanlock names */
- strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
- strncpy(res->name, resource, SANLK_NAME_LEN);
+ strncpy(res->lockspace_name, PyBytes_AsString(lockspace), SANLK_NAME_LEN);
+ strncpy(res->name, PyBytes_AsString(resource), SANLK_NAME_LEN);
/* init sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -437,15 +437,16 @@ py_init_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (rv != 0) {
__set_exception(rv, "Sanlock resource init failure");
- goto exit_fail;
+ goto finally;
}
+finally:
+ Py_XDECREF(lockspace);
+ Py_XDECREF(resource);
free(res);
+ if (rv != 0)
+ return NULL;
Py_RETURN_NONE;
-
-exit_fail:
- free(res);
- return NULL;
}
/* write_lockspace */
diff --git a/tests/python_test.py b/tests/python_test.py
index 0d97cb9..7406bcb 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -610,3 +610,12 @@ def test_end_event_parse_args(no_sanlock_daemon, name):
def test_init_lockspace_parse_args(no_sanlock_daemon, name):
with raises_sanlock_errno(errno.ENODEV):
sanlock.init_lockspace(name, "path")
+
+
+(a)pytest.mark.parametrize("name", LOCKSPACE_OR_RESOURCE_NAMES)
+def test_init_resource_parse_args(no_sanlock_daemon, name):
+ disks = [("path", 0)]
+ with raises_sanlock_errno(errno.ENOENT):
+ sanlock.init_resource(b"ls_name", name, disks)
+ with raises_sanlock_errno(errno.ENOENT):
+ sanlock.init_resource(name, b"res_name", disks)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months