[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [PATCH 1/2] tools/libs/evtchn: decouple more from mini-os
Mini-OS and libevtchn are using implementation details of each other. Change that by letting libevtchn use the new get_file_from_fd() function and the generic dev pointer of struct file from Mini-OS. By using private struct declarations Mini-OS will be able to drop the libevtchn specific definitions of struct evtchn_port_info and evtchn_port_list in future. Signed-off-by: Juergen Gross <jgross@xxxxxxxx> --- tools/libs/evtchn/minios.c | 82 +++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/tools/libs/evtchn/minios.c b/tools/libs/evtchn/minios.c index e5dfdc5ef5..3305102f22 100644 --- a/tools/libs/evtchn/minios.c +++ b/tools/libs/evtchn/minios.c @@ -38,16 +38,27 @@ #include "private.h" +LIST_HEAD(port_list, port_info); + +struct port_info { + LIST_ENTRY(port_info) list; + evtchn_port_t port; + unsigned long pending; + int bound; +}; + extern void minios_evtchn_close_fd(int fd); extern struct wait_queue_head event_queue; /* XXX Note: This is not threadsafe */ -static struct evtchn_port_info *port_alloc(int fd) +static struct port_info *port_alloc(int fd) { - struct evtchn_port_info *port_info; + struct port_info *port_info; + struct file *file = get_file_from_fd(fd); + struct port_list *port_list = file->dev; - port_info = malloc(sizeof(struct evtchn_port_info)); + port_info = malloc(sizeof(struct port_info)); if ( port_info == NULL ) return NULL; @@ -55,12 +66,12 @@ static struct evtchn_port_info *port_alloc(int fd) port_info->port = -1; port_info->bound = 0; - LIST_INSERT_HEAD(&files[fd].evtchn.ports, port_info, list); + LIST_INSERT_HEAD(port_list, port_info, list); return port_info; } -static void port_dealloc(struct evtchn_port_info *port_info) +static void port_dealloc(struct port_info *port_info) { if ( port_info->bound ) unbind_evtchn(port_info->port); @@ -75,12 +86,25 @@ static void port_dealloc(struct evtchn_port_info *port_info) */ int osdep_evtchn_open(xenevtchn_handle *xce, unsigned int flags) { - int fd = alloc_fd(FTYPE_EVTCHN); + int fd; + struct file *file; + struct port_list *list; + + list = malloc(sizeof(*list)); + if ( !list ) + return -1; + + fd = alloc_fd(FTYPE_EVTCHN); + file = get_file_from_fd(fd); - if ( fd == -1 ) + if ( !file ) + { + free(list); return -1; + } - LIST_INIT(&files[fd].evtchn.ports); + file->dev = list; + LIST_INIT(list); xce->fd = fd; printf("evtchn_open() -> %d\n", fd); @@ -104,12 +128,15 @@ int osdep_evtchn_restrict(xenevtchn_handle *xce, domid_t domid) void minios_evtchn_close_fd(int fd) { - struct evtchn_port_info *port_info, *tmp; + struct port_info *port_info, *tmp; + struct file *file = get_file_from_fd(fd); + struct port_list *port_list = file->dev; - LIST_FOREACH_SAFE(port_info, &files[fd].evtchn.ports, list, tmp) + LIST_FOREACH_SAFE(port_info, port_list, list, tmp) port_dealloc(port_info); + free(port_list); - files[fd].type = FTYPE_NONE; + file->type = FTYPE_NONE; } int xenevtchn_fd(xenevtchn_handle *xce) @@ -135,11 +162,14 @@ int xenevtchn_notify(xenevtchn_handle *xce, evtchn_port_t port) static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data) { int fd = (int)(intptr_t)data; - struct evtchn_port_info *port_info; + struct file *file = get_file_from_fd(fd); + struct port_info *port_info; + struct port_list *port_list; - assert(files[fd].type == FTYPE_EVTCHN); + assert(file && file->type == FTYPE_EVTCHN); + port_list = file->dev; mask_evtchn(port); - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + LIST_FOREACH(port_info, port_list, list) { if ( port_info->port == port ) goto found; @@ -150,7 +180,7 @@ static void evtchn_handler(evtchn_port_t port, struct pt_regs *regs, void *data) found: port_info->pending = 1; - files[fd].read = 1; + file->read = 1; wake_up(&event_queue); } @@ -158,7 +188,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_unbound_port(xenevtchn_handle *xce, uint32_t domid) { int fd = xce->fd; - struct evtchn_port_info *port_info; + struct port_info *port_info; int ret; evtchn_port_t port; @@ -191,7 +221,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, evtchn_port_t remote_port) { int fd = xce->fd; - struct evtchn_port_info *port_info; + struct port_info *port_info; evtchn_port_t local_port; int ret; @@ -222,9 +252,11 @@ xenevtchn_port_or_error_t xenevtchn_bind_interdomain(xenevtchn_handle *xce, int xenevtchn_unbind(xenevtchn_handle *xce, evtchn_port_t port) { int fd = xce->fd; - struct evtchn_port_info *port_info; + struct file *file = get_file_from_fd(fd); + struct port_info *port_info; + struct port_list *port_list = file->dev; - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + LIST_FOREACH(port_info, port_list, list) { if ( port_info->port == port ) { @@ -244,7 +276,7 @@ xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, unsigned int virq) { int fd = xce->fd; - struct evtchn_port_info *port_info; + struct port_info *port_info; evtchn_port_t port; assert(get_current() == main_thread); @@ -273,15 +305,17 @@ xenevtchn_port_or_error_t xenevtchn_bind_virq(xenevtchn_handle *xce, xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn_handle *xce) { int fd = xce->fd; - struct evtchn_port_info *port_info; + struct file *file = get_file_from_fd(fd); + struct port_info *port_info; + struct port_list *port_list = file->dev; unsigned long flags; evtchn_port_t ret = -1; local_irq_save(flags); - files[fd].read = 0; + file->read = 0; - LIST_FOREACH(port_info, &files[fd].evtchn.ports, list) + LIST_FOREACH(port_info, port_list, list) { if ( port_info->port != -1 && port_info->pending ) { @@ -292,7 +326,7 @@ xenevtchn_port_or_error_t xenevtchn_pending(xenevtchn_handle *xce) } else { - files[fd].read = 1; + file->read = 1; break; } } -- 2.26.2
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |