sanlock.spec
by David Teigland
sanlock.spec | 150 -----------------------------------------------------------
1 file changed, 150 deletions(-)
New commits:
commit 41eb722cceaaea820f7b0942cbc22e3bfb1b023c
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Jun 10 12:52:41 2011 -0500
remove spec file
instead of trying to keep it in sync with the real copies
diff --git a/sanlock.spec b/sanlock.spec
deleted file mode 100644
index 52b1ec9..0000000
--- a/sanlock.spec
+++ /dev/null
@@ -1,150 +0,0 @@
-%{!?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}
-Summary: A shared disk lock manager
-
-Group: System Environment/Base
-License: GPLv2+
-URL: https://fedorahosted.org/sanlock/
-Source0: https://fedorahosted.org/releases/s/a/sanlock/%{name}-%{version}.tar.bz2
-BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
-
-BuildRequires: libblkid-devel, libaio-devel
-
-Requires: %{name}-lib = %{version}-%{release}
-
-%description
-sanlock uses disk paxos to manage leases on shared storage.
-Hosts connected to a common SAN can use this to synchronize their
-access to the shared disks.
-
-%prep
-%setup -q
-
-%build
-# upstream does not require configure
-# 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
-make -C src \
- install LIB_LIBDIR=%{_libdir} \
- DESTDIR=$RPM_BUILD_ROOT
-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
-
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-%pre
-/usr/sbin/useradd -c "Sanlock" -s /sbin/nologin -r \
- -d /var/run/sanlock sanlock 2> /dev/null || :
-
-%post
-/sbin/chkconfig --add sanlock
-/sbin/chkconfig --add wdmd
-
-%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.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
-Requires: %{name} = %{version}-%{release}
-
-%description devel
-The %{name}-devel package contains libraries and header files for
-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_rv.h
-%{_includedir}/sanlock_admin.h
-%{_includedir}/sanlock_resource.h
-%{_includedir}/sanlock_direct.h
-
-%changelog
-* Mon Apr 4 2011 Federico Simoncelli <fsimonce(a)redhat.com> - 1.1.0-3
-- Add sanlock_admin.h header
-
-* Fri Feb 18 2011 Chris Feist <cfeist(a)redhat.com> - 1.1.0-2
-- Fixed install for wdmd
-
-* Thu Feb 17 2011 Chris Feist <cfeist(a)redhat.com> - 1.1.0-1
-- Updated to latest sources
-- Now include wdmd
-
-* Tue Feb 8 2011 Angus Salkeld <asalkeld(a)redhat.com> - 1.0-2
-- SPEC: Add docs and make more consistent with the fedora template
-
-* Mon Jan 10 2011 Fabio M. Di Nitto <fdinitto(a)redhat.com> - 1.0-1
-- first cut at rpm packaging
12 years, 9 months
2 commits - src/Makefile src/paxos_lease.c wdmd/main.c
by David Teigland
src/Makefile | 6 +++---
src/paxos_lease.c | 4 ++--
wdmd/main.c | 13 +++++++++----
3 files changed, 14 insertions(+), 9 deletions(-)
New commits:
commit eabcca788b5cf8b126bd7ba24991c37f952b9a02
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Jun 9 17:22:38 2011 -0500
sanlock: fix libwdmd linking
diff --git a/src/Makefile b/src/Makefile
index 93d0306..9491ce1 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -61,8 +61,8 @@ CFLAGS += -D_GNU_SOURCE -g \
-fasynchronous-unwind-tables \
-fdiagnostics-show-option
-CMD_LDFLAGS = -lpthread -lrt -laio -lblkid -lsanlock -lwdmd
-LIB_LDFLAGS = -lpthread -lrt -laio -lblkid -lwdmd
+CMD_LDFLAGS = -lpthread -lrt -laio -lblkid -lsanlock -L../wdmd -lwdmd
+LIB_LDFLAGS = -lpthread -lrt -laio -lblkid -L../wdmd -lwdmd
all: $(SHLIB_TARGET) $(CMD_TARGET)
@@ -73,7 +73,7 @@ $(SHLIB_TARGET): $(LIB_SOURCE)
ln -sf $(SHLIB_TARGET) $(LIB_TARGET).so.$(SOMAJOR)
$(CMD_TARGET): $(SHLIB_TARGET) $(CMD_SOURCE)
- $(CC) $(CFLAGS) $(CMD_LDFLAGS) $(CMD_SOURCE) -o $@ -L. -L../wdmd
+ $(CC) $(CFLAGS) $(CMD_LDFLAGS) $(CMD_SOURCE) -o $@ -L.
clean:
rm -f *.o *.so *.so.* $(CMD_TARGET)
commit 5772bd9c4f6b38132ed834bf4e48f899946ff923
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Jun 9 16:54:09 2011 -0500
sanlock/wdmd: shut up warnings
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 141c61d..e842b93 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -724,7 +724,7 @@ static int _leader_read_multiple(struct task *task,
int leaders_len, leader_reps_len;
int num_reads;
int num_disks = token->r.num_disks;
- int rv, d, i, found;
+ int rv = 0, d, i, found;
int error;
leaders_len = num_disks * sizeof(struct leader_record);
@@ -978,7 +978,7 @@ static int write_new_leader(struct task *task,
int num_disks = token->r.num_disks;
int num_writes = 0;
int error = SANLK_OK;
- int rv, d;
+ int rv = 0, d;
for (d = 0; d < num_disks; d++) {
rv = write_leader(task, &token->disks[d], nl);
diff --git a/wdmd/main.c b/wdmd/main.c
index a020b1e..e024c82 100644
--- a/wdmd/main.c
+++ b/wdmd/main.c
@@ -330,7 +330,7 @@ static int setup_listener_socket(int *listener_socket)
static int setup_clients(void)
{
- int rv, fd, ci;
+ int rv, fd = -1, ci;
rv = setup_listener_socket(&fd);
if (rv < 0)
@@ -610,10 +610,15 @@ static int test_scripts(void) { return 0; }
static void close_watchdog(void)
{
- write(dev_fd, "V", 1);
- close(dev_fd);
+ int rv;
+
+ rv = write(dev_fd, "V", 1);
+ if (rv < 0)
+ log_error("/dev/watchdog disarm write error %d", errno);
+ else
+ log_error("/dev/watchdog disarmed");
- log_error("/dev/watchdog disarmed");
+ close(dev_fd);
}
static int setup_watchdog(void)
12 years, 9 months
Changes to 'refs/tags/sanlock-1.3.0'
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 (205):
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
Fabio M. Di Nitto (5):
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
Federico Simoncelli (22):
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
Saggi Mizrahi (21):
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
12 years, 9 months
src/main.c
by David Teigland
src/main.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
New commits:
commit f6539563e48f05c5afc411c79031dd8beb9fffc9
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Jun 7 14:14:48 2011 -0500
sanlock: increase version to 1.3
diff --git a/src/main.c b/src/main.c
index 1145cf4..5ac6c54 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2311,7 +2311,7 @@ static void parse_arg_timeout(char *optstr)
}
#endif
-#define RELEASE_VERSION "1.2"
+#define RELEASE_VERSION "1.3"
/*
* daemon: acquires leases for the local host_id, associates them with a local
12 years, 9 months
3 commits - python/setup.py sanlock.spec src/Makefile tests/devcount.c
by David Teigland
python/setup.py | 2 +-
sanlock.spec | 2 --
src/Makefile | 20 ++++----------------
tests/devcount.c | 8 ++++++++
4 files changed, 13 insertions(+), 19 deletions(-)
New commits:
commit 39e6aa25e070d532d1ced0b74780346d028cdf93
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Jun 7 11:06:32 2011 -0500
libsanlock: link with LDFLAGS
diff --git a/src/Makefile b/src/Makefile
index f020aee..93d0306 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -62,12 +62,13 @@ CFLAGS += -D_GNU_SOURCE -g \
-fdiagnostics-show-option
CMD_LDFLAGS = -lpthread -lrt -laio -lblkid -lsanlock -lwdmd
+LIB_LDFLAGS = -lpthread -lrt -laio -lblkid -lwdmd
all: $(SHLIB_TARGET) $(CMD_TARGET)
$(SHLIB_TARGET): $(LIB_SOURCE)
- $(CC) $(CFLAGS) -shared -fPIC -o $@ -Wl,-soname=$(LIB_TARGET).so.$(SOMAJOR) $^
+ $(CC) $(CFLAGS) $(LIB_LDFLAGS) -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 108d5aeba6f1944877a93f5c2038a217a924d341
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Tue Jun 7 11:47:24 2011 -0400
libs: include libsanlock_direct into libsanlock
diff --git a/python/setup.py b/python/setup.py
index db36dc7..19520e5 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -6,7 +6,7 @@
from distutils.core import setup, Extension
-sanlocklib = ['sanlock', 'sanlock_direct', 'blkid', 'rt', 'aio']
+sanlocklib = ['sanlock']
sanlockmod = Extension(name = 'sanlockmod',
sources = ['sanlockmod.c'],
include_dirs = ['../src'],
diff --git a/sanlock.spec b/sanlock.spec
index c4cb013..52b1ec9 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -93,7 +93,6 @@ access to the shared disks.
%defattr(-,root,root,-)
%doc COPYING
%{_libdir}/libsanlock.so.*
-%{_libdir}/libsanlock_direct.so.*
%{_libdir}/libwdmd.so.*
%package python
@@ -127,7 +126,6 @@ developing applications that use %{name}.
%{_libdir}/libwdmd.so
%{_includedir}/wdmd.h
%{_libdir}/libsanlock.so
-%{_libdir}/libsanlock_direct.so
%{_includedir}/sanlock.h
%{_includedir}/sanlock_rv.h
%{_includedir}/sanlock_admin.h
diff --git a/src/Makefile b/src/Makefile
index 71283fa..f020aee 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -8,8 +8,6 @@ CMD_TARGET = sanlock
LIB_TARGET = libsanlock
-LIB2_TARGET = libsanlock_direct
-
HEADER_TARGET = sanlock.h sanlock_rv.h sanlock_resource.h sanlock_admin.h sanlock_direct.h
SOMAJOR=1
@@ -17,8 +15,6 @@ SOMINOR=0
SHLIB_TARGET = $(LIB_TARGET).so.$(SOMAJOR).$(SOMINOR)
-SHLIB2_TARGET = $(LIB2_TARGET).so.$(SOMAJOR).$(SOMINOR)
-
CMD_SOURCE = \
crc32c.c \
delta_lease.c \
@@ -36,9 +32,7 @@ CMD_SOURCE = \
LIB_SOURCE = \
client_msg.c \
client_resource.c \
- client_admin.c
-
-LIB2_SOURCE = \
+ client_admin.c \
crc32c.c \
diskio.c \
delta_lease.c \
@@ -70,7 +64,7 @@ CFLAGS += -D_GNU_SOURCE -g \
CMD_LDFLAGS = -lpthread -lrt -laio -lblkid -lsanlock -lwdmd
-all: $(SHLIB_TARGET) $(CMD_TARGET) $(SHLIB2_TARGET)
+all: $(SHLIB_TARGET) $(CMD_TARGET)
$(SHLIB_TARGET): $(LIB_SOURCE)
$(CC) $(CFLAGS) -shared -fPIC -o $@ -Wl,-soname=$(LIB_TARGET).so.$(SOMAJOR) $^
@@ -80,11 +74,6 @@ $(SHLIB_TARGET): $(LIB_SOURCE)
$(CMD_TARGET): $(SHLIB_TARGET) $(CMD_SOURCE)
$(CC) $(CFLAGS) $(CMD_LDFLAGS) $(CMD_SOURCE) -o $@ -L. -L../wdmd
-$(SHLIB2_TARGET): $(LIB2_SOURCE)
- $(CC) $(CFLAGS) -shared -fPIC -o $@ -Wl,-soname=$(LIB2_TARGET).so.$(SOMAJOR) $^
- ln -sf $(SHLIB2_TARGET) $(LIB2_TARGET).so
- ln -sf $(SHLIB2_TARGET) $(LIB2_TARGET).so.$(SOMAJOR)
-
clean:
rm -f *.o *.so *.so.* $(CMD_TARGET)
@@ -102,7 +91,5 @@ install: all
mkdir -p $(DESTDIR)/$(HEADER_DIR)
$(INSTALL) -c -m 755 $(CMD_TARGET) $(DESTDIR)/$(CMD_BINDIR)
$(INSTALL) -c -m 755 $(SHLIB_TARGET) $(DESTDIR)/$(LIB_LIBDIR)
- $(INSTALL) -c -m 755 $(SHLIB2_TARGET) $(DESTDIR)/$(LIB_LIBDIR)
cp -a $(LIB_TARGET).so $(DESTDIR)/$(LIB_LIBDIR)
- cp -a $(LIB2_TARGET).so $(DESTDIR)/$(LIB_LIBDIR)
$(INSTALL) -c -m 644 $(HEADER_TARGET) $(DESTDIR)/$(HEADER_DIR)
commit bfa5280a5df6374090a698b5bdf8abd7ca39fdef
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Jun 7 10:51:35 2011 -0500
devcount: use aio in init
diff --git a/tests/devcount.c b/tests/devcount.c
index 172eac3..ee9a9dd 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -1420,12 +1420,20 @@ int do_init(int argc, char *argv[])
strcpy(ls.name, "devcount");
strcpy(ls.host_id_disk.path, argv[2]);
+ printf("init sync\n");
rv = sanlock_direct_init(&ls, NULL, 0, INIT_NUM_HOSTS, 0);
if (rv < 0) {
printf("sanlock_direct_init lockspace error %d\n", rv);
return -1;
}
+ printf("init async\n");
+ rv = sanlock_direct_init(&ls, NULL, 0, INIT_NUM_HOSTS, 1);
+ if (rv < 0) {
+ printf("sanlock_direct_init lockspace error %d\n", rv);
+ return -1;
+ }
+
memset(resbuf, 0, sizeof(resbuf));
res = (struct sanlk_resource *)&resbuf;
strcpy(res->lockspace_name, "devcount");
12 years, 9 months
python/sanlockmod.c python/sanlock.py
by David Teigland
python/sanlock.py | 3 ++-
python/sanlockmod.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 32 insertions(+), 1 deletion(-)
New commits:
commit 2d7486c2f669543f10f53f09d315e43b81ba68fc
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Tue Jun 7 09:55:20 2011 -0400
python: add get_alignment function
diff --git a/python/sanlock.py b/python/sanlock.py
index 87e33b3..0909cc8 100644
--- a/python/sanlock.py
+++ b/python/sanlock.py
@@ -8,7 +8,8 @@ import sys
import sanlockmod
SANLOCK_FUNCTIONS = (
- 'register', 'add_lockspace', 'rem_lockspace', 'acquire', 'release'
+ 'register', 'add_lockspace', 'rem_lockspace', 'acquire', 'release',
+ 'get_alignment'
)
SanlockException = sanlockmod.exception
diff --git a/python/sanlockmod.c b/python/sanlockmod.c
index a042030..7e5f2af 100644
--- a/python/sanlockmod.c
+++ b/python/sanlockmod.c
@@ -287,6 +287,34 @@ exit_fail:
return NULL;
}
+static PyObject *
+py_get_alignment(PyObject *self, PyObject *args)
+{
+ int rv;
+ char *path;
+ struct sanlk_disk disk;
+
+ /* parse python tuple */
+ if (!PyArg_ParseTuple(args, "s", &path)) {
+ return NULL;
+ }
+
+ memset(&disk, 0, sizeof(struct sanlk_disk));
+ strncpy(disk.path, path, SANLK_PATH_LEN - 1);
+
+ /* get device alignment (gil disabled) */
+ Py_BEGIN_ALLOW_THREADS
+ rv = sanlock_direct_align(&disk);
+ Py_END_ALLOW_THREADS
+
+ if (rv < 0) {
+ __set_exception(SKERRNO(rv), "Unable to get device alignment");
+ return NULL;
+ }
+
+ return PyInt_FromLong(rv);
+}
+
static PyMethodDef
sanlockmod_methods[] = {
{"register", py_register, METH_NOARGS, "Register to SANLock daemon."},
@@ -302,6 +330,8 @@ sanlockmod_methods[] = {
"Acquire a resource lease for the current process."},
{"release", py_release, METH_VARARGS,
"Release a resource lease for the current process."},
+ {"get_alignment", py_get_alignment, METH_VARARGS,
+ "Get device alignment."},
{NULL, NULL, 0, NULL}
};
12 years, 9 months
2 commits - src/delta_lease.c src/direct.c src/direct.h src/direct_lib.c src/diskio.c src/host_id.c src/host_id.h src/main.c src/paxos_lease.c src/sanlock_direct.h tests/devcount.c
by David Teigland
src/delta_lease.c | 12 +-
src/direct.c | 70 +++++++++----
src/direct.h | 2
src/direct_lib.c | 20 +++
src/diskio.c | 22 ++--
src/host_id.c | 269 +++++++++++++++++++++++++++++++++------------------
src/host_id.h | 7 -
src/main.c | 92 ++++-------------
src/paxos_lease.c | 9 +
src/sanlock_direct.h | 7 +
tests/devcount.c | 9 +
11 files changed, 321 insertions(+), 198 deletions(-)
New commits:
commit ba49a1acb34ac3f003c8298a4b9e1293fab6759f
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Jun 3 13:18:00 2011 -0500
sanlock: official 1MB/8MB alignment
of lease areas and fix direct dump to work with these
alignments. Also add an api
sanlock_direct_align(disk) that returns 1MB if the
disk has 512 sectors and 8MB if the disk has 4k sectors
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 1e3f239..b4a1df7 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -24,6 +24,7 @@
#include "sanlock_internal.h"
#include "diskio.h"
+#include "direct.h"
#include "log.h"
#include "paxos_lease.h"
#include "delta_lease.h"
@@ -421,9 +422,15 @@ int delta_lease_init(struct task *task,
struct leader_record *leader;
char *iobuf, **p_iobuf;
int iobuf_len;
+ int align_size;
int i, rv;
- iobuf_len = disk->sector_size * max_hosts;
+ align_size = direct_align(disk);
+
+ if (disk->sector_size * max_hosts > align_size)
+ return -E2BIG;
+
+ iobuf_len = align_size;
p_iobuf = &iobuf;
diff --git a/src/direct.c b/src/direct.c
index 594285f..280c5c7 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -356,6 +356,16 @@ int direct_live_id(struct task *task,
return 0;
}
+int direct_align(struct sync_disk *disk)
+{
+ if (disk->sector_size == 512)
+ return 1024 * 1024;
+ else if (disk->sector_size == 4096)
+ return 8 * 1024 * 1024;
+ else
+ return -EINVAL;
+}
+
/*
* sanlock direct init -n <num_hosts> [-s LOCKSPACE] [-r RESOURCE]
*
@@ -418,7 +428,8 @@ int direct_dump(struct task *task, char *dump_path)
char sname[NAME_ID_SIZE+1];
char rname[NAME_ID_SIZE+1];
uint64_t sector_nr;
- int rv;
+ int sector_count, datalen, align_size;
+ int i, rv;
memset(&sd, 0, sizeof(struct sync_disk));
@@ -436,14 +447,19 @@ int direct_dump(struct task *task, char *dump_path)
if (rv < 0)
return -ENODEV;
- data = malloc(sd.sector_size);
+ rv = direct_align(&sd);
+ if (rv < 0)
+ goto out_close;
+
+ align_size = rv;
+ datalen = align_size;
+ sector_count = align_size / sd.sector_size;
+
+ data = malloc(datalen);
if (!data) {
rv = -ENOMEM;
goto out_close;
}
- lr = (struct leader_record *)data;
-
- sector_nr = 0;
printf("%8s %36s %36s %10s %4s %4s %s\n",
"offset",
@@ -454,26 +470,39 @@ int direct_dump(struct task *task, char *dump_path)
"gen",
"lver");
+ sector_nr = 0;
+
while (1) {
memset(sname, 0, sizeof(rname));
memset(rname, 0, sizeof(rname));
memset(data, 0, sd.sector_size);
- rv = read_sectors(&sd, sector_nr, 1, data, sd.sector_size,
+ rv = read_sectors(&sd, sector_nr, sector_count, data, datalen,
task, "dump");
- if (lr->magic == DELTA_DISK_MAGIC) {
- strncpy(sname, lr->space_name, NAME_ID_SIZE);
- strncpy(rname, lr->resource_name, NAME_ID_SIZE);
-
- printf("%08llu %36s %36s %010llu %04llu %04llu\n",
- (unsigned long long)(sector_nr * sd.sector_size),
- sname, rname,
- (unsigned long long)lr->timestamp,
- (unsigned long long)lr->owner_id,
- (unsigned long long)lr->owner_generation);
+ lr = (struct leader_record *)data;
- sector_nr += 1;
+ if (lr->magic == DELTA_DISK_MAGIC) {
+ for (i = 0; i < sector_count; i++) {
+ lr = (struct leader_record *)(data + (i * sd.sector_size));
+
+ if (!lr->magic)
+ continue;
+
+ /* has never been acquired, don't print */
+ if (!lr->owner_id && !lr->owner_generation)
+ continue;
+
+ strncpy(sname, lr->space_name, NAME_ID_SIZE);
+ strncpy(rname, lr->resource_name, NAME_ID_SIZE);
+
+ printf("%08llu %36s %36s %010llu %04llu %04llu\n",
+ (unsigned long long)((sector_nr + i) * sd.sector_size),
+ sname, rname,
+ (unsigned long long)lr->timestamp,
+ (unsigned long long)lr->owner_id,
+ (unsigned long long)lr->owner_generation);
+ }
} else if (lr->magic == PAXOS_DISK_MAGIC) {
strncpy(sname, lr->space_name, NAME_ID_SIZE);
strncpy(rname, lr->resource_name, NAME_ID_SIZE);
@@ -485,14 +514,11 @@ int direct_dump(struct task *task, char *dump_path)
(unsigned long long)lr->owner_id,
(unsigned long long)lr->owner_generation,
(unsigned long long)lr->lver);
-
- sector_nr += lr->max_hosts + 2;
} else {
- printf("%08llu %36s\n",
- (unsigned long long)(sector_nr * sd.sector_size),
- "uninitialized");
break;
}
+
+ sector_nr += sector_count;
}
rv = 0;
diff --git a/src/direct.h b/src/direct.h
index 99fb53b..952cc00 100644
--- a/src/direct.h
+++ b/src/direct.h
@@ -37,6 +37,8 @@ int direct_live_id(struct task *task,
uint64_t *owner_generation,
int *live);
+int direct_align(struct sync_disk *disk);
+
int direct_init(struct task *task,
struct sanlk_lockspace *ls,
struct sanlk_resource *res,
diff --git a/src/direct_lib.c b/src/direct_lib.c
index 6ccd339..50c75b2 100644
--- a/src/direct_lib.c
+++ b/src/direct_lib.c
@@ -122,3 +122,23 @@ int sanlock_direct_sector_size(struct sanlk_disk *disk_in)
return disk.sector_size;
}
+int sanlock_direct_align(struct sanlk_disk *disk_in)
+{
+ struct sync_disk disk;
+ int align_size, rv;
+
+ memset(&disk, 0, sizeof(disk));
+
+ memcpy(disk.path, disk_in->path, SANLK_PATH_LEN);
+
+ rv = open_disk(&disk);
+ if (rv < 0)
+ return rv;
+
+ align_size = direct_align(&disk);
+
+ close(disk.fd);
+
+ return align_size;
+}
+
diff --git a/src/diskio.c b/src/diskio.c
index 843559b..f386470 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -28,6 +28,7 @@
#include "sanlock_internal.h"
#include "diskio.h"
+#include "direct.h"
#include "log.h"
static int set_disk_properties(struct sync_disk *disk)
@@ -117,12 +118,14 @@ int open_disks_fd(struct sync_disk *disks, int num_disks)
/*
* set fd and sector_size
+ * verify offset is correctly aligned
* returns 0 for success or -EXXX
*/
int open_disk(struct sync_disk *disk)
{
struct stat st;
+ int align_size;
int fd, rv;
fd = open(disk->path, O_RDWR | O_DIRECT | O_SYNC, 0);
@@ -149,6 +152,17 @@ int open_disk(struct sync_disk *disk)
}
}
+ align_size = direct_align(disk);
+
+ if (disk->offset % align_size) {
+ rv = -EBADSLT;
+ log_error("invalid offset %llu align size %u %s",
+ (unsigned long long)disk->offset,
+ align_size, disk->path);
+ close(fd);
+ goto fail;
+ }
+
disk->fd = fd;
return 0;
@@ -161,7 +175,6 @@ int open_disk(struct sync_disk *disk)
/*
* set fd and sector_size in each disk
* verify all sector_size's match
- * verify sector_size is ok for previously set offset
* returns number of opened disks
*/
@@ -193,13 +206,6 @@ int open_disks(struct sync_disk *disks, int num_disks)
goto fail;
}
- if (disk->offset % disk->sector_size) {
- log_error("invalid offset %llu sector size %u %s",
- (unsigned long long)disk->offset,
- disk->sector_size, disk->path);
- goto fail;
- }
-
num_opens++;
}
return num_opens;
diff --git a/src/main.c b/src/main.c
index 25343b7..1145cf4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1919,7 +1919,6 @@ static void process_cmd_daemon(int ci, struct sm_header *h_recv)
auto_close = 0;
break;
case SM_CMD_RESTRICT:
- strcpy(client[ci].owner_name, "restrict");
cmd_restrict(ci, fd, h_recv);
auto_close = 0;
break;
@@ -2439,6 +2438,9 @@ static void print_usage(void)
printf(" <offset> offset on disk in bytes\n");
printf(" <lver> optional disk leader version of resource for acquire\n");
printf("\n");
+ printf("<offset> must be 1MB aligned for disks with 512 byte sectors\n");
+ printf(" and 8MB aligned for disks with 4096 byte sectors\n");
+ printf("\n");
}
static int read_command_line(int argc, char *argv[])
@@ -2842,7 +2844,6 @@ static int do_direct(void)
case ACT_DUMP:
rv = direct_dump(&main_task, com.dump_path);
- log_tool("dump done %d", rv);
break;
case ACT_READ_LEADER:
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index 25ddf37..141c61d 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -23,6 +23,7 @@
#include "sanlock_internal.h"
#include "diskio.h"
+#include "direct.h"
#include "log.h"
#include "crc32c.h"
#include "host_id.h"
@@ -1466,10 +1467,16 @@ int paxos_lease_init(struct task *task,
char *iobuf, **p_iobuf;
struct leader_record *leader;
int iobuf_len;
+ int align_size;
int aio_timeout = 0;
int rv, d;
- iobuf_len = token->disks[0].sector_size * (2 + max_hosts);
+ align_size = direct_align(&token->disks[0]);
+
+ if (token->disks[0].sector_size * (2 + max_hosts) > align_size)
+ return -E2BIG;
+
+ iobuf_len = align_size;
p_iobuf = &iobuf;
diff --git a/src/sanlock_direct.h b/src/sanlock_direct.h
index 435e1bd..d0976f6 100644
--- a/src/sanlock_direct.h
+++ b/src/sanlock_direct.h
@@ -44,4 +44,11 @@ int sanlock_direct_init(struct sanlk_lockspace *ls,
int sanlock_direct_sector_size(struct sanlk_disk *disk);
+/*
+ * Returns the alignment in bytes required by sanlock_direct_init()
+ * (1MB for disks with 512 sectors, 8MB for disks with 4096 sectors)
+ */
+
+int sanlock_direct_align(struct sanlk_disk *disk);
+
#endif
diff --git a/tests/devcount.c b/tests/devcount.c
index f897f74..172eac3 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -1358,7 +1358,7 @@ int do_init(int argc, char *argv[])
struct sanlk_resource *res;
struct sanlk_lockspace ls;
char command[4096];
- int rv, ss;
+ int rv, ss, align_size;
if (argc < 4)
return -1;
@@ -1404,6 +1404,13 @@ int do_init(int argc, char *argv[])
return -1;
}
+ align_size = sanlock_direct_align(&disk);
+ if (align_size != LEASE_SIZE) {
+ printf("sanlock_direct align %s error %d\n",
+ disk.path, align_size);
+ return -1;
+ }
+
if (ss != 512) {
printf("unsupported sector size %d\n", ss);
return -1;
commit b7b5783c3ea858eb01d77a3a3fc1e5546e3ce893
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Jun 2 16:58:36 2011 -0500
sanlock: fix adding lockspace
the same lockspace could be added multiple times
since there was no recording or checking of additions
in progress. Fix this mainly by adding a list of
lockspaces being added.
diff --git a/src/delta_lease.c b/src/delta_lease.c
index ead0101..1e3f239 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -233,7 +233,8 @@ int delta_lease_acquire(struct task *task,
while (1) {
memcpy(&leader1, &leader, sizeof(struct leader_record));
- log_space(sp, "delta_acquire delta_large_delay %d", delay);
+ log_space(sp, "delta_acquire delta_large_delay %d delay %d",
+ delta_large_delay, delay);
sleep(delay);
error = delta_lease_leader_read(task, disk, space_name, host_id,
diff --git a/src/host_id.c b/src/host_id.c
index 52b0054..0ae3138 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -31,8 +31,11 @@
#include "client_msg.h"
#include "task.h"
+static unsigned int space_id_counter = 1;
+
struct list_head spaces;
-struct list_head spaces_remove;
+struct list_head spaces_add;
+struct list_head spaces_rem;
pthread_mutex_t spaces_mutex = PTHREAD_MUTEX_INITIALIZER;
int print_space_state(struct space *sp, char *str)
@@ -64,19 +67,53 @@ int print_space_state(struct space *sp, char *str)
return strlen(str) + 1;
}
-static struct space *_search_space(char *name, struct sync_disk *disk,
- uint64_t host_id, struct list_head *head)
+static struct space *_search_space(char *name,
+ struct sync_disk *disk,
+ uint64_t host_id,
+ struct list_head *head1,
+ struct list_head *head2,
+ struct list_head *head3)
{
struct space *sp;
- list_for_each_entry(sp, head, list) {
- 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;
+ if (head1) {
+ list_for_each_entry(sp, head1, list) {
+ if (name && strncmp(sp->space_name, name, NAME_ID_SIZE))
+ continue;
+ if (disk && strncmp(sp->host_id_disk.path, disk->path, SANLK_PATH_LEN))
+ continue;
+ if (disk && sp->host_id_disk.offset != disk->offset)
+ continue;
+ if (host_id && sp->host_id != host_id)
+ continue;
+ return sp;
+ }
+ }
+ if (head2) {
+ list_for_each_entry(sp, head2, list) {
+ if (name && strncmp(sp->space_name, name, NAME_ID_SIZE))
+ continue;
+ if (disk && strncmp(sp->host_id_disk.path, disk->path, SANLK_PATH_LEN))
+ continue;
+ if (disk && sp->host_id_disk.offset != disk->offset)
+ continue;
+ if (host_id && sp->host_id != host_id)
+ continue;
+ return sp;
+ }
+ }
+ if (head3) {
+ list_for_each_entry(sp, head3, list) {
+ if (name && strncmp(sp->space_name, name, NAME_ID_SIZE))
+ continue;
+ if (disk && strncmp(sp->host_id_disk.path, disk->path, SANLK_PATH_LEN))
+ continue;
+ if (disk && sp->host_id_disk.offset != disk->offset)
+ continue;
+ if (host_id && sp->host_id != host_id)
+ continue;
+ return sp;
+ }
}
return NULL;
}
@@ -154,7 +191,7 @@ int host_id_check(struct task *task, struct space *sp)
return 1;
}
-static void *host_id_thread(void *arg_in)
+static void *lockspace_thread(void *arg_in)
{
struct task task;
struct space *sp;
@@ -216,16 +253,8 @@ static void *host_id_thread(void *arg_in)
sp->lease_status.renewal_last_success = last_success;
pthread_mutex_unlock(&sp->mutex);
- if (result < 0) {
- log_erros(sp, "host_id %llu acquire failed %d",
- (unsigned long long)our_host_id, result);
+ if (result < 0)
goto out;
- }
-
- log_erros(sp, "host_id %llu generation %llu acquire %llu",
- (unsigned long long)our_host_id,
- (unsigned long long)leader.owner_generation,
- (unsigned long long)leader.timestamp);
sp->host_generation = leader.owner_generation;
our_host_id_generation = leader.owner_generation;
@@ -271,13 +300,11 @@ static void *host_id_thread(void *arg_in)
sp->lease_status.renewal_last_success = last_success;
if (delta_length > task.id_renewal_seconds) {
- log_erros(sp, "host_id %llu renewed %llu delta_length %d too long",
- (unsigned long long)our_host_id,
+ log_erros(sp, "renewed %llu delta_length %d too long",
(unsigned long long)last_success,
delta_length);
} else if (com.debug_renew) {
- log_space(sp, "host_id %llu renewed %llu delta_length %d interval %d",
- (unsigned long long)our_host_id,
+ log_space(sp, "renewed %llu delta_length %d interval %d",
(unsigned long long)last_success,
delta_length, gap);
}
@@ -285,8 +312,8 @@ static void *host_id_thread(void *arg_in)
if (!sp->thread_stop)
update_watchdog_file(sp, last_success);
} else {
- log_erros(sp, "host_id %llu renewal error %d delta_length %d last_success %llu",
- (unsigned long long)our_host_id, result, delta_length,
+ log_erros(sp, "renewal error %d delta_length %d last_success %llu",
+ result, delta_length,
(unsigned long long)sp->lease_status.renewal_last_success);
}
stop = sp->thread_stop;
@@ -313,43 +340,81 @@ static void *host_id_thread(void *arg_in)
* watchdog needs to be active watching our host_id renewals.
*/
-int add_space(struct space *sp)
+int add_lockspace(struct sanlk_lockspace *ls)
{
+ struct space *sp, *sp2;
int rv, result;
- if (!sp->space_name[0]) {
- log_erros(sp, "add_space no name");
- rv = -EINVAL;
- goto fail;
+ if (!ls->name[0] || !ls->host_id || !ls->host_id_disk.path[0]) {
+ log_error("add_lockspace bad args id %llu name %zu path %zu",
+ (unsigned long long)ls->host_id,
+ strlen(ls->name), strlen(ls->host_id_disk.path));
+ return -EINVAL;
}
- if (!sp->host_id) {
- log_erros(sp, "add_space zero host_id");
- rv = -EINVAL;
- goto fail;
- }
+ sp = malloc(sizeof(struct space));
+ if (!sp)
+ return -ENOMEM;
+ memset(sp, 0, sizeof(struct space));
- if (space_exists(sp->space_name, &sp->host_id_disk, sp->host_id)) {
- log_erros(sp, "add_space exists");
+ memcpy(sp->space_name, ls->name, NAME_ID_SIZE);
+ memcpy(&sp->host_id_disk, &ls->host_id_disk, sizeof(struct sanlk_disk));
+ sp->host_id_disk.sector_size = 0;
+ sp->host_id_disk.fd = -1;
+ sp->host_id = ls->host_id;
+ pthread_mutex_init(&sp->mutex, NULL);
+
+ pthread_mutex_lock(&spaces_mutex);
+
+ /* search all lists for an identical lockspace */
+
+ sp2 = _search_space(sp->space_name, &sp->host_id_disk, sp->host_id,
+ &spaces, &spaces_add, NULL);
+ if (sp2) {
+ pthread_mutex_unlock(&spaces_mutex);
rv = -EEXIST;
- goto fail;
+ goto fail_free;
}
- if (space_exists(sp->space_name, NULL, 0)) {
- log_erros(sp, "add_space name exists with other host info");
+ sp2 = _search_space(sp->space_name, &sp->host_id_disk, sp->host_id,
+ &spaces_rem, NULL, NULL);
+ if (sp2) {
+ pthread_mutex_unlock(&spaces_mutex);
+ rv = -EAGAIN;
+ goto fail_free;
+ }
+
+ /* search all lists for a lockspace with the same name */
+
+ sp2 = _search_space(sp->space_name, NULL, 0,
+ &spaces, &spaces_add, &spaces_rem);
+ if (sp2) {
+ pthread_mutex_unlock(&spaces_mutex);
rv = -EINVAL;
- goto fail;
+ goto fail_free;
}
- log_space(sp, "add_space host_id %llu path %s offset %llu",
- (unsigned long long)sp->host_id,
- sp->host_id_disk.path,
- (unsigned long long)sp->host_id_disk.offset);
+ /* search all lists for a lockspace with the same host_id_disk */
- rv = pthread_create(&sp->thread, NULL, host_id_thread, sp);
+ sp2 = _search_space(NULL, &sp->host_id_disk, 0,
+ &spaces, &spaces_add, &spaces_rem);
+ if (sp2) {
+ pthread_mutex_unlock(&spaces_mutex);
+ rv = -EINVAL;
+ goto fail_free;
+ }
+
+ sp->space_id = space_id_counter++;
+ list_add(&sp->list, &spaces_add);
+ pthread_mutex_unlock(&spaces_mutex);
+
+ rv = pthread_create(&sp->thread, NULL, lockspace_thread, sp);
if (rv < 0) {
- log_erros(sp, "add_space create thread failed");
- goto fail;
+ log_erros(sp, "add_lockspace create thread failed");
+ pthread_mutex_lock(&spaces_mutex);
+ list_del(&sp->list);
+ pthread_mutex_unlock(&spaces_mutex);
+ goto fail_free;
}
while (1) {
@@ -365,41 +430,74 @@ int add_space(struct space *sp)
/* the thread exits right away if acquire fails */
pthread_join(sp->thread, NULL);
rv = result;
- goto fail;
+ goto fail_free;
}
+ /* once we move sp to spaces list, tokens can begin using it,
+ and the main loop will begin monitoring its renewals */
+
pthread_mutex_lock(&spaces_mutex);
- /* TODO: repeating check here unnecessary if we serialize adds and removes */
- 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;
- } else {
- list_add(&sp->list, &spaces);
- }
+ list_move(&sp->list, &spaces);
pthread_mutex_unlock(&spaces_mutex);
return 0;
- fail_stop:
- sp->thread_stop = 1;
- pthread_join(sp->thread, NULL);
- fail:
+ fail_free:
+ free(sp);
return rv;
}
-int rem_space(char *name, struct sync_disk *disk, uint64_t host_id)
+int rem_lockspace(struct sanlk_lockspace *ls)
{
- struct space *sp;
- int rv = -ENOENT;
+ struct space *sp, *sp2;
+ unsigned int id;
+ int rv, done;
pthread_mutex_lock(&spaces_mutex);
- sp = _search_space(name, disk, host_id, &spaces);
+
+ sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id,
+ &spaces_rem, NULL, NULL);
if (sp) {
- sp->external_remove = 1;
- rv = 0;
+ pthread_mutex_unlock(&spaces_mutex);
+ rv = -EINPROGRESS;
+ goto out;
}
+
+ sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id,
+ &spaces_add, NULL, NULL);
+ if (sp) {
+ pthread_mutex_unlock(&spaces_mutex);
+ rv = -EAGAIN;
+ goto out;
+ }
+
+ sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id,
+ &spaces, NULL, NULL);
+ if (!sp) {
+ pthread_mutex_unlock(&spaces_mutex);
+ rv = -ENOENT;
+ goto out;
+ }
+
+ sp->external_remove = 1;
+ id = sp->space_id;
pthread_mutex_unlock(&spaces_mutex);
+
+ while (1) {
+ pthread_mutex_lock(&spaces_mutex);
+ sp2 = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id,
+ &spaces, &spaces_rem, NULL);
+ if (sp2 && sp2->space_id == id)
+ done = 0;
+ else
+ done = 1;
+ pthread_mutex_unlock(&spaces_mutex);
+
+ if (done)
+ break;
+ sleep(1);
+ }
+ rv = 0;
+ out:
return rv;
}
@@ -412,16 +510,18 @@ int rem_space(char *name, struct sync_disk *disk, uint64_t host_id)
* "logical" point commented above in host_id_thread.
*/
-static int finish_space(struct space *sp, int wait)
+static int stop_lockspace_thread(struct space *sp, int wait)
{
int stop, rv;
pthread_mutex_lock(&sp->mutex);
stop = sp->thread_stop;
+ sp->thread_stop = 1;
pthread_mutex_unlock(&sp->mutex);
if (!stop) {
- log_erros(sp, "finish_space zero thread_stop");
+ /* should never happen */
+ log_erros(sp, "stop_lockspace_thread zero thread_stop");
return -EINVAL;
}
@@ -433,16 +533,16 @@ static int finish_space(struct space *sp, int wait)
return rv;
}
-void clear_spaces(int wait)
+void free_lockspaces(int wait)
{
struct space *sp, *safe;
int rv;
pthread_mutex_lock(&spaces_mutex);
- list_for_each_entry_safe(sp, safe, &spaces_remove, list) {
- rv = finish_space(sp, wait);
+ list_for_each_entry_safe(sp, safe, &spaces_rem, list) {
+ rv = stop_lockspace_thread(sp, wait);
if (!rv) {
- log_space(sp, "free sp");
+ log_space(sp, "free lockspace");
list_del(&sp->list);
free(sp);
}
@@ -450,23 +550,10 @@ void clear_spaces(int wait)
pthread_mutex_unlock(&spaces_mutex);
}
-int space_exists(char *name, struct sync_disk *disk, uint64_t host_id)
-{
- struct space *sp;
-
- pthread_mutex_lock(&spaces_mutex);
- sp = _search_space(name, disk, host_id, &spaces);
- if (!sp)
- sp = _search_space(name, disk, host_id, &spaces_remove);
- pthread_mutex_unlock(&spaces_mutex);
- if (sp)
- return 1;
- return 0;
-}
-
void setup_spaces(void)
{
INIT_LIST_HEAD(&spaces);
- INIT_LIST_HEAD(&spaces_remove);
+ INIT_LIST_HEAD(&spaces_add);
+ INIT_LIST_HEAD(&spaces_rem);
}
diff --git a/src/host_id.h b/src/host_id.h
index 56eb783..5cc8b50 100644
--- a/src/host_id.h
+++ b/src/host_id.h
@@ -14,10 +14,9 @@ int _get_space_info(char *space_name, struct space *sp_out);
int get_space_info(char *space_name, struct space *sp_out);
int host_id_disk_info(char *name, struct sync_disk *disk);
int host_id_check(struct task *task, struct space *sp);
-int add_space(struct space *sp);
-int rem_space(char *name, struct sync_disk *disk, uint64_t host_id);
-void clear_spaces(int wait);
-int space_exists(char *name, struct sync_disk *disk, uint64_t host_id);
+int add_lockspace(struct sanlk_lockspace *ls);
+int rem_lockspace(struct sanlk_lockspace *ls);
+void free_lockspaces(int wait);
void setup_spaces(void);
#endif
diff --git a/src/main.c b/src/main.c
index 31df837..25343b7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -80,8 +80,7 @@ static char command[COMMAND_MAX];
static int cmd_argc;
static char **cmd_argv;
static int external_shutdown;
-static int token_id_counter = 1;
-static int space_id_counter = 1;
+static unsigned int token_id_counter = 1;
struct cmd_args {
struct list_head list; /* thread_pool data */
@@ -106,7 +105,7 @@ struct thread_pool {
static struct thread_pool pool;
extern struct list_head spaces;
-extern struct list_head spaces_remove;
+extern struct list_head spaces_rem;
extern pthread_mutex_t spaces_mutex;
/* FIXME: add a mutex for client array so we don't try to expand it
@@ -587,7 +586,7 @@ static int main_loop(void)
sp->thread_stop = 1;
unlink_watchdog_file(sp);
pthread_mutex_unlock(&sp->mutex);
- list_move(&sp->list, &spaces_remove);
+ list_move(&sp->list, &spaces_rem);
} else {
kill_pids(sp);
}
@@ -616,7 +615,7 @@ static int main_loop(void)
if (empty && external_shutdown)
break;
- clear_spaces(0);
+ free_lockspaces(0);
gettimeofday(&now, NULL);
ms = time_diff(&last_check, &now);
@@ -626,7 +625,7 @@ static int main_loop(void)
poll_timeout = 1;
}
- clear_spaces(1);
+ free_lockspaces(1);
return 0;
}
@@ -794,7 +793,7 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca)
goto done;
}
- if (res.num_disks > MAX_DISKS) {
+ if (!res.num_disks || res.num_disks > MAX_DISKS) {
result = -ERANGE;
goto done;
}
@@ -851,8 +850,11 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca)
* of full length space_name+resource_name in each log message
* would make excessively long lines. */
- log_token(token, "lockspace %.48s resource %.48s has token_id %u for pid %u",
- token->r.lockspace_name, token->r.name, token->token_id, cl_pid);
+ log_token(token, "cmd_acquire %d,%d,%d %.48s:%.48s:%s:%llu",
+ cl_ci, cl_fd, cl_pid,
+ token->r.lockspace_name, token->r.name,
+ token->disks[0].path,
+ (unsigned long long)token->disks[0].offset);
}
rv = recv(fd, &opt, sizeof(struct sanlk_options), MSG_WAITALL);
@@ -1309,20 +1311,11 @@ static void cmd_inquire(struct task *task, struct cmd_args *ca)
static void cmd_add_lockspace(struct cmd_args *ca)
{
struct sm_header h;
- struct space *sp;
struct sanlk_lockspace lockspace;
int fd, rv, result;
fd = client[ca->ci_in].fd;
- log_debug("cmd_add_lockspace %d,%d", ca->ci_in, fd);
-
- sp = malloc(sizeof(struct space));
- if (!sp) {
- result = -ENOMEM;
- goto reply;
- }
-
rv = recv(fd, &lockspace, sizeof(struct sanlk_lockspace), MSG_WAITALL);
if (rv != sizeof(struct sanlk_lockspace)) {
log_error("cmd_add_lockspace %d,%d recv %d %d",
@@ -1331,32 +1324,13 @@ static void cmd_add_lockspace(struct cmd_args *ca)
goto reply;
}
- memset(sp, 0, sizeof(struct space));
- memcpy(sp->space_name, lockspace.name, NAME_ID_SIZE);
- sp->host_id = lockspace.host_id;
- memcpy(&sp->host_id_disk, &lockspace.host_id_disk,
- sizeof(struct sanlk_disk));
- sp->host_id_disk.fd = -1;
- pthread_mutex_init(&sp->mutex, NULL);
-
- pthread_mutex_lock(&spaces_mutex);
- sp->space_id = space_id_counter++;
- pthread_mutex_unlock(&spaces_mutex);
-
- /* We use the space_id in log messages because the full length
- * space_name in each log message woul dmake excessively long lines. */
-
- log_space(sp, "lockspace %.48s host_id %llu has space_id %u",
- sp->space_name, (unsigned long long)sp->host_id,
- sp->space_id);
-
- /* add_space returns once the host_id has been acquired and
- sp space has been added to the spaces list */
+ log_debug("cmd_add_lockspace %d,%d %.48s:%llu:%s:%llu",
+ ca->ci_in, fd, lockspace.name,
+ (unsigned long long)lockspace.host_id,
+ lockspace.host_id_disk.path,
+ (unsigned long long)lockspace.host_id_disk.offset);
- result = add_space(sp);
-
- if (result)
- free(sp);
+ result = add_lockspace(&lockspace);
reply:
log_debug("cmd_add_lockspace %d,%d done %d", ca->ci_in, fd, result);
@@ -1377,8 +1351,6 @@ static void cmd_rem_lockspace(struct cmd_args *ca)
fd = client[ca->ci_in].fd;
- log_debug("cmd_rem_lockspace %d,%d", ca->ci_in, fd);
-
rv = recv(fd, &lockspace, sizeof(struct sanlk_lockspace), MSG_WAITALL);
if (rv != sizeof(struct sanlk_lockspace)) {
log_error("cmd_rem_lockspace %d,%d recv %d %d",
@@ -1387,29 +1359,10 @@ static void cmd_rem_lockspace(struct cmd_args *ca)
goto reply;
}
- /* rem_space flags the sp as wanting to be removed, so follow with a
- wait loop until it's actually gone */
-
- /* TODO: we should probably prevent add_lockspace during an
- outstanding rem_lockspace and v.v. This would prevent problems
- with the space_exists name check below when the same lockspace
- name was removed and added at once */
-
- 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,
- (struct sync_disk *)&lockspace.host_id_disk,
- lockspace.host_id))
- break;
- sleep(1);
- }
+ log_debug("cmd_rem_lockspace %d,%d %.48s",
+ ca->ci_in, fd, lockspace.name);
+ result = rem_lockspace(&lockspace);
reply:
log_debug("cmd_rem_lockspace %d,%d done %d", ca->ci_in, fd, result);
12 years, 10 months
src/host_id.c src/main.c src/sanlock_internal.h src/token_manager.c tests/devcount.c tests/devcountn
by David Teigland
src/host_id.c | 7 ++++---
src/main.c | 23 +++++++++++++++++------
src/sanlock_internal.h | 2 ++
src/token_manager.c | 13 ++++++++-----
tests/devcount.c | 4 ++--
tests/devcountn | 1 +
6 files changed, 34 insertions(+), 16 deletions(-)
New commits:
commit 795995ae43f325dd791aeb274488f1da1ff607a1
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Jun 2 10:44:16 2011 -0500
sanlock: don't release tokens in dead lockspace
diff --git a/src/host_id.c b/src/host_id.c
index a523242..52b0054 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -42,6 +42,7 @@ int print_space_state(struct space *sp, char *str)
snprintf(str, SANLK_STATE_MAXSTR-1,
"space_id=%u "
"host_generation=%llu "
+ "space_dead=%d "
"killing_pids=%d "
"acquire_last_result=%d "
"renewal_last_result=%d "
@@ -51,6 +52,7 @@ int print_space_state(struct space *sp, char *str)
"renewal_last_success=%llu",
sp->space_id,
(unsigned long long)sp->host_generation,
+ sp->space_dead,
sp->killing_pids,
sp->lease_status.acquire_last_result,
sp->lease_status.renewal_last_result,
@@ -59,7 +61,7 @@ int print_space_state(struct space *sp, char *str)
(unsigned long long)sp->lease_status.renewal_last_attempt,
(unsigned long long)sp->lease_status.renewal_last_success);
- return strlen(str);
+ return strlen(str) + 1;
}
static struct space *_search_space(char *name, struct sync_disk *disk,
@@ -423,8 +425,6 @@ static int finish_space(struct space *sp, int wait)
return -EINVAL;
}
- log_space(sp, "finish_space");
-
if (wait)
rv = pthread_join(sp->thread, NULL);
else
@@ -442,6 +442,7 @@ void clear_spaces(int wait)
list_for_each_entry_safe(sp, safe, &spaces_remove, list) {
rv = finish_space(sp, wait);
if (!rv) {
+ log_space(sp, "free sp");
list_del(&sp->list);
free(sp);
}
diff --git a/src/main.c b/src/main.c
index c12ac7b..31df837 100644
--- a/src/main.c
+++ b/src/main.c
@@ -415,9 +415,14 @@ static int client_using_space(struct client *cl, struct space *sp)
continue;
if (strncmp(token->r.lockspace_name, sp->space_name, NAME_ID_SIZE))
continue;
- rv = 1;
+
log_spoke(sp, token, "client_using_space pid %d", cl->pid);
- break;
+ token->space_dead = sp->space_dead;
+ rv = 1;
+
+ /* we could break here after finding one if we didn't care
+ * about setting token->space_dead which isn't really
+ * necessary; it just avoids trying to release the token */
}
return rv;
}
@@ -536,7 +541,7 @@ static int main_loop(void)
struct timeval now, last_check;
int poll_timeout, check_interval;
unsigned int ms;
- int i, rv, empty;
+ int i, rv, empty, space_dead;
gettimeofday(&last_check, NULL);
poll_timeout = STANDARD_CHECK_INTERVAL;
@@ -588,9 +593,15 @@ static int main_loop(void)
}
check_interval = RECOVERY_CHECK_INTERVAL;
} else {
- if (external_shutdown || sp->external_remove ||
- !host_id_check(&main_task, sp)) {
- log_space(sp, "set killing_pids");
+ space_dead = !host_id_check(&main_task, sp);
+
+ if (space_dead || external_shutdown ||
+ sp->external_remove) {
+ log_space(sp, "set killing_pids dead %d "
+ "shutdown %d remove %d",
+ space_dead, external_shutdown,
+ sp->external_remove);
+ sp->space_dead = space_dead;
sp->killing_pids = 1;
kill_pids(sp);
check_interval = RECOVERY_CHECK_INTERVAL;
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 2729f6d..62b3f68 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -84,6 +84,7 @@ struct token {
/* internal */
int token_id; /* used to refer to this token instance in log messages */
+ int space_dead; /* don't bother trying to release if ls is dead */
int acquire_result;
int release_result;
struct leader_record leader; /* copy of last leader_record we wrote */
@@ -108,6 +109,7 @@ struct space {
struct sync_disk host_id_disk;
struct list_head list;
int space_id; /* used to refer to this space instance in log messages */
+ int space_dead;
int killing_pids;
int external_remove;
int thread_stop;
diff --git a/src/token_manager.c b/src/token_manager.c
index abb2eb5..c0fc485 100644
--- a/src/token_manager.c
+++ b/src/token_manager.c
@@ -210,9 +210,7 @@ static void *async_release_thread(void *arg GNUC_UNUSED)
pthread_mutex_unlock(&resource_mutex);
token = r->token;
-
- if (token->acquire_result == 1)
- release_token(&task, token);
+ release_token(&task, token);
/* we don't want to remove r from dispose_list until after the
lease is released because we don't want a new token for
@@ -237,8 +235,13 @@ void release_token_async(struct token *token)
r = find_resource(token, &resources);
if (r) {
/* assert r->token == token ? */
- list_move(&r->list, &dispose_resources);
- pthread_cond_signal(&resource_cond);
+ if (token->space_dead || (token->acquire_result != SANLK_OK)) {
+ _del_resource(r);
+ free(token);
+ } else {
+ list_move(&r->list, &dispose_resources);
+ pthread_cond_signal(&resource_cond);
+ }
}
pthread_mutex_unlock(&resource_mutex);
}
diff --git a/tests/devcount.c b/tests/devcount.c
index 817927c..f897f74 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -580,9 +580,9 @@ static int do_relock(int argc, char *argv[])
}
run_more:
- /* let the child run for 20 seconds before stopping it */
+ /* let the child run for 30 seconds before stopping it */
- for (i = 0; i < 20; i++) {
+ for (i = 0; i < 30; i++) {
rv = waitpid(pid, &status, WNOHANG);
if (rv == pid)
break;
diff --git a/tests/devcountn b/tests/devcountn
index 625eb33..8ef1b7a 100755
--- a/tests/devcountn
+++ b/tests/devcountn
@@ -10,6 +10,7 @@ if [ $# -le 3 ]; then
echo "devcountn N relock LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID"
echo "devcountn N wrap LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID"
echo "devcountn N migrate LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID MAXID"
+ echo "devcountn N expire LOCKDEV_BASE rw COUNTDEV_BASE SEC1 SEC2 HOSTID"
echo ""
echo "devcount <cmd> LOCKDEV1 rw COUNTDEV1 ..."
echo "devcount <cmd> LOCKDEV2 rw COUNTDEV2 ..."
12 years, 10 months
init.d/sanlock src/main.c
by David Teigland
init.d/sanlock | 11 +++++++++--
src/main.c | 17 ++++++++---------
2 files changed, 17 insertions(+), 11 deletions(-)
New commits:
commit 061d6d7b840e0b26636f01ecfa94f07b3bfd40c4
Author: David Teigland <teigland(a)redhat.com>
Date: Thu Jun 2 11:03:27 2011 -0500
sanlock: fix init restart
sanlock daemon creates and unlinks lockfile,
init.d/sanlock should not.
unlinking lockfile is the last thing sanlock
daemon should do.
init.d/sanlock restart should wait for stop
to finish (lockfile to be unlinked) before
doing start.
diff --git a/init.d/sanlock b/init.d/sanlock
index c05fa9c..d46dcef 100644
--- a/init.d/sanlock
+++ b/init.d/sanlock
@@ -33,7 +33,7 @@ start() {
daemon $prog daemon $SANLOCKOPTS
retval=$?
echo
- [ $retval -eq 0 ] && touch $lockfile
+ [ $retval -eq 0 ]
return $retval
}
@@ -42,11 +42,18 @@ stop() {
killproc -p $lockfile $prog -TERM
retval=$?
echo
- [ $retval -eq 0 ] && rm -f $lockfile
+ [ $retval -eq 0 ]
+}
+
+wait_for_stop() {
+ while [ -e $lockfile ]; do
+ sleep .5
+ done
}
restart() {
stop
+ wait_for_stop
start
}
diff --git a/src/main.c b/src/main.c
index 13b32a4..c12ac7b 100644
--- a/src/main.c
+++ b/src/main.c
@@ -2161,21 +2161,21 @@ static int do_daemon(void)
if (rv < 0)
return rv;
- setup_logging();
-
- setup_priority();
-
fd = lockfile(SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
if (fd < 0)
- goto out;
+ return fd;
+
+ setup_logging();
log_error("sanlock daemon started aio %d %d renew %d %d",
main_task.use_aio, main_task.io_timeout_seconds,
main_task.id_renewal_seconds, main_task.id_renewal_fail_seconds);
+ setup_priority();
+
rv = thread_pool_create(DEFAULT_MIN_WORKER_THREADS, com.max_worker_threads);
if (rv < 0)
- goto out_lockfile;
+ goto out_logging;
rv = setup_watchdog();
if (rv < 0)
@@ -2199,10 +2199,9 @@ static int do_daemon(void)
out_threads:
thread_pool_free();
- out_lockfile:
- unlink_lockfile(fd, SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
- out:
+ out_logging:
close_logging();
+ unlink_lockfile(fd, SANLK_RUN_DIR, SANLK_LOCKFILE_NAME);
return rv;
}
12 years, 10 months
3 commits - src/client_msg.h src/client_resource.c src/direct.c src/direct_lib.c src/diskio.c src/diskio.h src/host_id.c src/main.c src/paxos_lease.c src/sanlock_direct.h src/sanlock_resource.h src/sanlock_rv.h tests/devcount.c
by David Teigland
src/client_msg.h | 1
src/client_resource.c | 21 ++++++++++
src/direct.c | 10 ++--
src/direct_lib.c | 19 +++++++++
src/diskio.c | 100 ++++++++++++++++++++++++++++++++-----------------
src/diskio.h | 1
src/host_id.c | 12 +++--
src/main.c | 29 ++++++++++++++
src/paxos_lease.c | 36 +++++++++++++++++
src/sanlock_direct.h | 16 +++++++
src/sanlock_resource.h | 4 +
src/sanlock_rv.h | 1
tests/devcount.c | 55 ++++++++++++++++++++------
13 files changed, 246 insertions(+), 59 deletions(-)
New commits:
commit 053486def93b2bbc00104e6a457412dd242fb4ac
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 1 14:46:15 2011 -0500
sanlock: add checksum to dblocks
and verify dblock checksum before using the values
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index e9adcfb..25ddf37 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -34,6 +34,8 @@ struct request_record {
uint8_t force_mode;
};
+#define DBLOCK_CHECKSUM_LEN 48 /* ends before checksum field */
+
struct paxos_dblock {
uint64_t mbal;
uint64_t bal;
@@ -41,6 +43,7 @@ struct paxos_dblock {
uint64_t inp2; /* host_id generation */
uint64_t inp3; /* host_id's timestamp */
uint64_t lver;
+ uint32_t checksum;
};
static uint32_t roundup_power_of_two(uint32_t val)
@@ -201,6 +204,29 @@ static int read_request(struct task *task,
}
#endif
+static uint32_t dblock_checksum(struct paxos_dblock *pd)
+{
+ return crc32c((uint32_t)~1, (char *)pd, DBLOCK_CHECKSUM_LEN);
+}
+
+static int verify_dblock(struct token *token, struct paxos_dblock *pd)
+{
+ uint32_t sum;
+
+ if (!pd->checksum && !pd->mbal && !pd->bal && !pd->inp && !pd->lver)
+ return SANLK_OK;
+
+ sum = dblock_checksum(pd);
+
+ if (pd->checksum != sum) {
+ log_errot(token, "verify_dblock wrong checksum %x %x",
+ pd->checksum, sum);
+ return SANLK_DBLOCK_CHECKSUM;
+ }
+
+ return SANLK_OK;
+}
+
/*
* It's possible that we pick a bk_max from another host which has our own
* inp values in it, and we can end up commiting our own inp values, copied
@@ -301,6 +327,7 @@ static int run_ballot(struct task *task, struct token *token, int num_hosts,
memset(&dblock, 0, sizeof(struct paxos_dblock));
dblock.mbal = our_mbal;
dblock.lver = next_lver;
+ dblock.checksum = dblock_checksum(&dblock);
memset(&bk_max, 0, sizeof(struct paxos_dblock));
@@ -340,6 +367,10 @@ static int run_ballot(struct task *task, struct token *token, int num_hosts,
for (q = 0; q < num_hosts; q++) {
bk = (struct paxos_dblock *)(iobuf[d] + ((2 + q)*sector_size));
+ rv = verify_dblock(token, bk);
+ if (rv < 0)
+ continue;
+
if (bk->lver < dblock.lver)
continue;
@@ -417,6 +448,7 @@ static int run_ballot(struct task *task, struct token *token, int num_hosts,
dblock.inp3 = time(NULL);
}
dblock.bal = dblock.mbal;
+ dblock.checksum = dblock_checksum(&dblock);
if (bk_max.inp) {
/* not a problem, but interesting to see, so use log_error */
@@ -480,6 +512,10 @@ static int run_ballot(struct task *task, struct token *token, int num_hosts,
for (q = 0; q < num_hosts; q++) {
bk = (struct paxos_dblock *)(iobuf[d] + ((2 + q)*sector_size));
+ rv = verify_dblock(token, bk);
+ if (rv < 0)
+ continue;
+
if (bk->lver < dblock.lver)
continue;
diff --git a/src/sanlock_rv.h b/src/sanlock_rv.h
index c027828..6b0510f 100644
--- a/src/sanlock_rv.h
+++ b/src/sanlock_rv.h
@@ -20,6 +20,7 @@
#define SANLK_DBLOCK_WRITE -211
#define SANLK_DBLOCK_LVER -212
#define SANLK_DBLOCK_MBAL -213
+#define SANLK_DBLOCK_CHECKSUM -214
/* verify_leader, leader_read, leader_write (paxos or delta) */
commit 74fdc2def01fa3b805b158d5f53b73f3edd439f4
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 1 13:35:38 2011 -0500
sanlock: add sanlock_direct_sector_size api
gets and returns the sector size (i.e. 512, 4096)
that sanlock would use for a given a path (disk or file)
diff --git a/src/direct.c b/src/direct.c
index 8823355..594285f 100644
--- a/src/direct.c
+++ b/src/direct.c
@@ -202,8 +202,8 @@ static int do_delta_action(int action,
memcpy(&sd, &ls->host_id_disk, sizeof(struct sanlk_disk));
sd.fd = -1;
- rv = open_disks(&sd, 1);
- if (rv != 1)
+ rv = open_disk(&sd);
+ if (rv < 0)
return -ENODEV;
switch (action) {
@@ -417,8 +417,8 @@ int direct_dump(struct task *task, char *dump_path)
struct sync_disk sd;
char sname[NAME_ID_SIZE+1];
char rname[NAME_ID_SIZE+1];
- int num_opened, rv;
uint64_t sector_nr;
+ int rv;
memset(&sd, 0, sizeof(struct sync_disk));
@@ -432,8 +432,8 @@ int direct_dump(struct task *task, char *dump_path)
strncpy(sd.path, dump_path, SANLK_PATH_LEN);
sd.fd = -1;
- num_opened = open_disks(&sd, 1);
- if (num_opened != 1)
+ rv = open_disk(&sd);
+ if (rv < 0)
return -ENODEV;
data = malloc(sd.sector_size);
diff --git a/src/direct_lib.c b/src/direct_lib.c
index 3f2bac1..6ccd339 100644
--- a/src/direct_lib.c
+++ b/src/direct_lib.c
@@ -16,6 +16,7 @@
#include "sanlock_internal.h"
#include "sanlock_direct.h"
+#include "diskio.h"
#include "direct.h"
#include "task.h"
@@ -103,3 +104,21 @@ int sanlock_direct_init(struct sanlk_lockspace *ls,
return rv;
}
+int sanlock_direct_sector_size(struct sanlk_disk *disk_in)
+{
+ struct sync_disk disk;
+ int rv;
+
+ memset(&disk, 0, sizeof(disk));
+
+ memcpy(disk.path, disk_in->path, SANLK_PATH_LEN);
+
+ rv = open_disk(&disk);
+ if (rv < 0)
+ return rv;
+
+ close(disk.fd);
+
+ return disk.sector_size;
+}
+
diff --git a/src/diskio.c b/src/diskio.c
index ccf7a4d..843559b 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -73,15 +73,18 @@ void close_disks(struct sync_disk *disks, int num_disks)
int d;
for (d = 0; d < num_disks; d++) {
- if (disks[d].fd == -1) {
- log_error("close fd -1");
+ if (disks[d].fd == -1)
continue;
- }
close(disks[d].fd);
disks[d].fd = -1;
}
}
+/*
+ * set fd in each disk
+ * returns number of opened disks
+ */
+
int open_disks_fd(struct sync_disk *disks, int num_disks)
{
struct sync_disk *disk;
@@ -93,7 +96,7 @@ int open_disks_fd(struct sync_disk *disks, int num_disks)
if (disk->fd != -1) {
log_error("open fd %d exists %s", disk->fd, disk->path);
- return 0;
+ goto fail;
}
fd = open(disk->path, O_RDWR | O_DIRECT | O_SYNC, 0);
@@ -106,60 +109,90 @@ int open_disks_fd(struct sync_disk *disks, int num_disks)
num_opens++;
}
return num_opens;
+
+ fail:
+ close_disks(disks, num_disks);
+ return 0;
}
-/* return number of opened disks */
+/*
+ * set fd and sector_size
+ * returns 0 for success or -EXXX
+ */
+
+int open_disk(struct sync_disk *disk)
+{
+ struct stat st;
+ int fd, rv;
+
+ fd = open(disk->path, O_RDWR | O_DIRECT | O_SYNC, 0);
+ if (fd < 0) {
+ rv = -errno;
+ log_error("open error %d %s", rv, disk->path);
+ goto fail;
+ }
+
+ if (fstat(fd, &st) < 0) {
+ rv = -errno;
+ log_error("fstat error %d %s", rv, disk->path);
+ close(fd);
+ goto fail;
+ }
+
+ if (S_ISREG(st.st_mode)) {
+ disk->sector_size = 512;
+ } else {
+ rv = set_disk_properties(disk);
+ if (rv < 0) {
+ close(fd);
+ goto fail;
+ }
+ }
+
+ disk->fd = fd;
+ return 0;
+
+ fail:
+ if (rv >= 0)
+ rv = -1;
+ return rv;
+}
+
+/*
+ * set fd and sector_size in each disk
+ * verify all sector_size's match
+ * verify sector_size is ok for previously set offset
+ * returns number of opened disks
+ */
int open_disks(struct sync_disk *disks, int num_disks)
{
struct sync_disk *disk;
int num_opens = 0;
- int d, fd, rv;
+ int d, rv;
uint32_t ss = 0;
- uint64_t orig_offset;
- struct stat st;
for (d = 0; d < num_disks; d++) {
disk = &disks[d];
if (disk->fd != -1) {
log_error("open fd %d exists %s", disk->fd, disk->path);
- return 0;
- }
-
- fd = open(disk->path, O_RDWR | O_DIRECT | O_SYNC, 0);
- if (fd < 0) {
- log_error("open error %d %s", fd, disk->path);
- continue;
- }
-
- if (fstat(fd, &st) < 0) {
- log_error("fstat error %d %s", fd, disk->path);
- close(fd);
- continue;
+ rv = -ENOTEMPTY;
+ goto fail;
}
- if (S_ISREG(st.st_mode)) {
- disk->sector_size = 512;
- } else {
- rv = set_disk_properties(disk);
- if (rv < 0) {
- close(fd);
- continue;
- }
- }
+ rv = open_disk(disk);
+ if (rv < 0)
+ goto fail;
if (!ss) {
ss = disk->sector_size;
} else if (ss != disk->sector_size) {
log_error("inconsistent sector sizes %u %u %s",
ss, disk->sector_size, disk->path);
- close(fd);
goto fail;
}
- orig_offset = disk->offset;
-
if (disk->offset % disk->sector_size) {
log_error("invalid offset %llu sector size %u %s",
(unsigned long long)disk->offset,
@@ -167,7 +200,6 @@ int open_disks(struct sync_disk *disks, int num_disks)
goto fail;
}
- disk->fd = fd;
num_opens++;
}
return num_opens;
diff --git a/src/diskio.h b/src/diskio.h
index c6b2762..dd32958 100644
--- a/src/diskio.h
+++ b/src/diskio.h
@@ -10,6 +10,7 @@
#define __DISKIO_H__
void close_disks(struct sync_disk *disks, int num_disks);
+int open_disk(struct sync_disk *disks);
int open_disks(struct sync_disk *disks, int num_disks);
int open_disks_fd(struct sync_disk *disks, int num_disks);
diff --git a/src/host_id.c b/src/host_id.c
index 0318536..a523242 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -160,8 +160,9 @@ static void *host_id_thread(void *arg_in)
struct leader_record leader;
uint64_t our_host_id, our_host_id_generation;
time_t last_attempt, last_success;
- int rv, result, delta_length, gap, opened;
+ int rv, result, delta_length, gap;
int delta_result = 0;
+ int opened = 0;
int stop = 0;
sp = (struct space *)arg_in;
@@ -174,12 +175,13 @@ static void *host_id_thread(void *arg_in)
last_attempt = time(NULL);
- opened = open_disks(&sp->host_id_disk, 1);
- if (opened != 1) {
- log_erros(sp, "open_disk failed %s", sp->host_id_disk.path);
+ rv = open_disk(&sp->host_id_disk);
+ if (rv < 0) {
+ log_erros(sp, "open_disk %s error %d", sp->host_id_disk.path, rv);
result = -ENODEV;
goto set_status;
}
+ opened = 1;
result = delta_lease_acquire(&task, sp, &sp->host_id_disk, space_name,
our_host_id, our_host_id, &leader);
@@ -297,7 +299,7 @@ static void *host_id_thread(void *arg_in)
our_host_id, &leader, &leader);
if (opened)
- close_disks(&sp->host_id_disk, 1);
+ close(sp->host_id_disk.fd);
close_task_aio(&task);
return NULL;
diff --git a/src/sanlock_direct.h b/src/sanlock_direct.h
index 1bd9c54..435e1bd 100644
--- a/src/sanlock_direct.h
+++ b/src/sanlock_direct.h
@@ -9,6 +9,10 @@
#ifndef __SANLOCK_DIRECT_H__
#define __SANLOCK_DIRECT_H__
+/*
+ * Use io_timeout_sec = 0 for default value
+ */
+
int sanlock_direct_read_id(struct sanlk_lockspace *ls,
uint64_t *timestamp,
uint64_t *owner_id,
@@ -24,10 +28,20 @@ int sanlock_direct_live_id(struct sanlk_lockspace *ls,
int use_aio,
int io_timeout_sec);
-/* Use max_hosts = 0 for default max_hosts value */
+/*
+ * Use max_hosts = 0 for default max_hosts value
+ *
+ * Provide either lockspace or resource, not both
+ */
int sanlock_direct_init(struct sanlk_lockspace *ls,
struct sanlk_resource *res,
int max_hosts, int num_hosts, int use_aio);
+/*
+ * Returns sector size in bytes, -1 on error
+ */
+
+int sanlock_direct_sector_size(struct sanlk_disk *disk);
+
#endif
diff --git a/tests/devcount.c b/tests/devcount.c
index 04a35c4..817927c 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -21,6 +21,9 @@
#include "sanlock_resource.h"
#include "sanlock_direct.h"
+#define ONEMB 1048576
+#define LEASE_SIZE ONEMB
+
FILE *turn_file;
char count_path[PATH_MAX];
@@ -513,7 +516,7 @@ static int do_relock(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -697,7 +700,7 @@ static int do_lock(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -781,7 +784,7 @@ static int do_wrap(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -1032,7 +1035,7 @@ static int do_migrate(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -1215,7 +1218,7 @@ int do_expire(int argc, char *argv[])
res->num_disks = 1;
strncpy(res->disks[0].path, lock_path, SANLK_PATH_LEN);
res->disks[0].path[SANLK_PATH_LEN-1] = '\0';
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
/*
* argv[0] = devcount
@@ -1342,7 +1345,7 @@ int do_expire(int argc, char *argv[])
/*
* devcount init <lock_disk> <count_disk>
* sanlock direct init -n 8 -s devcount:0:<lock_disk>:0
- * sanlock direct init -n 8 -r devcount:resource<count_disk>:<lock_disk>:1024000
+ * sanlock direct init -n 8 -r devcount:resource<count_disk>:<lock_disk>:LEASE_SIZE
* dd if=/dev/zero of=<count_disk> bs=512 count=24
*/
@@ -1351,10 +1354,11 @@ int do_expire(int argc, char *argv[])
int do_init(int argc, char *argv[])
{
char resbuf[sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk)];
+ struct sanlk_disk disk;
struct sanlk_resource *res;
struct sanlk_lockspace ls;
char command[4096];
- int rv;
+ int rv, ss;
if (argc < 4)
return -1;
@@ -1374,21 +1378,37 @@ int do_init(int argc, char *argv[])
system(command);
- /* initialize first resource lease area at offset 1024000 */
+ /* initialize first resource lease area at offset LEASE_SIZE */
memset(command, 0, sizeof(command));
snprintf(command, sizeof(command),
- "sanlock direct init -n %d -r devcount:resource%s:%s:1024000",
+ "sanlock direct init -n %d -r devcount:resource%s:%s:%d",
INIT_NUM_HOSTS,
argv[3],
- argv[2]);
+ argv[2],
+ LEASE_SIZE);
printf("%s\n", command);
system(command);
#else
+ memset(&disk, 0, sizeof(disk));
+ strcpy(disk.path, argv[2]);
+
+ ss = sanlock_direct_sector_size(&disk);
+ if (ss < 0) {
+ printf("sanlock_direct_sector_size %s error %d\n",
+ disk.path, ss);
+ return -1;
+ }
+
+ if (ss != 512) {
+ printf("unsupported sector size %d\n", ss);
+ return -1;
+ }
+
memset(&ls, 0, sizeof(ls));
strcpy(ls.name, "devcount");
strcpy(ls.host_id_disk.path, argv[2]);
@@ -1405,7 +1425,7 @@ int do_init(int argc, char *argv[])
sprintf(res->name, "resource%s", argv[3]);
res->num_disks = 1;
strcpy(res->disks[0].path, argv[2]);
- res->disks[0].offset = 1024000;
+ res->disks[0].offset = LEASE_SIZE;
rv = sanlock_direct_init(NULL, res, 0, INIT_NUM_HOSTS, 0);
if (rv < 0) {
@@ -1459,15 +1479,15 @@ int main(int argc, char *argv[])
out:
/*
* sanlock direct init -n 8 -s devcount:0:/dev/bull/leases:0
- * sanlock direct init -n 8 -r devcount:resource/dev/bull/count:/dev/bull/leases:1024000
+ * sanlock direct init -n 8 -r devcount:resource/dev/bull/count:/dev/bull/leases:LEASE_SIZE
*
* host_id leases exists at <lock_disk> offset 0
- * first resource lease exists at <lock_disk> offset 1024000
+ * first resource lease exists at <lock_disk> offset LEASE_SIZE
*/
printf("devcount init <lock_disk> <count_disk>\n");
printf(" sanlock direct init -n 8 -s devcount:0:<lock_disk>:0\n");
- printf(" sanlock direct init -n 8 -r devcount:resource<count_disk>:<lock_disk>:1024000\n");
+ printf(" sanlock direct init -n 8 -r devcount:resource<count_disk>:<lock_disk>:LEASE_SIZE\n");
printf(" dd if=/dev/zero of=<count_disk> bs=512 count=24\n");
printf("\n");
printf("devcount rw <count_disk> <sec1> <sec2> <hostid>\n");
commit 09583fc87bbe7d5158da5416f318351eef8be180
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 1 11:09:54 2011 -0500
sanlock: add sanlock_restrict api
can be called on a connection to prevent sanlock from
accepting any further commands on that connection (but
it will still watch for the connection close)
diff --git a/src/client_msg.h b/src/client_msg.h
index 828acf5..dcb943a 100644
--- a/src/client_msg.h
+++ b/src/client_msg.h
@@ -21,6 +21,7 @@ enum {
SM_CMD_ACQUIRE = 7,
SM_CMD_RELEASE = 8,
SM_CMD_INQUIRE = 9,
+ SM_CMD_RESTRICT = 10,
};
#define SANLK_STATE_MAXSTR 4096
diff --git a/src/client_resource.c b/src/client_resource.c
index 5a807e1..ef334b9 100644
--- a/src/client_resource.c
+++ b/src/client_resource.c
@@ -48,6 +48,27 @@ int sanlock_register(void)
return sock;
}
+int sanlock_restrict(int sock, uint32_t flags)
+{
+ struct sm_header h;
+ int rv;
+
+ rv = send_header(sock, SM_CMD_RESTRICT, flags, 0, 0, -1);
+ if (rv < 0)
+ return rv;
+
+ memset(&h, 0, sizeof(h));
+
+ rv = recv(sock, &h, sizeof(h), MSG_WAITALL);
+ if (rv != sizeof(h)) {
+ rv = -1;
+ goto out;
+ }
+ rv = (int)h.data;
+ out:
+ return rv;
+}
+
int sanlock_acquire(int sock, int pid, uint32_t flags, int res_count,
struct sanlk_resource *res_args[],
struct sanlk_options *opt_in)
diff --git a/src/main.c b/src/main.c
index cc6d405..13b32a4 100644
--- a/src/main.c
+++ b/src/main.c
@@ -62,6 +62,7 @@ struct client {
int suspend;
int need_free;
int killing;
+ uint32_t cmd_flags;
char owner_name[SANLK_NAME_LEN+1];
pthread_mutex_t mutex;
void *workfn;
@@ -180,6 +181,7 @@ static void _client_free(int ci)
cl->suspend = 0;
cl->need_free = 0;
cl->killing = 0;
+ cl->cmd_flags = 0;
memset(cl->owner_name, 0, sizeof(cl->owner_name));
cl->workfn = NULL;
cl->deadfn = NULL;
@@ -1750,6 +1752,22 @@ static void cmd_log_dump(int fd, struct sm_header *h_recv)
write_log_dump(fd);
}
+static void cmd_restrict(int ci, int fd, struct sm_header *h_recv)
+{
+ struct sm_header h;
+
+ log_debug("cmd_restrict ci %d fd %d pid %d flags %x",
+ ci, fd, client[ci].pid, h_recv->cmd_flags);
+
+ client[ci].cmd_flags = h_recv->cmd_flags;
+
+ memcpy(&h, h_recv, sizeof(struct sm_header));
+ h.length = sizeof(h);
+ h.data = 0;
+ h.data2 = 0;
+ send(fd, &h, sizeof(h), MSG_NOSIGNAL);
+}
+
static void process_cmd_thread_lockspace(int ci_in, struct sm_header *h_recv)
{
struct cmd_args *ca;
@@ -1936,6 +1954,11 @@ static void process_cmd_daemon(int ci, struct sm_header *h_recv)
client[ci].deadfn = client_pid_dead;
auto_close = 0;
break;
+ case SM_CMD_RESTRICT:
+ strcpy(client[ci].owner_name, "restrict");
+ cmd_restrict(ci, fd, h_recv);
+ auto_close = 0;
+ break;
case SM_CMD_SHUTDOWN:
strcpy(client[ci].owner_name, "shutdown");
external_shutdown = 1;
@@ -1978,11 +2001,17 @@ static void process_connection(int ci)
ci, rv, h.magic, SM_MAGIC);
goto dead;
}
+ if (client[ci].cmd_flags & SANLK_RESTRICT_ALL) {
+ log_error("ci %d fd %d pid %d cmd %d restrict all",
+ ci, client[ci].fd, client[ci].pid, h.cmd);
+ goto dead;
+ }
client[ci].cmd_last = h.cmd;
switch (h.cmd) {
case SM_CMD_REGISTER:
+ case SM_CMD_RESTRICT:
case SM_CMD_SHUTDOWN:
case SM_CMD_STATUS:
case SM_CMD_LOG_DUMP:
diff --git a/src/sanlock_resource.h b/src/sanlock_resource.h
index f41f3e3..11f9ace 100644
--- a/src/sanlock_resource.h
+++ b/src/sanlock_resource.h
@@ -21,6 +21,10 @@
int sanlock_register(void);
+#define SANLK_RESTRICT_ALL 0x1
+
+int sanlock_restrict(int sock, uint32_t flags);
+
int sanlock_acquire(int sock, int pid, uint32_t flags, int res_count,
struct sanlk_resource *res_args[],
struct sanlk_options *opt_in);
diff --git a/tests/devcount.c b/tests/devcount.c
index f7d049e..04a35c4 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -558,6 +558,13 @@ static int do_relock(int argc, char *argv[])
log_debug("%s c %d sanlock_acquire done",
count_path, child_pid);
+ rv = sanlock_restrict(sock, SANLK_RESTRICT_ALL);
+ if (rv < 0) {
+ log_error("%s c %d sanlock_restrict error %d",
+ count_path, child_pid, sock);
+ exit(-1);
+ }
+
/* make child's stderr go to parent c2p[0] */
close(2);
dup(c2p[1]);
12 years, 10 months