src/client_cmd.c | 4 ++--
src/client_cmd.h | 2 +-
src/cmd.c | 14 +++++++++++++-
src/main.c | 4 ++--
src/sanlock.8 | 6 ++++--
5 files changed, 22 insertions(+), 8 deletions(-)
New commits:
commit 8a502f3d47149558aa2d7ad72e8b4a57e0a0ebbc
Author: David Teigland <teigland(a)redhat.com>
Date: Wed Jan 4 16:28:21 2012 -0600
sanlock: add force option to shutdown command
With -f 0 (default), the shutdown will be ignored if
any lockspaces exist.
With -f 1 (force), the behavior is as it has been;
the daemon forcibly cleans up then exits (cleanup:
pids killed, leases released, lockspaces removed.)
Signed-off-by: David Teigland <teigland(a)redhat.com>
diff --git a/src/client_cmd.c b/src/client_cmd.c
index 2662122..4d268cd 100644
--- a/src/client_cmd.c
+++ b/src/client_cmd.c
@@ -523,11 +523,11 @@ int sanlock_log_dump(int max_size)
return rv;
}
-int sanlock_shutdown(void)
+int sanlock_shutdown(uint32_t force)
{
int fd;
- fd = send_command(SM_CMD_SHUTDOWN, 0);
+ fd = send_command(SM_CMD_SHUTDOWN, force);
if (fd < 0)
return fd;
diff --git a/src/client_cmd.h b/src/client_cmd.h
index 6759c93..dcc29e1 100644
--- a/src/client_cmd.h
+++ b/src/client_cmd.h
@@ -12,6 +12,6 @@
int sanlock_status(int debug, char sort_arg);
int sanlock_host_status(int debug, char *lockspace_name);
int sanlock_log_dump(int max_size);
-int sanlock_shutdown(void);
+int sanlock_shutdown(uint32_t force);
#endif
diff --git a/src/cmd.c b/src/cmd.c
index bba9719..51e3878 100644
--- a/src/cmd.c
+++ b/src/cmd.c
@@ -1632,7 +1632,19 @@ void call_cmd_daemon(int ci, struct sm_header *h_recv, int
client_maxi)
break;
case SM_CMD_SHUTDOWN:
strcpy(client[ci].owner_name, "shutdown");
- external_shutdown = 1;
+ if (h_recv->data) {
+ /* force */
+ external_shutdown = 1;
+ } else {
+ pthread_mutex_lock(&spaces_mutex);
+ if (list_empty(&spaces) &&
+ list_empty(&spaces_rem) &&
+ list_empty(&spaces_add))
+ external_shutdown = 1;
+ else
+ log_debug("ignore shutdown for spaces");
+ pthread_mutex_unlock(&spaces_mutex);
+ }
break;
case SM_CMD_STATUS:
strcpy(client[ci].owner_name, "status");
diff --git a/src/main.c b/src/main.c
index 1efe3fb..2ab0aae 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1363,7 +1363,7 @@ static void print_usage(void)
printf("sanlock client status [-D] [-o p|s]\n");
printf("sanlock client host_status -s LOCKSPACE [-D]\n");
printf("sanlock client log_dump\n");
- printf("sanlock client shutdown\n");
+ printf("sanlock client shutdown [-f 0|1]\n");
printf("sanlock client init -s LOCKSPACE | -r RESOURCE\n");
printf("sanlock client align -s LOCKSPACE\n");
printf("sanlock client add_lockspace -s LOCKSPACE\n");
@@ -1717,7 +1717,7 @@ static int do_client(void)
case ACT_SHUTDOWN:
log_tool("shutdown");
- rv = sanlock_shutdown();
+ rv = sanlock_shutdown(com.force_mode);
log_tool("shutdown done %d", rv);
break;
diff --git a/src/sanlock.8 b/src/sanlock.8
index 0136fe9..fd8accb 100644
--- a/src/sanlock.8
+++ b/src/sanlock.8
@@ -261,8 +261,10 @@ Print the sanlock daemon internal debug log.
.B sanlock client shutdown
-Tell the sanlock daemon to exit. Any registered processes will be killed,
-their resource leases released, and lockspaces removed.
+Ask the sanlock daemon to exit. Without the force option (-f 0), the
+command will be ignored if any lockspaces exist. With the force option
+(-f 1), any registered processes will be killed, their resource leases
+released, and lockspaces removed.
.BR "sanlock client init -s" " LOCKSPACE"
.br