src/main.c src/paxos_lease.c src/token_manager.c tests/devcount.c
by David Teigland
src/main.c | 4 ++++
src/paxos_lease.c | 3 ++-
src/token_manager.c | 1 +
tests/devcount.c | 18 ++++++++++++------
4 files changed, 19 insertions(+), 7 deletions(-)
New commits:
commit 1e29cebddbc04b22a8dd8ec2b53b74521afbea44
Author: David Teigland <teigland(a)redhat.com>
Date: Tue Apr 5 15:02:07 2011 -0500
sanlock: fix release and inquire
sanlock_release was missing some cleanup, which caused
subsequent acquire to fail
sanlock_inquire was always giving 0 as current lver
diff --git a/src/main.c b/src/main.c
index 4ab96ed..7038ce7 100644
--- a/src/main.c
+++ b/src/main.c
@@ -848,6 +848,8 @@ static void *cmd_release_thread(void *args_in)
rv = release_token(token);
if (rv < 0)
result = -1;
+ close_disks(token->disks, token->r.num_disks);
+ del_resource(token);
free(token);
cl->tokens[j] = NULL;
}
@@ -879,6 +881,8 @@ static void *cmd_release_thread(void *args_in)
rv = release_token(token);
if (rv < 0)
result = -1;
+ close_disks(token->disks, token->r.num_disks);
+ del_resource(token);
free(token);
cl->tokens[j] = NULL;
found = 1;
diff --git a/src/paxos_lease.c b/src/paxos_lease.c
index c9c07cd..bd06d1f 100644
--- a/src/paxos_lease.c
+++ b/src/paxos_lease.c
@@ -608,7 +608,8 @@ int paxos_lease_acquire(struct token *token, int force,
uint64_t last_timestamp = 0;
int error;
- log_token(token, "paxos_acquire begin force %d", 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);
if (error < 0)
diff --git a/src/token_manager.c b/src/token_manager.c
index 2c88560..547d20d 100644
--- a/src/token_manager.c
+++ b/src/token_manager.c
@@ -137,6 +137,7 @@ int acquire_token(struct token *token, uint64_t acquire_lver,
return rv;
memcpy(&token->leader, &leader_ret, sizeof(struct leader_record));
+ token->r.lver = token->leader.lver;
return rv; /* DP_OK */
}
diff --git a/tests/devcount.c b/tests/devcount.c
index 1ddbd84..df538ac 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -1,5 +1,6 @@
#define _GNU_SOURCE
#include <sys/types.h>
+#include <sys/wait.h>
#include <sys/un.h>
#include <sys/mount.h>
#include <inttypes.h>
@@ -409,11 +410,10 @@ static int do_relock(int argc, char *argv[])
*/
j = 0;
- memset(av, 0, sizeof(char *) * COUNT_ARGS+1);
-
av[j++] = strdup(argv[0]);
for (i = 3; i < LOCK_ARGS; i++)
av[j++] = strdup(argv[i]);
+ av[j] = NULL;
while (1) {
pid = fork();
@@ -478,6 +478,10 @@ static int do_relock(int argc, char *argv[])
goto fail;
}
lver = res_inq->lver;
+
+ printf("%d sanlock_inquire %llu done\n", parent_pid,
+ (unsigned long long)lver);
+
free(res_inq);
free(state);
@@ -489,6 +493,8 @@ static int do_relock(int argc, char *argv[])
goto fail;
}
+ printf("%d sanlock_release done\n", parent_pid);
+
/* give a chance to someone else to acquire the lock in here */
usleep(1000000);
@@ -518,6 +524,7 @@ static int do_relock(int argc, char *argv[])
fail:
printf("test failed...\n");
sleep(1000000);
+ return -1;
}
/*
@@ -579,11 +586,10 @@ static int do_lock(int argc, char *argv[])
*/
j = 0;
- memset(av, 0, sizeof(char *) * COUNT_ARGS+1);
-
av[j++] = strdup(argv[0]);
for (i = 3; i < LOCK_ARGS; i++)
av[j++] = strdup(argv[i]);
+ av[j] = NULL;
while (1) {
pid = fork();
@@ -622,9 +628,9 @@ static int do_lock(int argc, char *argv[])
sleep(rand_int(0, 1));
}
- fail:
printf("test failed...\n");
sleep(1000000);
+ return -1;
}
#if 0
@@ -1017,7 +1023,6 @@ static int do_migrate(int argc, char *argv[])
int do_init(int argc, char *argv[])
{
char command[4096];
- char *colon;
if (argc < 4)
return -1;
@@ -1058,6 +1063,7 @@ int do_init(int argc, char *argv[])
printf("%s\n", command);
system(command);
+ return 0;
}
int main(int argc, char *argv[])
12 years, 12 months
2 commits - sanlock.spec
by David Teigland
sanlock.spec | 26 ++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)
New commits:
commit 0e8285baae4a39bc4db3028390a986e6f608290e
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Mon Apr 4 13:45:31 2011 +0100
rpm: add sanlock_admin.h header
diff --git a/sanlock.spec b/sanlock.spec
index 0e554ca..ce6e46e 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -1,6 +1,6 @@
Name: sanlock
Version: 1.1.0
-Release: 2%{?dist}
+Release: 3%{?dist}
Summary: A shared disk lock manager
Group: System Environment/Base
@@ -66,9 +66,13 @@ developing applications that use %{name}.
%doc COPYING
%{_libdir}/libsanlock.so
%{_includedir}/sanlock.h
+%{_includedir}/sanlock_admin.h
%{_includedir}/sanlock_resource.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
@@ -77,7 +81,7 @@ developing applications that use %{name}.
- 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.
+- 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
commit 02bebf96af6e0d69bc3d64f6e3b6a3b2a79381a1
Author: Federico Simoncelli <fsimonce(a)redhat.com>
Date: Mon Apr 4 10:00:10 2011 +0100
rpm: sync specfile with fedora
diff --git a/sanlock.spec b/sanlock.spec
index d69b5a7..0e554ca 100644
--- a/sanlock.spec
+++ b/sanlock.spec
@@ -1,12 +1,12 @@
Name: sanlock
-Version: 1.0
+Version: 1.1.0
Release: 2%{?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.gz
+Source0: https://fedorahosted.org/releases/s/a/sanlock/%{name}-%{version}.tar.bz2
BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
BuildRequires: libblkid-devel
@@ -24,6 +24,7 @@ access to the shared disks.
%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
%install
@@ -31,6 +32,9 @@ 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
%clean
rm -rf $RPM_BUILD_ROOT
@@ -43,7 +47,10 @@ rm -rf $RPM_BUILD_ROOT
%defattr(-,root,root,-)
%doc COPYING
%{_sbindir}/sanlock
+%{_sbindir}/wdmd
%{_libdir}/libsanlock.so.*
+%{_libdir}/libwdmd.*
+%{_includedir}/wdmd.h
%package devel
Summary: Development files for %{name}
@@ -62,6 +69,13 @@ developing applications that use %{name}.
%{_includedir}/sanlock_resource.h
%changelog
+* 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.
12 years, 12 months
tests/devcount.c
by David Teigland
tests/devcount.c | 204 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 204 insertions(+)
New commits:
commit fb9e1c158a684e3e5946cd0ab8e6c9aaef65b6cf
Author: David Teigland <teigland(a)redhat.com>
Date: Fri Apr 1 15:44:27 2011 -0500
devcount: add relock test
in progress, designed to test inquire+reacquire
diff --git a/tests/devcount.c b/tests/devcount.c
index d7eeef0..1ddbd84 100644
--- a/tests/devcount.c
+++ b/tests/devcount.c
@@ -325,6 +325,202 @@ static int do_count(int argc, char *argv[])
}
/*
+ * Test inquire and acquire with version
+ *
+ * lock:
+ * acquire (no lver)
+ * if fail
+ * goto lock;
+ * else
+ * goto run;
+ *
+ * relock:
+ * acquire with saved lver
+ * if fail (others may acquire in lock:)
+ * sigkill pid;
+ * goto lock;
+ * else
+ * sigcont pid;
+ * goto run;
+ *
+ * run:
+ * run rw for a while
+ * inquire pid
+ * save lver
+ * sigstop pid
+ * release ALL
+ * goto relock
+ *
+ */
+
+static int do_relock(int argc, char *argv[])
+{
+ char *av[COUNT_ARGS+1];
+ struct sanlk_lockspace lockspace;
+ struct sanlk_resource *res, *res_inq;
+ int i, j, pid, rv, sock, len, status;
+ int res_count;
+ uint32_t parent_pid = getpid();
+ uint64_t lver;
+ char *state;
+
+ if (argc < LOCK_ARGS)
+ return -1;
+
+ count_offset = 0;
+
+ strcpy(lock_path, argv[2]);
+ strcpy(count_path, argv[4]);
+ our_hostid = atoi(argv[7]);
+
+ len = sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk);
+ res = malloc(len);
+ memset(res, 0, len);
+ strcpy(res->lockspace_name, "devcount");
+ snprintf(res->name, SANLK_NAME_LEN, "resource%s", count_path);
+ res->name[SANLK_NAME_LEN-1] = '\0';
+ 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;
+
+ printf("%d lock_disk %s count_disk %s our_hostid %d\n",
+ parent_pid, lock_path, count_path, our_hostid);
+
+ memset(&lockspace, 0, sizeof(lockspace));
+ strcpy(lockspace.name, "devcount");
+ strcpy(lockspace.host_id_disk.path, lock_path);
+ lockspace.host_id_disk.offset = lock_offset;
+ lockspace.host_id = our_hostid;
+
+ rv = sanlock_add_lockspace(&lockspace, 0);
+ if (rv < 0) {
+ printf("%d sanlock_add_lockspace error %d\n", parent_pid, rv);
+ exit(EXIT_FAILURE);
+ }
+ printf("%d sanlock_add_lockspace done\n", parent_pid);
+
+ /*
+ * argv[0] = devcount
+ * argv[1] = relock
+ * argv[2] = <lock_disk>
+ * argv[3] = rw
+ * start copying at argv[3]
+ */
+
+ j = 0;
+ memset(av, 0, sizeof(char *) * COUNT_ARGS+1);
+
+ av[j++] = strdup(argv[0]);
+ for (i = 3; i < LOCK_ARGS; i++)
+ av[j++] = strdup(argv[i]);
+
+ while (1) {
+ pid = fork();
+ if (!pid) {
+ int child_pid = getpid();
+
+ printf("\n");
+
+ sock = sanlock_register();
+ if (sock < 0) {
+ printf("%d sanlock_register error %d\n",
+ child_pid, sock);
+ exit(-1);
+ }
+
+ res->flags = 0;
+ res->lver = 0;
+
+ rv = sanlock_acquire(sock, -1, 0, 1, &res, NULL);
+ if (rv < 0) {
+ printf("%d sanlock_acquire error %d\n",
+ child_pid, rv);
+ /* all hosts are trying to acquire so we
+ expect this to acquire only sometimes;
+ TODO: exit with an error for some rv's */
+ exit(0);
+ }
+ printf("%d sanlock_acquire done\n", child_pid);
+
+ execv(av[0], av);
+ perror("execv devcount problem");
+ exit(EXIT_FAILURE);
+ }
+
+ run_more:
+ /* let the child run for 10 seconds before stopping it */
+
+ for (i = 0; i < 10; i++) {
+ rv = waitpid(pid, &status, WNOHANG);
+ if (rv == pid)
+ break;
+ sleep(1);
+ }
+
+ /* we expect child to exit when it fails go acquire the lock
+ because it's held by someone else, or rw run time is up */
+
+ if (rv == pid) {
+ sleep(rand_int(0, 1));
+ continue;
+ }
+
+ rv = sanlock_inquire(-1, pid, 0, &res_count, &state);
+ if (rv < 0) {
+ /* FIXME: if child exited this should just continue */
+ printf("sanlock_inquire error %d\n", rv);
+ goto fail;
+ }
+ rv = sanlock_str_to_res(state, &res_inq);
+ if (rv < 0) {
+ printf("sanlock_str_to_res error %d %s\n", rv, state);
+ goto fail;
+ }
+ lver = res_inq->lver;
+ free(res_inq);
+ free(state);
+
+ kill(pid, SIGSTOP);
+
+ rv = sanlock_release(-1, pid, SANLK_REL_ALL, 0, NULL);
+ if (rv < 0) {
+ printf("sanlock_release error %d\n", rv);
+ goto fail;
+ }
+
+ /* give a chance to someone else to acquire the lock in here */
+ usleep(1000000);
+
+ res->flags = SANLK_RES_LVER;
+ res->lver = lver;
+
+ rv = sanlock_acquire(-1, pid, 0, 1, &res, NULL);
+ if (!rv) {
+ /* we got the lock back in the same version */
+
+ printf("%d sanlock_acquire %llu done\n", parent_pid,
+ (unsigned long long)lver);
+
+ kill(pid, SIGCONT);
+ goto run_more;
+ }
+
+ /* someone got the lock between our release and reacquire */
+
+ printf("%d sanlock_acquire %llu error %d\n", parent_pid,
+ (unsigned long long)lver, rv);
+
+ kill(pid, SIGKILL);
+ sleep(rand_int(0, 1));
+ }
+
+ fail:
+ printf("test failed...\n");
+ sleep(1000000);
+}
+
+/*
* devcount lock <lock_disk> rw <count_disk> <sec1> <sec2> <hostid>
* sanlock add_lockspace -s devcount:<hostid>:<lock_disk>:0
* devcount rw <count_disk> <sec1> <sec2> <hostid>
@@ -880,6 +1076,9 @@ int main(int argc, char *argv[])
else if (!strcmp(argv[1], "lock"))
rv = do_lock(argc, 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);
@@ -910,6 +1109,11 @@ int main(int argc, char *argv[])
printf(" sanlock add_lockspace -s devcount:<hostid>:<lock_disk>:0\n");
printf(" loop around fork, sanlock_acquire, exec devcount rw\n");
printf("\n");
+ printf("devcount relock <lock_disk> rw <count_disk> <sec1> <sec2> <hostid>\n");
+ printf(" sanlock add_lockspace -s devcount:<hostid>:<lock_disk>:0\n");
+ printf(" loop around fork, sanlock_acquire, exec devcount rw\n");
+ printf(" sigstop child, inquire, release, re-acquire, sigcont|sigkill\n");
+ printf("\n");
printf("devcount rw <count_disk> <sec1> <sec2> <hostid>\n");
printf(" rw: read count for sec1, looking for writes, then write for sec2\n");
printf(" wr: write count for sec1, then read for sec2, looking for writes\n");
13 years