[PATCH v4 0/2] Values instead of flags in python API.
by Vojtech Juranek
To have more consisten python API, value should be used for secor
size and alignment instead of flags. This patch set replaces flags
with values in public API, expose tuples with supported sector size
and alignment values and add some related tests.
The fourth version of this patch set addresses Nir's comments (besides
others squashes the changes into two patches).
Vojtech Juranek (2):
Accept values instead of flags for sector and aling parameters.
Expose tuples with supported align and sector values
python/example.py | 4 +-
python/sanlock.c | 141 ++++++++++++++++++++++++++++++++-----------
tests/python_test.py | 59 ++++++++++++++++++
3 files changed, 166 insertions(+), 38 deletions(-)
--
2.20.1
4 years, 11 months
[PATCH v5 0/2] Values instead of flags in python API.
by Vojtech Juranek
To have more consisten python API, value should be used for secor
size and alignment instead of flags. This patch set replaces flags
with values in public API, expose tuples with supported sector size
and alignment values and add some related tests.
The fifth version of this patch set addresses comments for patch set v4
which are mostly smaller fixes, one noteable change is switch from
Py_DECREF to Py_XDECREF so we don't have to check if the object is NULL.
Vojtech Juranek (2):
Accept values instead of flags for sector and aling parameters.
Expose tuples with supported align and sector values
python/example.py | 4 +-
python/sanlock.c | 133 ++++++++++++++++++++++++++++++++++---------
tests/python_test.py | 59 +++++++++++++++++++
3 files changed, 166 insertions(+), 30 deletions(-)
--
2.20.1
4 years, 11 months
Re: [PATCH v4 1/2] Accept values instead of flags for sector and aling parameters.
by Vojtech Juranek
> >> /* read_lockspace */
> >> PyDoc_STRVAR(pydoc_read_lockspace, "\
> >>
> >> -read_lockspace(path, offset=0, align=ALIGN1M, sector=SECTOR512)\n ->
> >> dict\n\
> >> -Read the lockspace information from a device at a specific offset.");
> >> +read_lockspace(path, offset=0, align=1048576, sector=512)\n -> dict\n\
> >> +Read the lockspace information from a device at a specific offset.\n\
> >> +Align can be one of (1048576, 2097152, 4194304, 8388608).\n\
> >> +Sector can be one of (512, 4096).");
> Reveal the missing docstring changes:
>
> read_lockspace(...)
> read_lockspace(path, offset=0, align=ALIGN1M, sector=SECTOR512)
>
> Should be now align=1048576, setor=512
that's strange, it's part of the patch, see above (and same for other doc
strings)
4 years, 11 months
[PATCH] python: Fix sanlock.SanlockException initialization
by Nir Soffer
If PyModule_AddObject() failed, an exception was set, and we must
return. The code importing the module will fail with the set exception.
While fixing this issue, use more standard code for handling global
python objects:
- Always increase error reference, to make sure the gloabl does not
become dangling pointer if sanlock.SanlockException is modified by the
application.
- If PyModule_AddObject() fails, decrease the referene.
- If the module is reloaded, do not create a new SanlockException object
and leak the previous object.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 2ad4497..a9c4cf6 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1614,17 +1614,20 @@ initsanlock(void)
sanlock_methods, pydoc_sanlock, NULL, PYTHON_API_VERSION);
if (py_module == NULL)
return;
- py_exception = initexception();
+ if (py_exception == NULL) {
+ py_exception = initexception();
+ if (py_exception == NULL)
+ return;
+ }
- if (py_exception == NULL)
+ Py_INCREF(py_exception);
+ if (PyModule_AddObject(py_module, "SanlockException", py_exception)) {
+ Py_DECREF(py_exception);
return;
-
- if (PyModule_AddObject(py_module, "SanlockException", py_exception) == 0) {
- Py_INCREF(py_exception);
}
#define PYSNLK_INIT_ADD_CONSTANT(x, y) \
if ((sk_constant = PyInt_FromLong(x)) != NULL) { \
if (PyModule_AddObject(py_module, y, sk_constant)) { \
--
2.17.2
4 years, 11 months
[PATCH v3 0/4] Values instead of flags in python API.
by Vojtech Juranek
To have more consisten python API, value should be used for secor
size and alignment instead of flags. This patch set replaces flags
with values in public API, expose tuples with supported sector size
and alignment values and add some related tests.
The third version of this patch set fixes mostly typos, formatting,
use constants instead of raw values in tests and fixes other stuff
which doesn't change the logic of original patch.
Vojtech Juranek (4):
tests: add sector and align parameters
Accept values instead of flags for sector and aling parameters.
Expose tuples with supported align and sector values
tests: add tests for invalid align and sector values
python/example.py | 4 +-
python/sanlock.c | 168 +++++++++++++++++++++++++++++++++----------
tests/python_test.py | 55 ++++++++++++--
3 files changed, 182 insertions(+), 45 deletions(-)
--
2.20.1
4 years, 11 months
[PATCH 1/4] tests: add sector and align parameters
by Vojtech Juranek
Add sector and align parameters to read and write lockspace and
resource calls to test_write_lockspace and test_write_resource tests
to test that these parameters are accepted. Other tests still use
calls without these parameters to test the defaults.
---
tests/python_test.py | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/tests/python_test.py b/tests/python_test.py
index 5029924..6393222 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -34,9 +34,12 @@ def test_write_lockspace(tmpdir, sanlock_daemon, size, offset):
path = str(tmpdir.join("lockspace"))
util.create_file(path, size)
- sanlock.write_lockspace("name", path, offset=offset, iotimeout=1)
+ sanlock.write_lockspace(
+ "name", path, offset=offset, iotimeout=1, align=sanlock.ALIGN1M,
+ sector=sanlock.SECTOR512)
- ls = sanlock.read_lockspace(path, offset=offset)
+ ls = sanlock.read_lockspace(
+ path, offset=offset, align=sanlock.ALIGN1M, sector=sanlock.SECTOR512)
assert ls == {"iotimeout": 1, "lockspace": "name"}
acquired = sanlock.inq_lockspace(
@@ -64,9 +67,12 @@ def test_write_resource(tmpdir, sanlock_daemon, size, offset):
util.create_file(path, size)
disks = [(path, offset)]
- sanlock.write_resource("ls_name", "res_name", disks)
+ sanlock.write_resource(
+ "ls_name", "res_name", disks, align=sanlock.ALIGN1M,
+ sector=sanlock.SECTOR512)
- res = sanlock.read_resource(path, offset=offset)
+ res = sanlock.read_resource(
+ path, offset=offset, align=sanlock.ALIGN1M, sector=sanlock.SECTOR512)
assert res == {
"lockspace": "ls_name",
"resource": "res_name",
--
2.20.1
4 years, 11 months