[PATCH] python: Fix issues introduced in latest 4k API changes
by Nir Soffer
Fix few issues in the latests 4k API changes:
- Fix ValueError when using align=8388608 - a break was missing.
- Remove the unneeded ALIGNX and SECTORX constants - seems that David
merged an older version of the patch which did not remove them.
- Fix capitalization and punctuation in new comments.
- Remove trailing whitespace.
- Wrap long enum difinition.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 20 +++++++++-----------
tests/python_test.py | 8 ++++----
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index a1215bd..d6841e8 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -152,11 +152,16 @@ add_sector_flag(int sector, uint32_t *flags)
return -1;
}
return 0;
}
-enum {ALIGNMENT_1M = 1048576, ALIGNMENT_2M = 2097152, ALIGNMENT_4M = 4194304, ALIGNMENT_8M = 8388608};
+enum {
+ ALIGNMENT_1M = 1048576,
+ ALIGNMENT_2M = 2097152,
+ ALIGNMENT_4M = 4194304,
+ ALIGNMENT_8M = 8388608
+};
static int
add_align_flag(long align, uint32_t *flags)
{
switch (align) {
@@ -169,10 +174,11 @@ add_align_flag(long align, uint32_t *flags)
case ALIGNMENT_4M:
*flags |= SANLK_RES_ALIGN4M;
break;
case ALIGNMENT_8M:
*flags |= SANLK_RES_ALIGN8M;
+ break;
default:
PyErr_Format(PyExc_ValueError, "Invalid align value: %ld", align);
return -1;
}
return 0;
@@ -439,11 +445,11 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (add_align_flag(align, &ls.flags) == -1)
return NULL;
if (add_sector_flag(sector, &ls.flags) == -1)
return NULL;
-
+
/* write sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_write_lockspace(&ls, max_hosts, 0, io_timeout);
Py_END_ALLOW_THREADS
@@ -1718,29 +1724,21 @@ initsanlock(void)
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_CLEAR_HOSTID, "SETEV_CLEAR_HOSTID");
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_CLEAR_EVENT, "SETEV_CLEAR_EVENT");
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_REPLACE_EVENT, "SETEV_REPLACE_EVENT");
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_ALL_HOSTS, "SETEV_ALL_HOSTS");
- /* Sector and align size flags */
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_SECTOR512, "SECTOR512");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_SECTOR4K, "SECTOR4K");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN1M, "ALIGN1M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN2M, "ALIGN2M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN4M, "ALIGN4M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN8M, "ALIGN8M");
-
#undef PYSNLK_INIT_ADD_CONSTANT
/* Tuples with supported sector size and alignment values */
PyObject *sector = Py_BuildValue("ii", SECTOR_SIZE_512, SECTOR_SIZE_4K);
if (!sector)
return;
if (PyModule_AddObject(py_module, "SECTOR_SIZE", sector)) {
Py_DECREF(sector);
return;
}
-
+
PyObject *align = Py_BuildValue("llll", ALIGNMENT_1M, ALIGNMENT_2M, ALIGNMENT_4M, ALIGNMENT_8M);
if (!align)
return;
if (PyModule_AddObject(py_module, "ALIGN_SIZE", align)) {
Py_DECREF(align);
diff --git a/tests/python_test.py b/tests/python_test.py
index a0474f1..1a6bbbd 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -35,17 +35,17 @@ SECTOR_SIZE_512 = 512
])
def test_write_lockspace(tmpdir, sanlock_daemon, size, offset):
path = str(tmpdir.join("lockspace"))
util.create_file(path, size)
- # test read and write with default alignment and sector size values
+ # Test read and write with default alignment and sector size values.
sanlock.write_lockspace("name", path, offset=offset, iotimeout=1)
ls = sanlock.read_lockspace(path, offset=offset)
assert ls == {"iotimeout": 1, "lockspace": "name"}
- # test read and write with explicit alignment and sector size values
+ # Test read and write with explicit alignment and sector size values.
sanlock.write_lockspace(
"name", path, offset=offset, iotimeout=1, align=ALIGNMENT_1M,
sector=SECTOR_SIZE_512)
ls = sanlock.read_lockspace(
@@ -75,21 +75,21 @@ def test_write_lockspace(tmpdir, sanlock_daemon, size, offset):
def test_write_resource(tmpdir, sanlock_daemon, size, offset):
path = str(tmpdir.join("resources"))
util.create_file(path, size)
disks = [(path, offset)]
- # test read and write with default alignment and sector size values
+ # Test read and write with default alignment and sector size values.
sanlock.write_resource("ls_name", "res_name", disks)
res = sanlock.read_resource(path, offset=offset)
assert res == {
"lockspace": "ls_name",
"resource": "res_name",
"version": 0
}
- # test read and write with explicit alignment and sector size values
+ # Test read and write with explicit alignment and sector size values.
sanlock.write_resource(
"ls_name", "res_name", disks, align=ALIGNMENT_1M,
sector=SECTOR_SIZE_512)
res = sanlock.read_resource(
--
2.17.2
4 years, 11 months
[sanlock] branch master updated: release 3.7.2
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new 8cdef50 release 3.7.2
8cdef50 is described below
commit 8cdef50a2feb581f34b2f475306c9fe4f9750f29
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Mon May 6 14:41:29 2019 -0500
release 3.7.2
---
VERSION | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/VERSION b/VERSION
index a76ccff..0b2eb36 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-3.7.1
+3.7.2
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] branch master updated: python: Fix issues introduced in
latest 4k API changes
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new 8184713 python: Fix issues introduced in latest 4k API changes
8184713 is described below
commit 8184713b5e0fbfe52cb243b3c938183ee15f56b2
Author: Nir Soffer <nirsof(a)gmail.com>
AuthorDate: Sun May 5 15:33:58 2019 +0300
python: Fix issues introduced in latest 4k API changes
Fix few issues in the latests 4k API changes:
- Fix ValueError when using align=8388608 - a break was missing.
- Remove the unneeded ALIGNX and SECTORX constants - seems that David
merged an older version of the patch which did not remove them.
- Fix capitalization and punctuation in new comments.
- Remove trailing whitespace.
- Wrap long enum difinition.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/sanlock.c | 20 +++++++++-----------
tests/python_test.py | 8 ++++----
2 files changed, 13 insertions(+), 15 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index a1215bd..d6841e8 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -154,7 +154,12 @@ add_sector_flag(int sector, uint32_t *flags)
return 0;
}
-enum {ALIGNMENT_1M = 1048576, ALIGNMENT_2M = 2097152, ALIGNMENT_4M = 4194304, ALIGNMENT_8M = 8388608};
+enum {
+ ALIGNMENT_1M = 1048576,
+ ALIGNMENT_2M = 2097152,
+ ALIGNMENT_4M = 4194304,
+ ALIGNMENT_8M = 8388608
+};
static int
add_align_flag(long align, uint32_t *flags)
@@ -171,6 +176,7 @@ add_align_flag(long align, uint32_t *flags)
break;
case ALIGNMENT_8M:
*flags |= SANLK_RES_ALIGN8M;
+ break;
default:
PyErr_Format(PyExc_ValueError, "Invalid align value: %ld", align);
return -1;
@@ -441,7 +447,7 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
if (add_sector_flag(sector, &ls.flags) == -1)
return NULL;
-
+
/* write sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_write_lockspace(&ls, max_hosts, 0, io_timeout);
@@ -1720,14 +1726,6 @@ initsanlock(void)
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_REPLACE_EVENT, "SETEV_REPLACE_EVENT");
PYSNLK_INIT_ADD_CONSTANT(SANLK_SETEV_ALL_HOSTS, "SETEV_ALL_HOSTS");
- /* Sector and align size flags */
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_SECTOR512, "SECTOR512");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_SECTOR4K, "SECTOR4K");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN1M, "ALIGN1M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN2M, "ALIGN2M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN4M, "ALIGN4M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN8M, "ALIGN8M");
-
#undef PYSNLK_INIT_ADD_CONSTANT
/* Tuples with supported sector size and alignment values */
@@ -1738,7 +1736,7 @@ initsanlock(void)
Py_DECREF(sector);
return;
}
-
+
PyObject *align = Py_BuildValue("llll", ALIGNMENT_1M, ALIGNMENT_2M, ALIGNMENT_4M, ALIGNMENT_8M);
if (!align)
return;
diff --git a/tests/python_test.py b/tests/python_test.py
index a0474f1..1a6bbbd 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -37,13 +37,13 @@ def test_write_lockspace(tmpdir, sanlock_daemon, size, offset):
path = str(tmpdir.join("lockspace"))
util.create_file(path, size)
- # test read and write with default alignment and sector size values
+ # Test read and write with default alignment and sector size values.
sanlock.write_lockspace("name", path, offset=offset, iotimeout=1)
ls = sanlock.read_lockspace(path, offset=offset)
assert ls == {"iotimeout": 1, "lockspace": "name"}
- # test read and write with explicit alignment and sector size values
+ # Test read and write with explicit alignment and sector size values.
sanlock.write_lockspace(
"name", path, offset=offset, iotimeout=1, align=ALIGNMENT_1M,
sector=SECTOR_SIZE_512)
@@ -77,7 +77,7 @@ def test_write_resource(tmpdir, sanlock_daemon, size, offset):
util.create_file(path, size)
disks = [(path, offset)]
- # test read and write with default alignment and sector size values
+ # Test read and write with default alignment and sector size values.
sanlock.write_resource("ls_name", "res_name", disks)
res = sanlock.read_resource(path, offset=offset)
@@ -87,7 +87,7 @@ def test_write_resource(tmpdir, sanlock_daemon, size, offset):
"version": 0
}
- # test read and write with explicit alignment and sector size values
+ # Test read and write with explicit alignment and sector size values.
sanlock.write_resource(
"ls_name", "res_name", disks, align=ALIGNMENT_1M,
sector=SECTOR_SIZE_512)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
Re: [PATCH] sanlock: Resource API should only support disks as a tuple
by Nir Soffer
On Sun, May 5, 2019 at 4:44 PM Amit Bawer <abawer.com(a)gmail.com> wrote:
> As stated in sanlock module help:
> The disks must be in the format: [(path, offset), ... ]
>
> Signed-off-by: Amit Bawer <abawer(a)redhat.com>
> ---
> python/sanlock.c | 2 --
> 1 file changed, 2 deletions(-)
>
> diff --git a/python/sanlock.c b/python/sanlock.c
> index a1215bd..aefcc3b 100644
> --- a/python/sanlock.c
> +++ b/python/sanlock.c
> @@ -109,8 +109,6 @@ __parse_resource(PyObject *obj, struct sanlk_resource
> **res_ret)
> __set_exception(EINVAL, "Invalid resource offset");
> goto exit_fail;
> }
> - } else if (PyString_Check(tuple)) {
> - p = PyString_AsString(tuple);
> }
>
This works, and we will fail later in:
114 if (p == NULL) {
115 __set_exception(EINVAL, "Invalid resource path");
116 goto exit_fail;
117 }
But the flow could be more clear, and we can simplify the code while
removing the
undocumented value.
Also, we should really fail with ValueError instead of SanlockException,
since the user
passed invalid value, and the invalid value should apear in the exception
string, like we do
when you pass invalid align value.
So I think what we should have is something like this (untested):
disk = PyList_GetItem(obj, i);
if (!PyTuple_Check(disk)) {
const char *s = "";
PyObject *r = PyObject_Repr(disk);
if (r)
s = PyString_AsString(r);
PyErr_Format(PyExc_ValueError, "Invalid disk value: %s", s);
Py_XDECREF(r);
goto exit_fail;
}
And then we can have the rest of the checks outside of the if block,
simplifying
the flow.
We should probably have a helper for raising a value error with invalid
object, including
the object repr() in the error message, so we can do:
if (!PyTuple_Check(disk)) {
set_value_error("invalid disk value: %s", disk);
goto exit_fail;
}
We can use this later for handling bad path or offset values.
Finally, we need a simple test verifying that we actually fail with the
expected exception type
and error message when providing invalid value, similar to the new tests
for invalid align/sector.
Nir
4 years, 11 months
[PATCH v7 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 seventh version of this patch doesn't contain any changes wrt v6,
but should be sent with 8bit encoding instead of base64.
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 | 137 ++++++++++++++++++++++++++++++++++---------
tests/python_test.py | 59 +++++++++++++++++++
3 files changed, 170 insertions(+), 30 deletions(-)
--
2.20.1
4 years, 11 months
[sanlock] 02/02: Expose tuples with supported align and sector
values
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit df34fc3d5a6935581dc9352dd91f00e4560f551e
Author: Vojtech Juranek <vjuranek(a)redhat.com>
AuthorDate: Thu Apr 25 11:57:08 2019 +0200
Expose tuples with supported align and sector values
Previous patch switched from accepting align and sector flags to values.
Exposing internal sanlock flags doesn't make sense now. Tuples with
supported sector size and alignment values should be exposed instead.
---
python/sanlock.c | 18 ++++++++++++++++++
tests/python_test.py | 8 ++++----
2 files changed, 22 insertions(+), 4 deletions(-)
diff --git a/python/sanlock.c b/python/sanlock.c
index 3cd91f2..a1215bd 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1729,4 +1729,22 @@ initsanlock(void)
PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN8M, "ALIGN8M");
#undef PYSNLK_INIT_ADD_CONSTANT
+
+ /* Tuples with supported sector size and alignment values */
+ PyObject *sector = Py_BuildValue("ii", SECTOR_SIZE_512, SECTOR_SIZE_4K);
+ if (!sector)
+ return;
+ if (PyModule_AddObject(py_module, "SECTOR_SIZE", sector)) {
+ Py_DECREF(sector);
+ return;
+ }
+
+ PyObject *align = Py_BuildValue("llll", ALIGNMENT_1M, ALIGNMENT_2M, ALIGNMENT_4M, ALIGNMENT_8M);
+ if (!align)
+ return;
+ if (PyModule_AddObject(py_module, "ALIGN_SIZE", align)) {
+ Py_DECREF(align);
+ return;
+ }
+
}
diff --git a/tests/python_test.py b/tests/python_test.py
index 5b1bb43..a0474f1 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -256,9 +256,9 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset):
@pytest.mark.parametrize("align, sector", [
# Invalid alignment
- (1024, 512),
+ (1024, sanlock.SECTOR_SIZE[0]),
# Invalid sector size
- (1048576, 8192),
+ (sanlock.ALIGN_SIZE[0], 8192),
])
def test_write_lockspace_invalid_align_sector(
tmpdir, sanlock_daemon, align, sector):
@@ -271,9 +271,9 @@ def test_write_lockspace_invalid_align_sector(
@pytest.mark.parametrize("align, sector", [
# Invalid alignment
- (1024, 512),
+ (1024, sanlock.SECTOR_SIZE[0]),
# Invalid sector size
- (1048576, 8192),
+ (sanlock.ALIGN_SIZE[0], 8192),
])
def test_write_resource_invalid_align_sector(
tmpdir, sanlock_daemon, align, sector):
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] 01/02: Accept values instead of flags for sector and
aling parameters.
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
commit 002e5c692504108324c76c5a2286306d286c1a99
Author: Vojtech Juranek <vjuranek(a)redhat.com>
AuthorDate: Thu Apr 25 10:07:00 2019 +0200
Accept values instead of flags for sector and aling parameters.
Currently appropriate sanlock flags are accepted for sector size and
alignment parameters. This can be confusing for users, which may try
to pass values instead of flags and this approach also exposes sanlock
internal implementation details.
In order to have consistent and more intuitive API, values should be
accepted for sector size and alignment parameters. This patch replaces
flags by values in calls which accept sector size and alignment.
This patch also adds validation of provided values. If the value is
not the supported one, error with error code EINVAL is thrown.
The supported values are:
sector: 512, 4096
align: 1048576, 2097152, 4194304, 8388608
The patch also adds 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 for invalid align and sector values are also added.
---
python/example.py | 4 +-
python/sanlock.c | 119 +++++++++++++++++++++++++++++++++++++++------------
tests/python_test.py | 59 +++++++++++++++++++++++++
3 files changed, 152 insertions(+), 30 deletions(-)
diff --git a/python/example.py b/python/example.py
index 4fe845d..cb8f3e9 100644
--- a/python/example.py
+++ b/python/example.py
@@ -29,10 +29,10 @@ def main():
fd = sanlock.register()
print "Initializing '%s'" % (LOCKSPACE_NAME,)
- sanlock.write_lockspace(LOCKSPACE_NAME, disk, max_hosts=0, iotimeout=0, align=sanlock.ALIGN1M, sector=sanlock.SECTOR512)
+ sanlock.write_lockspace(LOCKSPACE_NAME, disk, max_hosts=0, iotimeout=0, align=1048576, sector=512)
print "Initializing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME)
- sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, align=sanlock.ALIGN1M, sector=sanlock.SECTOR512)
+ sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, align=1048576, sector=512)
print "Acquiring the id '%i' on '%s'" % (HOST_ID, LOCKSPACE_NAME)
sanlock.add_lockspace(LOCKSPACE_NAME, HOST_ID, disk)
diff --git a/python/sanlock.c b/python/sanlock.c
index a9c4cf6..3cd91f2 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -135,6 +135,49 @@ exit_fail:
return -1;
}
+enum {SECTOR_SIZE_512 = 512, SECTOR_SIZE_4K = 4096};
+
+static int
+add_sector_flag(int sector, uint32_t *flags)
+{
+ switch (sector) {
+ case SECTOR_SIZE_512:
+ *flags |= SANLK_LSF_SECTOR512;
+ break;
+ case SECTOR_SIZE_4K:
+ *flags |= SANLK_LSF_SECTOR4K;
+ break;
+ default:
+ PyErr_Format(PyExc_ValueError, "Invalid sector value: %d", sector);
+ return -1;
+ }
+ return 0;
+}
+
+enum {ALIGNMENT_1M = 1048576, ALIGNMENT_2M = 2097152, ALIGNMENT_4M = 4194304, ALIGNMENT_8M = 8388608};
+
+static int
+add_align_flag(long align, uint32_t *flags)
+{
+ switch (align) {
+ case ALIGNMENT_1M:
+ *flags |= SANLK_RES_ALIGN1M;
+ break;
+ case ALIGNMENT_2M:
+ *flags |= SANLK_RES_ALIGN2M;
+ break;
+ case ALIGNMENT_4M:
+ *flags |= SANLK_RES_ALIGN4M;
+ break;
+ case ALIGNMENT_8M:
+ *flags |= SANLK_RES_ALIGN8M;
+ default:
+ PyErr_Format(PyExc_ValueError, "Invalid align value: %ld", align);
+ return -1;
+ }
+ return 0;
+}
+
static PyObject *
__hosts_to_list(struct sanlk_host *hss, int hss_count)
{
@@ -361,15 +404,17 @@ exit_fail:
/* write_lockspace */
PyDoc_STRVAR(pydoc_write_lockspace, "\
write_lockspace(lockspace, path, offset=0, max_hosts=0, iotimeout=0, \
-align=ALIGN1M, sector=SECTOR512)\n\
-Initialize or update a device to be used as sanlock lockspace.");
+align=1048576, sector=512)\n\
+Initialize or update a device to be used as sanlock lockspace.\n\
+Align can be one of (1048576, 2097152, 4194304, 8388608).\n\
+Sector can be one of (512, 4096).");
static PyObject *
py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, max_hosts = 0;
+ int rv, max_hosts = 0, sector = SECTOR_SIZE_512;
+ long align = ALIGNMENT_1M;
uint32_t io_timeout = 0;
- uint32_t align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
const char *lockspace, *path;
struct sanlk_lockspace ls;
@@ -380,7 +425,7 @@ 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|kiIII", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ss|kiIli", kwlist,
&lockspace, &path, &ls.host_id_disk.offset, &max_hosts,
&io_timeout, &align, §or)) {
return NULL;
@@ -391,9 +436,12 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
/* set alignment/sector flags */
- ls.flags |= align;
- ls.flags |= sector;
+ if (add_align_flag(align, &ls.flags) == -1)
+ return NULL;
+ if (add_sector_flag(sector, &ls.flags) == -1)
+ return NULL;
+
/* write sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
rv = sanlock_write_lockspace(&ls, max_hosts, 0, io_timeout);
@@ -409,15 +457,17 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* 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).");
static PyObject *
py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv;
+ int rv, sector = SECTOR_SIZE_512;
+ long align = ALIGNMENT_1M;
uint32_t io_timeout = 0;
- uint32_t align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
const char *path;
struct sanlk_lockspace ls;
PyObject *ls_info = NULL, *ls_entry = NULL;
@@ -428,7 +478,7 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
memset(&ls, 0, sizeof(struct sanlk_lockspace));
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kII", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kli", kwlist,
&path, &ls.host_id_disk.offset, &align, §or)) {
return NULL;
}
@@ -437,8 +487,11 @@ py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
strncpy(ls.host_id_disk.path, path, SANLK_PATH_LEN - 1);
/* set alignment/sector flags */
- ls.flags |= align;
- ls.flags |= sector;
+ if (add_align_flag(align, &ls.flags) == -1)
+ return NULL;
+
+ if (add_sector_flag(sector, &ls.flags) == -1)
+ return NULL;
/* read sanlock lockspace (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -481,14 +534,16 @@ exit_fail:
/* read_resource */
PyDoc_STRVAR(pydoc_read_resource, "\
-read_resource(path, offset=0, align=ALIGN1M, sector=SECTOR512) -> dict\n\
-Read the resource information from a device at a specific offset.");
+read_resource(path, offset=0, align=1048576, sector=512) -> dict\n\
+Read the resource 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).");
static PyObject *
py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, rs_len;
- uint32_t align=SANLK_RES_ALIGN1M, sector=SANLK_RES_SECTOR512;
+ int rv, rs_len, sector = SECTOR_SIZE_512;
+ long align = ALIGNMENT_1M;
const char *path;
struct sanlk_resource *rs;
PyObject *rs_info = NULL, *rs_entry = NULL;
@@ -509,7 +564,7 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
rs->num_disks = 1;
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kII", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|kli", kwlist,
&path, &(rs->disks[0].offset), &align, §or)) {
goto exit_fail;
}
@@ -518,8 +573,11 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
strncpy(rs->disks[0].path, path, SANLK_PATH_LEN - 1);
/* set alignment/sector flags */
- rs->flags |= align;
- rs->flags |= sector;
+ if (add_align_flag(align, &rs->flags) == -1)
+ goto exit_fail;
+
+ if (add_sector_flag(sector, &rs->flags) == -1)
+ goto exit_fail;
/* read sanlock resource (gil disabled) */
Py_BEGIN_ALLOW_THREADS
@@ -573,17 +631,19 @@ exit_fail:
/* write_resource */
PyDoc_STRVAR(pydoc_write_resource, "\
write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0, \
-clear=False, align=ALIGN1M, sector=SECTOR512)\n\
+clear=False, align=1048576, sector=512)\n\
Initialize a device to be used as sanlock resource.\n\
The disks must be in the format: [(path, offset), ... ].\n\
If clear is True, the resource is cleared so subsequent read will\n\
-return an error.");
+return an error.\n\
+Align can be one of (1048576, 2097152, 4194304, 8388608).\n\
+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;
- uint32_t align=SANLK_RES_ALIGN1M, sector=SANLK_RES_SECTOR512;
+ int rv, 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 *disks;
@@ -593,7 +653,7 @@ 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!|iiiII",
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiili",
kwlist, &lockspace, &resource, &PyList_Type, &disks, &max_hosts,
&num_hosts, &clear, &align, §or)) {
return NULL;
@@ -609,8 +669,11 @@ py_write_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
strncpy(rs->name, resource, SANLK_NAME_LEN);
/* set alignment/sector flags */
- rs->flags |= align;
- rs->flags |= sector;
+ if (add_align_flag(align, &rs->flags) == -1)
+ goto exit_fail;
+
+ if (add_sector_flag(sector, &rs->flags) == -1)
+ goto exit_fail;
if (clear) {
flags |= SANLK_WRITE_CLEAR;
diff --git a/tests/python_test.py b/tests/python_test.py
index 5029924..5b1bb43 100644
--- a/tests/python_test.py
+++ b/tests/python_test.py
@@ -23,6 +23,9 @@ LARGE_FILE_SIZE = 1024**4
LOCKSPACE_SIZE = 1024**2
MIN_RES_SIZE = 1024**2
+ALIGNMENT_1M = 1024**2
+SECTOR_SIZE_512 = 512
+
@pytest.mark.parametrize("size,offset", [
# Smallest offset.
@@ -34,11 +37,21 @@ def test_write_lockspace(tmpdir, sanlock_daemon, size, offset):
path = str(tmpdir.join("lockspace"))
util.create_file(path, size)
+ # test read and write with default alignment and sector size values
sanlock.write_lockspace("name", path, offset=offset, iotimeout=1)
ls = sanlock.read_lockspace(path, offset=offset)
assert ls == {"iotimeout": 1, "lockspace": "name"}
+ # test read and write with explicit alignment and sector size values
+ sanlock.write_lockspace(
+ "name", path, offset=offset, iotimeout=1, align=ALIGNMENT_1M,
+ sector=SECTOR_SIZE_512)
+
+ ls = sanlock.read_lockspace(
+ path, offset=offset, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
+ assert ls == {"iotimeout": 1, "lockspace": "name"}
+
acquired = sanlock.inq_lockspace(
"name", 1, path, offset=offset, wait=False)
assert acquired is False
@@ -64,6 +77,7 @@ def test_write_resource(tmpdir, sanlock_daemon, size, offset):
util.create_file(path, size)
disks = [(path, offset)]
+ # test read and write with default alignment and sector size values
sanlock.write_resource("ls_name", "res_name", disks)
res = sanlock.read_resource(path, offset=offset)
@@ -73,6 +87,19 @@ def test_write_resource(tmpdir, sanlock_daemon, size, offset):
"version": 0
}
+ # test read and write with explicit alignment and sector size values
+ sanlock.write_resource(
+ "ls_name", "res_name", disks, align=ALIGNMENT_1M,
+ sector=SECTOR_SIZE_512)
+
+ res = sanlock.read_resource(
+ path, offset=offset, align=ALIGNMENT_1M, sector=SECTOR_SIZE_512)
+ assert res == {
+ "lockspace": "ls_name",
+ "resource": "res_name",
+ "version": 0
+ }
+
owners = sanlock.read_resource_owners("ls_name", "res_name", disks)
assert owners == []
@@ -225,3 +252,35 @@ def test_acquire_release_resource(tmpdir, sanlock_daemon, size, offset):
owners = sanlock.read_resource_owners("ls_name", "res_name", disks)
assert owners == []
+
+
+(a)pytest.mark.parametrize("align, sector", [
+ # Invalid alignment
+ (1024, 512),
+ # Invalid sector size
+ (1048576, 8192),
+])
+def test_write_lockspace_invalid_align_sector(
+ tmpdir, sanlock_daemon, align, sector):
+ path = str(tmpdir.join("lockspace"))
+ util.create_file(path, LOCKSPACE_SIZE)
+
+ with pytest.raises(ValueError):
+ sanlock.write_lockspace("name", path, align=align, sector=sector)
+
+
+(a)pytest.mark.parametrize("align, sector", [
+ # Invalid alignment
+ (1024, 512),
+ # Invalid sector size
+ (1048576, 8192),
+])
+def test_write_resource_invalid_align_sector(
+ tmpdir, sanlock_daemon, align, sector):
+ path = str(tmpdir.join("resources"))
+ util.create_file(path, MIN_RES_SIZE)
+ disks = [(path, 0)]
+
+ with pytest.raises(ValueError):
+ sanlock.write_resource(
+ "ls_name", "res_name", disks, align=align, sector=sector)
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] branch master updated: Introduce end-of-line normalization
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new 51b2a3b Introduce end-of-line normalization
51b2a3b is described below
commit 51b2a3b2049ff0e90449b99e7b89b27555ef34f5
Author: David Teigland <teigland(a)redhat.com>
AuthorDate: Fri May 3 10:15:01 2019 -0500
Introduce end-of-line normalization
---
.gitattributes | 2 ++
1 file changed, 2 insertions(+)
diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000..4cab1f4
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,2 @@
+# Set the default behavior, in case people don't have core.autocrlf set.
+* text=auto
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[sanlock] branch master updated: python: Fix
sanlock.SanlockException initialization
by pagure@pagure.io
This is an automated email from the git hooks/post-receive script.
teigland pushed a commit to branch master
in repository sanlock.
The following commit(s) were added to refs/heads/master by this push:
new 962c05b python: Fix sanlock.SanlockException initialization
962c05b is described below
commit 962c05b3328abfe5d86a8437a770cdc0c6eb914c
Author: Nir Soffer <nirsof(a)gmail.com>
AuthorDate: Wed May 1 18:52:20 2019 +0300
python: Fix sanlock.SanlockException initialization
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
@@ -1616,13 +1616,16 @@ initsanlock(void)
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) \
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
4 years, 11 months
[PATCH v6 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 sixth version of this patch switches back from Py_XDECREF to
Py_DECREF and returns when creation of sector or align tuple fails.
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 | 137 ++++++++++++++++++++++++++++++++++---------
tests/python_test.py | 59 +++++++++++++++++++
3 files changed, 170 insertions(+), 30 deletions(-)
--
2.20.1
4 years, 11 months