src/delta_lease.c | 20 +++++++++++++++-----
src/direct_lib.c | 1 +
src/host_id.c | 8 +++++++-
src/main.c | 1 -
src/sanlock_internal.h | 1 +
5 files changed, 24 insertions(+), 7 deletions(-)
New commits:
commit 27d26b9ef1b68d28e8333ebc3ebea0d489f83f99
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jun 15 10:49:23 2011 -0500
sanlock: abort delta wait on shutdown
if the daemon is shutdown or the lockspace is removed
during one of the long add_lockspace/delta_acquire delays,
quit and return an error
diff --git a/src/delta_lease.c b/src/delta_lease.c
index 6806f94..a2683ad 100644
--- a/src/delta_lease.c
+++ b/src/delta_lease.c
@@ -215,7 +215,7 @@ int delta_lease_acquire(struct task *task,
struct leader_record leader;
struct leader_record leader1;
uint64_t new_ts;
- int error, delay, delta_large_delay;
+ int i, error, delay, delta_large_delay;
log_space(sp, "delta_acquire %llu begin", (unsigned long long)host_id);
@@ -253,12 +253,17 @@ int delta_lease_acquire(struct task *task,
while (1) {
memcpy(&leader1, &leader, sizeof(struct leader_record));
+ log_space(sp, "delta_acquire %llu delta_large_delay %d delay %d",
+ (unsigned long long)host_id, delta_large_delay, delay);
+
/* TODO: we could reread every several seconds to see if
it has changed, so we can abort more quickly if so */
- log_space(sp, "delta_acquire %llu delta_large_delay %d delay %d",
- (unsigned long long)host_id, delta_large_delay, delay);
- sleep(delay);
+ for (i = 0; i < delay; i++) {
+ if (sp->external_remove || external_shutdown)
+ return SANLK_ERROR;
+ sleep(1);
+ }
error = delta_lease_leader_read(task, disk, space_name, host_id,
&leader, "delta_acquire_wait");
@@ -305,7 +310,12 @@ int delta_lease_acquire(struct task *task,
delay = 2 * task->io_timeout_seconds;
log_space(sp, "delta_acquire %llu delta_short_delay %d",
(unsigned long long)host_id, delay);
- sleep(delay);
+
+ for (i = 0; i < delay; i++) {
+ if (sp->external_remove || external_shutdown)
+ return SANLK_ERROR;
+ sleep(1);
+ }
error = delta_lease_leader_read(task, disk, space_name, host_id, &leader,
"delta_acquire_check");
diff --git a/src/direct_lib.c b/src/direct_lib.c
index e31e514..f0a3dcb 100644
--- a/src/direct_lib.c
+++ b/src/direct_lib.c
@@ -14,6 +14,7 @@
#include <stddef.h>
#include <errno.h>
+#define EXTERN
#include "sanlock_internal.h"
#include "sanlock_direct.h"
#include "diskio.h"
diff --git a/src/host_id.c b/src/host_id.c
index 3586d34..33ffca4 100644
--- a/src/host_id.c
+++ b/src/host_id.c
@@ -437,6 +437,11 @@ int add_lockspace(struct sanlk_lockspace *ls)
and the main loop will begin monitoring its renewals */
pthread_mutex_lock(&spaces_mutex);
+ if (sp->external_remove || external_shutdown) {
+ rv = -1;
+ pthread_mutex_unlock(&spaces_mutex);
+ goto fail_free;
+ }
list_move(&sp->list, &spaces);
pthread_mutex_unlock(&spaces_mutex);
return 0;
@@ -465,8 +470,9 @@ int rem_lockspace(struct sanlk_lockspace *ls)
sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk,
ls->host_id,
&spaces_add, NULL, NULL);
if (sp) {
+ sp->external_remove = 1;
pthread_mutex_unlock(&spaces_mutex);
- rv = -EAGAIN;
+ rv = 0;
goto out;
}
diff --git a/src/main.c b/src/main.c
index e75e320..fec794e 100644
--- a/src/main.c
+++ b/src/main.c
@@ -79,7 +79,6 @@ static struct pollfd *pollfd = NULL;
static char command[COMMAND_MAX];
static int cmd_argc;
static char **cmd_argv;
-static int external_shutdown;
static unsigned int token_id_counter = 1;
struct cmd_args {
diff --git a/src/sanlock_internal.h b/src/sanlock_internal.h
index 560bbda..c38ebf8 100644
--- a/src/sanlock_internal.h
+++ b/src/sanlock_internal.h
@@ -514,6 +514,7 @@ enum {
ACT_READ_LEADER,
};
+EXTERN int external_shutdown;
EXTERN char our_host_name_global[SANLK_NAME_LEN+1];
#endif