src/client_cmd.c | 33 ++++++++++++++++++++++++++++++--- src/cmd.c | 44 ++++++++++++++++++++++++++++++++++++++++---- src/lockspace.c | 55 +++++++++++++++++++++++++++++++++++++++++-------------- src/resource.c | 4 ++++ 4 files changed, 115 insertions(+), 21 deletions(-)
New commits: commit 48bdf340c47e9696046ea99d912a4654435e1d77 Author: David Teigland teigland@redhat.com Date: Mon Oct 28 16:17:15 2013 -0500
sanlock: use ADD and REM suffix in status output
Display ADD or REM at the end of a lockspace or resource line from 'sanlock client status' to indicate that the lockspace/resource is currently being added or removed. The 'sanlock client gets' command already uses this convention for displaying lockspaces.
Signed-off-by: David Teigland teigland@redhat.com
diff --git a/src/client_cmd.c b/src/client_cmd.c index 6551aae..7723f88 100644 --- a/src/client_cmd.c +++ b/src/client_cmd.c @@ -73,6 +73,19 @@ static void status_client(struct sanlk_state *st, char *str, int debug) print_debug(str, st->str_len); }
+static const char *add_rem_str(struct sanlk_state *st, char *str) +{ + if (!st->str_len) + return NULL; + + if (strstr(str, "list=add")) + return "ADD"; + if (strstr(str, "list=rem")) + return "REM"; + + return NULL; +} + /* TODO: when path strings are exported, through status or inquire, we should export into a malloced buffer the size of the standard chars plus extra esc chars. */ @@ -81,16 +94,23 @@ static void status_lockspace(struct sanlk_state *st, char *str, char *bin, int d { struct sanlk_lockspace *ls = (struct sanlk_lockspace *)bin; char path[SANLK_PATH_LEN + 1]; + const char *add_rem;
memset(path, 0, sizeof(path)); sanlock_path_export(path, ls->host_id_disk.path, sizeof(path));
- printf("s %.48s:%llu:%s:%llu\n", + printf("s %.48s:%llu:%s:%llu", ls->name, (unsigned long long)ls->host_id, path, (unsigned long long)ls->host_id_disk.offset);
+ add_rem = add_rem_str(st, str); + if (add_rem) + printf(" %s\n", add_rem); + else + printf("\n"); + if (st->str_len && debug) print_debug(str, st->str_len); } @@ -100,6 +120,7 @@ static void status_resource(struct sanlk_state *st, char *str, char *bin, int de struct sanlk_resource *res = (struct sanlk_resource *)bin; struct sanlk_disk *disk; char path[SANLK_PATH_LEN + 1]; + const char *add_rem; int i;
printf("r %.48s:%.48s", res->lockspace_name, res->name); @@ -114,9 +135,15 @@ static void status_resource(struct sanlk_state *st, char *str, char *bin, int de }
if (res->flags & SANLK_RES_SHARED) - printf(":SH p %u\n", st->data32); + printf(":SH p %u", st->data32); + else + printf(":%llu p %u", (unsigned long long)st->data64, st->data32); + + add_rem = add_rem_str(st, str); + if (add_rem) + printf(" %s\n", add_rem); else - printf(":%llu p %u\n", (unsigned long long)st->data64, st->data32); + printf("\n");
if (st->str_len && debug) print_debug(str, st->str_len); diff --git a/src/cmd.c b/src/cmd.c index cea7f58..fd85ec2 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -2099,13 +2099,17 @@ static void cmd_status(int fd, struct sm_header *h_recv, int client_maxi) if (h_recv->data == SANLK_STATE_CLIENT) return;
+ /* N.B. the reporting function looks for the + strings "add" and "rem", so if changed, + the strings should be changed in both places. */ + pthread_mutex_lock(&spaces_mutex); list_for_each_entry(sp, &spaces, list) send_state_lockspace(fd, sp, "spaces"); list_for_each_entry(sp, &spaces_add, list) - send_state_lockspace(fd, sp, "spaces_add"); + send_state_lockspace(fd, sp, "add"); list_for_each_entry(sp, &spaces_rem, list) - send_state_lockspace(fd, sp, "spaces_rem"); + send_state_lockspace(fd, sp, "rem"); pthread_mutex_unlock(&spaces_mutex);
if (h_recv->data == SANLK_STATE_LOCKSPACE) diff --git a/src/resource.c b/src/resource.c index b2a7ba1..1e5b2df 100644 --- a/src/resource.c +++ b/src/resource.c @@ -57,6 +57,10 @@ static void free_resource(struct resource *r) free(r); }
+/* N.B. the reporting function looks for the + strings "add" and "rem", so if changed, they + should be changed in both places. */ + void send_state_resources(int fd) { struct resource *r;
commit 51a02b174720df9cf9628a541c71959f9bd99d5c Author: David Teigland teigland@redhat.com Date: Mon Oct 28 15:42:01 2013 -0500
sanlock: add some acquire error descriptions
Add some short user readable descriptions to the error log messages during acquire.
Signed-off-by: David Teigland teigland@redhat.com
diff --git a/src/cmd.c b/src/cmd.c index 38fc6ad..cea7f58 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -118,6 +118,38 @@ static int check_new_tokens_space(struct client *cl, return 0; }
+static const char *acquire_error_str(int error) +{ + switch (error) { + case SANLK_ACQUIRE_IDLIVE: + case SANLK_ACQUIRE_OWNED: + case SANLK_ACQUIRE_OTHER: + return "lease owned by other host"; + + case SANLK_ACQUIRE_SHRETRY: + return "shared lease contention"; + + case SANLK_DBLOCK_READ: + case SANLK_DBLOCK_WRITE: + case SANLK_LEADER_READ: + case SANLK_LEADER_WRITE: + return "lease io error"; + + case SANLK_LEADER_DIFF: + case SANLK_LEADER_MAGIC: + case SANLK_LEADER_VERSION: + case SANLK_LEADER_SECTORSIZE: + case SANLK_LEADER_LOCKSPACE: + case SANLK_LEADER_RESOURCE: + case SANLK_LEADER_NUMHOSTS: + case SANLK_LEADER_CHECKSUM: + return "lease data invalid"; + + default: + return ""; + }; +} + static void cmd_acquire(struct task *task, struct cmd_args *ca) { struct client *cl; @@ -342,8 +374,8 @@ static void cmd_acquire(struct task *task, struct cmd_args *ca) lvl = LOG_ERR; } log_level(0, token->token_id, NULL, lvl, - "cmd_acquire %d,%d,%d acquire_token %d", - cl_ci, cl_fd, cl_pid, rv); + "cmd_acquire %d,%d,%d acquire_token %d %s", + cl_ci, cl_fd, cl_pid, rv, acquire_error_str(rv)); result = rv; goto done; }
commit ace31f840b755a85f1d84969dba05cd19debc03a Author: David Teigland teigland@redhat.com Date: Mon Oct 28 15:05:53 2013 -0500
sanlock: add_lockspace error for conflicting lockspace definitions
Log an error message when the lockspace definition in add_lockspace conflicts with the name or path for an existing lockspace.
Signed-off-by: David Teigland teigland@redhat.com
diff --git a/src/lockspace.c b/src/lockspace.c index b5576ea..e96e1e1 100644 --- a/src/lockspace.c +++ b/src/lockspace.c @@ -43,7 +43,8 @@ static struct space *_search_space(const char *name, uint64_t host_id, struct list_head *head1, struct list_head *head2, - struct list_head *head3) + struct list_head *head3, + int *listnum) { int i; struct space *sp; @@ -63,6 +64,9 @@ static struct space *_search_space(const char *name, continue; if (host_id && sp->host_id != host_id) continue; + + if (listnum) + *listnum = i+1; return sp; } } @@ -71,7 +75,7 @@ static struct space *_search_space(const char *name,
struct space *find_lockspace(const char *name) { - return _search_space(name, NULL, 0, &spaces, &spaces_rem, &spaces_add); + return _search_space(name, NULL, 0, &spaces, &spaces_rem, &spaces_add, NULL); }
int _lockspace_info(const char *space_name, struct space_info *spi) @@ -587,6 +591,7 @@ static void free_sp(struct space *sp) int add_lockspace_start(struct sanlk_lockspace *ls, uint32_t io_timeout, struct space **sp_out) { struct space *sp, *sp2; + int listnum = 0; int rv;
if (!ls->name[0] || !ls->host_id || !ls->host_id_disk.path[0]) { @@ -614,7 +619,7 @@ int add_lockspace_start(struct sanlk_lockspace *ls, uint32_t io_timeout, struct /* search all lists for an identical lockspace */
sp2 = _search_space(sp->space_name, &sp->host_id_disk, sp->host_id, - &spaces, NULL, NULL); + &spaces, NULL, NULL, NULL); if (sp2) { pthread_mutex_unlock(&spaces_mutex); rv = -EEXIST; @@ -622,7 +627,7 @@ int add_lockspace_start(struct sanlk_lockspace *ls, uint32_t io_timeout, struct }
sp2 = _search_space(sp->space_name, &sp->host_id_disk, sp->host_id, - &spaces_add, NULL, NULL); + &spaces_add, NULL, NULL, NULL); if (sp2) { pthread_mutex_unlock(&spaces_mutex); rv = -EINPROGRESS; @@ -630,7 +635,7 @@ int add_lockspace_start(struct sanlk_lockspace *ls, uint32_t io_timeout, struct }
sp2 = _search_space(sp->space_name, &sp->host_id_disk, sp->host_id, - &spaces_rem, NULL, NULL); + &spaces_rem, NULL, NULL, NULL); if (sp2) { pthread_mutex_unlock(&spaces_mutex); rv = -EAGAIN; @@ -640,8 +645,19 @@ int add_lockspace_start(struct sanlk_lockspace *ls, uint32_t io_timeout, struct /* search all lists for a lockspace with the same name */
sp2 = _search_space(sp->space_name, NULL, 0, - &spaces, &spaces_add, &spaces_rem); + &spaces, &spaces_add, &spaces_rem, &listnum); if (sp2) { + log_error("add_lockspace %.48s:%llu:%.256s:%llu conflicts with name of list%d s%d %.48s:%llu:%.256s:%llu", + sp->space_name, + (unsigned long long)sp->host_id, + sp->host_id_disk.path, + (unsigned long long)sp->host_id_disk.offset, + listnum, + sp2->space_id, + sp2->space_name, + (unsigned long long)sp2->host_id, + sp2->host_id_disk.path, + (unsigned long long)sp2->host_id_disk.offset); pthread_mutex_unlock(&spaces_mutex); rv = -EINVAL; goto fail_free; @@ -650,8 +666,19 @@ int add_lockspace_start(struct sanlk_lockspace *ls, uint32_t io_timeout, struct /* search all lists for a lockspace with the same host_id_disk */
sp2 = _search_space(NULL, &sp->host_id_disk, 0, - &spaces, &spaces_add, &spaces_rem); + &spaces, &spaces_add, &spaces_rem, &listnum); if (sp2) { + log_error("add_lockspace %.48s:%llu:%.256s:%llu conflicts with path of list%d s%d %.48s:%llu:%.256s:%llu", + sp->space_name, + (unsigned long long)sp->host_id, + sp->host_id_disk.path, + (unsigned long long)sp->host_id_disk.offset, + listnum, + sp2->space_id, + sp2->space_name, + (unsigned long long)sp2->host_id, + sp2->host_id_disk.path, + (unsigned long long)sp2->host_id_disk.offset); pthread_mutex_unlock(&spaces_mutex); rv = -EINVAL; goto fail_free; @@ -757,7 +784,7 @@ int inq_lockspace(struct sanlk_lockspace *ls) pthread_mutex_lock(&spaces_mutex);
sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id, - &spaces, NULL, NULL); + &spaces, NULL, NULL, NULL);
if (sp) { rv = 0; @@ -767,7 +794,7 @@ int inq_lockspace(struct sanlk_lockspace *ls) }
sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id, - &spaces_add, &spaces_rem, NULL); + &spaces_add, &spaces_rem, NULL, NULL);
if (sp) rv = -EINPROGRESS; @@ -786,7 +813,7 @@ int rem_lockspace_start(struct sanlk_lockspace *ls, unsigned int *space_id) pthread_mutex_lock(&spaces_mutex);
sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id, - &spaces_rem, NULL, NULL); + &spaces_rem, NULL, NULL, NULL); if (sp) { pthread_mutex_unlock(&spaces_mutex); rv = -EINPROGRESS; @@ -794,7 +821,7 @@ int rem_lockspace_start(struct sanlk_lockspace *ls, unsigned int *space_id) }
sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id, - &spaces_add, NULL, NULL); + &spaces_add, NULL, NULL, NULL); if (sp) { /* add_lockspace will be aborted and undone and the sp will not be moved to the spaces list */ @@ -807,7 +834,7 @@ int rem_lockspace_start(struct sanlk_lockspace *ls, unsigned int *space_id) }
sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id, - &spaces, NULL, NULL); + &spaces, NULL, NULL, NULL); if (!sp) { pthread_mutex_unlock(&spaces_mutex); rv = -ENOENT; @@ -846,7 +873,7 @@ int rem_lockspace_wait(struct sanlk_lockspace *ls, unsigned int space_id) while (1) { pthread_mutex_lock(&spaces_mutex); sp = _search_space(ls->name, (struct sync_disk *)&ls->host_id_disk, ls->host_id, - &spaces, &spaces_rem, &spaces_add); + &spaces, &spaces_rem, &spaces_add, NULL); if (sp && (sp->space_id == space_id)) done = 0; else @@ -1031,7 +1058,7 @@ int get_hosts(struct sanlk_lockspace *ls, char *buf, int *len, int *count, int m host = (struct sanlk_host *)buf;
pthread_mutex_lock(&spaces_mutex); - sp = _search_space(ls->name, NULL, 0, &spaces, NULL, NULL); + sp = _search_space(ls->name, NULL, 0, &spaces, NULL, NULL, NULL); if (!sp) { rv = -ENOENT; goto out;
commit e1b87ddcb82c312ee37823ca43e4f24eba35e34c Author: David Teigland teigland@redhat.com Date: Mon Oct 28 14:21:17 2013 -0500
sanlock: fix debug status for add/rem lockspace
Fix sanlock status -D output which displayed "spaces_rem" for lockspaces on the spaces_add list (being added) "spaces_add" for lockspaces on the spaces_rem list (being removed)
Signed-off-by: David Teigland teigland@redhat.com
diff --git a/src/cmd.c b/src/cmd.c index 050f595..38fc6ad 100644 --- a/src/cmd.c +++ b/src/cmd.c @@ -2071,9 +2071,9 @@ static void cmd_status(int fd, struct sm_header *h_recv, int client_maxi) list_for_each_entry(sp, &spaces, list) send_state_lockspace(fd, sp, "spaces"); list_for_each_entry(sp, &spaces_add, list) - send_state_lockspace(fd, sp, "spaces_rem"); - list_for_each_entry(sp, &spaces_rem, list) send_state_lockspace(fd, sp, "spaces_add"); + list_for_each_entry(sp, &spaces_rem, list) + send_state_lockspace(fd, sp, "spaces_rem"); pthread_mutex_unlock(&spaces_mutex);
if (h_recv->data == SANLK_STATE_LOCKSPACE)
sanlock-devel@lists.fedorahosted.org