2 commits - src/client_cmd.c src/resource.c
David Teigland
teigland at fedoraproject.org
Thu Aug 23 15:51:49 UTC 2012
src/client_cmd.c | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
src/resource.c | 29 ++++++++++++++++-----
2 files changed, 94 insertions(+), 8 deletions(-)
New commits:
commit dba7985aebfa961779feca28d39d4407f7f8073a
Author: David Teigland <teigland at redhat.com>
Date: Thu Aug 23 10:46:09 2012 -0500
sanlock: show host_status for all lockspaces
when none are specified on the command line,
i.e. "sanlock client host_status"
Signed-off-by: David Teigland <teigland at redhat.com>
diff --git a/src/client_cmd.c b/src/client_cmd.c
index 25f8cc6..ee96ae2 100644
--- a/src/client_cmd.c
+++ b/src/client_cmd.c
@@ -416,7 +416,7 @@ int sanlock_status(int debug, char sort_arg)
return rv;
}
-int sanlock_host_status(int debug, char *lockspace_name)
+static int lockspace_host_status(int debug, char *lockspace_name)
{
struct sm_header h;
struct sanlk_state st;
@@ -474,6 +474,77 @@ int sanlock_host_status(int debug, char *lockspace_name)
return rv;
}
+int sanlock_host_status(int debug, char *lockspace_name)
+{
+ struct sm_header h;
+ struct sanlk_state state;
+ char maxstr[SANLK_STATE_MAXSTR];
+ char maxbin[SANLK_STATE_MAXSTR];
+ struct sanlk_state *st;
+ char *str, *bin;
+ struct sanlk_lockspace *ls;
+ int fd, rv, i;
+
+ if (lockspace_name && lockspace_name[0])
+ return lockspace_host_status(debug, lockspace_name);
+
+ fd = send_command(SM_CMD_STATUS, SANLK_STATE_LOCKSPACE);
+ if (fd < 0)
+ return fd;
+
+ rv = recv(fd, &h, sizeof(h), MSG_WAITALL);
+ if (rv < 0) {
+ rv = -errno;
+ close(fd);
+ return rv;
+ }
+ if (rv != sizeof(h)) {
+ close(fd);
+ return -1;
+ }
+
+ st = &state;
+ str = maxstr;
+ bin = maxbin;
+
+ while (1) {
+ memset(&state, 0, sizeof(state));
+ memset(maxstr, 0, sizeof(maxstr));
+ memset(maxbin, 0, sizeof(maxbin));
+
+ rv = recv(fd, st, sizeof(struct sanlk_state), MSG_WAITALL);
+ if (!rv)
+ break;
+ if (rv != sizeof(struct sanlk_state))
+ break;
+
+ if (st->str_len) {
+ rv = recv(fd, str, st->str_len, MSG_WAITALL);
+ if (rv != st->str_len)
+ break;
+ }
+
+ recv_bin(fd, st, bin);
+
+ if (st->type != SANLK_STATE_LOCKSPACE)
+ continue;
+
+ ls = (struct sanlk_lockspace *)bin;
+
+ sort_bufs[sort_count++] = strdup(ls->name);
+ }
+
+ close(fd);
+
+ for (i = 0; i < sort_count; i++) {
+ printf("lockspace %s\n", sort_bufs[i]);
+ lockspace_host_status(debug, sort_bufs[i]);
+ free(sort_bufs[i]);
+ }
+
+ return 0;
+}
+
int sanlock_log_dump(int max_size)
{
struct sm_header h;
commit eb6abcf10550ef544d427d6709b0894acb622845
Author: David Teigland <teigland at redhat.com>
Date: Thu Aug 23 09:53:42 2012 -0500
daemon: use helper for examine request kill
This kill() call was missed when moving kill to
the helper in 5c51530b5bccb8cfadc8a8591558b9ab99b95cb3
Signed-off-by: David Teigland <teigland at redhat.com>
diff --git a/src/resource.c b/src/resource.c
index 4ad4a05..7208d92 100644
--- a/src/resource.c
+++ b/src/resource.c
@@ -31,6 +31,7 @@
#include "resource.h"
#include "task.h"
#include "mode_block.h"
+#include "helper.h"
/* from cmd.c */
void send_state_resource(int fd, struct resource *r, const char *list_name, int pid, uint32_t token_id);
@@ -812,9 +813,10 @@ static int examine_token(struct task *task, struct token *token,
static void do_req_kill_pid(struct token *tt, int pid)
{
+ struct helper_msg hm;
struct resource *r;
uint32_t flags;
- int found = 0;
+ int rv, found = 0;
pthread_mutex_lock(&resource_mutex);
r = find_resource(tt, &resources_held);
@@ -833,16 +835,29 @@ static void do_req_kill_pid(struct token *tt, int pid)
log_debug("do_req_kill_pid %d flags %x %.48s:%.48s",
pid, flags, tt->r.lockspace_name, tt->r.name);
- /* TODO: share code with kill_pids() to gradually
- * escalate from killscript, SIGTERM, SIGKILL */
+ if (helper_kill_fd == -1) {
+ log_error("do_req_kill_pid %d no helper fd", pid);
+ return;
+ }
+
+ /* TODO: handle kill via runpath? or select signal? escalate? */
- kill(pid, SIGTERM);
+ memset(&hm, 0, sizeof(hm));
+ hm.type = HELPER_MSG_KILLPID;
+ hm.pid = pid;
+ hm.sig = SIGKILL;
if (flags & R_RESTRICT_SIGKILL)
- return;
+ hm.sig = SIGTERM;
+
+ retry:
+ rv = write(helper_kill_fd, &hm, sizeof(hm));
+ if (rv == -1 && errno == EINTR)
+ goto retry;
- sleep(1);
- kill(pid, SIGKILL);
+ if (rv == -1)
+ log_error("do_req_kill_pid %d helper write error %d",
+ pid, errno);
}
int set_resource_examine(char *space_name, char *res_name)
More information about the sanlock-devel
mailing list