4 commits - python/Makefile python/sanlock.c python/sanlockmod.c python/sanlock.py python/setup.py sanlock.spec
by David Teigland
python/Makefile | 3
python/sanlock.c | 180 -------------------------------------------
python/sanlock.py | 16 +++
python/sanlockmod.c | 215 ++++++++++++++++++++++++++++++++++++++++++++++++++++
python/setup.py | 9 +-
sanlock.spec | 22 +++++
6 files changed, 263 insertions(+), 182 deletions(-)
New commits:
commit 10489d2e5904f57541fdd92e8b99f4b88e8be411
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Apr 13 11:00:25 2011 +0100
python: pass a lockspace copy to str_to_lockspace
sanlock_str_to_lockspace is destructive
diff --git a/python/sanlockmod.c b/python/sanlockmod.c
index a782b7a..65ead2a 100644
--- a/python/sanlockmod.c
+++ b/python/sanlockmod.c
@@ -35,20 +35,33 @@ py_register(PyObject *self, PyObject *args)
static int
__parse_lockspace(PyObject *args, struct sanlk_lockspace *ret_ls)
{
- char *lockspace;
+ char *lockspace, *lockspace_arg;
/* parse python tuple */
if (!PyArg_ParseTuple(args, "s", &lockspace)) {
return -1;
}
+ /* sanlock_str_to_lockspace is destructive */
+ lockspace_arg = strdup(lockspace);
+
+ if (lockspace_arg == NULL) {
+ PyErr_SetString(sanlockmod_exception, "SANLock extension memory error");
+ return -1;
+ }
+
/* convert lockspace string to structure */
- if (sanlock_str_to_lockspace(lockspace, ret_ls) != 0) {
+ if (sanlock_str_to_lockspace(lockspace_arg, ret_ls) != 0) {
PyErr_SetString(sanlockmod_exception, "Invalid SANLock lockspace");
- return -1;
+ goto exit_fail;
}
+ free(lockspace_arg);
return 0;
+
+exit_fail:
+ free(lockspace_arg);
+ return -1;
}
static PyObject *
commit 6506dc4cd68a2585bbae2077e6dc58c9dcfdafa4
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Apr 13 11:00:24 2011 +0100
rpm: add python binding package
diff --git a/python/Makefile b/python/Makefile
index e48a72d..c72c253 100644
--- a/python/Makefile
+++ b/python/Makefile
@@ -7,6 +7,9 @@
all:
python setup.py build
+install:
+ python setup.py install --root=$(DESTDIR)
+
clean:
rm -rf build
diff --git a/python/setup.py b/python/setup.py
index f8b34df..843216c 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -6,7 +6,11 @@
from distutils.core import setup, Extension
-sanlockmod = Extension('sanlockmod', sources=['sanlockmod.c'], libraries=['sanlock'])
+sanlockmod = Extension(name = 'sanlockmod',
+ sources = ['sanlockmod.c'],
+ include_dirs = ['../src'],
+ library_dirs = ['../src'],
+ libraries = ['sanlock'])
setup(name = 'SANLock',
version = '1.0',
diff --git a/sanlock.spec b/sanlock.spec
index d936756..5eadafe 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -1,3 +1,5 @@
+%{!?python_sitearch: %global python_sitearch %(%{__python} -c "from distutils.sysconfig import get_python_lib; print(get_python_lib(1))")}
+
Name: sanlock
Version: 1.1.0
Release: 3%{?dist}
@@ -26,6 +28,7 @@ access to the shared disks.
# upstream does not support _smp_mflags
CFLAGS=$RPM_OPT_FLAGS make -C wdmd
CFLAGS=$RPM_OPT_FLAGS make -C src
+CFLAGS=$RPM_OPT_FLAGS make -C python
%install
rm -rf $RPM_BUILD_ROOT
@@ -35,6 +38,9 @@ make -C src \
make -C wdmd \
install LIB_LIBDIR=%{_libdir} \
DESTDIR=$RPM_BUILD_ROOT
+make -C python \
+ install LIB_LIBDIR=%{_libdir} \
+ DESTDIR=$RPM_BUILD_ROOT
install -D -m 755 init.d/sanlock $RPM_BUILD_ROOT/%{_initddir}/sanlock
install -D -m 755 init.d/wdmd $RPM_BUILD_ROOT/%{_initddir}/wdmd
@@ -85,6 +91,22 @@ access to the shared disks.
%{_libdir}/libsanlock.so.*
%{_libdir}/libwdmd.so.*
+%package python
+Summary: Python bindings for the sanlock library
+Group: Development/Libraries
+
+%description python
+The %{name}-python package contains a module that permits applications
+written in the Python programming language to use the interface
+supplied by the sanlock library.
+
+%files python
+%defattr(-,root,root,-)
+%doc COPYING
+%{python_sitearch}/SANLock-1.0-py2.6.egg-info
+%{python_sitearch}/sanlock.py*
+%{python_sitearch}/sanlockmod.so
+
%package devel
Summary: Development files for %{name}
Group: Development/Libraries
commit d5ac787ec2f255a06506f4c513fe9a4052969399
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Apr 13 11:00:23 2011 +0100
python: wrap sanlock extension with a module
diff --git a/python/sanlock.c b/python/sanlock.c
deleted file mode 100644
index ed11d79..0000000
--- a/python/sanlock.c
+++ /dev/null
@@ -1,202 +0,0 @@
-/*
- * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
- *
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU General Public License v.2.
- */
-
-#include <Python.h>
-#include <sanlock.h>
-#include <sanlock_resource.h>
-#include <sanlock_admin.h>
-
-int __sanlock_fd = -1;
-PyObject *py_module;
-
-/* SANLock exception */
-static PyObject *sanlock_exception;
-
-static PyObject *
-py_register(PyObject *self, PyObject *args)
-{
- Py_BEGIN_ALLOW_THREADS
- __sanlock_fd = sanlock_register();
- Py_END_ALLOW_THREADS
-
- if (__sanlock_fd < 0) {
- PyErr_SetString(sanlock_exception, "SANLock registration failed");
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static int
-__parse_lockspace(PyObject *args, struct sanlk_lockspace *ret_ls)
-{
- char *lockspace;
-
- /* parse python tuple */
- if (!PyArg_ParseTuple(args, "s", &lockspace)) {
- return -1;
- }
-
- /* convert lockspace string to structure */
- if (sanlock_str_to_lockspace(lockspace, ret_ls) != 0) {
- PyErr_SetString(sanlock_exception, "Invalid SANLock lockspace");
- return -1;
- }
-
- return 0;
-}
-
-static PyObject *
-py_add_lockspace(PyObject *self, PyObject *args)
-{
- int rv;
- struct sanlk_lockspace ls;
-
- if (__parse_lockspace(args, &ls) != 0) {
- return NULL;
- }
-
- /* add sanlock lockspace (gil disabled) */
- Py_BEGIN_ALLOW_THREADS
- rv = sanlock_add_lockspace(&ls, 0 );
- Py_END_ALLOW_THREADS
-
- if (rv != 0) {
- PyErr_SetString(sanlock_exception, "SANLock lockspace add failure");
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *
-py_rem_lockspace(PyObject *self, PyObject *args)
-{
- int rv;
- struct sanlk_lockspace ls;
-
- if (__parse_lockspace(args, &ls) != 0) {
- return NULL;
- }
-
- /* remove sanlock lockspace (gil disabled) */
- Py_BEGIN_ALLOW_THREADS
- rv = sanlock_rem_lockspace(&ls, 0);
- Py_END_ALLOW_THREADS
-
- if (rv != 0) {
- PyErr_SetString(sanlock_exception, "SANLock lockspace remove failure");
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static int
-__parse_resource(PyObject *args, struct sanlk_resource **ret_res)
-{
- char *resource;
-
- /* parse python tuple */
- if (!PyArg_ParseTuple(args, "s", &resource)) {
- return -1;
- }
-
- /* convert resource string to structure */
- if (sanlock_str_to_res(resource, ret_res) != 0) {
- PyErr_SetString(sanlock_exception, "Invalid SANLock resource");
- return -1;
- }
-
- return 0;
-}
-
-static PyObject *
-py_acquire(PyObject *self, PyObject *args)
-{
- int rv;
- struct sanlk_resource *res;
-
- if (__parse_resource(args, &res) != 0) {
- return NULL;
- }
-
- /* acquire resource (gil disabled) */
- Py_BEGIN_ALLOW_THREADS
- rv = sanlock_acquire(__sanlock_fd, -1, 0, 1, &res, 0);
- Py_END_ALLOW_THREADS
-
- if (rv != 0) {
- PyErr_SetString(sanlock_exception, "SANLock resource not acquired");
- goto exit_fail;
- }
-
- free(res);
- Py_RETURN_NONE;
-
-exit_fail:
- free(res);
- return NULL;
-}
-
-static PyObject *
-py_release(PyObject *self, PyObject *args)
-{
- int rv;
- struct sanlk_resource *res;
-
- if (__parse_resource(args, &res) != 0) {
- return NULL;
- }
-
- /* release resource (gil disabled)*/
- Py_BEGIN_ALLOW_THREADS
- rv = sanlock_release(__sanlock_fd, -1, 0, 1, &res);
- Py_END_ALLOW_THREADS
-
- if (rv != 0) {
- PyErr_SetString(sanlock_exception, "SANLock resource not released");
- goto exit_fail;
- }
-
- free(res);
- Py_RETURN_NONE;
-
-exit_fail:
- free(res);
- return NULL;
-}
-
-static PyMethodDef
-sanlock_methods[] = {
- {"register", py_register, METH_NOARGS, "Register to sanlock daemon."},
- {"add_lockspace", py_add_lockspace, METH_VARARGS,
- "Add a lockspace, acquiring a host_id in it."},
- {"rem_lockspace", py_rem_lockspace, METH_VARARGS,
- "Remove a lockspace, releasing our host_id in it."},
- {"acquire", py_acquire, METH_VARARGS,
- "Acquire leases for the current process."},
- {"release", py_release, METH_VARARGS,
- "Release leases for the current process."},
- {NULL, NULL, 0, NULL}
-};
-
-PyMODINIT_FUNC
-initsanlock(void)
-{
- py_module = Py_InitModule("sanlock", sanlock_methods);
-
- /* Python's module loader doesn't support clean recovery from errors */
- if (py_module == NULL)
- return;
-
- /* Initializing sanlock exception */
- sanlock_exception = PyErr_NewException("sanlock.exception", NULL, NULL);
- Py_INCREF(sanlock_exception);
- PyModule_AddObject(py_module, "exception", sanlock_exception);
-}
diff --git a/python/sanlock.py b/python/sanlock.py
new file mode 100644
index 0000000..35ccb3b
--- /dev/null
+++ b/python/sanlock.py
@@ -0,0 +1,16 @@
+# Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+
+import sys
+import sanlockmod
+
+SANLOCK_FUNCTIONS = ('register', 'add_lockspace',
+ 'rem_lockspace', 'acquire', 'release')
+
+for skfun in SANLOCK_FUNCTIONS:
+ setattr(sys.modules[__name__], skfun, getattr(sanlockmod, skfun))
+del skfun
+
diff --git a/python/sanlockmod.c b/python/sanlockmod.c
new file mode 100644
index 0000000..a782b7a
--- /dev/null
+++ b/python/sanlockmod.c
@@ -0,0 +1,202 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ */
+
+#include <Python.h>
+#include <sanlock.h>
+#include <sanlock_resource.h>
+#include <sanlock_admin.h>
+
+int __sanlockmod_fd = -1;
+PyObject *py_module;
+
+/* SANLock exception */
+static PyObject *sanlockmod_exception;
+
+static PyObject *
+py_register(PyObject *self, PyObject *args)
+{
+ Py_BEGIN_ALLOW_THREADS
+ __sanlockmod_fd = sanlock_register();
+ Py_END_ALLOW_THREADS
+
+ if (__sanlockmod_fd < 0) {
+ PyErr_SetString(sanlockmod_exception, "SANLock registration failed");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static int
+__parse_lockspace(PyObject *args, struct sanlk_lockspace *ret_ls)
+{
+ char *lockspace;
+
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &lockspace)) {
+ return -1;
+ }
+
+ /* convert lockspace string to structure */
+ if (sanlock_str_to_lockspace(lockspace, ret_ls) != 0) {
+ PyErr_SetString(sanlockmod_exception, "Invalid SANLock lockspace");
+ return -1;
+ }
+
+ return 0;
+}
+
+static PyObject *
+py_add_lockspace(PyObject *self, PyObject *args)
+{
+ int rv;
+ struct sanlk_lockspace ls;
+
+ if (__parse_lockspace(args, &ls) != 0) {
+ return NULL;
+ }
+
+ /* add sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_add_lockspace(&ls, 0 );
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ PyErr_SetString(sanlockmod_exception, "SANLock lockspace add failure");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+py_rem_lockspace(PyObject *self, PyObject *args)
+{
+ int rv;
+ struct sanlk_lockspace ls;
+
+ if (__parse_lockspace(args, &ls) != 0) {
+ return NULL;
+ }
+
+ /* remove sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_rem_lockspace(&ls, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ PyErr_SetString(sanlockmod_exception, "SANLock lockspace remove failure");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static int
+__parse_resource(PyObject *args, struct sanlk_resource **ret_res)
+{
+ char *resource;
+
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &resource)) {
+ return -1;
+ }
+
+ /* convert resource string to structure */
+ if (sanlock_str_to_res(resource, ret_res) != 0) {
+ PyErr_SetString(sanlockmod_exception, "Invalid SANLock resource");
+ return -1;
+ }
+
+ return 0;
+}
+
+static PyObject *
+py_acquire(PyObject *self, PyObject *args)
+{
+ int rv;
+ struct sanlk_resource *res;
+
+ if (__parse_resource(args, &res) != 0) {
+ return NULL;
+ }
+
+ /* acquire resource (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_acquire(__sanlockmod_fd, -1, 0, 1, &res, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ PyErr_SetString(sanlockmod_exception, "SANLock resource not acquired");
+ goto exit_fail;
+ }
+
+ free(res);
+ Py_RETURN_NONE;
+
+exit_fail:
+ free(res);
+ return NULL;
+}
+
+static PyObject *
+py_release(PyObject *self, PyObject *args)
+{
+ int rv;
+ struct sanlk_resource *res;
+
+ if (__parse_resource(args, &res) != 0) {
+ return NULL;
+ }
+
+ /* release resource (gil disabled)*/
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_release(__sanlockmod_fd, -1, 0, 1, &res);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
+ PyErr_SetString(sanlockmod_exception, "SANLock resource not released");
+ goto exit_fail;
+ }
+
+ free(res);
+ Py_RETURN_NONE;
+
+exit_fail:
+ free(res);
+ return NULL;
+}
+
+static PyMethodDef
+sanlockmod_methods[] = {
+ {"register", py_register, METH_NOARGS, "Register to SANLock daemon."},
+ {"add_lockspace", py_add_lockspace, METH_VARARGS,
+ "Add a lockspace, acquiring a host_id in it."},
+ {"rem_lockspace", py_rem_lockspace, METH_VARARGS,
+ "Remove a lockspace, releasing our host_id in it."},
+ {"acquire", py_acquire, METH_VARARGS,
+ "Acquire leases for the current process."},
+ {"release", py_release, METH_VARARGS,
+ "Release leases for the current process."},
+ {NULL, NULL, 0, NULL}
+};
+
+PyMODINIT_FUNC
+initsanlockmod(void)
+{
+ py_module = Py_InitModule("sanlockmod", sanlockmod_methods);
+
+ /* Python's module loader doesn't support clean recovery from errors */
+ if (py_module == NULL)
+ return;
+
+ /* Initializing sanlock exception */
+ sanlockmod_exception = PyErr_NewException("sanlockmod.exception", NULL, NULL);
+ Py_INCREF(sanlockmod_exception);
+ PyModule_AddObject(py_module, "exception", sanlockmod_exception);
+}
diff --git a/python/setup.py b/python/setup.py
index acf3810..f8b34df 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -6,9 +6,10 @@
from distutils.core import setup, Extension
-module1 = Extension('sanlock', sources=['sanlock.c'], libraries=['sanlock'])
+sanlockmod = Extension('sanlockmod', sources=['sanlockmod.c'], libraries=['sanlock'])
setup(name = 'SANLock',
version = '1.0',
description = 'SANLock python package',
- ext_modules = [module1])
+ ext_modules = [sanlockmod],
+ py_modules = ['sanlock'])
commit 6550399984a1af9ba58903660c655237ed60e810
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Wed Apr 13 11:00:22 2011 +0100
python: release the gil during sanlock operations
diff --git a/python/sanlock.c b/python/sanlock.c
index 7e6f46f..ed11d79 100644
--- a/python/sanlock.c
+++ b/python/sanlock.c
@@ -20,7 +20,9 @@ static PyObject *sanlock_exception;
static PyObject *
py_register(PyObject *self, PyObject *args)
{
+ Py_BEGIN_ALLOW_THREADS
__sanlock_fd = sanlock_register();
+ Py_END_ALLOW_THREADS
if (__sanlock_fd < 0) {
PyErr_SetString(sanlock_exception, "SANLock registration failed");
@@ -42,7 +44,7 @@ __parse_lockspace(PyObject *args, struct sanlk_lockspace *ret_ls)
/* convert lockspace string to structure */
if (sanlock_str_to_lockspace(lockspace, ret_ls) != 0) {
- PyErr_SetString(sanlock_exception, "Invalid sanlock resource");
+ PyErr_SetString(sanlock_exception, "Invalid SANLock lockspace");
return -1;
}
@@ -52,14 +54,19 @@ __parse_lockspace(PyObject *args, struct sanlk_lockspace *ret_ls)
static PyObject *
py_add_lockspace(PyObject *self, PyObject *args)
{
+ int rv;
struct sanlk_lockspace ls;
if (__parse_lockspace(args, &ls) != 0) {
return NULL;
}
- /* add sanlock lockspace */
- if (sanlock_add_lockspace(&ls, 0 ) != 0) {
+ /* add sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_add_lockspace(&ls, 0 );
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
PyErr_SetString(sanlock_exception, "SANLock lockspace add failure");
return NULL;
}
@@ -70,14 +77,19 @@ py_add_lockspace(PyObject *self, PyObject *args)
static PyObject *
py_rem_lockspace(PyObject *self, PyObject *args)
{
+ int rv;
struct sanlk_lockspace ls;
if (__parse_lockspace(args, &ls) != 0) {
return NULL;
}
- /* remove sanlock lockspace */
- if (sanlock_rem_lockspace(&ls, 0 ) != 0) {
+ /* remove sanlock lockspace (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_rem_lockspace(&ls, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
PyErr_SetString(sanlock_exception, "SANLock lockspace remove failure");
return NULL;
}
@@ -97,7 +109,7 @@ __parse_resource(PyObject *args, struct sanlk_resource **ret_res)
/* convert resource string to structure */
if (sanlock_str_to_res(resource, ret_res) != 0) {
- PyErr_SetString(sanlock_exception, "Invalid sanlock resource");
+ PyErr_SetString(sanlock_exception, "Invalid SANLock resource");
return -1;
}
@@ -107,14 +119,19 @@ __parse_resource(PyObject *args, struct sanlk_resource **ret_res)
static PyObject *
py_acquire(PyObject *self, PyObject *args)
{
+ int rv;
struct sanlk_resource *res;
if (__parse_resource(args, &res) != 0) {
return NULL;
}
- /* acquire resource */
- if (sanlock_acquire(__sanlock_fd, -1, 0, 1, &res, 0) != 0) {
+ /* acquire resource (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_acquire(__sanlock_fd, -1, 0, 1, &res, 0);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
PyErr_SetString(sanlock_exception, "SANLock resource not acquired");
goto exit_fail;
}
@@ -130,14 +147,19 @@ exit_fail:
static PyObject *
py_release(PyObject *self, PyObject *args)
{
+ int rv;
struct sanlk_resource *res;
if (__parse_resource(args, &res) != 0) {
return NULL;
}
- /* release resource */
- if (sanlock_release(__sanlock_fd, -1, 0, 1, &res) != 0) {
+ /* release resource (gil disabled)*/
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_release(__sanlock_fd, -1, 0, 1, &res);
+ Py_END_ALLOW_THREADS
+
+ if (rv != 0) {
PyErr_SetString(sanlock_exception, "SANLock resource not released");
goto exit_fail;
}
12 years, 7 months
src/direct.c src/main.c src/sanlock_direct.h src/sanlock_internal.h
by David Teigland
src/direct.c | 127 ++++++++++++++++++++++++++++++++++++++++---------
src/main.c | 43 +++++++++++++++-
src/sanlock_direct.h | 18 +++++-
src/sanlock_internal.h | 2
4 files changed, 160 insertions(+), 30 deletions(-)
New commits:
commit f74858fbe8aa50240f0267d5c503fdf7a7eab31c
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 12 16:39:57 2011 -0500
sanlock: read_id and live_id commands
sanlock direct read_id -- read and print the state of a host_id
sanlock direct live_id -- monitor and print the liveness of a host_id
diff --git a/src/direct.c b/src/direct.c
index 6bd10e7..c7aeeed 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -131,27 +131,28 @@ int sanlock_direct_release(void)
return do_paxos_action();
}
-static int do_delta_action(void)
+static int do_delta_action(int action, struct sanlk_lockspace *ls,
+ struct leader_record *leader_ret)
{
struct leader_record leader;
struct sync_disk sd;
struct space space;
int rv;
- if (!com.lockspace.name[0])
+ if (!ls->name[0])
return -1;
- if (!com.lockspace.host_id_disk.path[0])
+ if (!ls->host_id_disk.path[0])
return -1;
- if (!com.lockspace.host_id)
+ if (!ls->host_id)
return -1;
/* for log_space in delta functions */
memset(&space, 0, sizeof(space));
memset(&sd, 0, sizeof(struct sync_disk));
- memcpy(&sd, &com.lockspace.host_id_disk, sizeof(struct sanlk_disk));
+ memcpy(&sd, &ls->host_id_disk, sizeof(struct sanlk_disk));
rv = open_disks(&sd, 1);
if (rv != 1) {
@@ -159,35 +160,47 @@ static int do_delta_action(void)
return -1;
}
- switch (com.action) {
+ switch (action) {
case ACT_ACQUIRE_ID:
rv = delta_lease_acquire(&space, &sd,
- com.lockspace.name,
- com.lockspace.host_id,
- com.lockspace.host_id,
+ ls->name,
+ ls->host_id,
+ ls->host_id,
&leader);
break;
case ACT_RENEW_ID:
rv = delta_lease_renew(&space, &sd,
- com.lockspace.name,
- com.lockspace.host_id,
- com.lockspace.host_id,
+ ls->name,
+ ls->host_id,
+ ls->host_id,
&leader);
break;
case ACT_RELEASE_ID:
rv = delta_lease_leader_read(&sd,
- com.lockspace.name,
- com.lockspace.host_id,
+ ls->name,
+ ls->host_id,
&leader);
if (rv < 0)
return rv;
rv = delta_lease_release(&space, &sd,
- com.lockspace.name,
- com.lockspace.host_id,
+ ls->name,
+ ls->host_id,
&leader, &leader);
break;
+ case ACT_READ_ID:
+ rv = delta_lease_leader_read(&sd,
+ ls->name,
+ ls->host_id,
+ &leader);
+ break;
}
+ if (rv == DP_OK)
+ rv = 0;
+
+ if (leader_ret)
+ memcpy(leader_ret, &leader, sizeof(struct leader_record));
+
return rv;
}
@@ -198,19 +211,89 @@ static int do_delta_action(void)
* sanlock client add_lockspace|rem_lockspace -s LOCKSPACE
*/
-int sanlock_direct_acquire_id(void)
+int sanlock_direct_acquire_id(struct sanlk_lockspace *ls)
+{
+ return do_delta_action(ACT_ACQUIRE_ID, ls, NULL);
+}
+
+int sanlock_direct_release_id(struct sanlk_lockspace *ls)
+{
+ return do_delta_action(ACT_RELEASE_ID, ls, NULL);
+}
+
+int sanlock_direct_renew_id(struct sanlk_lockspace *ls)
{
- return do_delta_action();
+ return do_delta_action(ACT_RENEW_ID, ls, NULL);
}
-int sanlock_direct_release_id(void)
+int sanlock_direct_read_id(struct sanlk_lockspace *ls,
+ uint64_t *timestamp,
+ uint64_t *owner_id,
+ uint64_t *owner_generation)
{
- return do_delta_action();
+ struct leader_record leader;
+ int rv;
+
+ memset(&leader, 0, sizeof(struct leader_record));
+
+ rv = do_delta_action(ACT_READ_ID, ls, &leader);
+
+ *timestamp = leader.timestamp;
+ *owner_id = leader.owner_id;
+ *owner_generation = leader.owner_generation;
+
+ return rv;
}
-int sanlock_direct_renew_id(void)
+int sanlock_direct_live_id(struct sanlk_lockspace *ls,
+ uint64_t *timestamp,
+ uint64_t *owner_id,
+ uint64_t *owner_generation,
+ int *live)
{
- return do_delta_action();
+ struct leader_record leader_begin;
+ struct leader_record leader;
+ time_t start;
+ int rv;
+
+ rv = do_delta_action(ACT_READ_ID, ls, &leader_begin);
+ if (rv < 0)
+ return rv;
+
+ start = time(NULL);
+
+ while (1) {
+ sleep(1);
+
+ rv = do_delta_action(ACT_READ_ID, ls, &leader);
+ if (rv < 0)
+ return rv;
+
+ if (leader.timestamp != leader_begin.timestamp) {
+ *live = 1;
+ break;
+ }
+
+ if (leader.owner_id != leader_begin.owner_id) {
+ *live = 2;
+ break;
+ }
+
+ if (leader.owner_generation != leader_begin.owner_generation) {
+ *live = 3;
+ break;
+ }
+
+ if (time(NULL) - start > to.host_id_timeout_seconds) {
+ *live = 0;
+ break;
+ }
+ }
+
+ *timestamp = leader.timestamp;
+ *owner_id = leader.owner_id;
+ *owner_generation = leader.owner_generation;
+ return 0;
}
/*
diff --git a/src/main.c b/src/main.c
index 3063dc6..f40fbef 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2211,6 +2211,8 @@ static void print_usage(void)
printf(" acquire_id acquire a host_id lease\n");
printf(" release_id release a host_id lease\n");
printf(" renew_id renew a host_id lease\n");
+ printf(" read_id read a host_id lease, print the state\n");
+ printf(" live_id monitor a host_id lease for liveness\n");
printf("\n");
printf("daemon\n");
printf(" -D debug: no fork and print all logging to stderr\n");
@@ -2274,7 +2276,7 @@ static void print_usage(void)
printf(" -i <num> host_id of local host\n");
printf(" -g <num> host_id generation of local host\n");
printf("\n");
- printf("direct acquire_id|renew_id|release_id -s LOCKSPACE\n");
+ printf("direct acquire_id|renew_id|release_id|read_id|live_id -s LOCKSPACE\n");
printf(" -a <num> use async io (1 yes, 0 no)\n");
printf("\n");
@@ -2384,6 +2386,10 @@ static int read_command_line(int argc, char *argv[])
com.action = ACT_RELEASE_ID;
else if (!strcmp(act, "renew_id"))
com.action = ACT_RENEW_ID;
+ else if (!strcmp(act, "read_id"))
+ com.action = ACT_READ_ID;
+ else if (!strcmp(act, "live_id"))
+ com.action = ACT_LIVE_ID;
else {
log_tool("direct action \"%s\" is unknown", act);
exit(EXIT_FAILURE);
@@ -2651,6 +2657,8 @@ static int do_client(void)
static int do_direct(void)
{
+ uint64_t timestamp, owner_id, owner_generation;
+ int live;
int rv;
switch (com.action) {
@@ -2671,15 +2679,42 @@ static int do_direct(void)
break;
case ACT_ACQUIRE_ID:
- rv = sanlock_direct_acquire_id();
+ rv = sanlock_direct_acquire_id(&com.lockspace);
break;
case ACT_RELEASE_ID:
- rv = sanlock_direct_release_id();
+ rv = sanlock_direct_release_id(&com.lockspace);
break;
case ACT_RENEW_ID:
- rv = sanlock_direct_renew_id();
+ rv = sanlock_direct_renew_id(&com.lockspace);
+ break;
+
+ case ACT_READ_ID:
+ rv = sanlock_direct_read_id(&com.lockspace,
+ ×tamp,
+ &owner_id,
+ &owner_generation);
+
+ log_tool("result %d timestamp %llu owner_id %llu owner_generation %llu",
+ rv,
+ (unsigned long long)timestamp,
+ (unsigned long long)owner_id,
+ (unsigned long long)owner_generation);
+ break;
+
+ case ACT_LIVE_ID:
+ rv = sanlock_direct_live_id(&com.lockspace,
+ ×tamp,
+ &owner_id,
+ &owner_generation,
+ &live);
+
+ log_tool("result %d live %d timestamp %llu owner_id %llu owner_generation %llu",
+ rv, live,
+ (unsigned long long)timestamp,
+ (unsigned long long)owner_id,
+ (unsigned long long)owner_generation);
break;
default:
diff --git a/src/sanlock_direct.h b/src/sanlock_direct.h
index d14c19c..e997216 100644
--- a/src/sanlock_direct.h
+++ b/src/sanlock_direct.h
@@ -13,9 +13,19 @@ int sanlock_direct_init(void);
int sanlock_direct_dump(void);
int sanlock_direct_acquire(void);
int sanlock_direct_release(void);
-int sanlock_direct_migrate(void);
-int sanlock_direct_acquire_id(void);
-int sanlock_direct_release_id(void);
-int sanlock_direct_renew_id(void);
+int sanlock_direct_acquire_id(struct sanlk_lockspace *ls);
+int sanlock_direct_release_id(struct sanlk_lockspace *ls);
+int sanlock_direct_renew_id(struct sanlk_lockspace *ls);
+
+int sanlock_direct_read_id(struct sanlk_lockspace *ls,
+ uint64_t *timestamp,
+ uint64_t *owner_id,
+ uint64_t *owner_generation);
+
+int sanlock_direct_live_id(struct sanlk_lockspace *ls,
+ uint64_t *timestamp,
+ uint64_t *owner_id,
+ uint64_t *owner_generation,
+ int *live);
#endif
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 0fa14e5..88cabe1 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -308,6 +308,8 @@ enum {
ACT_ACQUIRE_ID,
ACT_RELEASE_ID,
ACT_RENEW_ID,
+ ACT_READ_ID,
+ ACT_LIVE_ID,
ACT_INIT,
ACT_DUMP,
};
12 years, 7 months
2 commits - python/Makefile python/python-sync_manager.spec.in python/sanlock.c python/setup.py python/syncManager.py
by David Teigland
python/Makefile | 26 ++---
python/python-sync_manager.spec.in | 52 ----------
python/sanlock.c | 180 +++++++++++++++++++++++++++++++++++++
python/setup.py | 19 ++-
python/syncManager.py | 111 ----------------------
5 files changed, 204 insertions(+), 184 deletions(-)
New commits:
commit 9924949c58a35e685b7cdf3a5c5063c7886e94fe
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Tue Apr 12 19:37:18 2011 +0100
python: add python binding
diff --git a/python/Makefile b/python/Makefile
new file mode 100644
index 0000000..e48a72d
--- /dev/null
+++ b/python/Makefile
@@ -0,0 +1,12 @@
+# Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+
+all:
+ python setup.py build
+
+clean:
+ rm -rf build
+
diff --git a/python/sanlock.c b/python/sanlock.c
new file mode 100644
index 0000000..7e6f46f
--- /dev/null
+++ b/python/sanlock.c
@@ -0,0 +1,180 @@
+/*
+ * Copyright (C) 2011 Red Hat, Inc. All rights reserved.
+ *
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU General Public License v.2.
+ */
+
+#include <Python.h>
+#include <sanlock.h>
+#include <sanlock_resource.h>
+#include <sanlock_admin.h>
+
+int __sanlock_fd = -1;
+PyObject *py_module;
+
+/* SANLock exception */
+static PyObject *sanlock_exception;
+
+static PyObject *
+py_register(PyObject *self, PyObject *args)
+{
+ __sanlock_fd = sanlock_register();
+
+ if (__sanlock_fd < 0) {
+ PyErr_SetString(sanlock_exception, "SANLock registration failed");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static int
+__parse_lockspace(PyObject *args, struct sanlk_lockspace *ret_ls)
+{
+ char *lockspace;
+
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &lockspace)) {
+ return -1;
+ }
+
+ /* convert lockspace string to structure */
+ if (sanlock_str_to_lockspace(lockspace, ret_ls) != 0) {
+ PyErr_SetString(sanlock_exception, "Invalid sanlock resource");
+ return -1;
+ }
+
+ return 0;
+}
+
+static PyObject *
+py_add_lockspace(PyObject *self, PyObject *args)
+{
+ struct sanlk_lockspace ls;
+
+ if (__parse_lockspace(args, &ls) != 0) {
+ return NULL;
+ }
+
+ /* add sanlock lockspace */
+ if (sanlock_add_lockspace(&ls, 0 ) != 0) {
+ PyErr_SetString(sanlock_exception, "SANLock lockspace add failure");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+py_rem_lockspace(PyObject *self, PyObject *args)
+{
+ struct sanlk_lockspace ls;
+
+ if (__parse_lockspace(args, &ls) != 0) {
+ return NULL;
+ }
+
+ /* remove sanlock lockspace */
+ if (sanlock_rem_lockspace(&ls, 0 ) != 0) {
+ PyErr_SetString(sanlock_exception, "SANLock lockspace remove failure");
+ return NULL;
+ }
+
+ Py_RETURN_NONE;
+}
+
+static int
+__parse_resource(PyObject *args, struct sanlk_resource **ret_res)
+{
+ char *resource;
+
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &resource)) {
+ return -1;
+ }
+
+ /* convert resource string to structure */
+ if (sanlock_str_to_res(resource, ret_res) != 0) {
+ PyErr_SetString(sanlock_exception, "Invalid sanlock resource");
+ return -1;
+ }
+
+ return 0;
+}
+
+static PyObject *
+py_acquire(PyObject *self, PyObject *args)
+{
+ struct sanlk_resource *res;
+
+ if (__parse_resource(args, &res) != 0) {
+ return NULL;
+ }
+
+ /* acquire resource */
+ if (sanlock_acquire(__sanlock_fd, -1, 0, 1, &res, 0) != 0) {
+ PyErr_SetString(sanlock_exception, "SANLock resource not acquired");
+ goto exit_fail;
+ }
+
+ free(res);
+ Py_RETURN_NONE;
+
+exit_fail:
+ free(res);
+ return NULL;
+}
+
+static PyObject *
+py_release(PyObject *self, PyObject *args)
+{
+ struct sanlk_resource *res;
+
+ if (__parse_resource(args, &res) != 0) {
+ return NULL;
+ }
+
+ /* release resource */
+ if (sanlock_release(__sanlock_fd, -1, 0, 1, &res) != 0) {
+ PyErr_SetString(sanlock_exception, "SANLock resource not released");
+ goto exit_fail;
+ }
+
+ free(res);
+ Py_RETURN_NONE;
+
+exit_fail:
+ free(res);
+ return NULL;
+}
+
+static PyMethodDef
+sanlock_methods[] = {
+ {"register", py_register, METH_NOARGS, "Register to sanlock daemon."},
+ {"add_lockspace", py_add_lockspace, METH_VARARGS,
+ "Add a lockspace, acquiring a host_id in it."},
+ {"rem_lockspace", py_rem_lockspace, METH_VARARGS,
+ "Remove a lockspace, releasing our host_id in it."},
+ {"acquire", py_acquire, METH_VARARGS,
+ "Acquire leases for the current process."},
+ {"release", py_release, METH_VARARGS,
+ "Release leases for the current process."},
+ {NULL, NULL, 0, NULL}
+};
+
+PyMODINIT_FUNC
+initsanlock(void)
+{
+ py_module = Py_InitModule("sanlock", sanlock_methods);
+
+ /* Python's module loader doesn't support clean recovery from errors */
+ if (py_module == NULL)
+ return;
+
+ /* Initializing sanlock exception */
+ sanlock_exception = PyErr_NewException("sanlock.exception", NULL, NULL);
+ Py_INCREF(sanlock_exception);
+ PyModule_AddObject(py_module, "exception", sanlock_exception);
+}
diff --git a/python/setup.py b/python/setup.py
new file mode 100644
index 0000000..acf3810
--- /dev/null
+++ b/python/setup.py
@@ -0,0 +1,14 @@
+# Copyright (C) 2010-2011 Red Hat, Inc. All rights reserved.
+#
+# This copyrighted material is made available to anyone wishing to use,
+# modify, copy, or redistribute it subject to the terms and conditions
+# of the GNU General Public License v.2.
+
+from distutils.core import setup, Extension
+
+module1 = Extension('sanlock', sources=['sanlock.c'], libraries=['sanlock'])
+
+setup(name = 'SANLock',
+ version = '1.0',
+ description = 'SANLock python package',
+ ext_modules = [module1])
commit bee107aa3b690158767d37ec079d754ccff63ac9
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Tue Apr 12 19:37:17 2011 +0100
python: remove unused python code
diff --git a/python/Makefile b/python/Makefile
deleted file mode 100644
index 3f1f49c..0000000
--- a/python/Makefile
+++ /dev/null
@@ -1,18 +0,0 @@
-
-INSTALL=$(shell which install)
-RPMTOP=$(shell bash -c "pwd -P")/rpmbuild
-rpmversion:=0.1
-rpmrelease:=1.$(shell date +%Y%m%d)git
-TARBALL=python-sync-manger-$(rpmversion)-$(rpmrelease).tar.gz
-
-rpm:
- rm -rf $(RPMTOP)
- mkdir $(RPMTOP)
- mkdir $(RPMTOP)/BUILD $(RPMTOP)/BUILDROOT $(RPMTOP)/RPMS $(RPMTOP)/SOURCES $(RPMTOP)/SPECS $(RPMTOP)/SRPMS
- tar zcf $(TARBALL) `git ls-files`
- mv $(TARBALL) $(RPMTOP)/SOURCES
- sed 's/^Version:.*/Version: $(rpmversion)/;s/^Release:.*/Release: $(rpmrelease)%{?dist}/;s/^Source0:.*/Source0: $(TARBALL)/' \
- python-sync_manager.spec.in > python-sync_manager.spec
- rpmbuild -v -ba --define="_topdir $(RPMTOP)" \
- --define="_sourcedir $(RPMTOP)/SOURCES" \
- ./python-sync_manager.spec
diff --git a/python/python-sync_manager.spec.in b/python/python-sync_manager.spec.in
deleted file mode 100644
index f05b91f..0000000
--- a/python/python-sync_manager.spec.in
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-Name: python-sync-manager
-Version: 0.1
-Release: 1.19700101git%{?dist}
-Summary: Python bindings for sync-manager
-
-Group: Development/Tools
-License: GPLv2+
-URL: http://http://cleopatra.tlv.redhat.com/qumrawiki/Sync%20Manager
-Source0: %{name}-%{version}.tar.gz
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}
-
-BuildRequires: python-devel
-Requires: python >= 2.6
-Requires: sync-manager = %{version}-%{release}
-
-%description
-Sync Manager is a program to manage disk paxos based leases.
-It helps synchronizing access to shared resource in a distributed system.
-This is the python bindings for it.
-
-%prep
-%setup -q -c
-
-%build
-FLAGS="$RPM_OPT_FLAGS" %{__python} setup.py build
-
-%install
-rm -rf $RPM_BUILD_ROOT
-%{__python} setup.py install -O1 --skip-build --root $RPM_BUILD_ROOT
-
-
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-
-%files
-%define egg_name %(echo %{name} | sed "s/-/_/g")
-
-%defattr(-,root,root,-)
-%{python_sitelib}/syncManager.py
-%{python_sitelib}/syncManager.pyc
-%{python_sitelib}/syncManager.pyo
-%{python_sitelib}/%{egg_name}-%{version}-py?.?.egg-info
-
-%doc
-
-
-
-%changelog
-
diff --git a/python/setup.py b/python/setup.py
deleted file mode 100644
index 1fb9bce..0000000
--- a/python/setup.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from distutils.core import setup
-setup(name='python-sync-manager',
- version='0.1',
- py_modules=['syncManager'],
- )
diff --git a/python/syncManager.py b/python/syncManager.py
deleted file mode 100644
index e0080ea..0000000
--- a/python/syncManager.py
+++ /dev/null
@@ -1,111 +0,0 @@
-import subprocess
-import SocketServer
-import os
-import sys
-import logging
-from select import select
-from StringIO import StringIO
-
-SYNCMANAGER_PATH = "/usr/libexec/sync_manager"
-
-class SyncManagerException(Exception):
- def __init__(self, msg, errno, stdout, stderr):
- Exception.__init__(self, msg)
- self.errno = errno
- self.stdout = stdout
- self.stderr = stderr
-
-class SyncManager(object):
- _log = logging.getLogger("SyncManager");
- def __init__(self, name):
- self.name = name
- self.syncManagerPath = SYNCMANAGER_PATH
-
- def initStorage(self, leases, numberOfHosts, maximumNumberOfHosts = None):
- self._log.debug("Initializing leases on '%s'", leases)
- numberOfHosts = int(numberOfHosts)
- args = ["-n", self.name, "-h", str(numberOfHosts)]
-
- if not maximumNumberOfHosts is None:
- args.extend(["-H", str(maximumNumberOfHosts)])
-
- args.extend(self._compileLeaseArgs(leases))
- self._runTool("init", args)
-
- def acquireLeases(self, leases):
- args = ["-n", self.name]
-
- args.extend(self._compileLeaseArgs(leases))
- self._runTool("acquire", args)
-
- def setHostID(self, hostID):
- args = ["-n", self.name, "-i", str(hostID)]
- self._runTool("set_host_id", args)
-
- def releaseLeases(self, resources):
- args = ["-n", self.name]
-
- for resource in resources:
- args.extend(["-r", resource])
-
- self._runTool("release", args)
-
- def _compileLeaseArgs(self, leases):
- args = []
- for lease, disks in leases:
- mangledDisks = ["%s:%d" % (os.path.abspath(disk).replace("\\", "\\\\").replace(":", "\\:"), offset) for (disk, offset) in disks]
- args.extend(["-l", "%s:%s" % (lease, ":".join(mangledDisks))])
-
- return args
-
- def _runToolAsync(self, command, args):
- cmd = [self.syncManagerPath] + [command, "-D"] + args
- self._log.debug("Running syncmanager CMD:'%s'", subprocess.list2cmdline(cmd))
- mngr = subprocess.Popen(cmd,
- stdin = subprocess.PIPE,
- stdout = subprocess.PIPE,
- stderr = subprocess.PIPE
- )
- return mngr
-
- def _runTool(self, command, args):
- mngr = self._runToolAsync(command, args)
- stdout = StringIO()
- stderr = StringIO()
- empty = False
- while (mngr.poll() is None) or (not empty):
- readyObjects = select([mngr.stdout, mngr.stderr], [], [], 1)[0]
- for obj in readyObjects:
- line = obj.readline().replace("\n", "")
- if line == "":
- empty = True
- continue
- if obj is mngr.stdout:
- stdout.write(line)
- stdout.write("\n")
- else:
- stderr.write(line)
- stderr.write("\n")
-
- empty = False
-
- self._log.debug("synctool - %s" % line)
-
- rc = mngr.returncode
- stdout.seek(0)
- stderr.seek(0)
- stdout = stdout.read()
- stderr = stderr.read()
- if rc != 0:
- cmd = ["sync_manager", command] + args;
- cmd = subprocess.list2cmdline(cmd)
-
- raise SyncManagerException("SyncManager failed (CMD:%s) (RC:%d) (OUT:%s) (ERR:%s)" %
- (cmd, rc, stdout, stderr),
- errno = rc,
- stdout = stdout,
- stderr = stderr)
-
-
- return (stdout, stderr)
-
12 years, 7 months
2 commits - tests/devcount.c
by David Teigland
tests/devcount.c | 247 +++++++++++++++++++++----------------------------------
1 file changed, 98 insertions(+), 149 deletions(-)
New commits:
commit bb627701c28e00a0c710e50aed1fd52f94daf733
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 12 13:40:57 2011 -0500
devcount: new migrate test
dest forks (e.g. libvirtd creates qemu pid)
dest child does sanlock_register, waits for parent (e.g. qemu incoming paused)
source parent does sanlock_inquire
source parent sigstop child, sanlock_release, writes state to disk
dest parent reads state from disk, sanlock_acquire(child_pid, state.lver)
dest parent tells child to run (e.g. qemu incoming resumed)
dest child execs rw
source parent sigkill child
diff --git a/tests/devcount.c b/tests/devcount.c
index f050f44..c4f83cd 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -706,13 +706,14 @@ static int do_wrap(int argc, char *argv[])
exit(EXIT_FAILURE);
}
-
/*
- * dest forks (libvirtd creates qemu pid)
+ * Test migration sequence (source inquires/releases, dest acquires lver)
+ *
+ * dest forks (e.g. libvirtd creates qemu pid)
* dest child does sanlock_register, waits for parent (e.g. qemu incoming paused)
- * dest parent (libvirtd) reads state from disk, waits for source...
- * source parent sigstop child, sanlock_release, writes flag to disk
- * dest parent reads flag from disk, sanlock_acquire(child_pid, lver)
+ * source parent does sanlock_inquire
+ * source parent sigstop child, sanlock_release, writes state to disk
+ * dest parent reads state from disk, sanlock_acquire(child_pid, state.lver)
* dest parent tells child to run (e.g. qemu incoming resumed)
* dest child execs rw
* source parent sigkill child
@@ -771,8 +772,8 @@ static void write_migrate_incoming(char *state_in)
goto fail;
}
- printf("write state \"%s\"\n", wbuf);
-
+ /* printf("write_migrate_incoming \"%s\"\n", wbuf); */
+
close(fd);
return;
@@ -830,6 +831,7 @@ static int wait_migrate_incoming(uint64_t *lver)
/* init case to get things going */
if (!rbuf[0] && our_hostid == 1) {
+ *lver = 0;
return 1;
}
@@ -844,10 +846,12 @@ static int wait_migrate_incoming(uint64_t *lver)
}
val = atoi(val_str);
- if ((val % max_hostid)+1 != our_hostid) {
+ if (val != our_hostid) {
goto retry;
}
+ /* printf("wait_migrate_incoming \"%s\"\n", rbuf); */
+
*target_str = '\0';
rv = sanlock_str_to_res(rbuf, &res);
@@ -887,6 +891,7 @@ static int do_migrate(int argc, char *argv[])
struct sanlk_lockspace lockspace;
struct sanlk_resource *res;
int i, j, pid, rv, sock, len, status, init;
+ int pfd[2];
int res_count;
uint32_t parent_pid = getpid();
uint64_t lver;
@@ -948,9 +953,11 @@ static int do_migrate(int argc, char *argv[])
av[j] = NULL;
while (1) {
+ pipe(pfd);
pid = fork();
if (!pid) {
int child_pid = getpid();
+ char junk;
printf("\n");
@@ -962,7 +969,11 @@ static int do_migrate(int argc, char *argv[])
}
printf("%d pause\n", child_pid);
- pause(); /* pause child until parent resumes */
+
+ read(pfd[0], &junk, 1);
+ close(pfd[0]);
+ close(pfd[1]);
+
printf("%d resume\n", child_pid);
execv(av[0], av);
@@ -988,7 +999,10 @@ static int do_migrate(int argc, char *argv[])
printf("%d sanlock_acquire done init %d lver %llu\n", parent_pid,
init, (unsigned long long)lver);
- kill(pid, SIGCONT); /* resume child */
+ /* tell child to resume */
+ write(pfd[1], "\n", 1);
+ close(pfd[0]);
+ close(pfd[1]);
/* let the child run for 10 seconds before stopping it;
if the child exits before the 10 seconds, the sanlock_inquire
@@ -1024,6 +1038,7 @@ static int do_migrate(int argc, char *argv[])
fail:
printf("test failed...\n");
sleep(10000000);
+ return -1;
}
/*
commit ebef48cd1961aabc3a86360a555a63f3791266ba
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 12 11:37:27 2011 -0500
WIP devcount migrate
diff --git a/tests/devcount.c b/tests/devcount.c
index 0e7902c..f050f44 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -706,15 +706,34 @@ static int do_wrap(int argc, char *argv[])
exit(EXIT_FAILURE);
}
-#if 0
-/* counting block: count_path offset 0
- * incoming block: count_path offset 4K
- * stopped block: count_path offset 8K */
-static void write_migrate(char *state, int offset)
+/*
+ * dest forks (libvirtd creates qemu pid)
+ * dest child does sanlock_register, waits for parent (e.g. qemu incoming paused)
+ * dest parent (libvirtd) reads state from disk, waits for source...
+ * source parent sigstop child, sanlock_release, writes flag to disk
+ * dest parent reads flag from disk, sanlock_acquire(child_pid, lver)
+ * dest parent tells child to run (e.g. qemu incoming resumed)
+ * dest child execs rw
+ * source parent sigkill child
+ */
+
+static void write_migrate_incoming(char *state_in)
{
+ char target_str[32];
+ char state[1024];
char *wbuf, **p_wbuf;
int fd, rv;
+ int offset = 4096;
+ int target;
+
+ target = (our_hostid % max_hostid) + 1;
+
+ memset(state, 0, sizeof(state));
+ memset(target_str, 0, sizeof(target_str));
+ sprintf(target_str, " target=%d", target);
+ strcat(state, state_in);
+ strcat(state, target_str);
if (strlen(state) > 512) {
printf("state string too long\n");
@@ -752,6 +771,8 @@ static void write_migrate(char *state, int offset)
goto fail;
}
+ printf("write state \"%s\"\n", wbuf);
+
close(fd);
return;
@@ -760,22 +781,13 @@ static void write_migrate(char *state, int offset)
sleep(10000000);
}
-static void write_migrate_incoming(char *state)
-{
- write_migrate(state, 4096);
-}
-
-static void write_migrate_stopped(char *state)
-{
- write_migrate(state, 4096*2);
-}
-
/* read incoming block until it's set and our_hostid is next */
-static int wait_migrate_incoming(char *state_out)
+static int wait_migrate_incoming(uint64_t *lver)
{
+ struct sanlk_resource *res;
char *rbuf, **p_rbuf, *wbuf, **p_wbuf;
- char *owner_id, *val_str;
+ char *target_str, *val_str;
int fd, rv, val;
int offset = 4096;
@@ -821,12 +833,12 @@ static int wait_migrate_incoming(char *state_out)
return 1;
}
- owner_id = strstr(rbuf, "leader.owner_id=");
- if (!owner_id) {
+ target_str = strstr(rbuf, " target=");
+ if (!target_str) {
goto retry;
}
- val_str = strstr(owner_id, "=") + 1;
+ val_str = strstr(target_str, "=") + 1;
if (!val_str) {
goto retry;
}
@@ -836,78 +848,19 @@ static int wait_migrate_incoming(char *state_out)
goto retry;
}
- strcpy(state_out, rbuf);
-
- memset(wbuf, 0, 512);
- strcpy(wbuf, "empty");
-
- lseek(fd, offset, SEEK_SET);
-
- rv = write(fd, wbuf, 512);
- if (rv != 512) {
- perror("write failed");
- goto fail;
- }
-
- close(fd);
- return 0;
-
- fail:
- printf("wait_migrate_incoming failed %s\n", state_out);
- sleep(10000000);
-}
-
-/* read stopped block until it matches state_in */
-
-static void wait_migrate_stopped(char *state_in)
-{
- char *rbuf, **p_rbuf, *wbuf, **p_wbuf;
- int fd, rv;
- int offset = 4096 * 2;
-
- fd = open(count_path, O_RDWR | O_DIRECT | O_SYNC, 0);
- if (fd < 0) {
- perror("open failed");
- goto fail;
- }
-
- rv = ioctl(fd, BLKFLSBUF);
- if (rv) {
- perror("BLKFLSBUF failed");
- goto fail;
- }
-
- p_rbuf = &rbuf;
- p_wbuf = &wbuf;
+ *target_str = '\0';
- rv = posix_memalign((void *)p_rbuf, getpagesize(), 512);
- if (rv) {
- perror("posix_memalign failed");
- goto fail;
- }
-
- rv = posix_memalign((void *)p_wbuf, getpagesize(), 512);
- if (rv) {
- perror("posix_memalign failed");
- goto fail;
- }
-
- retry:
- lseek(fd, offset, SEEK_SET);
-
- rv = read(fd, rbuf, 512);
- if (rv != 512) {
- perror("read failed");
+ rv = sanlock_str_to_res(rbuf, &res);
+ if (rv < 0) {
+ printf("str_to_res error %d\n", rv);
goto fail;
}
- rbuf[511] = '\0';
-
- if (strcmp(rbuf, state_in)) {
- sleep(1);
- goto retry;
- }
+ *lver = res->lver;
+ free(res);
+ /* strcpy(state_out, rbuf); */
memset(wbuf, 0, 512);
+ sprintf(wbuf, "%s", "empty");
lseek(fd, offset, SEEK_SET);
@@ -918,25 +871,26 @@ static void wait_migrate_stopped(char *state_in)
}
close(fd);
- return;
+ return 0;
fail:
- printf("wait_migrate_stopped failed %s\n", state_in);
+ printf("wait_migrate_incoming failed\n");
sleep(10000000);
+ return -1;
}
#define MAX_MIGRATE_STATE 512 /* keep in one block for simplicity */
static int do_migrate(int argc, char *argv[])
{
- char incoming[MAX_MIGRATE_STATE];
char *av[MIGRATE_ARGS+1];
- char *state;
struct sanlk_lockspace lockspace;
struct sanlk_resource *res;
- struct sanlk_options *opt;
- int i, j, pid, rv, sock, len, status, init, target;
+ int i, j, pid, rv, sock, len, status, init;
+ int res_count;
uint32_t parent_pid = getpid();
+ uint64_t lver;
+ char *state;
if (argc < MIGRATE_ARGS)
return -1;
@@ -959,11 +913,7 @@ static int do_migrate(int argc, char *argv[])
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
res->disks[0].offset = 1024000;
- len = sizeof(struct sanlk_options) + MAX_MIGRATE_STATE;
- opt = malloc(len);
- memset(opt, 0, len);
-
- printf("%d lock_disk %s count_disk %s our_hostid %d max_hostid\n",
+ printf("%d lock_disk %s count_disk %s our_hostid %d max_hostid %d\n",
parent_pid, lock_path, count_path, our_hostid, max_hostid);
memset(&lockspace, 0, sizeof(lockspace));
@@ -992,29 +942,18 @@ static int do_migrate(int argc, char *argv[])
*/
j = 0;
- memset(av, 0, sizeof(char *) * MIGRATE_ARGS+1);
-
av[j++] = strdup(argv[0]);
for (i = 3; i < MIGRATE_ARGS; i++)
av[j++] = strdup(argv[i]);
-
- memset(incoming, 0, sizeof(incoming));
+ av[j] = NULL;
while (1) {
- init = wait_migrate_incoming(incoming);
-
pid = fork();
if (!pid) {
int child_pid = getpid();
printf("\n");
- if (!init) {
- opt->flags = SANLK_FLG_INCOMING;
- opt->len = strlen(incoming);
- strncpy(opt->str, incoming, MAX_MIGRATE_STATE);
- }
-
sock = sanlock_register();
if (sock < 0) {
printf("%d sanlock_register error %d\n",
@@ -1022,73 +961,70 @@ static int do_migrate(int argc, char *argv[])
exit(-1);
}
- rv = sanlock_acquire(sock, -1, 1, &res, opt);
- if (rv < 0) {
- printf("%d sanlock_acquire error %d in %s\n",
- child_pid, rv, opt->str);
- /* only one host should be trying to acquire
- so this should always succeed */
- exit(-1);
- }
- printf("%d sanlock_acquire done\n", child_pid);
-
- if (init)
- goto skip_setowner;
+ printf("%d pause\n", child_pid);
+ pause(); /* pause child until parent resumes */
+ printf("%d resume\n", child_pid);
- wait_migrate_stopped(incoming);
-
- rv = sanlock_setowner(sock, -1);
- if (rv < 0) {
- printf("%d sanlock_setowner error %d\n",
- child_pid, rv);
- exit(-1);
- }
- printf("%d sanlock_setowner done\n", child_pid);
- skip_setowner:
execv(av[0], av);
perror("execv devcount problem");
exit(EXIT_FAILURE);
}
+ init = wait_migrate_incoming(&lver); /* from source */
+
+ if (init) {
+ res->flags = 0;
+ res->lver = 0;
+ } else {
+ res->flags = SANLK_RES_LVER;
+ res->lver = lver;
+ }
+
+ rv = sanlock_acquire(-1, pid, 0, 1, &res, NULL);
+ if (rv < 0) {
+ printf("%d sanlock_acquire error %d\n", parent_pid, rv);
+ exit(0);
+ }
+ printf("%d sanlock_acquire done init %d lver %llu\n", parent_pid,
+ init, (unsigned long long)lver);
+
+ kill(pid, SIGCONT); /* resume child */
+
/* let the child run for 10 seconds before stopping it;
- if the child exits before the 10 seconds, the sanlock_migrate
+ if the child exits before the 10 seconds, the sanlock_inquire
call should return an error */
sleep(10);
- /* exercise both migrate options: giving target on host or not */
-
- if (rand_int(1,3) == 1)
- target = (our_hostid % max_hostid) + 1;
- else
- target = 0;
-
- rv = sanlock_migrate(-1, pid, target, &state);
- if (rv < 0 || !state) {
- printf("%d sanlock_migrate error %d\n", parent_pid, rv);
+ rv = sanlock_inquire(-1, pid, 0, &res_count, &state);
+ if (rv < 0) {
+ printf("sanlock_inquire error %d\n", rv);
goto fail;
}
-
- write_migrate_incoming(state);
+ printf("%d sanlock_inquire done\n", parent_pid);
kill(pid, SIGSTOP);
- write_migrate_stopped(state);
+ rv = sanlock_release(-1, pid, SANLK_REL_ALL, 0, NULL);
+ if (rv < 0) {
+ printf("sanlock_release error %d\n", rv);
+ goto fail;
+ }
+ printf("%d sanlock_release done\n", parent_pid);
+
+ write_migrate_incoming(state); /* to dest */
kill(pid, SIGKILL);
waitpid(pid, &status, 0);
free(state);
-
- /* TODO: goto fail if exit status is an error */
}
fail:
printf("test failed...\n");
sleep(10000000);
}
-#endif
/*
* devcount init <lock_disk> <count_disk>
@@ -1165,10 +1101,8 @@ int main(int argc, char *argv[])
else if (!strcmp(argv[1], "relock"))
rv = do_relock(argc, argv);
-#if 0
else if (!strcmp(argv[1], "migrate"))
rv = do_migrate(argc, argv);
-#endif
if (!rv)
return 0;
12 years, 7 months
src/client_resource.c src/main.c src/sanlock_resource.h
by David Teigland
src/client_resource.c | 43 +++++++++++++++++++++++++++++++++++++++++++
src/main.c | 35 +----------------------------------
src/sanlock_resource.h | 6 ++++++
3 files changed, 50 insertions(+), 34 deletions(-)
New commits:
commit b7dfd532299dff2c03c0596f4ed5a50fb02c6484
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 12 11:47:17 2011 -0500
sanlock: add str_to_lockspace to lib
to convert string format to struct sanlk_lockspace
diff --git a/src/client_resource.c b/src/client_resource.c
index 90416d0..5a807e1 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -554,3 +554,46 @@ int sanlock_state_to_args(char *res_state,
return rv;
}
+/*
+ * convert to struct sanlk_lockspace from string with format:
+ * <lockspace_name>:<host_id>:<path>:<offset>
+ */
+
+int sanlock_str_to_lockspace(char *str, struct sanlk_lockspace *ls)
+{
+ char *host_id = NULL;
+ char *path = NULL;
+ char *offset = NULL;
+
+ if (str)
+ host_id = strstr(str, ":");
+ if (host_id)
+ path = strstr(host_id+1, ":");
+ if (host_id && path)
+ offset = strstr(path+1, ":");
+
+ if (host_id) {
+ *host_id = '\0';
+ host_id++;
+ }
+ if (path) {
+ *path = '\0';
+ path++;
+ }
+ if (offset) {
+ *offset= '\0';
+ offset++;
+ }
+
+ if (str)
+ strncpy(ls->name, str, NAME_ID_SIZE);
+ if (host_id)
+ ls->host_id = atoll(host_id);
+ if (path)
+ strncpy(ls->host_id_disk.path, path, SANLK_PATH_LEN-1);
+ if (offset)
+ ls->host_id_disk.offset = atoll(offset);
+
+ return 0;
+}
+
diff --git a/src/main.c b/src/main.c
index 7dbc573..3063dc6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2049,42 +2049,9 @@ static int do_daemon(void)
return rv;
}
-/* arg = <lockspace_name>:<host_id>:<path>:<offset> */
-
static int parse_arg_lockspace(char *arg)
{
- char *host_id = NULL;
- char *path = NULL;
- char *offset = NULL;
-
- if (arg)
- host_id = strstr(arg, ":");
- if (host_id)
- path = strstr(host_id+1, ":");
- if (host_id && path)
- offset = strstr(path+1, ":");
-
- if (host_id) {
- *host_id = '\0';
- host_id++;
- }
- if (path) {
- *path = '\0';
- path++;
- }
- if (offset) {
- *offset= '\0';
- offset++;
- }
-
- if (arg)
- strncpy(com.lockspace.name, arg, NAME_ID_SIZE);
- if (host_id)
- com.lockspace.host_id = atoll(host_id);
- if (path)
- strncpy(com.lockspace.host_id_disk.path, path, SANLK_PATH_LEN-1);
- if (offset)
- com.lockspace.host_id_disk.offset = atoll(offset);
+ sanlock_str_to_lockspace(arg, &com.lockspace);
log_debug("lockspace %s host_id %llu path %s offset %llu",
com.lockspace.name,
diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h
index fe822fc..f41f3e3 100644
--- a/src/sanlock_resource.h
+++ b/src/sanlock_resource.h
@@ -74,5 +74,11 @@ int sanlock_state_to_args(char *res_state,
int *res_count,
struct sanlk_resource ***res_args);
+/*
+ * convert to struct sanlk_lockspace from string with format:
+ * <lockspace_name>:<host_id>:<path>:<offset>
+ */
+
+int sanlock_str_to_lockspace(char *str, struct sanlk_lockspace *ls);
#endif
12 years, 7 months
wdmd/main.c wdmd/Makefile
by David Teigland
wdmd/Makefile | 3 +-
wdmd/main.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 71 insertions(+), 7 deletions(-)
New commits:
commit 5cbc95ea9952f7741440a6e874f171e71f7bafef
Author: David Teigland <teigland(a)redhat.com>
Date: Mon Apr 11 14:49:20 2011 -0500
wdmd: enable test scripts
diff --git a/wdmd/Makefile b/wdmd/Makefile
index 959163a..65d767f 100644
--- a/wdmd/Makefile
+++ b/wdmd/Makefile
@@ -41,7 +41,8 @@ CFLAGS += -D_GNU_SOURCE -g \
-Wp,-D_FORTIFY_SOURCE=2 \
-fexceptions \
-fasynchronous-unwind-tables \
- -fdiagnostics-show-option
+ -fdiagnostics-show-option \
+ -DTEST_SCRIPTS
CMD_LDFLAGS = -lwdmd
TEST_LDFLAGS = -lwdmd
diff --git a/wdmd/main.c b/wdmd/main.c
index f320317..a020b1e 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -23,6 +23,7 @@
#include <signal.h>
#include <sched.h>
#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/un.h>
@@ -84,6 +85,7 @@ static int client_maxi;
static int client_size = 0;
static struct client *client = NULL;
static struct pollfd *pollfd = NULL;
+const char *client_built = " client";
#define log_debug(fmt, args...) \
@@ -377,6 +379,7 @@ static int active_clients(void)
#ifdef TEST_FILES
+const char *files_built = " files";
static DIR *files_dir;
static void close_files(void)
@@ -452,6 +455,7 @@ static int test_files(void)
#else
+const char *files_built = NULL;
static void close_files(void) { }
static int setup_files(void) { return 0; }
static int test_files(void) { return 0; }
@@ -461,6 +465,7 @@ static int test_files(void) { return 0; }
#ifdef TEST_SCRIPTS
static DIR *scripts_dir;
+const char *scripts_built = " scripts";
static void close_scripts(void)
{
@@ -469,10 +474,22 @@ static void close_scripts(void)
static int setup_scripts(void)
{
+ mode_t old_umask;
+ int rv;
+
+ old_umask = umask(0022);
+ rv = mkdir(SCRIPTS_DIR, 0777);
+ if (rv < 0 && errno != EEXIST)
+ goto out;
+
scripts_dir = opendir(SCRIPTS_DIR);
if (!scripts_dir)
- return -1;
- return 0;
+ rv = -errno;
+ else
+ rv = 0;
+ out:
+ umask(old_umask);
+ return rv;
}
static int run_script(char *name, int i)
@@ -480,7 +497,7 @@ static int run_script(char *name, int i)
int pid;
if (i >= MAX_SCRIPTS) {
- log_error("max scripts %d, ignore %s", MAX_SCRIPTS, de->d_name);
+ log_error("max scripts %d, ignore %s", MAX_SCRIPTS, name);
return -1;
}
@@ -491,6 +508,7 @@ static int run_script(char *name, int i)
return -errno;
if (pid) {
+ log_debug("run_script %d %s", pid, name);
scripts[i].pid = pid;
return 0;
} else {
@@ -542,6 +560,9 @@ static int check_script(int i)
}
}
out:
+ log_debug("check_script %d rv %d begin %llu",
+ scripts[i].pid, rv, (unsigned long long)begin);
+
scripts[i].pid = 0;
return rv;
}
@@ -555,7 +576,9 @@ static int test_scripts(void)
memset(scripts, 0, sizeof(scripts));
- while ((de = readdir(script_dir))) {
+ rewinddir(scripts_dir);
+
+ while ((de = readdir(scripts_dir))) {
if (de->d_name[0] == '.')
continue;
@@ -577,6 +600,7 @@ static int test_scripts(void)
#else
+const char *scripts_built = NULL;
static void close_scripts(void) { }
static int setup_scripts(void) { return 0; }
static int test_scripts(void) { return 0; }
@@ -827,6 +851,15 @@ static void setup_priority(void)
}
}
+static void print_usage(void)
+{
+ printf("Usage:\n");
+ printf("wdmd [options]\n\n");
+ printf("version print version\n");
+ printf("help print usage\n");
+ printf("-D debug: no fork and print all logging to stderr\n");
+}
+
/* If wdmd exits abnormally, /dev/watchdog will eventually fire, and clients
can detect wdmd is gone and begin to shut down cleanly ahead of the reset.
But what if wdmd is restarted before the wd fires? It will begin petting
@@ -834,15 +867,40 @@ static void setup_priority(void)
know if this situation is important enough to try to prevent. One way
would be for wdmd to fail starting if it found a pid file left over from
its previous run. */
+
+#define RELEASE_VERSION "1.0"
int main(int argc, char *argv[])
{
int rv;
- /* TODO: real option parsing, including -h 0 */
+ /*
+ * TODO: real option parsing, including
+ * -h <num> use high priority features (1 yes, 0 no, default 1)
+ * -c <num> enable test clients (1 yes, 0 no, default ...)
+ * -s <num> enable test scripts (1 yes, 0 no, default ...)
+ * -f <num> enable test files (1 yes, 0 no, default ...)
+ */
+
+ if ((argc > 1) &&
+ !strcmp(argv[1], "version")) {
+ printf("wdmd version %s tests_built%s%s%s\n", RELEASE_VERSION,
+ scripts_built ? scripts_built : "",
+ client_built ? client_built : "",
+ files_built ? files_built : "");
+ return 0;
+ }
+
+ if ((argc > 1) &&
+ (!strcmp(argv[1], "help") || !strcmp(argv[1], "--help") || !strcmp(argv[1], "-h"))) {
+ print_usage();
+ return 0;
+ }
- if (argc > 1 && !strcmp(argv[1], "-D"))
+ if ((argc > 1) &&
+ !strcmp(argv[1], "-D")) {
daemon_debug = 1;
+ }
if (!daemon_debug) {
if (daemon(0, 0) < 0) {
@@ -854,6 +912,11 @@ int main(int argc, char *argv[])
openlog("wdmd", LOG_CONS | LOG_PID, LOG_DAEMON);
+ log_error("wdmd started tests_built%s%s%s\n",
+ scripts_built ? scripts_built : "",
+ client_built ? client_built : "",
+ files_built ? files_built : "");
+
setup_priority();
rv = lockfile();
12 years, 7 months
src/host_id.c src/host_id.h src/main.c
by David Teigland
src/host_id.c | 46 +++++++++++++++++++++-------------------------
src/host_id.h | 4 ++--
src/main.c | 8 ++++++--
3 files changed, 29 insertions(+), 29 deletions(-)
New commits:
commit 951d2206702c10381aa74e2ada1fd414b9a710bc
Author: David Teigland <teigland(a)redhat.com>
Date: Mon Apr 11 13:18:12 2011 -0500
sanlock: add lockspace checks
When comparing lockspaces, do a full compare of name, and
host_id path/offset/id when possible. This prevent adding
two lockspaces with the same name but different host_id info.
(Of course two lockspaces with the same never should never
be created in the first place. We can't fully protect
against that, so it's a user error, but we can reject it
when we see it.)
diff --git a/src/host_id.c b/src/host_id.c
index 4f9091a..535307e 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -71,12 +71,17 @@ int print_space_state(struct space *sp, char *str)
return strlen(str);
}
-static struct space *_search_space(char *space_name, struct list_head *head)
+static struct space *_search_space(char *name, struct sync_disk *disk,
+ uint64_t host_id, struct list_head *head)
{
struct space *sp;
list_for_each_entry(sp, head, list) {
- if (strncmp(sp->space_name, space_name, NAME_ID_SIZE))
+ if (strncmp(sp->space_name, name, NAME_ID_SIZE))
+ continue;
+ if (disk && strncmp(sp->host_id_disk.path, disk->path, SANLK_PATH_LEN))
+ continue;
+ if (host_id && sp->host_id != host_id)
continue;
return sp;
}
@@ -107,21 +112,6 @@ int get_space_info(char *space_name, struct space *sp_out)
return rv;
}
-#if 0
-uint64_t get_our_host_id(char *space_name)
-{
- struct space *sp;
- uint64_t id = 0;
-
- pthread_mutex_lock(&spaces_mutex);
- sp = _search_space(space_name, &spaces);
- if (sp)
- id = sp->host_id;
- pthread_mutex_unlock(&spaces_mutex);
- return id;
-}
-#endif
-
int host_id_leader_read(char *space_name, uint64_t host_id,
struct leader_record *leader_ret)
{
@@ -299,12 +289,18 @@ int add_space(struct space *sp)
{
int rv, result;
- if (space_exists(sp->space_name)) {
+ if (space_exists(sp->space_name, &sp->host_id_disk, sp->host_id)) {
log_erros(sp, "add_space exists");
rv = -EEXIST;
goto fail;
}
+ if (space_exists(sp->space_name, NULL, 0)) {
+ log_erros(sp, "add_space name exists with other host info");
+ rv = -EINVAL;
+ goto fail;
+ }
+
rv = open_disks(&sp->host_id_disk, 1);
if (rv != 1) {
log_erros(sp, "add_space open_disk failed %d %s",
@@ -340,8 +336,8 @@ int add_space(struct space *sp)
pthread_mutex_lock(&spaces_mutex);
/* TODO: repeating check here unnecessary if we serialize adds and removes */
- if (_search_space(sp->space_name, &spaces) ||
- _search_space(sp->space_name, &spaces_remove)) {
+ if (_search_space(sp->space_name, NULL, 0, &spaces) ||
+ _search_space(sp->space_name, NULL, 0, &spaces_remove)) {
pthread_mutex_unlock(&spaces_mutex);
log_erros(sp, "add_space duplicate name");
goto fail_stop;
@@ -360,13 +356,13 @@ int add_space(struct space *sp)
return rv;
}
-int rem_space(char *space_name)
+int rem_space(char *name, struct sync_disk *disk, uint64_t host_id)
{
struct space *sp;
int rv = -ENOENT;
pthread_mutex_lock(&spaces_mutex);
- sp = _search_space(space_name, &spaces);
+ sp = _search_space(name, disk, host_id, &spaces);
if (sp) {
sp->external_remove = 1;
rv = 0;
@@ -429,14 +425,14 @@ void clear_spaces(int wait)
pthread_mutex_unlock(&spaces_mutex);
}
-int space_exists(char *space_name)
+int space_exists(char *name, struct sync_disk *disk, uint64_t host_id)
{
struct space *sp;
pthread_mutex_lock(&spaces_mutex);
- sp = _search_space(space_name, &spaces);
+ sp = _search_space(name, disk, host_id, &spaces);
if (!sp)
- sp = _search_space(space_name, &spaces_remove);
+ sp = _search_space(name, disk, host_id, &spaces_remove);
pthread_mutex_unlock(&spaces_mutex);
if (sp)
return 1;
diff --git a/src/host_id.h b/src/host_id.h
index 26c9701..b329b9a 100644
--- a/src/host_id.h
+++ b/src/host_id.h
@@ -15,9 +15,9 @@ int get_space_info(char *space_name, struct space *sp_out);
int host_id_leader_read(char *space_name, uint64_t host_id, struct leader_record *leader_ret);
int host_id_renewed(struct space *sp);
int add_space(struct space *sp);
-int rem_space(char *space_name);
+int rem_space(char *name, struct sync_disk *disk, uint64_t host_id);
void clear_spaces(int wait);
-int space_exists(char *space_name);
+int space_exists(char *name, struct sync_disk *disk, uint64_t host_id);
void setup_spaces(void);
#endif
diff --git a/src/main.c b/src/main.c
index 0763b86..7dbc573 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1372,13 +1372,17 @@ static void *cmd_rem_lockspace_thread(void *args_in)
with the space_exists name check below when the same lockspace
name was removed and added at once */
- result = rem_space(lockspace.name);
+ result = rem_space(lockspace.name,
+ (struct sync_disk *)&lockspace.host_id_disk,
+ lockspace.host_id);
if (result < 0)
goto reply;
while (1) {
- if (!space_exists(lockspace.name))
+ if (!space_exists(lockspace.name,
+ (struct sync_disk *)&lockspace.host_id_disk,
+ lockspace.host_id))
break;
sleep(1);
}
12 years, 7 months
src/delta_lease.c src/direct.c src/host_id.c src/paxos_lease.c src/paxos_lease.h
by David Teigland
src/delta_lease.c | 6 +++---
src/direct.c | 11 ++++-------
src/host_id.c | 2 ++
src/paxos_lease.c | 10 ++++++----
src/paxos_lease.h | 3 ++-
5 files changed, 17 insertions(+), 15 deletions(-)
New commits:
commit e9ad19ab206e48fcecd09c69da9efe0740797643
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Apr 8 13:58:18 2011 -0500
sanlock: debug message changes
remove the host_id renewal messages since they fill up the log
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 003b2f5..6804e78 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -211,7 +211,7 @@ int delta_lease_renew(struct space *sp, struct sync_disk *disk,
uint64_t new_ts;
int error, delay;
- log_space(sp, "delta_renew %llu begin", (unsigned long long)host_id);
+ /* log_space(sp, "delta_renew %llu begin", (unsigned long long)host_id); */
error = delta_lease_leader_read(disk, space_name, host_id, &leader);
if (error < 0)
@@ -229,7 +229,7 @@ int delta_lease_renew(struct space *sp, struct sync_disk *disk,
leader.timestamp = new_ts;
leader.checksum = leader_checksum(&leader);
- log_space(sp, "delta_renew write new %llu", (unsigned long long)new_ts);
+ /* log_space(sp, "delta_renew write new %llu", (unsigned long long)new_ts); */
error = write_sector(disk, host_id - 1, (char *)&leader,
sizeof(struct leader_record),
@@ -238,7 +238,7 @@ int delta_lease_renew(struct space *sp, struct sync_disk *disk,
return error;
delay = 2 * to.io_timeout_seconds;
- log_space(sp, "delta_renew sleep 2d %d", delay);
+ /* log_space(sp, "delta_renew sleep 2d %d", delay); */
sleep(delay);
error = delta_lease_leader_read(disk, space_name, host_id, &leader);
diff --git a/src/direct.c b/src/direct.c
index bb36e2e..6bd10e7 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -90,24 +90,21 @@ static int do_paxos_action(void)
case ACT_ACQUIRE:
rv = paxos_lease_acquire(token, 0, &leader_ret, 0, com.num_hosts);
if (rv < 0) {
- log_tool("cannot acquire lease on %s",
- token->r.name);
+ log_tool("cannot acquire lease on %s", token->r.name);
return -1;
}
break;
case ACT_RELEASE:
- rv = paxos_lease_leader_read(token, &leader_read);
+ rv = paxos_lease_leader_read(token, &leader_read, "direct_release");
if (rv < 0) {
- log_tool("cannot read lease on %s",
- token->r.name);
+ log_tool("cannot read lease on %s", token->r.name);
return -1;
}
rv = paxos_lease_release(token, &leader_read, &leader_ret);
if (rv < 0) {
- log_tool("cannot release lease on %s",
- token->r.name);
+ log_tool("cannot release lease on %s", token->r.name);
return -1;
}
break;
diff --git a/src/host_id.c b/src/host_id.c
index 242779a..4f9091a 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -263,9 +263,11 @@ static void *host_id_thread(void *arg_in)
sp->lease_status.max_renewal_time = t;
}
+ /*
log_space(sp, "host_id %llu renewal %llu interval %d",
(unsigned long long)sp->host_id,
(unsigned long long)t, good_diff);
+ */
if (!sp->thread_stop)
update_watchdog_file(sp, t);
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index bd06d1f..b4797b2 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -464,7 +464,8 @@ static int leaders_match(struct leader_record *a, struct leader_record *b)
return 0;
}
-int paxos_lease_leader_read(struct token *token, struct leader_record *leader_ret)
+int paxos_lease_leader_read(struct token *token, struct leader_record *leader_ret,
+ const char *caller)
{
struct leader_record prev_leader;
struct leader_record *leaders;
@@ -551,8 +552,9 @@ int paxos_lease_leader_read(struct token *token, struct leader_record *leader_re
goto fail;
}
- log_token(token, "leader_read owner %llu lver %llu hosts %llu "
+ log_token(token, "%s leader_read owner %llu lver %llu hosts %llu "
"time %llu res %s",
+ caller ? caller : "unknown",
(unsigned long long)prev_leader.owner_id,
(unsigned long long)prev_leader.lver,
(unsigned long long)prev_leader.num_hosts,
@@ -611,7 +613,7 @@ int paxos_lease_acquire(struct token *token, int force,
log_token(token, "paxos_acquire begin lver %llu force %d",
(unsigned long long)acquire_lver, force);
- error = paxos_lease_leader_read(token, &prev_leader);
+ error = paxos_lease_leader_read(token, &prev_leader, "paxos_acquire");
if (error < 0)
goto out;
@@ -859,7 +861,7 @@ int paxos_lease_release(struct token *token,
struct leader_record leader;
int error;
- error = paxos_lease_leader_read(token, &leader);
+ error = paxos_lease_leader_read(token, &leader, "paxos_release");
if (error < 0) {
log_errot(token, "release error cannot read leader");
goto out;
diff --git a/src/paxos_lease.h b/src/paxos_lease.h
index 1f87fc0..afdfe58 100644
--- a/src/paxos_lease.h
+++ b/src/paxos_lease.h
@@ -11,7 +11,8 @@
uint32_t leader_checksum(struct leader_record *lr);
int majority_disks(struct token *token, int num);
-int paxos_lease_leader_read(struct token *token, struct leader_record *leader_ret);
+int paxos_lease_leader_read(struct token *token, struct leader_record *leader_ret,
+ const char *caller);
int paxos_lease_acquire(struct token *token, int force,
struct leader_record *leader_ret,
uint64_t acquire_lver,
12 years, 7 months
4 commits - sanlock.spec src/client_admin.c src/client_resource.c src/diskio.c src/Makefile
by David Teigland
sanlock.spec | 45 ++++++++++++++++++++++++++++++++++++++++-----
src/Makefile | 2 +-
src/client_admin.c | 1 -
src/client_resource.c | 1 -
src/diskio.c | 16 ++++++++++++++--
5 files changed, 55 insertions(+), 10 deletions(-)
New commits:
commit b8141bc0491fc73272756a672a6a52776d3f873e
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Apr 8 12:09:16 2011 -0500
sanlock: clean up warnings
diff --git a/src/client_admin.c b/src/client_admin.c
index 0cb4c15..2c90ad1 100644
--- a/src/client_admin.c
+++ b/src/client_admin.c
@@ -34,7 +34,6 @@
int sanlock_shutdown(void)
{
- struct sm_header h;
int fd;
fd = send_command(SM_CMD_SHUTDOWN, 0);
diff --git a/src/client_resource.c b/src/client_resource.c
index 46eceae..90416d0 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -551,7 +551,6 @@ int sanlock_state_to_args(char *res_state,
free(args[i]);
}
free(args);
- fail:
return rv;
}
commit e0f4b429d5edd6c501f36b525b92c90fda0dda79
Author: Daniel P. Berrange <berrange(a)redhat.com>
Date: Fri Apr 8 11:27:48 2011 +0100
Ensure libsanlock.so is built with debug/warning flags
diff --git a/src/Makefile b/src/Makefile
index 3cbd0e0..9513ec2 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -59,7 +59,7 @@ CMD_LDFLAGS = -lpthread -lrt -lblkid -lsanlock -lwdmd
all: $(SHLIB_TARGET) $(CMD_TARGET)
$(SHLIB_TARGET): $(LIB_SOURCE)
- $(CC) -shared -fPIC -o $@ -Wl,-soname=$(LIB_TARGET).so.$(SOMAJOR) $^
+ $(CC) $(CFLAGS) -shared -fPIC -o $@ -Wl,-soname=$(LIB_TARGET).so.$(SOMAJOR) $^
ln -sf $(SHLIB_TARGET) $(LIB_TARGET).so
ln -sf $(SHLIB_TARGET) $(LIB_TARGET).so.$(SOMAJOR)
commit 49248ca37fa7520c443ccd7b43bbed995a5b5831
Author: Daniel P. Berrange <berrange(a)redhat.com>
Date: Fri Apr 8 11:27:24 2011 +0100
Hard code a sector size of 512 if the lease volume is a regular file
libblkid can't determine sector size if the lease volume is a
regular file. Short-circuit libblkid for such files and hardcode
a sector size of 512.
diff --git a/src/diskio.c b/src/diskio.c
index 3c01650..78a5fee 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -20,6 +20,7 @@
#include <syslog.h>
#include <sys/types.h>
#include <sys/time.h>
+#include <sys/stat.h>
#include <aio.h>
#include <blkid/blkid.h>
@@ -82,6 +83,7 @@ int open_disks(struct sync_disk *disks, int num_disks)
int d, fd, rv;
uint32_t ss = 0;
uint64_t orig_offset;
+ struct stat st;
for (d = 0; d < num_disks; d++) {
disk = &disks[d];
@@ -91,12 +93,22 @@ int open_disks(struct sync_disk *disks, int num_disks)
continue;
}
- rv = set_disk_properties(disk);
- if (rv < 0) {
+ if (fstat(fd, &st) < 0) {
+ log_error("fstat error %d %s", fd, disk->path);
close(fd);
continue;
}
+ if (S_ISREG(st.st_mode)) {
+ disk->sector_size = 512;
+ } else {
+ rv = set_disk_properties(disk);
+ if (rv < 0) {
+ close(fd);
+ continue;
+ }
+ }
+
if (!ss) {
ss = disk->sector_size;
} else if (ss != disk->sector_size) {
commit f95e049c23c0e4ab5baaca429ebc701207021d3c
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Thu Apr 7 16:57:55 2011 +0100
rpm: add the lib package, install the initscripts
diff --git a/sanlock.spec b/sanlock.spec
index ce6e46e..d936756 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -11,7 +11,7 @@ BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libblkid-devel
-#Requires: <nothing>
+Requires: %{name}-lib = %{version}-%{release}
%description
sanlock uses disk paxos to manage leases on shared storage.
@@ -35,22 +35,55 @@ make -C src \
make -C wdmd \
install LIB_LIBDIR=%{_libdir} \
DESTDIR=$RPM_BUILD_ROOT
+install -D -m 755 init.d/sanlock $RPM_BUILD_ROOT/%{_initddir}/sanlock
+install -D -m 755 init.d/wdmd $RPM_BUILD_ROOT/%{_initddir}/wdmd
%clean
rm -rf $RPM_BUILD_ROOT
-%post -p /sbin/ldconfig
+%post
+/sbin/chkconfig --add sanlock
+/sbin/chkconfig --add wdmd
-%postun -p /sbin/ldconfig
+%preun
+if [ $1 = 0 ]; then
+ /sbin/service sanlock stop > /dev/null 2>&1
+ /sbin/service wdmd stop > /dev/null 2>&1
+ /sbin/chkconfig --del sanlock
+ /sbin/chkconfig --del wdmd
+fi
+
+%postun
+#/sbin/service sanlock condrestart >/dev/null 2>&1 || :
+#/sbin/service wdmd condrestart >/dev/null 2>&1 || :
%files
%defattr(-,root,root,-)
%doc COPYING
+%{_initddir}/sanlock
+%{_initddir}/wdmd
%{_sbindir}/sanlock
%{_sbindir}/wdmd
+
+%package lib
+Summary: A shared disk lock manager library
+Group: System Environment/Libraries
+
+%description lib
+The %{name}-lib package contains the runtime libraries for sanlock,
+a shared disk lock manager.
+Hosts connected to a common SAN can use this to synchronize their
+access to the shared disks.
+
+%post lib -p /sbin/ldconfig
+
+%postun lib -p /sbin/ldconfig
+
+%files lib
+%defattr(-,root,root,-)
+%doc COPYING
%{_libdir}/libsanlock.so.*
-%{_libdir}/libwdmd.*
-%{_includedir}/wdmd.h
+%{_libdir}/libwdmd.so.*
%package devel
Summary: Development files for %{name}
@@ -64,6 +97,8 @@ developing applications that use %{name}.
%files devel
%defattr(-,root,root,-)
%doc COPYING
+%{_libdir}/libwdmd.so
+%{_includedir}/wdmd.h
%{_libdir}/libsanlock.so
%{_includedir}/sanlock.h
%{_includedir}/sanlock_admin.h
12 years, 7 months
src/host_id.c
by David Teigland
src/host_id.c | 1 +
1 file changed, 1 insertion(+)
New commits:
commit e87d928c860dc52678be143e6347ec4d34b4ec43
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 5 15:35:28 2011 -0500
sanlock: add_lockspace EEXIST
return an error if the lockspace exists
diff --git a/src/host_id.c b/src/host_id.c
index b3dc51f..51be22a 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -289,6 +289,7 @@ int add_space(struct space *sp)
if (space_exists(sp->space_name)) {
log_erros(sp, "add_space exists");
+ rv = -EEXIST;
goto fail;
}
12 years, 8 months