6 commits - VERSION python/example.py python/sanlock.c
by David Teigland
VERSION | 2
python/example.py | 23 ++++
python/sanlock.c | 296 ++++++++++++++++++++++++++++++++++++++++++++++++++----
3 files changed, 299 insertions(+), 22 deletions(-)
New commits:
commit 8163bc7b56be4cbe747dc1f3ad9a6f3bca368eb5
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Jul 12 14:10:28 2013 -0500
release 2.8
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/VERSION b/VERSION
index 1effb00..a4412fa 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-2.7
+2.8
commit b7ace62d08a71e8eb72e597ec6134f21dfbfee80
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jun 14 12:15:40 2013 -0400
python: add support to read resource owners
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/example.py b/python/example.py
index f3cd414..14e81a8 100644
--- a/python/example.py
+++ b/python/example.py
@@ -49,6 +49,9 @@ def main():
print "Lockspace '%s' hosts: " % LOCKSPACE_NAME, hosts_list
break
time.sleep(5)
+ print "Resource '%s' owners: " % RESOURCE_NAME, \
+ sanlock.read_resource_owners(
+ LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS)
print "Releasing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME)
sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd)
except Exception as e:
diff --git a/python/sanlock.c b/python/sanlock.c
index c1067ae..b62b8bc 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -1091,6 +1091,58 @@ exit_fail:
return NULL;
}
+/* read_resource_owners */
+PyDoc_STRVAR(pydoc_read_resource_owners, "\
+read_resource_owners(lockspace, resource, disks) -> list\n\
+Returns the list of hosts owning a resource, the list is not filtered and\n\
+it might contain hosts that are currently failing or dead. The hosts are\n\
+returned in the same format used by get_hosts.\n\
+The disks must be in the format: [(path, offset), ... ]");
+
+static PyObject *
+py_read_resource_owners(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, hss_count = 0;
+ const char *lockspace, *resource;
+ struct sanlk_resource *res = NULL;
+ struct sanlk_host *hss = NULL;
+ PyObject *disks, *ls_list = NULL;
+
+ static char *kwlist[] = {"lockspace", "resource", "disks", NULL};
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!", kwlist,
+ &lockspace, &resource, &PyList_Type, &disks)) {
+ return NULL;
+ }
+
+ /* parse and check sanlock resource */
+ if (__parse_resource(disks, &res) < 0) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
+ strncpy(res->name, resource, SANLK_NAME_LEN);
+
+ /* read resource owners (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_read_resource_owners(res, 0, &hss, &hss_count);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Unable to read resource owners");
+ goto exit_fail;
+ }
+
+ ls_list = __hosts_to_list(hss, hss_count);
+
+exit_fail:
+ if (res) free(res);
+ if (hss) free(hss);
+ return ls_list;
+}
+
/* killpath */
PyDoc_STRVAR(pydoc_killpath, "\
killpath(path, args [, slkfd=fd])\n\
@@ -1217,6 +1269,8 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_get_lockspaces},
{"get_hosts", (PyCFunction) py_get_hosts,
METH_VARARGS|METH_KEYWORDS, pydoc_get_hosts},
+ {"read_resource_owners", (PyCFunction) py_read_resource_owners,
+ METH_VARARGS|METH_KEYWORDS, pydoc_read_resource_owners},
{"acquire", (PyCFunction) py_acquire,
METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
{"release", (PyCFunction) py_release,
commit b1158a23d0d82797472fc1404a90348e60b0cdb4
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jun 14 12:15:39 2013 -0400
python: add the get_hosts support
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/example.py b/python/example.py
index 875ddc8..f3cd414 100644
--- a/python/example.py
+++ b/python/example.py
@@ -1,4 +1,5 @@
import os
+import time
import signal
import tempfile
import sanlock
@@ -37,6 +38,17 @@ def main():
print "Acquiring '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME)
sanlock.acquire(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd,
version=0)
+ while True:
+ print "Trying to get lockspace '%s' hosts" % LOCKSPACE_NAME
+ try:
+ hosts_list = sanlock.get_hosts(LOCKSPACE_NAME)
+ except sanlock.SanlockException as e:
+ if e.errno != os.errno.EAGAIN:
+ raise
+ else:
+ print "Lockspace '%s' hosts: " % LOCKSPACE_NAME, hosts_list
+ break
+ time.sleep(5)
print "Releasing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME)
sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd)
except Exception as e:
diff --git a/python/sanlock.c b/python/sanlock.c
index 6ad3469..c1067ae 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -134,6 +134,75 @@ exit_fail:
return -1;
}
+static PyObject *
+__hosts_to_list(struct sanlk_host *hss, int hss_count)
+{
+ int i, rv;
+ PyObject *ls_list = NULL, *ls_entry = NULL, *ls_value = NULL;
+
+ /* prepare the dictionary holding the information */
+ if ((ls_list = PyList_New(0)) == NULL)
+ goto exit_fail;
+
+ for (i = 0; i < hss_count; i++) {
+ if ((ls_entry = PyDict_New()) == NULL)
+ goto exit_fail;
+
+ /* fill the dictionary information: host_id */
+ if ((ls_value = PyInt_FromLong(hss[i].host_id)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "host_id", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: generation */
+ if ((ls_value = PyInt_FromLong(hss[i].generation)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "generation", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: timestamp */
+ if ((ls_value = PyInt_FromLong(hss[i].timestamp)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "timestamp", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: io_timeout */
+ if ((ls_value = PyInt_FromLong(hss[i].io_timeout)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "io_timeout", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ /* fill the dictionary information: flags */
+ if ((ls_value = PyInt_FromLong(hss[i].flags)) == NULL)
+ goto exit_fail;
+ rv = PyDict_SetItemString(ls_entry, "flags", ls_value);
+ Py_DECREF(ls_value);
+ if (rv != 0)
+ goto exit_fail;
+
+ if (PyList_Append(ls_list, ls_entry) != 0)
+ goto exit_fail;
+
+ Py_DECREF(ls_entry);
+ }
+
+ return ls_list;
+
+ /* failure */
+exit_fail:
+ Py_XDECREF(ls_entry);
+ Py_XDECREF(ls_list);
+ return NULL;
+}
+
/* register */
PyDoc_STRVAR(pydoc_register, "\
register() -> int\n\
@@ -694,7 +763,7 @@ py_rem_lockspace(PyObject *self __unused, PyObject *args, PyObject *keywds)
/* get_lockspaces */
PyDoc_STRVAR(pydoc_get_lockspaces, "\
-get_lockspaces() -> dict\n\
+get_lockspaces() -> list\n\
Return the list of lockspaces currently managed by sanlock. The reported\n\
flag indicates whether the lockspace is acquired (0) or in transition.\n\
The possible transition values are LSFLAG_ADD if the lockspace is in the\n\
@@ -714,7 +783,7 @@ py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds)
Py_END_ALLOW_THREADS
if (rv < 0) {
- __set_exception(rv, "Sanlock get lockspace failure");
+ __set_exception(rv, "Sanlock get lockspaces failure");
goto exit_fail;
}
@@ -784,6 +853,51 @@ exit_fail:
return NULL;
}
+/* get_hosts */
+PyDoc_STRVAR(pydoc_get_hosts, "\
+get_hosts(lockspace, host_id=0) -> list\n\
+Return the list of hosts currently alive in a lockspace. When the host_id\n\
+is specified then only the requested host status is returned. The reported\n\
+flag indicates whether the host is free (HOST_FREE), alive (HOST_LIVE),\n\
+failing (HOST_FAIL), dead (HOST_DEAD) or unknown (HOST_UNKNOWN).\n\
+The unknown state is the default when sanlock just joined the lockspace\n\
+and didn't collect enough information to determine the real status of other\n\
+hosts. The dictionary returned also contains: the generation, the last\n\
+timestamp and the io_timeout.\n");
+
+static PyObject *
+py_get_hosts(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, hss_count = 0;
+ uint64_t host_id = 0;
+ const char *lockspace = NULL;
+ struct sanlk_host *hss = NULL;
+ PyObject *ls_list = NULL;
+
+ static char *kwlist[] = {"lockspace", "host_id", NULL};
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "s|k", kwlist,
+ &lockspace, &host_id)) {
+ return NULL;
+ }
+
+ /* get all the lockspaces (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_get_hosts(lockspace, host_id, &hss, &hss_count, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv < 0) {
+ __set_exception(rv, "Sanlock get hosts failure");
+ goto exit_fail;
+ }
+
+ ls_list = __hosts_to_list(hss, hss_count);
+
+exit_fail:
+ if (hss) free(hss);
+ return ls_list;
+}
/* acquire */
PyDoc_STRVAR(pydoc_acquire, "\
@@ -1101,6 +1215,8 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_rem_lockspace},
{"get_lockspaces", (PyCFunction) py_get_lockspaces,
METH_VARARGS|METH_KEYWORDS, pydoc_get_lockspaces},
+ {"get_hosts", (PyCFunction) py_get_hosts,
+ METH_VARARGS|METH_KEYWORDS, pydoc_get_hosts},
{"acquire", (PyCFunction) py_acquire,
METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
{"release", (PyCFunction) py_release,
@@ -1182,5 +1298,12 @@ initsanlock(void)
PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_FORCE, "REQ_FORCE");
PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_GRACEFUL, "REQ_GRACEFUL");
+ /* hosts list flags */
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_FREE, "HOST_FREE");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_LIVE, "HOST_LIVE");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_FAIL, "HOST_FAIL");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_DEAD, "HOST_DEAD");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_HOST_UNKNOWN, "HOST_UNKNOWN");
+
#undef PYSNLK_INIT_ADD_CONSTANT
}
commit 69289407971b5c8625a0bc0414c18691c92d9237
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jun 14 12:15:38 2013 -0400
python: add the support for the resource request
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 13919ea..6ad3469 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -462,7 +462,7 @@ py_read_resource(PyObject *self __unused, PyObject *args, PyObject *keywds)
goto exit_fail;
/* fill the dictionary information: version */
- if ((rs_entry = PyInt_FromLong(rs->lver)) == NULL)
+ if ((rs_entry = PyLong_FromUnsignedLong(rs->lver)) == NULL)
goto exit_fail;
rv = PyDict_SetItemString(rs_info, "version", rs_entry);
Py_DECREF(rs_entry);
@@ -788,7 +788,7 @@ exit_fail:
/* acquire */
PyDoc_STRVAR(pydoc_acquire, "\
acquire(lockspace, resource, disks \
-[, slkfd=fd, pid=owner, shared=False, version=0])\n\
+[, slkfd=fd, pid=owner, shared=False, version=None])\n\
Acquire a resource lease for the current process (using the slkfd argument\n\
to specify the sanlock file descriptor) or for an other process (using the\n\
pid argument). If shared is True the resource will be acquired in the shared\n\
@@ -798,16 +798,16 @@ The disks must be in the format: [(path, offset), ... ]\n");
static PyObject *
py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
{
- int rv, sanlockfd = -1, pid = -1, shared = 0, version = 0;
+ int rv, sanlockfd = -1, pid = -1, shared = 0;
const char *lockspace, *resource;
struct sanlk_resource *res;
- PyObject *disks;
+ PyObject *disks, *version = Py_None;
static char *kwlist[] = {"lockspace", "resource", "disks", "slkfd",
"pid", "shared", "version", NULL};
/* parse python tuple */
- if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiii", kwlist,
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iiiO", kwlist,
&lockspace, &resource, &PyList_Type, &disks, &sanlockfd, &pid,
&shared, &version)) {
return NULL;
@@ -834,9 +834,13 @@ py_acquire(PyObject *self __unused, PyObject *args, PyObject *keywds)
}
/* prepare the resource version */
- if (version) {
+ if (version != Py_None) {
res->flags |= SANLK_RES_LVER;
- res->lver = version;
+ res->lver = PyInt_AsUnsignedLongMask(version);
+ if (res->lver == -1) {
+ __set_exception(EINVAL, "Unable to convert the version value");
+ goto exit_fail;
+ }
}
/* acquire sanlock resource (gil disabled) */
@@ -907,6 +911,72 @@ exit_fail:
return NULL;
}
+/* request */
+PyDoc_STRVAR(pydoc_request, "\
+request(lockspace, resource, disks [, action=REQ_GRACEFUL, version=None])\n\
+Request the owner of a resource to do something specified by action.\n\
+The possible values for action are: REQ_GRACEFUL to request a graceful\n\
+release of the resource and REQ_FORCE to sigkill the owner of the\n\
+resource (forcible release). The version should be either the next version\n\
+to acquire or None (which automatically uses the next version).\n\
+The disks must be in the format: [(path, offset), ... ]");
+
+static PyObject *
+py_request(PyObject *self __unused, PyObject *args, PyObject *keywds)
+{
+ int rv, action = SANLK_REQ_GRACEFUL, flags = 0;
+ const char *lockspace, *resource;
+ struct sanlk_resource *res;
+ PyObject *disks, *version = Py_None;
+
+ static char *kwlist[] = {"lockspace", "resource", "disks", "action",
+ "version", NULL};
+
+ /* parse python tuple */
+ if (!PyArg_ParseTupleAndKeywords(args, keywds, "ssO!|iO", kwlist,
+ &lockspace, &resource, &PyList_Type, &disks, &action, &version)) {
+ return NULL;
+ }
+
+ /* parse and check sanlock resource */
+ if (__parse_resource(disks, &res) < 0) {
+ return NULL;
+ }
+
+ /* prepare sanlock names */
+ strncpy(res->lockspace_name, lockspace, SANLK_NAME_LEN);
+ strncpy(res->name, resource, SANLK_NAME_LEN);
+
+ /* prepare the resource version */
+ if (version == Py_None) {
+ flags = SANLK_REQUEST_NEXT_LVER;
+ } else {
+ res->flags |= SANLK_RES_LVER;
+ res->lver = PyInt_AsUnsignedLongMask(version);
+ if (res->lver == -1) {
+ __set_exception(EINVAL, "Unable to convert the version value");
+ goto exit_fail;
+ }
+ }
+
+ /* request sanlock resource (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_request(flags, action, res);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ __set_exception(rv, "Sanlock request not submitted");
+ goto exit_fail;
+ }
+
+ free(res);
+ Py_RETURN_NONE;
+
+exit_fail:
+ free(res);
+ return NULL;
+}
+
/* killpath */
PyDoc_STRVAR(pydoc_killpath, "\
killpath(path, args [, slkfd=fd])\n\
@@ -1035,6 +1105,8 @@ sanlock_methods[] = {
METH_VARARGS|METH_KEYWORDS, pydoc_acquire},
{"release", (PyCFunction) py_release,
METH_VARARGS|METH_KEYWORDS, pydoc_release},
+ {"request", (PyCFunction) py_request,
+ METH_VARARGS|METH_KEYWORDS, pydoc_request},
{"killpath", (PyCFunction) py_killpath,
METH_VARARGS|METH_KEYWORDS, pydoc_killpath},
{NULL, NULL, 0, NULL}
@@ -1102,8 +1174,13 @@ initsanlock(void)
} \
}
+ /* lockspaces list flags */
PYSNLK_INIT_ADD_CONSTANT(SANLK_LSF_ADD, "LSFLAG_ADD");
PYSNLK_INIT_ADD_CONSTANT(SANLK_LSF_REM, "LSFLAG_REM");
+ /* resource request flags */
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_FORCE, "REQ_FORCE");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_REQ_GRACEFUL, "REQ_GRACEFUL");
+
#undef PYSNLK_INIT_ADD_CONSTANT
}
commit 6042d5904fa884ee62dc5e84d2e19814a5509810
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jun 14 12:15:37 2013 -0400
python: improve example with signals and exceptions
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/example.py b/python/example.py
index 354579e..875ddc8 100644
--- a/python/example.py
+++ b/python/example.py
@@ -1,4 +1,5 @@
import os
+import signal
import tempfile
import sanlock
@@ -6,7 +7,12 @@ HOST_ID = 1
LOCKSPACE_NAME = "lockspace1"
RESOURCE_NAME = "resource1"
+def sigTermHandler():
+ print "SIGTERM signal received"
+
def main():
+ signal.signal(signal.SIGTERM, sigTermHandler)
+
print "Creating the sanlock disk"
fd, disk = tempfile.mkstemp()
os.close(fd)
@@ -33,6 +39,8 @@ def main():
version=0)
print "Releasing '%s' on '%s'" % (RESOURCE_NAME, LOCKSPACE_NAME)
sanlock.release(LOCKSPACE_NAME, RESOURCE_NAME, SNLK_DISKS, slkfd=fd)
+ except Exception as e:
+ print "Exception: ", e
finally:
print "Releasing the id '%i' on '%s'" % (HOST_ID, LOCKSPACE_NAME)
sanlock.rem_lockspace(LOCKSPACE_NAME, HOST_ID, disk)
commit f1c42c9caacd95ab62988ab6ecb3a6e5422b85eb
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Fri Jun 14 12:15:36 2013 -0400
python: rename SANLK_LSF flags and constants macro
Signed-off-by: Federico Simoncelli <fsimonce(a)redhat.com>
diff --git a/python/sanlock.c b/python/sanlock.c
index 7d39deb..13919ea 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -697,9 +697,9 @@ PyDoc_STRVAR(pydoc_get_lockspaces, "\
get_lockspaces() -> dict\n\
Return the list of lockspaces currently managed by sanlock. The reported\n\
flag indicates whether the lockspace is acquired (0) or in transition.\n\
-The possible transition values are SANLK_LSF_ADD if the lockspace is in\n\
-the process of being acquired, and SANLK_LSF_REM if it's in the process\n\
-of being released.\n");
+The possible transition values are LSFLAG_ADD if the lockspace is in the\n\
+process of being acquired, and LSFLAG_REM if it's in the process of being\n\
+released.\n");
static PyObject *
py_get_lockspaces(PyObject *self __unused, PyObject *args, PyObject *keywds)
@@ -1095,15 +1095,15 @@ initsanlock(void)
Py_INCREF(py_exception);
}
- if ((sk_constant = PyInt_FromLong(SANLK_LSF_ADD)) != NULL) {
- if (PyModule_AddObject(py_module, "SANLK_LSF_ADD", sk_constant)) {
- Py_DECREF(sk_constant);
- }
+#define PYSNLK_INIT_ADD_CONSTANT(x, y) \
+ if ((sk_constant = PyInt_FromLong(x)) != NULL) { \
+ if (PyModule_AddObject(py_module, y, sk_constant)) { \
+ Py_DECREF(sk_constant); \
+ } \
}
- if ((sk_constant = PyInt_FromLong(SANLK_LSF_REM)) != NULL) {
- if (PyModule_AddObject(py_module, "SANLK_LSF_REM", sk_constant)) {
- Py_DECREF(sk_constant);
- }
- }
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_LSF_ADD, "LSFLAG_ADD");
+ PYSNLK_INIT_ADD_CONSTANT(SANLK_LSF_REM, "LSFLAG_REM");
+
+#undef PYSNLK_INIT_ADD_CONSTANT
}
10 years, 9 months
Changes to 'refs/tags/sanlock-2.8'
by David Teigland
Changes since the dawn of time:
Daniel P. Berrange (15):
Fix const-ness of many APIs.
Fix warnings in watchdog module
Fix function prototypes for no-arg methods
Remove use of 'index' as a variable name
Make many functions static
Fix missing include in logging file
Annotate many unused parameters to avoid warnings
Remove redundant redeclaration of 'to' variable
Fix args to execv()
Remove redundant arg to 'run_command'
Rename optarg to optionarg to avoid clashing with getopt.h
Disable the read_request method since it is unused
Add many more compiler warning flags & safety checks
Hard code a sector size of 512 if the lease volume is a regular file
Ensure libsanlock.so is built with debug/warning flags
David Teigland (418):
sync_manager: initial commit
sync_manager: misc updates
sync_manager: misc updates
sync_manager: misc updates
sync_manager: misc updates
sync_manager: add more logging
sync_manager: misc updates
sync_manager: misc updates
sync_manager: num_hosts/MAX_HOSTS stuff
daemon: reworking notions of resource_id/token_name
sync_manager: resource lockfiles
sync_manager: lease arg processing
sync_manager: Began multiple lease support
sync_manager: use first command line arg as action
sync_manager: leader record changes and verify
sync_manager: clean up released leases
sync_manager: move functions around
sync_manager: add more tool actions
sync_manager: naming changes
sync_manager: separate token index and id
sync_manager: fix index usage and other misc
sync_manager: use pthread cond in acquire
sync_manager: write all log entries
sync_manager: simplify polling
sync_manager: fix waitpid use
sync_manager: acquire can fail early
sync_manager: write log entries at exit
sync_manager: add test program
sync_manager: move secondary pid check
sync_manager: fix disk paxos contention
devcount: fix verify checks
sync_manager: add GPL license file
sync_manager: fix leader block offsets
sync_manager: increase COMMAND_MAX
sync_manager: renewal should verify
sync_manager: use sector size from libblkid
sync_manager: use a real checksum function
sync_manager: add libblkid to spec file
sync_manager: print status info
sync_manager: one watchdog file per lease
sync_manager: lease_threads handle watchdog files
sync_manager: fix/add some text/comments
sync_manager: refactor read/write
sync_manager: move disk io functions
sync_manager: remove token arg
sync_manager: rename paxos_disk sync_disk
sync_manager: add aio read/write
sync_manager: make io_timeout_seconds a diskio arg
sync_manager: forgot to add new files
sync_manager: use log thread
sync_manager: client connections
sync_manager: connection processing
sync_manager: send/recv pid
sync_manager: add write_sectors
sync_manager: restructuring
sync_manager: write_sectors code factoring
sync_manager: daemonize
sync_manager: releasing leases
sync_manager: async releasing
sync_manager: release fixes
sync_manager: add direct and indirect acquire/release
sync_manager: reacquire resources
sync_manager: move code
sync_manager: same pid may reacquire resource
sync_manager: lease migration
sync_manager: handle client errors
sync_manager: improve error handling
sync_manager: host_id leases
sync_manager: remove empty files
sync_manager: print initialization info
sync_manager: rename files
sync_manager: clean up header org
sync_manager: delta_lease implementation
sync_manager: accept offset units
sync_manager: fix up init output
sync_manager: put back watchdog calls
sync_manager: fix start_host_id error paths
sync_manager: add log_error's for watchdog file errors
sync_manager: actual timeouts
sync_manager: change timeouts on cmd line
sanlock: create new external api
sanlock: build libsanlock
sanlock: use MAX_LEASES everywhere
sanlock: add libvirt plugin
sanlock plugin: couple minor fixes
sanlock: clean up /var file names
sanlock plugin: fix symbol needed by libvirt
sanlock: add some debug output
sanlock plugin: fix uuid copy
sanlock plugin: fix names
sanlock: add "owner_name"
sanlock: fix renewal checks
sanlock: clean up host_id types
sanlock: set_host_id command
sanlock: fix killing pids
sanlock: add status command
sanlock: set version to 1.0
sanlock: delta_lease cleanup
sanlock: changing num_hosts
sanlock: add dump command
sanlock: renewal timings
sanlock: add direct option
sanlock: check for watchdog file
sanlock: recovery fixes
lock_driver_sanlock: fix compile problems
sanlock: improve command options
sanlock: tidying help text
sanlock: move binary to /usr/sbin
sanlock: add init script
sanlock: fix sigterm shutdown
sanlock: init stop
sanlock: add wdtest command
sanlock.spec: new url
lock_driver_sanlock: remove close
sanlock: introduce lockspaces
lock_driver_sanlock: remove files
sanlock: better logging functions
sanlock: misc log message
sanlock.spec: sbin not libexec
sanlock init: remove watchdog reference
wdmd: watchdog multiplexing daemon
sanlock: add code to use wdmd
sanlock/wdmd: use wdmd in sanlock
sanlock/wdmd: add copyright header to source files
sanlock: rename sanlock source dir
sanlock: move tests dir
move COPYING file
wdmd: use signalfd for signal handling
Fix Makefile comments
wdmd: fix daemon debug option
wdmd: add init script
sanlock.spec: updates
sanlock.spec: src dir
sanlock: build with uninstalled libwdmd
sanlock: version 1.1
sanlock: high priority options
wdmd: high priority options
sanlock: return migration state
sanlock: migration.txt describes libvirt/sanlock steps
libsanlock: include admin functions
sanlock: fix host_id expiration check
sanlock: migration working
devcount: migrate test
sanlock: setowner improvements
sanlock: migrate to target fix
sanlock: fix wdmd stop order
sanlock: various fixes
sanlock: remove wdtest
sanlock: remove migration
sanlock: clean up command return data
sanlock: add resource string conversion functions
sanlock: rework internal structs
devcount: add relock test
sanlock: fix release and inquire
sanlock: add_lockspace EEXIST
sanlock: rework client handling
sanlock: clean up warnings
sanlock: debug message changes
sanlock: add lockspace checks
wdmd: enable test scripts
sanlock: add str_to_lockspace to lib
WIP devcount migrate
devcount: new migrate test
sanlock: read_id and live_id commands
sanlock: check lockspace name and host_id
sanlock: remove remaining cluster_mode
sanlock: add libsanlock_direct
devcountn: start multiple devcount tests
devcount: small changes
sanlock: new return values
sanlock: misc changes and fix
sanlock: log error of full bad block
sanlock: interval between renewal checks
sanlock: renewal changes
sanlock: fix log_dump
sanlock: fix find_client_pid
sanlock: fix host_id reads from paxos_acquire
sanlock: init with one write
devcount: improve output
devcount: new pause/resume
devcount: add expire test
sanlock: correct paxos usage
sanlock: direct read_leader
sanlock: paxos delays
sanlock: use thread pool
sanlock: client status output format changes
sanlock: fix inquire of dead pid
sanlock: use native linux aio
sanlock: i/o changes
sanlock: aio changes
sanlock: reduce paxos acquire read ops
sanlock: quiet error case
sanlock: don't free aio buf until event completes
sanlock: io timeout related changes
sanlock: read dblocks in single aligned io
sanlock: add sanlock_restrict api
sanlock: add sanlock_direct_sector_size api
sanlock: add checksum to dblocks
sanlock: fix init restart
sanlock: don't release tokens in dead lockspace
sanlock: fix adding lockspace
sanlock: official 1MB/8MB alignment
devcount: use aio in init
libsanlock: link with LDFLAGS
sanlock: increase version to 1.3
sanlock/wdmd: shut up warnings
sanlock: fix libwdmd linking
remove spec file
sanlock: use a completed read after renewal timeout
sanlock: use unique host name in delta leases
sanlock: remove sector_size api
sanlock: abort delta wait on shutdown
sanlock: fix add_lockspace failure
sanlk_load: add new test
sanlock: fix recv and inquire
sanlock: initial pid_dead check in acquire
sanlock: release 1.4
sanlock: generate a uuid for host id
sanlock: return -EINPROGRESS from add_lockspace
sanlk_load: periodically kill and replace a pid
sanlock: zero num_hosts uses DEFAULT_MAX_HOSTS
tests: misc changes
sanlock: break paxos_acquire wait loop
sanlock: increase log line to 512 bytes
sanlock: change a log_error to log_debug
sanlock: fail host_id when corrupted
sanlock: release 1.5
sanlock: release 1.6
sanlock: handle colon escaping in path strings
wdmd: add option for high priority
wdmd: use accept4 with SOCK_NONBLOCK
wdmd: tidy sun_addr snprintf
wdmd: pid and sock file changes
wdmd: add man page
wdmd: disable test scripts
sanlock: use accept4 with SOCK_NONBLOCK
sanlock: tidy sun_addr snprintf
sanlock: add explicit -luuid
sanlock: pid and sock file changes
sanlock: add man page
sanlock/wdmd: improve mkdir of run dir
wdmd: new build flags
sanlock: new build flags
sanlock/wdmd: use monotonic time
sanlock: build with pie
sanlock/wdmd: nonblocking listening/accept
sanlock: add missing monotime files
sanlock: update man page
sanlock: man page update
sanlock: update man page and help text
sanlock: print connections limit
release: sanlock 1.7
makefile: install mode for man pages
sanlock: read align_size in renewal
sanlock: check other host_id leases
sanlock: minor fixes and cleanups
sanlock: add request api/cmd
sanlock: crc code tidying
sanlock/wdmd: add license header to files
sanlock: create libsanlock_client
sanlock: move client code
remove COPYING file
sanlock: remove internal header from sanlock_sock
libsanlock_client: use LGPLv2+
libwdmd: use LGPLv2+
sanlock_rv.h: switch to LGPLv2+
README.license: document licenses
sanlock: client align and init
sanlock: write request record
sanlock: request struct magic and version numbers
sanlock: set bitmap for requests
sanlock: examine resource requests
sanlock: update man page
sanlock: remove old comment
sanlock: renaming functions
sanlock: optimize paxos wait
sanlock: use flags in struct resource
sanlock: restructure lockspace checks
sanlock: remove BLOCK_WD force mode
libsanlock: fix function stubs
sanlock: new status and host_status
sanlock: improve status output
sanlock: status output sorting
sanlock: SIGTERM and SIGKILL for REQ_KILL_PID
sanlock: add flag RESTRICT_SIGKILL
sanlock: setup fewer aio events
sanlock: move cmd processing
sanlock: suppress log messages
sanlock: rename source files
sanlock: improve killing pids
sanlock: fix log_dump
version 1.8
sanlock: quick host_id reacquire
sanlock: add force option to shutdown command
simpler copyright line
default to GPLv2+ for our original files
sanlock: improve daemon permission errors
add systemd files
fixing up init stuff
release 1.9
sanlock: setmode
Revert "sanlock: setmode"
sanlock: fix error exit
sanlock: fix debug line
init scripts: fix path to restorecon
sanlock: shared mode for leases
sanlock: fix missing close_disks
sanlock: fix problem in paxos
sanlock: add paxos sanity check
sanlock: fix leaking fd
sanlock: change to paxos algorithm
sanlock: change ondisk version
sanlock: remove log noise
sanlock: ignore SIGTERM if lockspaces exist
sanlock: quiet more error messages
sanlk_load: munging variable names
sanlk_load: add shared locks
sanlock: kill client connection on recv error
sanlk_load: ignore release errors
sanlock: set sector_size in shared tokens
sanlock man page: mention SH
release 2.0
sanlock: clean up warnings
sanlock: fix inquire state string
sanlock: retry transient sh failures
sanlock: status for all shared tokens
sanlock: add a logrotate file
release 2.1
python: fix path strncpy
sanlock: remove physical sector size requirement
sanlock: add sample sysconfig file
sanlock: ASYNC flag for lockspace add and rem
sanlock: UNUSED flag for lockspace rem
release 2.2
sanlock.log: empty file to install from rpm
Revert "sanlock.log: empty file to install from rpm"
sanlock: remove limits.conf
sysconfig: remove user option
init: root user
release 2.3
latest spec file
sanlock.spec: fix exclusive arch
sanlock/wdmd: use /var/log/subsys/file
daemon: skip setup_groups when no -U or -G
sanlock.spec: require useradd and groupadd
sanlock.spec updated
daemon: don't put struct space on stack
daemon: fix add_lockspace that has been removed
daemon: fix inquire lver
daemon: graceful pid handling
Revert "init: make explicit to run sanlock as root"
remove spec file
release 2.4
daemon: include resource.h
daemon: fix lockfile ownership
wdmd: use lockfile mode 644
sanlock: use lockfile mode 644
wdmd: use shm_open to prevent restart
sanlock: remove umask 0
sanlock/wdmd: remove global connection
daemon: extend grace time
wdmd: close device when test fails
wdmd: preemptive close before test fails
wdmd: pet after reopen and use 1 sec interval after failure
sanlock: base kill sig on last renewal
clientn: add tests
tests: add test-recovery script
sanlock: fix paxos acquire host_id check
daemon: use helper for examine request kill
sanlock: show host_status for all lockspaces
sanlock: fix status of lockspaces in add and rem
sanlock: adjustable io timeouts
sanlock: add direct next_free command
sanlock: request force_mode 2 is SIGUSR1
sanlock: print escape chars in path from status
release 2.5
sanlock: configurable mlockall level
sanlock: change log level for startup and io timeouts
sanlock: update man page
sanlock: fix aborted command clearing
sanlock: client add_lockspace with timeout
sanlock: print command output to stdout
wdmd: new script handling
fence_sanlock: new code
fence_sanlock: various fixes and changes
fence_sanlock: variable alignment
fence_sanlockd: use init script
fence_sanlock: add man pages
fence_sanlock: use SIGHUP for shutdown
fence_sanlock: handle two node fence duel
sanlock/wdmd: get version from common file
wdmd: show option values in start message
release 2.6
fix systemd service files
wdmd: use mode 775 for run dir
sanlock: clean up daemon exit error path
sanlock: read and write apis for lockspace and resource
sanlock: new get_lockspaces api
sanlock: get_lockspaces count only
sanlock: make get_lockspaces allocate space for data
wdmd: dynamically select working watchdog device
fence_sanlock: fix man page name of path arg
sanlock: shutdown or rem_lockspace should SIGKILL
sanlock: fix usage output typos
release 2.7
sanlock: add request killpath
sanlock/fence_sanlock: request modes FORCE and GRACEFUL
sanlock: update request types in man page
sanlock: add get_hosts api
sanlock: remove direct read_id and live_id
sanlock: add read_resource_owners
sanlock: add test_resource_owners
sanlock: add flag SANLK_REQUEST_NEXT_LVER
sanlock: improve check of max_hosts and num_hosts
sanlock: add a comment
test: add another test program
sanlock: check for null arg in sanlock_request
release 2.8
David Weber (3):
Fix order of linking
Install another symlink to shared library
Replace restrict field name with restricted
Fabio M. Di Nitto (15):
build: sanlock should link with libsanlock
build: install shared lib header files and fix DESTDIR usage
build: drop rpm target
spec file: do first cut for total spec file
build: fix linking with libsanlock and install target
fence_sanlock: add install bits
fence_sanlockd: add missing \n
fence_sanlock: cleanup shell usage
fence_sanlock: don't restart fence_sanlockd if it's already running
fence_sanlock: add basic metadata to integrate with ccs_config_validate
fence_sanlock: improve action_on error checking and report
fence_sanlock: unify code and silence some operations
fence_sanlockd init: cleanup, remove hardcoded paths and use system service
fence_sanlock: fix build to be selfcontained
systemd: add fence_sanlockd service file
Federico Simoncelli (76):
rpm: sync specfile with fedora
rpm: add sanlock_admin.h header
rpm: add the lib package, install the initscripts
python: remove unused python code
python: add python binding
python: release the gil during sanlock operations
python: wrap sanlock extension with a module
rpm: add python binding package
python: pass a lockspace copy to str_to_lockspace
makefile: fix install typo
rpm: add sanlock_direct header
python: add sanlock init functions and exception
direct: close disks after initialization
python: register process only once
daemon: configurable socket permissions
rpm: add sanlock user and group
python: exceptions must contain the errno
rpm: add missing libaio-devel dependency
rpm: add daemon options in the init file
python: add missing aio library
python: add get_alignment function
libs: include libsanlock_direct into libsanlock
python: align num_hosts and max_hosts defaults
python: expose sanlock file descriptor
python: improve error reporting
python: parse lockspaces and resources natively
python: add usage example
python: initial support for sanlock errors
python: document the sanlock module
python: module cleanup
build: fix documentation install path
client: return appropriate errno on failure
python: expose errno in the exception
python: acquire leases for other processes
sanlock: implement the inq_lockspace command
python: add the inq_lockspace command binding
misc: run sanlock daemon as sanlock user
wdmd: use getopt to parse the command line
wdmd: make socket group ownership configurable
python: add shared resource parameter to acquire
python: release leases for other processes
python: ASYNC flag for lockspace add and rem
python: UNUSED flag for lockspace rem
log: add full time and date to the log messages
sanlock: set the supplementary groups at startup
log: add the thread id in the log messages
sanlock: fix an rv check typo in setup_groups
init: add a stop timeout for the sanlock service
build: add a generic rpm spec file
init: make explicit to run sanlock as root
wdmd: load the softdog module when needed
sanlock: WAIT flag for sanlock_inq_lockspace
daemon: drop root privileges and use the helper
init: use checkpid when stopping the services
sanlock: expose sanlock path import and export utils
sanlock: configuring the core dump output
python: fix the tuple parsing for py_add_lockspace
sanlock: use signal handler for all terminating signals
systemd: add wdmd dependency for sanlock
wdmd: trap also SIGINT for a clean exit
wdmd: make the watchdog device configurable
python: fix typo for the offset parameter
python: add write lockspace and resource
python: add read lockspace and resource
wdmd: fix miscellaneous build warnings
misc: add wdmd to gitignore
python: fix multiple issues reported by cpychecker
python: add get_lockspaces
python: use the write commands in example.py
python: add the versioning support to acquire
python: return lease version in read_resource
python: rename SANLK_LSF flags and constants macro
python: improve example with signals and exceptions
python: add the support for the resource request
python: add the get_hosts support
python: add support to read resource owners
Saggi Mizrahi (25):
Added the begining of the testing and debugging tools
Better handling of max hosts
sync_manager: Updated tests to work with new lease struct
sync_manager: fixed skipping first arg in command
sync_manager: acquire and release actions
sync_manager: minor fixes
sync_manager: renamed stuff
sync_manager: made acquire synchronous again
sync_manager: added set_host_id action
sync_manager: use kill(0) for secondary pid check
sync_manager: make rpm and install
sync_manager: spec file update
sync_manager: Allow longer resource names
sync_manager: allow repeated set_host_id
sync_manager: Added escaping for the leases arg
sync_manager: Created the python bindings for sync_manager
sync_manager: listener socket permissions
sync_manager: Updated python binding and tests
sync_manager: Made 'token' a const in log_level
sync_manager: refactor messaging system
sync_manager: use getsockopt PEERCRED
Fix various build warnings
Tidy up some copy pasted code
Set constness in some places
Add a gitignore file
10 years, 9 months
Branch 'lvb' - src/cmd.c src/direct.c src/paxos_lease.c src/paxos_lease.h src/resource.c src/resource.h src/sanlock_resource.h tests/sanlk_rename.c
by David Teigland
src/cmd.c | 56 +++++++++++++++++++++++++++++++++--
src/direct.c | 2 -
src/paxos_lease.c | 4 ++
src/paxos_lease.h | 1
src/resource.c | 24 ++++++++-------
src/resource.h | 3 +
src/sanlock_resource.h | 19 +++++++++++-
tests/sanlk_rename.c | 77 +++++++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 170 insertions(+), 16 deletions(-)
New commits:
commit 3fd9e04789e220ef85bb9b852c8d2d957d55707a
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jul 10 16:32:47 2013 -0500
sanlock: add SANLK_REL_RENAME
Used to rename a resource when releasing the lease.
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/cmd.c b/src/cmd.c
index 4ca87f2..da56d9d 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -65,7 +65,7 @@ static void release_cl_tokens(struct task *task, struct client *cl)
token = cl->tokens[j];
if (!token)
continue;
- release_token(task, token);
+ release_token(task, token, NULL);
free(token);
}
}
@@ -76,7 +76,7 @@ static void release_new_tokens(struct task *task, struct token *new_tokens[],
int i;
for (i = 0; i < acquire_count; i++)
- release_token(task, new_tokens[i]);
+ release_token(task, new_tokens[i], NULL);
for (i = 0; i < alloc_count; i++)
free(new_tokens[i]);
@@ -477,6 +477,8 @@ static void cmd_release(struct task *task, struct cmd_args *ca)
struct token *token;
struct token *rem_tokens[SANLK_MAX_RESOURCES];
struct sanlk_resource res;
+ struct sanlk_resource new;
+ struct sanlk_resource *resrename = NULL;
int fd, rv, i, j, found, pid_dead;
int rem_tokens_count = 0;
int result = 0;
@@ -506,6 +508,54 @@ static void cmd_release(struct task *task, struct cmd_args *ca)
goto do_remove;
}
+ if (ca->header.cmd_flags & SANLK_REL_RENAME) {
+ rv = recv(fd, &res, sizeof(struct sanlk_resource), MSG_WAITALL);
+ if (rv != sizeof(struct sanlk_resource)) {
+ log_error("cmd_release %d,%d,%d recv res %d %d",
+ cl_ci, cl_fd, cl_pid, rv, errno);
+ result = -ENOTCONN;
+ goto do_remove;
+ }
+
+ /* second res struct has new name for first res */
+ rv = recv(fd, &new, sizeof(struct sanlk_resource), MSG_WAITALL);
+ if (rv != sizeof(struct sanlk_resource)) {
+ log_error("cmd_release %d,%d,%d recv new %d %d",
+ cl_ci, cl_fd, cl_pid, rv, errno);
+ result = -ENOTCONN;
+ goto do_remove;
+ }
+
+ found = 0;
+
+ pthread_mutex_lock(&cl->mutex);
+ for (j = 0; j < SANLK_MAX_RESOURCES; j++) {
+ token = cl->tokens[j];
+ if (!token)
+ continue;
+
+ if (memcmp(token->r.lockspace_name, res.lockspace_name, NAME_ID_SIZE))
+ continue;
+ if (memcmp(token->r.name, res.name, NAME_ID_SIZE))
+ continue;
+
+ rem_tokens[rem_tokens_count++] = token;
+ cl->tokens[j] = NULL;
+ found = 1;
+ break;
+ }
+ pthread_mutex_unlock(&cl->mutex);
+
+ if (!found) {
+ log_error("cmd_release %d,%d,%d no resource %.48s",
+ cl_ci, cl_fd, cl_pid, res.name);
+ result = -1;
+ }
+
+ resrename = &new;
+ goto do_remove;
+ }
+
/* caller is specifying specific resources to release */
for (i = 0; i < ca->header.data; i++) {
@@ -548,7 +598,7 @@ static void cmd_release(struct task *task, struct cmd_args *ca)
for (i = 0; i < rem_tokens_count; i++) {
token = rem_tokens[i];
- rv = release_token(task, token);
+ rv = release_token(task, token, resrename);
if (rv < 0)
result = rv;
free(token);
diff --git a/src/direct.c b/src/direct.c
index 63684b8..ed6cca4 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -132,7 +132,7 @@ static int do_paxos_action(int action, struct task *task, int io_timeout,
rv = paxos_lease_leader_read(task, token, &leader, "direct_release");
if (rv < 0)
break;
- rv = paxos_lease_release(task, token, &leader, leader_ret);
+ rv = paxos_lease_release(task, token, NULL, &leader, leader_ret);
break;
case ACT_READ_LEADER:
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 69a4ed1..3b21017 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -1669,6 +1669,7 @@ int paxos_lease_renew(struct task *task,
int paxos_lease_release(struct task *task,
struct token *token,
+ struct sanlk_resource *resrename,
struct leader_record *leader_last,
struct leader_record *leader_ret)
{
@@ -1725,6 +1726,9 @@ int paxos_lease_release(struct task *task,
*/
}
+ if (resrename)
+ memcpy(leader.resource_name, resrename->name, NAME_ID_SIZE);
+
leader.timestamp = LEASE_FREE;
leader.write_id = token->host_id;
leader.write_generation = token->host_generation;
diff --git a/src/paxos_lease.h b/src/paxos_lease.h
index d924923..588cb39 100644
--- a/src/paxos_lease.h
+++ b/src/paxos_lease.h
@@ -29,6 +29,7 @@ int paxos_lease_acquire(struct task *task,
int paxos_lease_release(struct task *task,
struct token *token,
+ struct sanlk_resource *resrename,
struct leader_record *leader_last,
struct leader_record *leader_ret);
diff --git a/src/resource.c b/src/resource.c
index 2fa0752..b2a7ba1 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -556,12 +556,13 @@ static int acquire_disk(struct task *task, struct token *token,
/* return < 0 on error, 1 on success */
static int release_disk(struct task *task, struct token *token,
- struct leader_record *leader)
+ struct sanlk_resource *resrename,
+ struct leader_record *leader)
{
struct leader_record leader_tmp;
int rv;
- rv = paxos_lease_release(task, token, leader, &leader_tmp);
+ rv = paxos_lease_release(task, token, resrename, leader, &leader_tmp);
log_token(token, "release_disk rv %d", rv);
@@ -572,7 +573,9 @@ static int release_disk(struct task *task, struct token *token,
return rv; /* SANLK_OK */
}
-static int _release_token(struct task *task, struct token *token, int opened, int nodisk)
+static int _release_token(struct task *task, struct token *token,
+ struct sanlk_resource *resrename,
+ int opened, int nodisk)
{
struct resource *r = token->resource;
uint64_t lver;
@@ -642,7 +645,7 @@ static int _release_token(struct task *task, struct token *token, int opened, in
if (r->flags & R_LVB_WRITE_RELEASE)
write_lvb_block(task, r, token);
- rv = release_disk(task, token, &r->leader);
+ rv = release_disk(task, token, resrename, &r->leader);
}
close_disks(token->disks, token->r.num_disks);
@@ -664,17 +667,18 @@ static int _release_token(struct task *task, struct token *token, int opened, in
static int release_token_nodisk(struct task *task, struct token *token)
{
- return _release_token(task, token, 0, 1);
+ return _release_token(task, token, NULL, 0, 1);
}
static int release_token_opened(struct task *task, struct token *token)
{
- return _release_token(task, token, 1, 0);
+ return _release_token(task, token, NULL, 1, 0);
}
-int release_token(struct task *task, struct token *token)
+int release_token(struct task *task, struct token *token,
+ struct sanlk_resource *resrename)
{
- return _release_token(task, token, 0, 0);
+ return _release_token(task, token, resrename, 0, 0);
}
/* We're releasing a token from the main thread, in which we don't want to block,
@@ -931,7 +935,7 @@ int acquire_token(struct task *task, struct token *token, uint32_t cmd_flags,
release_token_opened(task, token);
return rv;
} else {
- release_disk(task, token, &leader);
+ release_disk(task, token, NULL, &leader);
/* the token is kept, the paxos lease is released but with shared set */
goto out;
}
@@ -1195,7 +1199,7 @@ static void resource_thread_release(struct task *task, struct resource *r, struc
if (r->flags & R_LVB_WRITE_RELEASE)
write_lvb_block(task, r, tt);
- release_disk(task, tt, &r->leader);
+ release_disk(task, tt, NULL, &r->leader);
}
close_disks(tt->disks, tt->r.num_disks);
diff --git a/src/resource.h b/src/resource.h
index 25e9c58..11ea4c0 100644
--- a/src/resource.h
+++ b/src/resource.h
@@ -17,7 +17,8 @@ void check_mode_block(struct token *token, int q, char *dblock);
int acquire_token(struct task *task, struct token *token, uint32_t cmd_flags,
char *killpath, char *killargs);
-int release_token(struct task *task, struct token *token);
+int release_token(struct task *task, struct token *token,
+ struct sanlk_resource *resrename);
void release_token_async(struct token *token);
int request_token(struct task *task, struct token *token, uint32_t force_mode,
diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h
index 9c6112f..f691032 100644
--- a/src/sanlock_resource.h
+++ b/src/sanlock_resource.h
@@ -31,8 +31,25 @@
/* acquire flags */
#define SANLK_ACQUIRE_LVB 0x00000001
-/* release flags */
+/*
+ * release flags
+ *
+ * SANLK_REL_ALL
+ * Release all resources held by the client.
+ * The res args are ignored.
+ *
+ * SANLK_REL_RENAME
+ * Rename the resource lease on disk when it
+ * is released. The resource is freed and
+ * renamed in a single disk operation (write
+ * to the leader record.) The first res
+ * arg is the resource to release, and the
+ * second resource arg contains the new name
+ * for the first resource.
+ */
+
#define SANLK_REL_ALL 0x00000001
+#define SANLK_REL_RENAME 0x00000002
/*
* request flags
diff --git a/tests/sanlk_rename.c b/tests/sanlk_rename.c
new file mode 100644
index 0000000..4043c3e
--- /dev/null
+++ b/tests/sanlk_rename.c
@@ -0,0 +1,77 @@
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/un.h>
+#include <sys/mount.h>
+#include <sys/signalfd.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <limits.h>
+#include <time.h>
+#include <signal.h>
+
+#include "sanlock.h"
+#include "sanlock_resource.h"
+
+/* gcc with -lsanlock */
+
+int main(int argc, char *argv[])
+{
+ char rd[sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk)];
+ char rd2[sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk)];
+ struct sanlk_resource *res;
+ struct sanlk_resource *res2;
+ struct sanlk_resource **res_args;
+ int fd, rv;
+
+ if (argc < 6) {
+ printf("acquire with old name, release with new name\n");
+ printf("sanlk_rename <lockspace_name> <resource_name_old> <resource_name_new> <path> <resource_offset>\n");
+ return -1;
+ }
+
+ res_args = malloc(2 * sizeof(struct sanlk_resource *));
+
+ memset(rd, 0, sizeof(rd));
+ memset(rd2, 0, sizeof(rd2));
+
+ res = (struct sanlk_resource *)&rd;
+ res2 = (struct sanlk_resource *)&rd2;
+
+ res_args[0] = res;
+ res_args[1] = res2;
+
+ strcpy(res->lockspace_name, argv[1]);
+ strcpy(res->name, argv[2]);
+ strcpy(res2->name, argv[3]);
+ res->num_disks = 1;
+ strcpy(res->disks[0].path, argv[4]);
+ res->disks[0].offset = atoi(argv[5]);
+
+ fd = sanlock_register();
+ if (fd < 0) {
+ fprintf(stderr, "register error %d\n", fd);
+ return -1;
+ }
+
+ rv = sanlock_acquire(fd, -1, 0, 1, &res, NULL);
+ if (rv < 0) {
+ fprintf(stderr, "acquire error %d\n", rv);
+ return -1;
+ }
+
+ rv = sanlock_release(fd, -1, SANLK_REL_RENAME, 2, res_args);
+ if (rv < 0) {
+ fprintf(stderr, "release error %d\n", rv);
+ return -1;
+ }
+
+ return 0;
+}
+
10 years, 9 months
Changes to 'lvb'
by David Teigland
New branch 'lvb' available with the following commits:
commit 0de21c97925b2cbad0e412402c9a074642a47138
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jul 10 11:19:32 2013 -0500
sanlock: add lvb feature
set_lvb and get_lvb allow up to a sector size of
application specific data to be stored with a
resource lease. They are similar to the lvb
feature found in the dlm.
host 1:
sanlock_acquire(ACQUIRE_LVB, r)
application data written to lvb
sanlock_set_lvb(r, lvb)
sanlock_release(r)
The lvb data is copied to the sanlock daemon in set_lvb,
and written to the resource lease on disk in release.
host 2:
sanlock_acquire(ACQUIRE_LVB, r)
sanlock_get_lvb(r, lvb)
application data read from lvb
sanlock_release(r)
The lvb data is read by the sanlock daemon from disk
in acquire, and copied to the application in get_lvb.
Signed-off-by: David Teigland <teigland(a)redhat.com>
10 years, 9 months
src/client.c
by David Teigland
src/client.c | 3 +++
1 file changed, 3 insertions(+)
New commits:
commit cd62001cba5793a93678060e42f86d32e32707e4
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Jul 9 14:11:20 2013 -0500
sanlock: check for null arg in sanlock_request
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/client.c b/src/client.c
index 38a9692..6ecf431 100644
--- a/src/client.c
+++ b/src/client.c
@@ -1044,6 +1044,9 @@ int sanlock_request(uint32_t flags, uint32_t force_mode,
{
int fd, rv, datalen;
+ if (!res)
+ return -EINVAL;
+
datalen = sizeof(struct sanlk_resource) +
sizeof(struct sanlk_disk) * res->num_disks;
10 years, 9 months
Can the hostId be self-organization by the servers themselves ?
by Qixiaozhen
Hi, all
As everyone known, the host id is the essential of sanlock. It identifies all the servers with different offset in the shared disk.
Could the host id be self-organization by the servers themselves ? In this condition, the manager node that generated the unique host id would be useless.
My thought lists here:
1. Get the system uuid with dmidecode.
2. System uuid maps into a uint32 integer.
3. Calculate the host id with the hash function with the uint32 integer. Hash function f(x) = value % MAX_HOST_ID
a) Once the conflict occurs, choose its neighbor id.
b) The detection of conflict can use the bitmap in the delta lease.
Is this idea feasibility?
Thank you.
Qi
10 years, 9 months
How can I build and install the sanlock(v2.7) with the source code?
by Qixiaozhen
Hi,all
1) Does anyone tell me that how can I build and install the sanlock(v2.7) with the source code?
2) How can I build it into the rpm package?
I have tried the solution of the two questions above. But less helpful information was found in the internet.
Thank you.
Qi
10 years, 9 months