Protect the global events list, tgt_events_list, with a lock. Signed-off-by: Chandra Seetharaman <sekharan@xxxxxxxxxx> --- usr/tgtd.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) Index: tgt-102236c/usr/tgtd.c =================================================================== --- tgt-102236c.orig/usr/tgtd.c +++ tgt-102236c/usr/tgtd.c @@ -30,6 +30,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <pthread.h> #include <ctype.h> #include <sys/resource.h> #include <sys/epoll.h> @@ -166,10 +167,15 @@ int do_tgt_event_add(int efd, struct lis return err; } +static pthread_mutex_t tgt_events_lock; int tgt_event_add(int fd, int events, event_handler_t handler, void *data) { - return do_tgt_event_add(ep_fd, &tgt_events_list, fd, events, handler, + int ret; + pthread_mutex_lock(&tgt_events_lock); + ret = do_tgt_event_add(ep_fd, &tgt_events_list, fd, events, handler, data); + pthread_mutex_unlock(&tgt_events_lock); + return ret; } static struct event_data *tgt_event_lookup(struct list_head *list, int fd) @@ -204,7 +210,9 @@ void do_tgt_event_del(int efd, struct li void tgt_event_del(int fd) { + pthread_mutex_lock(&tgt_events_lock); do_tgt_event_del(ep_fd, &tgt_events_list, fd); + pthread_mutex_unlock(&tgt_events_lock); } int do_tgt_event_modify(int efd, struct list_head *list, int fd, int events) @@ -227,7 +235,11 @@ int do_tgt_event_modify(int efd, struct int tgt_event_modify(int fd, int events) { - return do_tgt_event_modify(ep_fd, &tgt_events_list, fd, events); + int ret; + pthread_mutex_lock(&tgt_events_lock); + ret = do_tgt_event_modify(ep_fd, &tgt_events_list, fd, events); + pthread_mutex_unlock(&tgt_events_lock); + return ret; } void tgt_init_sched_event(struct event_data *evt, @@ -457,6 +469,7 @@ int main(int argc, char **argv) sigaction(SIGINT, &sa_new, &sa_old); sigaction(SIGPIPE, &sa_new, &sa_old); sigaction(SIGTERM, &sa_new, &sa_old); + pthread_mutex_init(&tgt_events_lock, NULL); pagesize = sysconf(_SC_PAGESIZE); for (pageshift = 0;; pageshift++) -- 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