The constants used SANLK_RES_ prefix, which is not needed, confusing,
and make client code uglier.
- SANLK_ prefix is not needed since all the constants are in the sanlock
module namespace (e.g sanlock.ALIGN1M).
- RES_ prefix is incorrect because the alignment and sector size are
used for lockspace, rindex and resources.
The help for the python functions mentioned the C API constants names
(e.g. SANLK_LSF_ALIGN1M). Now we mention the python constant name (e.g
ALIGN1M) which is the value the user of this module must use.
Since this version was not released yet, we still have time to fix this
API.
Signed-off-by: Nir Soffer <nsoffer(a)redhat.com>
---
python/example.py | 4 ++--
python/sanlock.c | 26 ++++++++++++--------------
2 files changed, 14 insertions(+), 16 deletions(-)
diff --git a/python/example.py b/python/example.py
index c0adf54..4fe845d 100644
--- a/python/example.py
+++ b/python/example.py
@@ -27,14 +27,14 @@ def main():
print "Registering to sanlock"
fd = sanlock.register()
print "Initializing '%s'" % (LOCKSPACE_NAME,)
- sanlock.write_lockspace(LOCKSPACE_NAME, disk, max_hosts=0, iotimeout=0,
align=sanlock.SANLK_RES_ALIGN1M, sector=sanlock.SANLK_RES_SECTOR512)
+ sanlock.write_lockspace(LOCKSPACE_NAME, disk, max_hosts=0, iotimeout=0,
align=sanlock.ALIGN1M, sector=sanlock.SECTOR512)
print "Initializing '%s' on '%s'" % (RESOURCE_NAME,
LOCKSPACE_NAME)
- sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS,
align=sanlock.SANLK_RES_ALIGN1M, sector=sanlock.SANLK_RES_SECTOR512)
+ sanlock.write_resource(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS,
align=sanlock.ALIGN1M, sector=sanlock.SECTOR512)
print "Acquiring the id '%i' on '%s'" % (HOST_ID,
LOCKSPACE_NAME)
sanlock.add_lockspace(LOCKSPACE_NAME, HOST_ID, disk)
try:
diff --git a/python/sanlock.c b/python/sanlock.c
index 5ddb6d4..b387307 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -359,11 +359,11 @@ exit_fail:
}
/* write_lockspace */
PyDoc_STRVAR(pydoc_write_lockspace, "\
write_lockspace(lockspace, path, offset=0, max_hosts=0, iotimeout=0, \
-align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512)\n\
+align=ALIGN1M, sector=SECTOR512)\n\
Initialize or update a device to be used as sanlock lockspace.");
static PyObject *
py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
@@ -407,12 +407,11 @@ py_write_lockspace(PyObject *self __unused, PyObject *args, PyObject
*keywds)
Py_RETURN_NONE;
}
/* read_lockspace */
PyDoc_STRVAR(pydoc_read_lockspace, "\
-read_lockspace(path, offset=0 \
-align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512)\n -> dict\n\
+read_lockspace(path, offset=0, align=ALIGN1M, sector=SECTOR512)\n -> dict\n\
Read the lockspace information from a device at a specific offset.");
static PyObject *
py_read_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
@@ -480,19 +479,18 @@ exit_fail:
return NULL;
}
/* read_resource */
PyDoc_STRVAR(pydoc_read_resource, "\
-read_resource(path, offset=0, \
-align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512) -> dict\n\
+read_resource(path, offset=0, align=ALIGN1M, sector=SECTOR512) -> dict\n\
Read the resource information from a device at a specific offset.");
static PyObject *
py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
int rv, rs_len;
- uint32_t align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
+ uint32_t align=SANLK_RES_ALIGN1M, sector=SANLK_RES_SECTOR512;
const char *path;
struct sanlk_resource *rs;
PyObject *rs_info = NULL, *rs_entry = NULL;
static char *kwlist[] = {"path", "offset", "align",
"sector", NULL};
@@ -573,21 +571,21 @@ exit_fail:
}
/* write_resource */
PyDoc_STRVAR(pydoc_write_resource, "\
write_resource(lockspace, resource, disks, max_hosts=0, num_hosts=0, \
-clear=False, align=SANLK_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512)\n\
+clear=False, align=ALIGN1M, sector=SECTOR512)\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.");
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_LSF_ALIGN1M, sector=SANLK_LSF_SECTOR512;
+ uint32_t align=SANLK_RES_ALIGN1M, sector=SANLK_RES_SECTOR512;
const char *lockspace, *resource;
struct sanlk_resource *rs;
PyObject *disks;
uint32_t flags = 0;
@@ -1654,14 +1652,14 @@ initsanlock(void)
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, "SANLK_RES_SECTOR512");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_SECTOR4K, "SANLK_RES_SECTOR4K");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN1M, "SANLK_RES_ALIGN1M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN2M, "SANLK_RES_ALIGN2M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN4M, "SANLK_RES_ALIGN4M");
- PYSNLK_INIT_ADD_CONSTANT(SANLK_RES_ALIGN8M, "SANLK_RES_ALIGN8M");
+ 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
}
--
2.17.2