[stgt] [PATCH 01/12] Export event management routines

Chandra Seetharaman sekharan at us.ibm.com
Mon Sep 27 23:06:36 CEST 2010


add tgt_event_* helper functions

This enables us to handle events for non main process.

Signed-off-by: FUJITA Tomonori <fujita.tomonori at lab.ntt.co.jp>
Signed-off-by: Chandra Seetharaman <sekharan at us.ibm.com>

---
 usr/tgtd.c |   39 ++++++++++++++++++++++++++++-----------
 usr/tgtd.h |    5 +++++
 2 files changed, 33 insertions(+), 11 deletions(-)

Index: tgt-102236c/usr/tgtd.h
===================================================================
--- tgt-102236c.orig/usr/tgtd.h
+++ tgt-102236c/usr/tgtd.h
@@ -335,6 +335,11 @@ struct event_data {
 	struct list_head e_list;
 };
 
+int do_tgt_event_add(int efd, struct list_head *list, int fd, int events,
+		     event_handler_t handler, void *data);
+void do_tgt_event_del(int efd, struct list_head *list, int fd);
+int do_tgt_event_modify(int efd, struct list_head *list, int fd, int events);
+
 int call_program(const char *cmd,
 		    void (*callback)(void *data, int result), void *data,
 		    char *output, int op_len, int flags);
Index: tgt-102236c/usr/tgtd.c
===================================================================
--- tgt-102236c.orig/usr/tgtd.c
+++ tgt-102236c/usr/tgtd.c
@@ -138,7 +138,8 @@ set_rlimit:
 	return 0;
 }
 
-int tgt_event_add(int fd, int events, event_handler_t handler, void *data)
+int do_tgt_event_add(int efd, struct list_head *list, int fd, int events,
+		     event_handler_t handler, void *data)
 {
 	struct epoll_event ev;
 	struct event_data *tev;
@@ -155,39 +156,45 @@ int tgt_event_add(int fd, int events, ev
 	memset(&ev, 0, sizeof(ev));
 	ev.events = events;
 	ev.data.ptr = tev;
-	err = epoll_ctl(ep_fd, EPOLL_CTL_ADD, fd, &ev);
+	err = epoll_ctl(efd, EPOLL_CTL_ADD, fd, &ev);
 	if (err) {
 		eprintf("Cannot add fd, %m\n");
 		free(tev);
 	} else
-		list_add(&tev->e_list, &tgt_events_list);
+		list_add(&tev->e_list, list);
 
 	return err;
 }
 
-static struct event_data *tgt_event_lookup(int fd)
+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,
+				data);
+}
+
+static struct event_data *tgt_event_lookup(struct list_head *list, int fd)
 {
 	struct event_data *tev;
 
-	list_for_each_entry(tev, &tgt_events_list, e_list) {
+	list_for_each_entry(tev, list, e_list) {
 		if (tev->fd == fd)
 			return tev;
 	}
 	return NULL;
 }
 
-void tgt_event_del(int fd)
+void do_tgt_event_del(int efd, struct list_head *list, int fd)
 {
 	struct event_data *tev;
 	int ret;
 
-	tev = tgt_event_lookup(fd);
+	tev = tgt_event_lookup(list, fd);
 	if (!tev) {
 		eprintf("Cannot find event %d\n", fd);
 		return;
 	}
 
-	ret = epoll_ctl(ep_fd, EPOLL_CTL_DEL, fd, NULL);
+	ret = epoll_ctl(efd, EPOLL_CTL_DEL, fd, NULL);
 	if (ret < 0)
 		eprintf("fail to remove epoll event, %s\n", strerror(errno));
 
@@ -195,12 +202,17 @@ void tgt_event_del(int fd)
 	free(tev);
 }
 
-int tgt_event_modify(int fd, int events)
+void tgt_event_del(int fd)
+{
+	do_tgt_event_del(ep_fd, &tgt_events_list, fd);
+}
+
+int do_tgt_event_modify(int efd, struct list_head *list, int fd, int events)
 {
 	struct epoll_event ev;
 	struct event_data *tev;
 
-	tev = tgt_event_lookup(fd);
+	tev = tgt_event_lookup(list, fd);
 	if (!tev) {
 		eprintf("Cannot find event %d\n", fd);
 		return -EINVAL;
@@ -210,7 +222,12 @@ int tgt_event_modify(int fd, int events)
 	ev.events = events;
 	ev.data.ptr = tev;
 
-	return epoll_ctl(ep_fd, EPOLL_CTL_MOD, fd, &ev);
+	return epoll_ctl(efd, EPOLL_CTL_MOD, fd, &ev);
+}
+
+int tgt_event_modify(int fd, int events)
+{
+	return do_tgt_event_modify(ep_fd, &tgt_events_list, fd, events);
 }
 
 void tgt_init_sched_event(struct event_data *evt,
--
To unsubscribe from this list: send the line "unsubscribe stgt" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html



More information about the stgt mailing list