src/main.c | 51 ++++++++++++++++++++++----------------------------- tests/devcount.c | 13 ++++++++----- 2 files changed, 30 insertions(+), 34 deletions(-)
New commits: commit c411d521d6560f0e015211571f98931c1f792b40 Author: David Teigland teigland@redhat.com Date: Wed Apr 20 15:44:39 2011 -0500
sanlock: fix find_client_pid
don't release the pthread mutex between finding a matching pid for a ci, and using that ci.
diff --git a/src/main.c b/src/main.c index 5468990..d5e3067 100644 --- a/src/main.c +++ b/src/main.c @@ -296,23 +296,6 @@ static int client_add(int fd, void (*workfn)(int ci), void (*deadfn)(int ci)) return -1; }
-static int find_client_pid(int pid) -{ - struct client *cl; - int i; - - for (i = 0; i < client_size; i++) { - cl = &client[i]; - pthread_mutex_lock(&cl->mutex); - if (cl->used && cl->pid == pid) { - pthread_mutex_unlock(&cl->mutex); - return i; - } - pthread_mutex_unlock(&cl->mutex); - } - return -1; -} - static int get_peer_pid(int fd, int *pid) { struct ucred cred; @@ -1704,30 +1687,40 @@ static void process_cmd_thread_resource(int ci_in, struct sm_header *h_recv) struct sm_header h; struct client *cl; int result = 0; - int rv, ci_target; + int rv, i, ci_target; + + ca = malloc(sizeof(struct cmd_args)); + if (!ca) { + result = -ENOMEM; + goto fail; + }
if (h_recv->data2 != -1) { /* lease for another registered client with pid specified by data2 */ - ci_target = find_client_pid(h_recv->data2); + ci_target = -1; + + for (i = 0; i < client_size; i++) { + cl = &client[i]; + pthread_mutex_lock(&cl->mutex); + if (cl->pid != h_recv->data2) { + pthread_mutex_unlock(&cl->mutex); + continue; + } + ci_target = i; + break; + } if (ci_target < 0) { result = -ESRCH; goto fail; } } else { /* lease for this registered client */ - ci_target = ci_in; - }
- ca = malloc(sizeof(struct cmd_args)); - if (!ca) { - result = -ENOMEM; - goto fail; + ci_target = ci_in; + cl = &client[ci_target]; + pthread_mutex_lock(&cl->mutex); }
- cl = &client[ci_target]; - - pthread_mutex_lock(&cl->mutex); - if (!cl->used) { log_error("cmd %d %d,%d,%d not used", h_recv->cmd, ci_target, cl->fd, cl->pid); diff --git a/tests/devcount.c b/tests/devcount.c index 074b495..dcfe60a 100644 --- a/tests/devcount.c +++ b/tests/devcount.c @@ -1001,6 +1001,8 @@ static int do_migrate(int argc, char *argv[]) * dd if=/dev/zero of=<count_disk> bs=512 count=24 */
+#define INIT_NUM_HOSTS 8 + int do_init(int argc, char *argv[]) { char resbuf[sizeof(struct sanlk_resource) + sizeof(struct sanlk_disk)]; @@ -1020,8 +1022,8 @@ int do_init(int argc, char *argv[]) memset(command, 0, sizeof(command));
snprintf(command, sizeof(command), - "sanlock direct init -n 8 -s devcount:0:%s:0", - argv[2]); + "sanlock direct init -n %d -s devcount:0:%s:0", + INIT_NUM_HOSTS, argv[2]);
printf("%s\n", command);
@@ -1033,7 +1035,8 @@ int do_init(int argc, char *argv[])
snprintf(command, sizeof(command), - "sanlock direct init -n 8 -r devcount:resource%s:%s:1024000", + "sanlock direct init -n %d -r devcount:resource%s:%s:1024000", + INIT_NUM_HOSTS, argv[3], argv[2]);
@@ -1045,7 +1048,7 @@ int do_init(int argc, char *argv[]) strcpy(ls.name, "devcount"); strcpy(ls.host_id_disk.path, argv[2]);
- rv = sanlock_direct_init(&ls, NULL, 0, 8, 0); + rv = sanlock_direct_init(&ls, NULL, 0, INIT_NUM_HOSTS, 0); if (rv < 0) { printf("sanlock_direct_init lockspace error %d\n", rv); return -1; @@ -1059,7 +1062,7 @@ int do_init(int argc, char *argv[]) strcpy(res->disks[0].path, argv[2]); res->disks[0].offset = 1024000;
- rv = sanlock_direct_init(NULL, res, 0, 8, 0); + rv = sanlock_direct_init(NULL, res, 0, INIT_NUM_HOSTS, 0); if (rv < 0) { printf("sanlock_direct_init resource error %d\n", rv); return -1;
sanlock-devel@lists.fedorahosted.org