[stgt] [PATCH 01/12] Export event management routines
Chandra Seetharaman
sekharan at us.ibm.com
Mon Sep 27 07:20:27 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-1.0.8.4/usr/tgtd.h
===================================================================
--- tgt-1.0.8.4.orig/usr/tgtd.h
+++ tgt-1.0.8.4/usr/tgtd.h
@@ -334,6 +334,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 run_ext_program(const char *cmd,
void (*callback)(void *data, int result), void *data);
#endif
Index: tgt-1.0.8.4/usr/tgtd.c
===================================================================
--- tgt-1.0.8.4.orig/usr/tgtd.c
+++ tgt-1.0.8.4/usr/tgtd.c
@@ -135,7 +135,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;
@@ -152,39 +153,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));
@@ -192,12 +199,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;
@@ -207,7 +219,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