Ok, we need this for pthread per target. = From: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx> Subject: [PATCH] iscsi: target->events_list race target->events_list can be accessed by the main and target pthreads. Signed-off-by: FUJITA Tomonori <fujita.tomonori@xxxxxxxxxxxxx> --- usr/iscsi/iscsi_tcp.c | 11 +++++++++++ usr/iscsi/iscsid.h | 1 + usr/iscsi/target.c | 6 ++++++ 3 files changed, 18 insertions(+), 0 deletions(-) diff --git a/usr/iscsi/iscsi_tcp.c b/usr/iscsi/iscsi_tcp.c index 471eea0..d1edd84 100644 --- a/usr/iscsi/iscsi_tcp.c +++ b/usr/iscsi/iscsi_tcp.c @@ -31,6 +31,7 @@ #include <netinet/tcp.h> #include <sys/epoll.h> #include <sys/socket.h> +#include <pthread.h> #include "iscsid.h" #include "tgtd.h" @@ -170,8 +171,10 @@ static void iscsi_tcp_event_handler(int fd, int events, void *data) if (tcp_conn->pthread) { struct iscsi_target *target = conn->session->target; + pthread_mutex_lock(&target->event_lock); do_tgt_event_del(target->efd, &target->events_list, tcp_conn->fd); + pthread_mutex_unlock(&target->event_lock); /* let the main thread handle this */ tcp_conn->pthread = 0; tgt_event_modify(tcp_conn->fd, EPOLLIN|EPOLLOUT|EPOLLERR); @@ -283,9 +286,15 @@ static void iscsi_tcp_conn_nexus_init(struct iscsi_connection *conn) if (iscsi_pthread_per_target()) { /* remove the conn from the main thread. */ conn->tp->ep_event_modify(conn, 0); + + pthread_mutex_lock(&target->event_lock); + do_tgt_event_add(target->efd, &target->events_list, tcp_conn->fd, EPOLLIN, iscsi_tcp_event_handler, conn); + + pthread_mutex_unlock(&target->event_lock); + tcp_conn->pthread = 1; } @@ -368,8 +377,10 @@ static void iscsi_event_modify(struct iscsi_connection *conn, int events) if (tcp_conn->pthread) { struct iscsi_target *target = conn->session->target; + pthread_mutex_lock(&target->event_lock); do_tgt_event_modify(target->efd, &target->events_list, tcp_conn->fd, events); + pthread_mutex_unlock(&target->event_lock); } else { ret = tgt_event_modify(tcp_conn->fd, events); if (ret) diff --git a/usr/iscsi/iscsid.h b/usr/iscsi/iscsid.h index 40f3ff4..1e70d81 100644 --- a/usr/iscsi/iscsid.h +++ b/usr/iscsi/iscsid.h @@ -246,6 +246,7 @@ struct iscsi_target { struct list_head isns_list; int efd; + pthread_mutex_t event_lock; struct list_head events_list; struct bs_finish bsfin; diff --git a/usr/iscsi/target.c b/usr/iscsi/target.c index cd45fb0..b547626 100644 --- a/usr/iscsi/target.c +++ b/usr/iscsi/target.c @@ -256,6 +256,8 @@ void iscsi_target_destroy(int tid) list_del(&target->tlist); + pthread_mutex_init(&target->event_lock, NULL); + if (target->bsfin.thread) { target->stop_pthread = 1; pthread_kill(target->bsfin.thread, SIGUSR2); @@ -283,9 +285,13 @@ static void *iscsi_thread_fn(void *arg) sigaddset(&mask, SIGUSR2); pthread_sigmask(SIG_BLOCK, &mask, NULL); + pthread_mutex_lock(&t->event_lock); + do_tgt_event_add(t->efd, &t->events_list, sig_fd, EPOLLIN, bs_sig_request_done, &t->bsfin); + pthread_mutex_unlock(&t->event_lock); + retry: nevent = epoll_wait(t->efd, events, ARRAY_SIZE(events), 1000); if (nevent < 0) { -- 1.6.5 -- To unsubscribe from this list: send the line "unsubscribe stgt" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html