Clean up python align and sector constants

Add patch for upstream commit af126ed0c3d0 (python: Clean up alignment
and sector constants).
This commit is contained in:
Nir Soffer 2019-04-12 22:48:36 +03:00
parent 3ec7562457
commit c74119db70
2 changed files with 155 additions and 1 deletions

View File

@ -0,0 +1,149 @@
From af126ed0c3d0088344727eb36107c8807aca2129 Mon Sep 17 00:00:00 2001
From: Nir Soffer <nirsof@gmail.com>
Date: Fri, 12 Apr 2019 05:02:50 +0300
Subject: [PATCH] python: Clean up alignment and sector constants
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@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

View File

@ -1,6 +1,6 @@
Name: sanlock Name: sanlock
Version: 3.7.1 Version: 3.7.1
Release: 1%{?dist} Release: 2%{?dist}
Summary: A shared storage lock manager Summary: A shared storage lock manager
License: GPLv2 and GPLv2+ and LGPLv2+ License: GPLv2 and GPLv2+ and LGPLv2+
@ -16,12 +16,14 @@ Requires(post): systemd-sysv
Requires(preun): systemd-units Requires(preun): systemd-units
Requires(postun): systemd-units Requires(postun): systemd-units
Source0: https://releases.pagure.org/sanlock/%{name}-%{version}.tar.gz Source0: https://releases.pagure.org/sanlock/%{name}-%{version}.tar.gz
Patch0: 0001-python-Clean-up-alignment-and-sector-constants.patch
%description %description
The sanlock daemon manages leases for applications on hosts using shared storage. The sanlock daemon manages leases for applications on hosts using shared storage.
%prep %prep
%setup -q %setup -q
%patch0 -p1
%build %build
%set_build_flags %set_build_flags
@ -176,6 +178,9 @@ common sanlock lockspace.
%changelog %changelog
* Fri Apr 12 2019 Nir Soffer <nsoffer@redhat.com> - 3.7.1-2
- Cleanup up align and sector constants
* Mon Apr 8 2019 Nir Soffer <nsoffer@redhat.com> - 3.7.1-1 * Mon Apr 8 2019 Nir Soffer <nsoffer@redhat.com> - 3.7.1-1
- Update to sanlock 3.7.1 - Update to sanlock 3.7.1
- Fix read_resource_owners (414abfe) - Fix read_resource_owners (414abfe)