[sanlock] 03/14: python: Rename __parse_resource to parse_disks
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 3dcbf2a616f43c8a93391049b3be4a13130a0dcd
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Fri Jun 14 20:38:48 2019 +0300
python: Rename __parse_resource to parse_disks
Underscore prefix is reserved for the compiler and standard library so
we should not use it for our helpers.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 42b46fb..4155b51 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -22,7 +22,7 @@
/* Functions prototypes */
static void set_sanlock_error(int en, char *msg);
-static int __parse_resource(PyObject *obj, struct sanlk_resource **res_ret);
+static int parse_disks(PyObject *obj, struct sanlk_resource **res_ret);
static void set_error(PyObject *exception, const char* format, PyObject* obj);
/* Sanlock module */
@@ -173,7 +173,7 @@ finally:
}
static int
-__parse_resource(PyObject *obj, struct sanlk_resource **res_ret)
+parse_disks(PyObject *obj, struct sanlk_resource **res_ret)
{
int i, num_disks, res_len;
struct sanlk_resource *res;
@@ -481,7 +481,7 @@ py_init_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) < 0) {
+ if (parse_disks(disks, &res) < 0) {
goto finally;
}
@@ -747,7 +747,7 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &rs) < 0) {
+ if (parse_disks(disks, &rs) < 0) {
goto finally;
}
@@ -1118,7 +1118,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) < 0) {
+ if (parse_disks(disks, &res) < 0) {
goto finally;
}
@@ -1185,7 +1185,7 @@ py_release(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) < 0) {
+ if (parse_disks(disks, &res) < 0) {
goto finally;
}
@@ -1241,7 +1241,7 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) < 0) {
+ if (parse_disks(disks, &res) < 0) {
goto finally;
}
@@ -1313,7 +1313,7 @@ py_read_resource_owners(PyObject *self __unused, PyObject *args, PyObject *keywd
}
/* parse and check sanlock resource */
- if (__parse_resource(disks, &res) < 0) {
+ if (parse_disks(disks, &res) < 0) {
goto finally;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 02/14: python: Rename __set_exception to set_sanlock_error
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 e40db2ecd00c3376fe1b1dc7f5ed4c021031a9ff
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Fri Jun 14 20:30:52 2019 +0300
python: Rename __set_exception to set_sanlock_error
Underscore prefix is reserved for the compiler and standard library so
we should not use it for our helpers.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 58 ++++++++++++++++++++++++++++----------------------------
1 file changed, 29 insertions(+), 29 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 7574141..42b46fb 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -21,7 +21,7 @@
#define BIND_ERROR -1000
/* Functions prototypes */
-static void __set_exception(int en, char *msg);
+static void set_sanlock_error(int en, char *msg);
static int __parse_resource(PyObject *obj, struct sanlk_resource **res_ret);
static void set_error(PyObject *exception, const char* format, PyObject* obj);
@@ -36,7 +36,7 @@ of the GNU General Public License v2 or (at your option) any later version.");
static PyObject *py_exception;
static void
-__set_exception(int en, char *msg)
+set_sanlock_error(int en, char *msg)
{
const char *err_name;
PyObject *exc_tuple;
@@ -323,7 +323,7 @@ py_register(PyObject *self __unused, PyObject *args)
Py_END_ALLOW_THREADS
if (sanlockfd < 0) {
- __set_exception(sanlockfd, "Sanlock registration failed");
+ set_sanlock_error(sanlockfd, "Sanlock registration failed");
return NULL;
}
@@ -356,7 +356,7 @@ py_get_alignment(PyObject *self __unused, PyObject *args)
Py_END_ALLOW_THREADS
if (rv < 0) {
- __set_exception(rv, "Unable to get device alignment");
+ set_sanlock_error(rv, "Unable to get device alignment");
goto finally;
}
@@ -442,7 +442,7 @@ py_init_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock lockspace init failure");
+ set_sanlock_error(rv, "Sanlock lockspace init failure");
goto finally;
}
@@ -495,7 +495,7 @@ py_init_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock resource init failure");
+ set_sanlock_error(rv, "Sanlock resource init failure");
goto finally;
}
@@ -556,7 +556,7 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock lockspace write failure");
+ set_sanlock_error(rv, "Sanlock lockspace write failure");
goto finally;
}
@@ -612,7 +612,7 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock lockspace read failure");
+ set_sanlock_error(rv, "Sanlock lockspace read failure");
goto finally;
}
@@ -688,7 +688,7 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock resource read failure");
+ set_sanlock_error(rv, "Sanlock resource read failure");
goto finally;
}
@@ -772,7 +772,7 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock resource write failure");
+ set_sanlock_error(rv, "Sanlock resource write failure");
goto finally;
}
@@ -831,7 +831,7 @@ py_add_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock lockspace add failure");
+ set_sanlock_error(rv, "Sanlock lockspace add failure");
goto finally;
}
@@ -901,7 +901,7 @@ finally:
Py_RETURN_NONE;
}
- __set_exception(rv, "Sanlock lockspace inquire failure");
+ set_sanlock_error(rv, "Sanlock lockspace inquire failure");
return NULL;
}
@@ -957,7 +957,7 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock lockspace remove failure");
+ set_sanlock_error(rv, "Sanlock lockspace remove failure");
goto finally;
}
@@ -991,7 +991,7 @@ py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv < 0) {
- __set_exception(rv, "Sanlock get lockspaces failure");
+ set_sanlock_error(rv, "Sanlock get lockspaces failure");
goto exit_fail;
}
@@ -1069,7 +1069,7 @@ py_get_hosts(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv < 0) {
- __set_exception(rv, "Sanlock get hosts failure");
+ set_sanlock_error(rv, "Sanlock get hosts failure");
goto finally;
}
@@ -1113,7 +1113,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* check if any of the slkfd or pid parameters was given */
if (sanlockfd == -1 && pid == -1) {
- __set_exception(EINVAL, "Invalid slkfd and pid values");
+ set_sanlock_error(EINVAL, "Invalid slkfd and pid values");
goto finally;
}
@@ -1136,7 +1136,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
res->flags |= SANLK_RES_LVER;
res->lver = pyinteger_as_unsigned_long_long_mask(version);
if (res->lver == (uint64_t)-1) {
- __set_exception(EINVAL, "Unable to convert the version value");
+ set_sanlock_error(EINVAL, "Unable to convert the version value");
goto finally;
}
}
@@ -1147,7 +1147,7 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock resource not acquired");
+ set_sanlock_error(rv, "Sanlock resource not acquired");
goto finally;
}
@@ -1199,7 +1199,7 @@ py_release(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock resource not released");
+ set_sanlock_error(rv, "Sanlock resource not released");
goto finally;
}
@@ -1256,7 +1256,7 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
res->flags |= SANLK_RES_LVER;
res->lver = pyinteger_as_unsigned_long_long_mask(version);
if (res->lver == (uint64_t)-1) {
- __set_exception(EINVAL, "Unable to convert the version value");
+ set_sanlock_error(EINVAL, "Unable to convert the version value");
goto finally;
}
}
@@ -1267,7 +1267,7 @@ py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Sanlock request not submitted");
+ set_sanlock_error(rv, "Sanlock request not submitted");
goto finally;
}
@@ -1335,7 +1335,7 @@ py_read_resource_owners(PyObject *self __unused, PyObject *args, PyObject *keywd
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Unable to read resource owners");
+ set_sanlock_error(rv, "Unable to read resource owners");
goto finally;
}
@@ -1373,7 +1373,7 @@ parse_killpath_item(PyObject *item, char *kpargs, size_t *kplen)
/* adding 2 for the space separator ' ' and the '\0' terminator */
if (*kplen + arg_len + 2 > SANLK_HELPER_ARGS_LEN) {
- __set_exception(EINVAL, "Killpath arguments are too long");
+ set_sanlock_error(EINVAL, "Killpath arguments are too long");
goto finally;
}
@@ -1423,7 +1423,7 @@ py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* checking the path length */
if (PyBytes_Size(path) + 1 > SANLK_HELPER_PATH_LEN) {
- __set_exception(EINVAL, "Killpath path argument too long");
+ set_sanlock_error(EINVAL, "Killpath path argument too long");
goto finally;
}
@@ -1444,7 +1444,7 @@ py_killpath(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv != 0) {
- __set_exception(rv, "Killpath script not configured");
+ set_sanlock_error(rv, "Killpath script not configured");
goto finally;
}
@@ -1495,7 +1495,7 @@ py_reg_event(PyObject *self __unused, PyObject *args)
Py_END_ALLOW_THREADS
if (fd < 0) {
- __set_exception(fd, "Unable to register event fd");
+ set_sanlock_error(fd, "Unable to register event fd");
goto finally;
}
@@ -1547,7 +1547,7 @@ py_get_event(PyObject *self __unused, PyObject *args)
break;
if (rv != 0) {
- __set_exception(rv, "Unable to get events");
+ set_sanlock_error(rv, "Unable to get events");
goto exit_fail;
}
@@ -1638,7 +1638,7 @@ py_end_event(PyObject *self __unused, PyObject *args)
Py_END_ALLOW_THREADS
if (rv < 0) {
- __set_exception(rv, "Unable to unregister event fd");
+ set_sanlock_error(rv, "Unable to unregister event fd");
goto finally;
}
@@ -1723,7 +1723,7 @@ py_set_event(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv < 0) {
- __set_exception(rv, "Unable to set event");
+ set_sanlock_error(rv, "Unable to set event");
goto finally;
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[sanlock] 01/14: python: Remove CPyChecker support
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 1ff38e0e2cd7f4234c20e33ffeec3815da0df438
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Fri Jun 14 20:24:14 2019 +0300
python: Remove CPyChecker support
We don't use use this tool, lets remove old craft.
If someone wants to add this back it must have proper documentation and
integrated in the build system.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 18 ++----------------
1 file changed, 2 insertions(+), 16 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 7f0916a..7574141 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -16,27 +16,13 @@
#define __unused __attribute__ ((unused))
#endif
-#ifdef WITH_CPYCHECKER_SETS_EXCEPTION_ATTRIBUTE
-#define __sets_exception \
- __attribute__((cpychecker_sets_exception))
-#else
-#define __sets_exception
-#endif
-
-#ifdef WITH_CPYCHECKER_NEGATIVE_RESULT_SETS_EXCEPTION_ATTRIBUTE
-#define __neg_sets_exception \
- __attribute__((cpychecker_negative_result_sets_exception))
-#else
-#define __neg_sets_exception
-#endif
-
#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;
+static void __set_exception(int en, char *msg);
+static int __parse_resource(PyObject *obj, struct sanlk_resource **res_ret);
static void set_error(PyObject *exception, const char* format, PyObject* obj);
/* Sanlock module */
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 9 months
[PATCH 00/14] Python extension cleanups
by Nir Soffer
Lately I spent lot of time reviewing changes to the this messy code, and
it is time to clean up the mess. I'm planning many more cleanups, but
this is enough for today.
Nir Soffer (14):
python: Remove CPyChecker support
python: Rename __set_exception to set_sanlock_error
python: Rename __parse_resource to parse_disks
python: Rename __hosts_to_list to hosts_to_list
python: Fix copyright years
python: Add missing license blob to python files
python: Remove meaningless "All rights reserved"
python: Use C99 standard
python: Limit the scope of for loop counter
python: Remove unneeded check for null
python: Streamline hosts_to_list
python: Streamline py_get_lockspaces()
python: Unify indentation
python: Unify resource variables names
python/example.py | 7 +
python/sanlock.c | 310 ++++++++++++++++++++-----------------------
python/setup.py | 3 +-
tests/conftest.py | 6 +
tests/constants.py | 6 +
tests/daemon_test.py | 6 +
tests/direct_test.py | 6 +
tests/python_test.py | 6 +
tests/storage.py | 6 +
tests/units.py | 6 +
tests/util.py | 6 +
11 files changed, 204 insertions(+), 164 deletions(-)
--
2.17.2
4 years, 9 months
[PATCH v2 0/8] Python extension cleanups (continued)
by Nir Soffer
More cleanups patches based on my last cleanups series.
The path legnth validation fix is a very old issue, but it can be nice
to deliver in 3.8.1. More fixes are needed for truncating silently
lockspace path, lockspace name and resource name.
These are only the new patches since v1. I will combine all pathes in
v3.
v1 was here:
https://lists.fedorahosted.org/archives/list/sanlock-devel@lists.fedoraho...
The changes are also availale in:
https://github.com/nirs/sanlock/tree/cleanups-v2
Based on commit 50a6590db428769e653282f11eb3051c31938a92 (python: Unify
resource variables names).
Nir Soffer (8):
python: Use Py_BuildValue to create event dicts
python: Use Py_CLEAR
python: Streamline initexception
python: Extract create_resource() helper
python: Replace memset() with initializer
python: Add missing arg parsing tests
python: Add failing tests for long disk path
python: Fail with ValueError if disk path is too long
python/sanlock.c | 191 ++++++++++++++++---------------------------
tests/constants.py | 4 +
tests/python_test.py | 98 ++++++++++++++++++++++
3 files changed, 172 insertions(+), 121 deletions(-)
--
2.17.2
4 years, 10 months
[PATCH v3 0/2] tests for clearing resource
by Vojtech Juranek
Add tests for clearing the resource. Also extract reading sanlock
magic number into helper function.
Vojtech Juranek (2):
tests: replace reading of magic number by helper function
tests: add tests for clearing resource
tests/constants.py | 4 +++
tests/python_test.py | 72 ++++++++++++++++++++++++++++++++++----------
tests/util.py | 11 +++++++
3 files changed, 71 insertions(+), 16 deletions(-)
--
2.20.1
4 years, 10 months
[PATCH 0/2] Streamline tests output
by Nir Soffer
Streamline tests output by using normal mode and not listing skipped
tests in the short test summary.
Here is example output from travis build:
$ pytest
============================= test session starts ==============================
platform linux -- Python 3.7.1, pytest-4.3.1, py-1.7.0, pluggy-0.8.0
rootdir: /home/travis/build/nirs/sanlock, inifile: tox.ini
collected 210 items
tests/daemon_test.py ........... [ 5%]
tests/direct_test.py .. [ 6%]
tests/python_test.py ........ssssssssssss........ssssssssssssss......... [ 30%]
...............ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss. [ 64%]
ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.ss.......... [ 99%]
.. [100%]
========================== slowest 10 test durations ===========================
6.02s call tests/python_test.py::test_add_rem_lockspace_async
6.02s call tests/python_test.py::test_add_rem_lockspace[1099511627776-1099510579200]
6.02s call tests/python_test.py::test_add_rem_lockspace[1048576-0]
4.06s call tests/python_test.py::test_acquire_release_resource[1048576-0]
4.05s call tests/python_test.py::test_acquire_release_resource[1099511627776-1099510579200]
3.21s call tests/daemon_test.py::test_create
3.12s call tests/daemon_test.py::test_delete
3.09s call tests/daemon_test.py::test_lookup
3.05s call tests/daemon_test.py::test_lookup_missing
0.42s call tests/daemon_test.py::test_start_after_kill
=================== 104 passed, 106 skipped in 46.73 seconds ===================
The command "pytest" exited with 0.
0.60s$ flake8 --statistics tests python
The command "flake8 --statistics tests python" exited with 0.
Based on commit edf1e08326daa39a2e453d936fa9a99dd0ec136c (python:
Convert example.py to python 3)
Nir Soffer (2):
python: Don't report skipped tests
python: Use pytest normal mode
README.dev | 9 +++++++++
tox.ini | 5 ++---
2 files changed, 11 insertions(+), 3 deletions(-)
--
2.17.2
4 years, 10 months
[sanlock] 02/02: python: Use pytest normal mode
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 a4ded879ecbddbc2328a2e59298fdaeae430c16f
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Sun Jun 16 18:28:33 2019 +0300
python: Use pytest normal mode
We have too many tests to use verbose mode. If verbose more is needed it
can be enabled using:
tox -e py36 tests/python_test.py -- -vv
Or using environment variable:
export PYTEST_ADDOPTS=-vv
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
README.dev | 9 +++++++++
tox.ini | 3 +--
2 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/README.dev b/README.dev
index 8ade5e6..7f3df2c 100644
--- a/README.dev
+++ b/README.dev
@@ -41,6 +41,15 @@ To run basic lint and style check:
$ tox -e flake8
+Sometimes when debugging failing tests verbose mode is useful. You can
+enable it using:
+
+ $ tox -e py36 tests/python_test.py -- -vv
+
+Or using environment variable:
+
+ export PYTEST_ADDOPTS=-vv
+
Testing 4K support
==================
diff --git a/tox.ini b/tox.ini
index 0cadfb5..4a28561 100644
--- a/tox.ini
+++ b/tox.ini
@@ -29,10 +29,9 @@ commands = flake8 --statistics tests python
[pytest]
# Notes:
# --basetemp: we must use /var/tmp as sanlock uses direct I/O.
-# -vv: increasing verbosify twice shows more detailed failures tracebacks.
# -rxX show extra test summary: (x)failed, (X)passed,
# --durations: show slowest test duration
-addopts = -rxX -vv --basetemp=/var/tmp/sanlock --durations=10
+addopts = -rxX --basetemp=/var/tmp/sanlock --durations=10
[flake8]
show_source = True
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
[sanlock] 01/02: python: Don't report skipped tests
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 1a6283528075469cdb7f75859bb3333c560e7a55
Author: Nir Soffer <nsoffer(a)redhat.com>
AuthorDate: Sun Jun 16 18:27:20 2019 +0300
python: Don't report skipped tests
In the short test summary, report only (x)failed and (X)passed tests.
Skipped tests are normal, used when a test cannot run in the current
environment. (x)failed or (X)passed tests must be fixed and should be
listed.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
tox.ini | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tox.ini b/tox.ini
index 0e337ce..0cadfb5 100644
--- a/tox.ini
+++ b/tox.ini
@@ -30,9 +30,9 @@ commands = flake8 --statistics tests python
# Notes:
# --basetemp: we must use /var/tmp as sanlock uses direct I/O.
# -vv: increasing verbosify twice shows more detailed failures tracebacks.
-# -rxs: show extra test summary: (s)skipped, (x)failed
+# -rxX show extra test summary: (x)failed, (X)passed,
# --durations: show slowest test duration
-addopts = -rxs -vv --basetemp=/var/tmp/sanlock --durations=10
+addopts = -rxX -vv --basetemp=/var/tmp/sanlock --durations=10
[flake8]
show_source = True
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 10 months
Re: [PATCH v2 4/8] python: Extract create_resource() helper
by Nir Soffer
On Mon, Jun 17, 2019 at 1:04 PM Pavel Bar <pbar(a)redhat.com> wrote:
>
>
> On Sun, Jun 16, 2019 at 11:50 PM Nir Soffer <nirsof(a)gmail.com> wrote:
>
>> Replace duplicate code for allocating and initializing sanlk_resource
>> struct with a helper.
>>
>> Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
>> ---
>> python/sanlock.c | 46 +++++++++++++++++++++++-----------------------
>> 1 file changed, 23 insertions(+), 23 deletions(-)
>>
>> diff --git a/python/sanlock.c b/python/sanlock.c
>> index 5c2fd1a..6824e01 100644
>> --- a/python/sanlock.c
>> +++ b/python/sanlock.c
>> @@ -170,29 +170,38 @@ parse_single_disk(PyObject* disk, struct
>> sanlk_disk* res_disk)
>> finally:
>> Py_XDECREF(path);
>> return rv;
>> }
>>
>> +static struct sanlk_resource *
>> +create_resource(int num_disks)
>> +{
>> + size_t size = sizeof(struct sanlk_resource) +
>> + sizeof(struct sanlk_disk) * num_disks;
>> +
>> + struct sanlk_resource *res = calloc(1, size);
>> + if (res == NULL) {
>> + PyErr_NoMemory();
>> + return NULL;
>> + }
>> +
>> + res->num_disks = num_disks;
>> +
>> + return res;
>> +}
>> +
>> static int
>> parse_disks(PyObject *obj, struct sanlk_resource **res_ret)
>> {
>> - int num_disks, res_len;
>> + int num_disks;
>> struct sanlk_resource *res;
>>
>
> What about declaring the local variables when first used, thus immediately
> initializing them? I think C99 provides that.
> I.e.,
> int num_disks = PyList_Size(obj);
> struct sanlk_resource *res = create_resource(num_disks);
> Moreover, in this case they will be at the beginning of the block anyway.
>
This is not needed to fix the problem I'm trying to solve here.
We can do this work later if needed.
>> num_disks = PyList_Size(obj);
>>
>> - res_len = sizeof(struct sanlk_resource) +
>> - (sizeof(struct sanlk_disk) * num_disks);
>> - res = malloc(res_len);
>> -
>> - if (res == NULL) {
>> - PyErr_NoMemory();
>> + res = create_resource(num_disks);
>> + if (res == NULL)
>> return -1;
>> - }
>> -
>> - memset(res, 0, res_len);
>> - res->num_disks = num_disks;
>>
>> for (int i = 0; i < num_disks; i++) {
>> PyObject *disk = PyList_GetItem(obj,i);
>>
>> if (!parse_single_disk(disk, &(res->disks[i]))) {
>> @@ -637,30 +646,21 @@ Align can be one of (1048576, 2097152, 4194304,
>> 8388608).\n\
>> Sector can be one of (512, 4096).");
>>
>> static PyObject *
>> py_read_resource(PyObject *self __unused, PyObject *args, PyObject
>> *keywds)
>> {
>> - int rv = -1, res_len, sector = SECTOR_SIZE_512;
>> + int rv = -1, sector = SECTOR_SIZE_512;
>> long align = ALIGNMENT_1M;
>> PyObject *path = NULL;
>> struct sanlk_resource *res;
>> PyObject *res_info = NULL;
>>
>> static char *kwlist[] = {"path", "offset", "align", "sector", NULL};
>>
>> - /* allocate the needed memory for the resource and one disk */
>> - res_len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
>> - res = malloc(res_len);
>> -
>> - if (res == NULL) {
>> - PyErr_NoMemory();
>> + res = create_resource(1 /* num_disks */);
>>
>
> Not sure the comment is needed.
>
>
>> + if (res == NULL)
>> return NULL;
>> - }
>> -
>> - /* initialize resource and disk structures */
>> - memset(res, 0, res_len);
>> - res->num_disks = 1;
>>
>> /* parse python tuple */
>> if (!PyArg_ParseTupleAndKeywords(args, keywds, "O&|kli", kwlist,
>> pypath_converter, &path, &(res->disks[0].offset), &align,
>> §or)) {
>> goto finally;
>> --
>> 2.17.2
>>
>>
4 years, 10 months