From 3c40f2a3ff23320340da2cd858ef9b4ed720b1ed Mon Sep 17 00:00:00 2001 From: David Teigland Date: Mar 07 2012 21:37:52 +0000 Subject: sanlock: status for all shared tokens For the status command, output a resource once for each token so the specific pid and token_id can be included. Signed-off-by: David Teigland --- diff --git a/src/cmd.c b/src/cmd.c index 60d36b2..7a44ce2 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -1293,17 +1293,20 @@ static int print_state_lockspace(struct space *sp, char *str, const char *list_n return strlen(str) + 1; } -static int print_state_resource(struct resource *r, char *str, const char *list_name) +static int print_state_resource(struct resource *r, char *str, const char *list_name, + uint32_t token_id) { memset(str, 0, SANLK_STATE_MAXSTR); snprintf(str, SANLK_STATE_MAXSTR-1, "list=%s " "flags=%x " - "lver=%llu", + "lver=%llu " + "token_id=%u", list_name, r->flags, - (unsigned long long)r->leader.lver); + (unsigned long long)r->leader.lver, + token_id); return strlen(str) + 1; } @@ -1399,9 +1402,11 @@ static void send_state_lockspace(int fd, struct space *sp, const char *list_name send(fd, &lockspace, sizeof(lockspace), MSG_NOSIGNAL); } -void send_state_resource(int fd, struct resource *r, const char *list_name); +void send_state_resource(int fd, struct resource *r, const char *list_name, + int pid, uint32_t token_id); -void send_state_resource(int fd, struct resource *r, const char *list_name) +void send_state_resource(int fd, struct resource *r, const char *list_name, + int pid, uint32_t token_id) { struct sanlk_state st; char str[SANLK_STATE_MAXSTR]; @@ -1411,11 +1416,11 @@ void send_state_resource(int fd, struct resource *r, const char *list_name) memset(&st, 0, sizeof(st)); st.type = SANLK_STATE_RESOURCE; - st.data32 = r->pid; + st.data32 = pid; st.data64 = r->leader.lver; strncpy(st.name, r->r.name, NAME_ID_SIZE); - str_len = print_state_resource(r, str, list_name); + str_len = print_state_resource(r, str, list_name, token_id); st.str_len = str_len; diff --git a/src/resource.c b/src/resource.c index 664d69e..6e6de5d 100644 --- a/src/resource.c +++ b/src/resource.c @@ -33,7 +33,8 @@ #include "mode_block.h" /* from cmd.c */ -void send_state_resource(int fd, struct resource *r, const char *list_name); +void send_state_resource(int fd, struct resource *r, const char *list_name, int pid, uint32_t token_id); + /* from main.c */ int get_rand(int a, int b); @@ -50,14 +51,20 @@ static pthread_cond_t resource_cond; void send_state_resources(int fd) { struct resource *r; + struct token *token; pthread_mutex_lock(&resource_mutex); - list_for_each_entry(r, &resources_held, list) - send_state_resource(fd, r, "resources_held"); - list_for_each_entry(r, &resources_add, list) - send_state_resource(fd, r, "resources_add"); + list_for_each_entry(r, &resources_held, list) { + list_for_each_entry(token, &r->tokens, list) + send_state_resource(fd, r, "held", token->pid, token->token_id); + } + + list_for_each_entry(r, &resources_add, list) { + list_for_each_entry(token, &r->tokens, list) + send_state_resource(fd, r, "add", token->pid, token->token_id); + } list_for_each_entry(r, &resources_rem, list) - send_state_resource(fd, r, "resources_rem"); + send_state_resource(fd, r, "rem", r->pid, r->release_token_id); pthread_mutex_unlock(&resource_mutex); }