From 4599cf191ad85f322f473cc78b6b8936bb6be383 Mon Sep 17 00:00:00 2001 From: Matthew Dillon Date: Wed, 23 May 2007 08:57:10 +0000 Subject: [PATCH] * Greatly reduce the complexity of the LWKT messaging and port abstraction. Significantly reduce the overhead of the subsystem. * The message abort algorithm has been rewritten. It now sends a separate message to issue the abort instead of trying to requeue the original message. This also means the TAILQ embedded in the lwkt_msg structure can be used by unrelated code during processing of the message. * Numerous MSGF_ flags have been removed, and all the LWKT msg/port algorithms have been rewritten and simplified. The message structure is now only touched by the current owner in all situations. * Numerous structural fields have been removed. In particular, the fields used for message abort sequencing have been simplified and we do not try to embed a 'command' field in the base LWKT message any more. * Clean up the netmsg abstraction, which is used all over the network stack. Instead of trying to overload fields in lwkt_msg we now simply extend the base lwkt_msg into struct netmsg. The function dispatch now takes a netmsg and returns void (before we had to return EASYNC), and we no longer need weird casts. Accept/connect message aborts are now greatly simplified. --- sys/bus/usb/usb_ethersubr.c | 5 +- sys/dev/acpica5/Osd/OsdSchedule.c | 5 +- sys/kern/kern_poll.c | 12 +- sys/kern/lwkt_msgport.c | 567 +++++++++--------------------- sys/kern/uipc_msg.c | 320 +++++++++-------- sys/kern/uipc_socket2.c | 8 +- sys/kern/uipc_syscalls.c | 35 +- sys/net/netisr.c | 53 +-- sys/net/netisr.h | 75 ++-- sys/net/netmsg.h | 55 +-- sys/net/netmsg2.h | 63 ++++ sys/net/pf/pf.c | 23 +- sys/net/ppp/if_ppp.c | 5 +- sys/net/route.c | 65 ++-- sys/netgraph/netgraph/ng_base.c | 8 +- sys/netinet/if_ether.c | 37 +- sys/netinet/ip6.h | 5 +- sys/netinet/ip_input.c | 31 +- sys/netinet/tcp_subr.c | 44 ++- sys/netinet/tcp_syncache.c | 25 +- sys/netinet/tcp_usrreq.c | 48 ++- sys/netinet6/ip6_input.c | 12 +- sys/netproto/atalk/aarp.c | 6 +- sys/netproto/atalk/at_extern.h | 8 +- sys/netproto/atalk/ddp_input.c | 9 +- sys/netproto/atm/atm_subr.c | 7 +- sys/netproto/ipx/ipx_input.c | 8 +- sys/netproto/natm/natm.c | 8 +- sys/netproto/ns/ns_input.c | 8 +- sys/sys/msgport.h | 89 ++--- sys/sys/msgport2.h | 57 +-- 31 files changed, 743 insertions(+), 958 deletions(-) create mode 100644 sys/net/netmsg2.h diff --git a/sys/bus/usb/usb_ethersubr.c b/sys/bus/usb/usb_ethersubr.c index d12de05213..b7fc2d5631 100644 --- a/sys/bus/usb/usb_ethersubr.c +++ b/sys/bus/usb/usb_ethersubr.c @@ -31,7 +31,7 @@ * * * $FreeBSD: src/sys/dev/usb/usb_ethersubr.c,v 1.17 2003/11/14 11:09:45 johan Exp $ - * $DragonFly: src/sys/bus/usb/usb_ethersubr.c,v 1.17 2006/12/10 02:03:56 sephe Exp $ + * $DragonFly: src/sys/bus/usb/usb_ethersubr.c,v 1.18 2007/05/23 08:57:10 dillon Exp $ */ /* @@ -73,7 +73,7 @@ Static int netisr_inited = 0; -Static int +Static void usbintr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -84,7 +84,6 @@ usbintr(struct netmsg *msg) (*ifp->if_input)(ifp, m); lwkt_serialize_exit(ifp->if_serializer); /* the msg is embedded in the mbuf, do not reply it */ - return EASYNC; } void diff --git a/sys/dev/acpica5/Osd/OsdSchedule.c b/sys/dev/acpica5/Osd/OsdSchedule.c index d9198c179f..85f98e05f7 100644 --- a/sys/dev/acpica5/Osd/OsdSchedule.c +++ b/sys/dev/acpica5/Osd/OsdSchedule.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/dev/acpica/Osd/OsdSchedule.c,v 1.28 2004/05/06 02:18:58 njl Exp $ - * $DragonFly: src/sys/dev/acpica5/Osd/OsdSchedule.c,v 1.7 2007/01/17 17:31:19 y0netan1 Exp $ + * $DragonFly: src/sys/dev/acpica5/Osd/OsdSchedule.c,v 1.8 2007/05/23 08:57:10 dillon Exp $ */ /* @@ -130,8 +130,7 @@ AcpiOsExecute(ACPI_EXECUTE_TYPE Type, ACPI_OSD_EXEC_CALLBACK Function, /* Note: Interrupt Context */ at = kmalloc(sizeof(*at), M_ACPITASK, M_INTWAIT | M_ZERO); - lwkt_initmsg(&at->at_msg, &acpi_afree_rport, 0, - lwkt_cmd_op_none, lwkt_cmd_op_none); + lwkt_initmsg(&at->at_msg, &acpi_afree_rport, 0); at->at_function = Function; at->at_context = Context; at->at_type = Type; diff --git a/sys/kern/kern_poll.c b/sys/kern/kern_poll.c index d675dd61eb..2b530cc5c7 100644 --- a/sys/kern/kern_poll.c +++ b/sys/kern/kern_poll.c @@ -25,7 +25,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/kern/kern_poll.c,v 1.2.2.4 2002/06/27 23:26:33 luigi Exp $ - * $DragonFly: src/sys/kern/kern_poll.c,v 1.26 2007/04/30 07:18:53 dillon Exp $ + * $DragonFly: src/sys/kern/kern_poll.c,v 1.27 2007/05/23 08:57:04 dillon Exp $ */ #include "opt_polling.h" @@ -45,8 +45,8 @@ /* the two netisr handlers */ static int sysctl_pollhz(SYSCTL_HANDLER_ARGS); static int sysctl_polling(SYSCTL_HANDLER_ARGS); -static int netisr_poll(struct netmsg *); -static int netisr_pollmore(struct netmsg *); +static void netisr_poll(struct netmsg *); +static void netisr_pollmore(struct netmsg *); static void pollclock(systimer_t, struct intrframe *); void init_device_poll(void); /* init routine */ @@ -309,7 +309,7 @@ pollclock(systimer_t info __unused, struct intrframe *frame __unused) static struct timeval poll_start_t; /* ARGSUSED */ -static int +static void netisr_pollmore(struct netmsg *msg) { struct timeval t; @@ -353,7 +353,6 @@ netisr_pollmore(struct netmsg *msg) } out: crit_exit(); - return(EASYNC); } /* @@ -367,7 +366,7 @@ out: * section to operate. */ /* ARGSUSED */ -static int +static void netisr_poll(struct netmsg *msg) { static int reg_frac_count; @@ -446,7 +445,6 @@ netisr_poll(struct netmsg *msg) schednetisr(NETISR_POLLMORE); phase = 4; crit_exit(); - return(EASYNC); } /* diff --git a/sys/kern/lwkt_msgport.c b/sys/kern/lwkt_msgport.c index 728a5b21d7..21633656cb 100644 --- a/sys/kern/lwkt_msgport.c +++ b/sys/kern/lwkt_msgport.c @@ -34,7 +34,7 @@ * NOTE! This file may be compiled for userland libraries as well as for * the kernel. * - * $DragonFly: src/sys/kern/lwkt_msgport.c,v 1.39 2007/05/23 02:09:39 dillon Exp $ + * $DragonFly: src/sys/kern/lwkt_msgport.c,v 1.40 2007/05/23 08:57:04 dillon Exp $ */ #ifdef _KERNEL @@ -97,40 +97,28 @@ MALLOC_DEFINE(M_LWKTMSG, "lwkt message", "lwkt message"); #ifdef SMP static void lwkt_replyport_remote(lwkt_msg_t msg); static void lwkt_putport_remote(lwkt_msg_t msg); -static void lwkt_abortmsg_remote(lwkt_msg_t msg); #endif /* * lwkt_sendmsg() * - * Send a message asynchronously. This function requests asynchronous - * completion and calls lwkt_beginmsg(). If the target port decides to - * run the message synchronously this function will automatically queue - * the message to the current thread's message queue to present a - * consistent interface to the caller. + * Request asynchronous completion and call lwkt_beginmsg(). The + * target port can opt to execute the message synchronously or + * asynchronously and this function will automatically queue the + * response if the target executes the message synchronously. * - * The message's ms_cmd must be initialized and its ms_flags must - * be zero'd out. lwkt_sendmsg() will initialize the ms_abort_port - * (abort chasing port). If abort is supported, ms_abort must also be - * initialized. - * - * NOTE: you cannot safely request an abort until lwkt_sendmsg() returns - * to the caller. - * - * NOTE: MSGF_DONE is left set. The target port must clear it if the - * message is to be handled asynchronously, while the synchronous case - * can just ignore it. + * NOTE: The message is in an indeterminant state until this call + * returns. The caller should not mess with it (e.g. try to abort it) + * until then. */ void lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg) { int error; - msg->ms_flags |= MSGF_ASYNC; - msg->ms_flags &= ~(MSGF_REPLY1 | MSGF_REPLY2 | MSGF_QUEUED | \ - MSGF_ABORTED | MSGF_RETRIEVED); - KKASSERT(msg->ms_reply_port != NULL); - msg->ms_abort_port = msg->ms_reply_port; + KKASSERT(msg->ms_reply_port != NULL && + (msg->ms_flags & (MSGF_DONE|MSGF_QUEUED)) == MSGF_DONE); + msg->ms_flags &= ~(MSGF_REPLY | MSGF_SYNC | MSGF_DONE); if ((error = lwkt_beginmsg(port, msg)) != EASYNC) { lwkt_replymsg(msg, error); } @@ -139,38 +127,24 @@ lwkt_sendmsg(lwkt_port_t port, lwkt_msg_t msg) /* * lwkt_domsg() * - * Send a message synchronously. This function requests synchronous - * completion and calls lwkt_beginmsg(). If the target port decides to - * run the message asynchronously this function will block waiting for - * the message to complete. Since MSGF_ASYNC is not set the target - * will not attempt to queue the reply to a reply port but will simply - * wake up anyone waiting on the message. - * - * A synchronous error code is always returned. - * - * The message's ms_cmd must be initialized, and its ms_flags must be - * at least zero'd out. lwkt_domsg() will initialize the message's - * ms_abort_port (abort chasing port). If abort is supported, ms_abort - * must also be initialized. - * - * NOTE: you cannot safely request an abort until lwkt_domsg() blocks. - * XXX this probably needs some work. - * - * NOTE: MSGF_DONE is left set. The target port must clear it if the - * message is to be handled asynchronously, while the synchronous case - * can just ignore it. + * Request asynchronous completion and call lwkt_beginmsg(). The + * target port can opt to execute the message synchronously or + * asynchronously and this function will automatically queue the + * response if the target executes the message synchronously. */ int lwkt_domsg(lwkt_port_t port, lwkt_msg_t msg) { int error; - msg->ms_flags &= ~(MSGF_ASYNC | MSGF_REPLY1 | MSGF_REPLY2 | \ - MSGF_QUEUED | MSGF_ABORTED | MSGF_RETRIEVED); - KKASSERT(msg->ms_reply_port != NULL); - msg->ms_abort_port = msg->ms_reply_port; + KKASSERT(msg->ms_reply_port != NULL && + (msg->ms_flags & (MSGF_DONE|MSGF_QUEUED)) == MSGF_DONE); + msg->ms_flags &= ~(MSGF_REPLY | MSGF_DONE); + msg->ms_flags |= MSGF_SYNC; if ((error = lwkt_beginmsg(port, msg)) == EASYNC) { error = lwkt_waitmsg(msg); + } else { + msg->ms_flags |= MSGF_DONE | MSGF_REPLY; } return(error); } @@ -194,7 +168,6 @@ lwkt_initport(lwkt_port_t port, thread_t td) port->mp_putport = lwkt_default_putport; port->mp_waitport = lwkt_default_waitport; port->mp_replyport = lwkt_default_replyport; - port->mp_abortport = lwkt_default_abortport; } /* @@ -212,20 +185,8 @@ lwkt_initport_null_rport(lwkt_port_t port, thread_t td) * lwkt_getport() * * Retrieve the next message from the port's message queue, return NULL - * if no messages are pending. Note that callers CANNOT use the - * MSGF_ABORTED flag as a litmus test to determine if a message - * was aborted. The flag only indicates that an abort was requested. - * The message's error code will indicate whether an abort occured - * (typically by returning EINTR). - * - * Note that once a message has been dequeued it is subject to being - * requeued via an IPI based abort request if it is not marked MSGF_DONE. - * - * If the message has been aborted we have to guarentee that abort - * semantics are properly followed. The target port will always see - * the original message at least once, and if it does not reply the - * message before looping on its message port again it will then see - * the message again with ms_cmd set to ms_abort. + * if no messages are pending. The retrieved message will either be a + * request or a reply based on the MSGF_REPLY bit. * * The calling thread MUST own the port. */ @@ -234,34 +195,11 @@ static __inline void _lwkt_pullmsg(lwkt_port_t port, lwkt_msg_t msg) { - if ((msg->ms_flags & MSGF_ABORTED) == 0) { - /* - * normal case, remove and return the message. - */ - TAILQ_REMOVE(&port->mp_msgq, msg, ms_node); - msg->ms_flags = (msg->ms_flags & ~MSGF_QUEUED) | MSGF_RETRIEVED; - } else { - if (msg->ms_flags & MSGF_RETRIEVED) { - /* - * abort case, message already returned once, remove and - * return the aborted message a second time after setting - * ms_cmd to ms_abort. - */ - TAILQ_REMOVE(&port->mp_msgq, msg, ms_node); - msg->ms_flags &= ~MSGF_QUEUED; - msg->ms_cmd = msg->ms_abort; - } else { - /* - * abort case, abort races initial message retrieval. The - * message is returned normally but not removed from the - * queue. On the next loop the 'aborted' message will be - * dequeued and returned. Note that if the caller replies - * to the message it will be dequeued (the abort becomes a - * NOP). - */ - msg->ms_flags |= MSGF_RETRIEVED; - } - } + /* + * normal case, remove and return the message. + */ + TAILQ_REMOVE(&port->mp_msgq, msg, ms_node); + msg->ms_flags &= ~MSGF_QUEUED; } void * @@ -278,47 +216,6 @@ lwkt_getport(lwkt_port_t port) return(msg); } -/* - * This inline helper function completes processing of a reply from an - * unknown cpu context. - * - * The message is being returned to the specified port. The port is - * owned by the mp_td thread. If we are on the same cpu as the mp_td - * thread we can trivially queue the message to the reply port and schedule - * the target thread, otherwise we have to send an ipi message to the - * correct cpu. - * - * This inline must be entered with a critical section already held. - * Note that the IPIQ callback function (*_remote) is entered with a - * critical section already held, and we obtain one in lwkt_replyport(). - */ -static __inline -void -_lwkt_replyport(lwkt_port_t port, lwkt_msg_t msg, int force) -{ - thread_t td = port->mp_td; - - if (force || td->td_gd == mycpu) { - /* - * We can only reply the message if the abort has caught up with us, - * or if no abort was issued (same case). - */ - if (msg->ms_abort_port == port) { - KKASSERT((msg->ms_flags & MSGF_QUEUED) == 0); - TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); - msg->ms_flags |= MSGF_DONE | MSGF_QUEUED | MSGF_REPLY2; - if (port->mp_flags & MSGPORTF_WAITING) - lwkt_schedule(td); - } - } else { -#ifdef SMP - lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_replyport_remote, msg); -#else - panic("lwkt_replyport: thread %p has bad gd pointer", td); -#endif - } -} - #ifdef SMP /* @@ -329,43 +226,65 @@ static void lwkt_replyport_remote(lwkt_msg_t msg) { - _lwkt_replyport(msg->ms_reply_port, msg, 1); + lwkt_port_t port = msg->ms_reply_port; + +#ifdef INVARIANTS + KKASSERT(msg->ms_flags & MSGF_INTRANSIT); + msg->ms_flags &= ~MSGF_INTRANSIT; +#endif + TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); + msg->ms_flags |= MSGF_REPLY | MSGF_DONE | MSGF_QUEUED; + if (port->mp_flags & MSGPORTF_WAITING) + lwkt_schedule(port->mp_td); } #endif /* - * This function is called in the context of the target to reply a message. + * lwkt_default_replyport() - Backend to lwkt_replymsg() + * + * Called with the reply port as an argument but in the context of the + * original target port. + * * The critical section protects us from IPIs on the this CPU. */ void lwkt_default_replyport(lwkt_port_t port, lwkt_msg_t msg) { - crit_enter(); - msg->ms_flags |= MSGF_REPLY1; - - /* - * An abort may have caught up to us while we were processing the - * message. If this occured we have to dequeue the message from the - * target port in the context of our current cpu before we can finish - * replying it. - */ - if (msg->ms_flags & MSGF_QUEUED) { - KKASSERT(msg->ms_flags & MSGF_ABORTED); - TAILQ_REMOVE(&msg->ms_target_port->mp_msgq, msg, ms_node); - msg->ms_flags &= ~MSGF_QUEUED; - } + KKASSERT((msg->ms_flags & (MSGF_DONE|MSGF_QUEUED)) == 0); - /* - * Do reply port processing for async messages. Just mark the message - * done and wakeup the owner of the reply port for synchronous messages. - */ - if (msg->ms_flags & MSGF_ASYNC) { - _lwkt_replyport(port, msg, 0); - } else { - msg->ms_flags |= MSGF_DONE; + crit_enter(); + if (msg->ms_flags & MSGF_SYNC) { + /* + * If a synchronous completion has been requested, just wakeup + * the message without bothering to queue it to the target port. + */ + msg->ms_flags |= MSGF_DONE | MSGF_REPLY; if (port->mp_flags & MSGPORTF_WAITING) lwkt_schedule(port->mp_td); + } else { + /* + * If an asynchronous completion has been requested the message + * must be queued to the reply port. MSGF_REPLY cannot be set + * until the message actually gets queued. + */ +#ifdef SMP + if (port->mp_td->td_gd == mycpu) { +#endif + TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); + msg->ms_flags |= MSGF_REPLY | MSGF_DONE | MSGF_QUEUED; + if (port->mp_flags & MSGPORTF_WAITING) + lwkt_schedule(port->mp_td); +#ifdef SMP + } else { +#ifdef INVARIANTS + msg->ms_flags |= MSGF_INTRANSIT; +#endif + msg->ms_flags |= MSGF_REPLY; + lwkt_send_ipiq(port->mp_td->td_gd, + (ipifunc1_t)lwkt_replyport_remote, msg); + } +#endif } crit_exit(); } @@ -378,50 +297,18 @@ lwkt_default_replyport(lwkt_port_t port, lwkt_msg_t msg) void lwkt_null_replyport(lwkt_port_t port, lwkt_msg_t msg) { - crit_enter(); - msg->ms_flags |= MSGF_DONE|MSGF_REPLY1; - crit_exit(); + msg->ms_flags |= MSGF_DONE | MSGF_REPLY; } /* - * lwkt_default_putport() - * - * This function is typically assigned to the mp_putport port vector. - * - * Queue a message to the target port and wakeup the thread owning it. - * This function always returns EASYNC and may be assigned to a - * message port's mp_putport function vector. Note that we must set - * MSGF_QUEUED prior to sending any IPIs in order to interlock against - * ABORT requests and other tests that might be performed. + * lwkt_default_putport() - Backend to lwkt_beginmsg() * - * Note that messages start out as synchronous entities, and as an - * optimization MSGF_DONE is usually left set (so in the synchronous path - * no modifications to ms_flags are ever required). If a message becomes - * async, i.e. you return EASYNC, then MSGF_DONE must be cleared or - * lwkt_replymsg() will wind up being a NOP. + * Called with the target port as an argument but in the context of the + * reply port. This function always implements an asynchronous put to + * the target message port, and thus returns EASYNC. * - * The inline must be called from a critical section (the remote function - * is called from an IPI and will be in a critical section). + * The message must already have cleared MSGF_DONE and MSGF_REPLY */ -static -__inline -void -_lwkt_putport(lwkt_port_t port, lwkt_msg_t msg, int force) -{ - thread_t td = port->mp_td; - - if (force || td->td_gd == mycpu) { - TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); - if (port->mp_flags & MSGPORTF_WAITING) - lwkt_schedule(td); - } else { -#ifdef SMP - lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_putport_remote, msg); -#else - panic("lwkt_putport: thread %p has bad gd pointer", td); -#endif - } -} #ifdef SMP @@ -429,21 +316,16 @@ static void lwkt_putport_remote(lwkt_msg_t msg) { + lwkt_port_t port = msg->ms_target_port; + #ifdef INVARIANTS - /* - * try to catch a free-after-send issue. - */ - if (msg->ms_target_port == (void *)0xdeadc0de) { - int i; - for (i = 0; i < 1000000; ++i) { - if (msg->ms_target_port != (void *)0xdeadc0de) - break; - cpu_lfence(); - } - panic("msg %p ms_target_port is bogus: reads %p after %d loops\n", msg, msg->ms_target_port, i); - } + KKASSERT(msg->ms_flags & MSGF_INTRANSIT); + msg->ms_flags &= ~MSGF_INTRANSIT; #endif - _lwkt_putport(msg->ms_target_port, msg, 1); + TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); + msg->ms_flags |= MSGF_QUEUED; + if (port->mp_flags & MSGPORTF_WAITING) + lwkt_schedule(port->mp_td); } #endif @@ -451,25 +333,34 @@ lwkt_putport_remote(lwkt_msg_t msg) int lwkt_default_putport(lwkt_port_t port, lwkt_msg_t msg) { - crit_enter(); - msg->ms_flags |= MSGF_QUEUED; /* abort interlock */ - msg->ms_flags &= ~MSGF_DONE; + KKASSERT((msg->ms_flags & (MSGF_DONE | MSGF_REPLY)) == 0); + msg->ms_target_port = port; - _lwkt_putport(port, msg, 0); + crit_enter(); +#ifdef SMP + if (port->mp_td->td_gd == mycpu) { +#endif + msg->ms_flags |= MSGF_QUEUED; + TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); + if (port->mp_flags & MSGPORTF_WAITING) + lwkt_schedule(port->mp_td); +#ifdef SMP + } else { +#ifdef INVARIANTS + msg->ms_flags |= MSGF_INTRANSIT; +#endif + lwkt_send_ipiq(port->mp_td->td_gd, + (ipifunc1_t)lwkt_putport_remote, msg); + } +#endif crit_exit(); - return(EASYNC); + return (EASYNC); } /* * lwkt_forwardmsg() * - * Forward a message received on one port to another port. The forwarding - * function must deal with a pending abort but othewise essentially just - * issues a putport to the target port. - * - * An abort may have two side effects: First, the message may have been - * requeued to the current target port. If so, we must dequeue it before - * we can forward it. + * Forward a message received on one port to another port. */ int lwkt_forwardmsg(lwkt_port_t port, lwkt_msg_t msg) @@ -477,12 +368,7 @@ lwkt_forwardmsg(lwkt_port_t port, lwkt_msg_t msg) int error; crit_enter(); - if (msg->ms_flags & MSGF_QUEUED) { - KKASSERT(msg->ms_flags & MSGF_ABORTED); - TAILQ_REMOVE(&msg->ms_target_port->mp_msgq, msg, ms_node); - msg->ms_flags &= ~MSGF_QUEUED; - } - msg->ms_flags &= ~MSGF_RETRIEVED; + KKASSERT((msg->ms_flags & (MSGF_QUEUED|MSGF_DONE|MSGF_REPLY)) == 0); if ((error = port->mp_putport(port, msg)) != EASYNC) lwkt_replymsg(msg, error); crit_exit(); @@ -492,138 +378,35 @@ lwkt_forwardmsg(lwkt_port_t port, lwkt_msg_t msg) /* * lwkt_abortmsg() * - * Aborting a message is a fairly complex task. The first order of - * business is to get the message to the cpu that owns the target - * port, during which we may have to do some port chasing due to - * message forwarding operations. + * Attempt to abort a message. This only works if MSGF_ABORTABLE is set. + * The caller must ensure that the message will not be both replied AND + * destroyed while the abort is in progress. * - * NOTE! Since an aborted message is requeued all message processing - * loops should check the MSGF_ABORTED flag. + * This function issues a callback which might block! */ void lwkt_abortmsg(lwkt_msg_t msg) { - lwkt_port_t port; - thread_t td; - /* - * A critical section protects us from reply IPIs on this cpu. We - * can only abort messages that have not yet completed (DONE), are not - * in the midst of being replied (REPLY1), and which support the - * abort function (ABORTABLE). + * A critical section protects us from reply IPIs on this cpu. */ crit_enter(); - if ((msg->ms_flags & (MSGF_DONE|MSGF_REPLY1|MSGF_ABORTABLE)) == MSGF_ABORTABLE) { - /* - * Chase the message. If REPLY1 is set the message has been replied - * all the way back to the originator, otherwise it is sitting on - * ms_target_port (but we can only complete processing if we are - * on the same cpu as the selected port in order to avoid - * SMP cache synchronization issues). - * - * When chasing through multiple ports ms_flags may not be - * synchronized to the current cpu, but it WILL be synchronized - * with regards to testing the MSGF_REPLY1 bit once we reach the - * target port that made the reply and since the cpu owning - * some port X stores the new port in ms_target_port if the message - * is forwarded, the current port will only ever equal the target - * port when we are on the correct cpu. - */ - if (msg->ms_flags & MSGF_REPLY1) - port = msg->ms_reply_port; - else - port = msg->ms_target_port; - - cpu_ccfence(); /* don't let the compiler reload ms_*_port */ - - /* - * The chase call must run on the cpu owning the port. Fully - * synchronous ports (mp_td == NULL) can run the call on any cpu. - */ - td = port->mp_td; - if (td && td->td_gd != mycpu) { -#ifdef SMP - lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_abortmsg_remote, msg); -#else - panic("lwkt_abortmsg: thread %p has bad gd pointer", td); -#endif - } else { - port->mp_abortport(port, msg); - } - } - crit_exit(); -} -#ifdef SMP - -static -void -lwkt_abortmsg_remote(lwkt_msg_t msg) -{ - lwkt_port_t port; - thread_t td; - - if (msg->ms_flags & MSGF_REPLY1) - port = msg->ms_reply_port; - else - port = msg->ms_target_port; - cpu_ccfence(); /* don't let the compiler reload ms_*_port */ - td = port->mp_td; - if (td->td_gd != mycpu) { - lwkt_send_ipiq(td->td_gd, (ipifunc1_t)lwkt_abortmsg_remote, msg); - } else { - port->mp_abortport(port, msg); - } -} - -#endif - -/* - * The mp_abortport function is called when the abort has finally caught up - * to the target port or (if the message has been replied) the reply port. - */ -void -lwkt_default_abortport(lwkt_port_t port, lwkt_msg_t msg) -{ /* - * Set ms_abort_port to ms_reply_port to indicate the completion of - * the messaging chasing portion of the abort request. Note that - * the passed port is the port that we finally caught up to, not - * necessarily the reply port. + * Shortcut the operation if the message has already been returned. + * The callback typically constructs a lwkt_msg with the abort request, + * issues it synchronously, and waits for completion. The callback + * is not required to actually abort the message and the target port, + * upon receiving an abort request message generated by the callback + * should check whether the original message has already completed or + * not. */ - msg->ms_abort_port = msg->ms_reply_port; - - if (msg->ms_flags & MSGF_REPLY2) { - /* - * If REPLY2 is set we must have chased it all the way back to - * the reply port, but the replyport code has not queued the message - * (because it was waiting for the abort to catch up). We become - * responsible for queueing the message to the reply port. - */ - KKASSERT((msg->ms_flags & MSGF_QUEUED) == 0); - KKASSERT(port == msg->ms_reply_port); - TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); - msg->ms_flags |= MSGF_DONE | MSGF_QUEUED; - if (port->mp_flags & MSGPORTF_WAITING) - lwkt_schedule(port->mp_td); - } else if ((msg->ms_flags & (MSGF_QUEUED|MSGF_REPLY1)) == 0) { - /* - * Abort on the target port. The message has not yet been replied - * and must be requeued to the target port. - */ - msg->ms_flags |= MSGF_ABORTED | MSGF_QUEUED; - TAILQ_INSERT_TAIL(&port->mp_msgq, msg, ms_node); - if (port->mp_flags & MSGPORTF_WAITING) - lwkt_schedule(port->mp_td); - } else if ((msg->ms_flags & MSGF_REPLY1) == 0) { - /* - * The message has not yet been retrieved by the target port, set - * MSGF_ABORTED so the target port can requeue the message abort after - * retrieving it. - */ - msg->ms_flags |= MSGF_ABORTED; + if (msg->ms_flags & MSGF_ABORTABLE) { + if ((msg->ms_flags & (MSGF_DONE|MSGF_REPLY)) == 0) + msg->ms_abortfn(msg); } + crit_exit(); } /* @@ -633,13 +416,14 @@ lwkt_default_abortport(lwkt_port_t port, lwkt_msg_t msg) * queue, block until a message is ready. This function never * returns NULL. * - * If msg is non-NULL, block until the requested message has been returned - * to the port then dequeue and return it. DO NOT USE THIS TO WAIT FOR - * INCOMING REQUESTS, ONLY USE THIS TO WAIT FOR REPLIES. + * If msg is non-NULL, block until the requested message has been + * replied, then dequeue and return it. + * + * NOTE: This function should not be used to wait for specific + * incoming requests because MSGF_DONE only applies to replies. * * Note that the API does not currently support multiple threads waiting - * on a port. By virtue of owning the port it is controlled by our - * cpu and we can safely manipulate it's contents. + * on a single port. The port must be owned by the caller. */ void * lwkt_default_waitport(lwkt_port_t port, lwkt_msg_t msg) @@ -650,6 +434,9 @@ lwkt_default_waitport(lwkt_port_t port, lwkt_msg_t msg) KKASSERT(port->mp_td == td); crit_enter_quick(td); if (msg == NULL) { + /* + * Wait for any message + */ if ((msg = TAILQ_FIRST(&port->mp_msgq)) == NULL) { port->mp_flags |= MSGPORTF_WAITING; td->td_flags |= TDF_BLOCKED; @@ -663,56 +450,48 @@ lwkt_default_waitport(lwkt_port_t port, lwkt_msg_t msg) _lwkt_pullmsg(port, msg); } else { /* - * If a message is not marked done, or if it is queued, we have work - * to do. Note that MSGF_DONE is always set in the context of the - * reply port's cpu. + * Wait for a specific message. */ - if ((msg->ms_flags & (MSGF_DONE|MSGF_QUEUED)) != MSGF_DONE) { - /* - * We must own the reply port to safely mess with it's contents. - */ - port = msg->ms_reply_port; - KKASSERT(port->mp_td == td); - - if ((msg->ms_flags & MSGF_DONE) == 0) { - port->mp_flags |= MSGPORTF_WAITING; /* saved by the BGL */ - sentabort = 0; - do { -#ifdef _KERNEL - /* - * MSGF_PCATCH is only set by processes which wish to - * abort the message they are blocked on when a signal - * occurs. Note that we still must wait for message - * completion after sending an abort request. - */ - if (msg->ms_flags & MSGF_PCATCH) { - if (sentabort == 0 && CURSIG(port->mp_td->td_lwp)) { - sentabort = 1; - lwkt_abortmsg(msg); - continue; - } + KKASSERT(msg->ms_reply_port == port); + if ((msg->ms_flags & MSGF_DONE) == 0) { + sentabort = 0; + while ((msg->ms_flags & MSGF_DONE) == 0) { + /* + * MSGF_PCATCH is only set by processes which wish to + * abort the message they are blocked on when a signal + * occurs. Note that we still must wait for message + * completion after sending an abort request. + */ + if (msg->ms_flags & MSGF_PCATCH) { + if (sentabort == 0 && CURSIG(port->mp_td->td_lwp)) { + sentabort = 1; + lwkt_abortmsg(msg); + continue; } -#endif - /* - * XXX set TDF_SINTR so 'ps' knows the difference between - * an interruptable wait and a disk wait. YYY eventually - * move LWP_SINTR to TDF_SINTR to reduce duplication. - */ - td->td_flags |= TDF_SINTR | TDF_BLOCKED; - lwkt_deschedule_self(td); - lwkt_switch(); - td->td_flags &= ~(TDF_SINTR | TDF_BLOCKED); - } while ((msg->ms_flags & MSGF_DONE) == 0); - port->mp_flags &= ~MSGPORTF_WAITING; /* saved by the BGL */ - } - /* - * We own the message now. - */ - if (msg->ms_flags & MSGF_QUEUED) { - msg->ms_flags &= ~MSGF_QUEUED; - TAILQ_REMOVE(&port->mp_msgq, msg, ms_node); + } + + /* + * XXX set TDF_SINTR so 'ps' knows the difference between + * an interruptable wait and a disk wait. YYY eventually + * move LWP_SINTR to TDF_SINTR to reduce duplication. + */ + port->mp_flags |= MSGPORTF_WAITING; + td->td_flags |= TDF_SINTR | TDF_BLOCKED; + lwkt_deschedule_self(td); + lwkt_switch(); + td->td_flags &= ~(TDF_SINTR | TDF_BLOCKED); + port->mp_flags &= ~MSGPORTF_WAITING; } } + + /* + * Once the MSGF_DONE bit is set, the message is stable. We + * can just check MSGF_QUEUED to determine + */ + if (msg->ms_flags & MSGF_QUEUED) { + msg->ms_flags &= ~MSGF_QUEUED; + TAILQ_REMOVE(&port->mp_msgq, msg, ms_node); + } } crit_exit_quick(td); return(msg); diff --git a/sys/kern/uipc_msg.c b/sys/kern/uipc_msg.c index b683a355d4..ced607e836 100644 --- a/sys/kern/uipc_msg.c +++ b/sys/kern/uipc_msg.c @@ -30,7 +30,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/kern/uipc_msg.c,v 1.16 2007/04/22 01:13:10 dillon Exp $ + * $DragonFly: src/sys/kern/uipc_msg.c,v 1.17 2007/05/23 08:57:05 dillon Exp $ */ #include @@ -43,6 +43,7 @@ #include #include #include +#include #include #include @@ -55,11 +56,11 @@ so_pru_abort(struct socket *so) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_ABORT); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_abort), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_abort); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_abort; msg.nm_so = so; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -75,12 +76,12 @@ so_pru_accept(struct socket *so, struct sockaddr **nam) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_ACCEPT); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_accept), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_accept); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_accept; msg.nm_so = so; msg.nm_nam = nam; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); #endif } @@ -93,13 +94,13 @@ so_pru_attach(struct socket *so, int proto, struct pru_attach_info *ai) lwkt_port_t port; port = so->so_proto->pr_mport(NULL, NULL, PRU_ATTACH); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_attach), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_attach); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_attach; msg.nm_so = so; msg.nm_proto = proto; msg.nm_ai = ai; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -112,13 +113,13 @@ so_pru_bind(struct socket *so, struct sockaddr *nam, struct thread *td) /* Send mesg to thread for new address. */ port = so->so_proto->pr_mport(NULL, nam, PRU_BIND); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_bind), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_bind); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_bind; msg.nm_so = so; msg.nm_nam = nam; msg.nm_td = td; /* used only for prison_ip() XXX JH */ - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -130,13 +131,13 @@ so_pru_connect(struct socket *so, struct sockaddr *nam, struct thread *td) lwkt_port_t port; port = so->so_proto->pr_mport(so, nam, PRU_CONNECT); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_connect), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_connect); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_connect; msg.nm_so = so; msg.nm_nam = nam; msg.nm_td = td; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -148,12 +149,12 @@ so_pru_connect2(struct socket *so1, struct socket *so2) lwkt_port_t port; port = so1->so_proto->pr_mport(so1, NULL, PRU_CONNECT2); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_connect2), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_connect2); msg.nm_prufn = so1->so_proto->pr_usrreqs->pru_connect2; msg.nm_so1 = so1; msg.nm_so2 = so2; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -168,15 +169,15 @@ so_pru_control(struct socket *so, u_long cmd, caddr_t data, struct ifnet *ifp) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_CONTROL); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_control), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_control); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_control; msg.nm_so = so; msg.nm_cmd = cmd; msg.nm_data = data; msg.nm_ifp = ifp; msg.nm_td = td; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); #endif } @@ -189,11 +190,11 @@ so_pru_detach(struct socket *so) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_DETACH); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_detach), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_detach); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_detach; msg.nm_so = so; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -205,11 +206,11 @@ so_pru_disconnect(struct socket *so) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_DISCONNECT); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_disconnect), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_disconnect); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_disconnect; msg.nm_so = so; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -221,12 +222,12 @@ so_pru_listen(struct socket *so, struct thread *td) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_LISTEN); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_listen), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_listen); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_listen; msg.nm_so = so; msg.nm_td = td; /* used only for prison_ip() XXX JH */ - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -238,12 +239,12 @@ so_pru_peeraddr(struct socket *so, struct sockaddr **nam) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_PEERADDR); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_peeraddr), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_peeraddr); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_peeraddr; msg.nm_so = so; msg.nm_nam = nam; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -255,12 +256,12 @@ so_pru_rcvd(struct socket *so, int flags) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_RCVD); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_rcvd), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_rcvd); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_rcvd; msg.nm_so = so; msg.nm_flags = flags; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -272,13 +273,13 @@ so_pru_rcvoob(struct socket *so, struct mbuf *m, int flags) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_RCVOOB); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_rcvoob), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_rcvoob); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_rcvoob; msg.nm_so = so; msg.nm_m = m; msg.nm_flags = flags; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -291,8 +292,8 @@ so_pru_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_SEND); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_send), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_send); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_send; msg.nm_so = so; msg.nm_flags = flags; @@ -300,7 +301,7 @@ so_pru_send(struct socket *so, int flags, struct mbuf *m, struct sockaddr *addr, msg.nm_addr = addr; msg.nm_control = control; msg.nm_td = td; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -312,12 +313,12 @@ so_pru_sense(struct socket *so, struct stat *sb) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_SENSE); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_sense), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_sense); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_sense; msg.nm_so = so; msg.nm_stat = sb; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -329,11 +330,11 @@ so_pru_shutdown(struct socket *so) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_SHUTDOWN); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_shutdown), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_shutdown); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_shutdown; msg.nm_so = so; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -345,12 +346,12 @@ so_pru_sockaddr(struct socket *so, struct sockaddr **nam) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_SOCKADDR); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_sockaddr), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_sockaddr); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_sockaddr; msg.nm_so = so; msg.nm_nam = nam; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -362,14 +363,14 @@ so_pru_sopoll(struct socket *so, int events, struct ucred *cred) lwkt_port_t port; port = so->so_proto->pr_mport(so, NULL, PRU_SOPOLL); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_sopoll), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_sopoll); msg.nm_prufn = so->so_proto->pr_usrreqs->pru_sopoll; msg.nm_so = so; msg.nm_events = events; msg.nm_cred = cred; msg.nm_td = curthread; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); } @@ -383,12 +384,12 @@ so_pr_ctloutput(struct socket *so, struct sockopt *sopt) int error; port = so->so_proto->pr_mport(so, NULL); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(netmsg_pru_ctloutput), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_pru_ctloutput); msg.nm_prfn = so->so_proto->pr_ctloutput; msg.nm_so = so; msg.nm_sopt = sopt; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); return (error); #endif } @@ -399,204 +400,188 @@ so_pr_ctloutput(struct socket *so, struct sockopt *sopt) * our dispatcher ignores the return value, but since we are handling * the replymsg ourselves we return EASYNC by convention. */ -int -netmsg_pru_abort(lwkt_msg_t msg) +void +netmsg_pru_abort(netmsg_t msg) { struct netmsg_pru_abort *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so)); } #ifdef notused -int -netmsg_pru_accept(lwkt_msg_t msg) +void +netmsg_pru_accept(netmsg_t msg) { struct netmsg_pru_accept *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_nam)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so, nm->nm_nam)); } #endif -int -netmsg_pru_attach(lwkt_msg_t msg) +void +netmsg_pru_attach(netmsg_t msg) { struct netmsg_pru_attach *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_proto, nm->nm_ai)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, + nm->nm_prufn(nm->nm_so, nm->nm_proto, nm->nm_ai)); } -int -netmsg_pru_bind(lwkt_msg_t msg) +void +netmsg_pru_bind(netmsg_t msg) { struct netmsg_pru_bind *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_nam, nm->nm_td)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, + nm->nm_prufn(nm->nm_so, nm->nm_nam, nm->nm_td)); } -int -netmsg_pru_connect(lwkt_msg_t msg) +void +netmsg_pru_connect(netmsg_t msg) { struct netmsg_pru_connect *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_nam, nm->nm_td)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, + nm->nm_prufn(nm->nm_so, nm->nm_nam, nm->nm_td)); } -int -netmsg_pru_connect2(lwkt_msg_t msg) +void +netmsg_pru_connect2(netmsg_t msg) { struct netmsg_pru_connect2 *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so1, nm->nm_so2)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so1, nm->nm_so2)); } -int -netmsg_pru_control(lwkt_msg_t msg) +void +netmsg_pru_control(netmsg_t msg) { struct netmsg_pru_control *nm = (void *)msg; int error; error = nm->nm_prufn(nm->nm_so, nm->nm_cmd, nm->nm_data, nm->nm_ifp, nm->nm_td); - lwkt_replymsg(msg, error); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, error); } -int -netmsg_pru_detach(lwkt_msg_t msg) +void +netmsg_pru_detach(netmsg_t msg) { struct netmsg_pru_detach *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so)); } -int -netmsg_pru_disconnect(lwkt_msg_t msg) +void +netmsg_pru_disconnect(netmsg_t msg) { struct netmsg_pru_disconnect *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so)); } -int -netmsg_pru_listen(lwkt_msg_t msg) +void +netmsg_pru_listen(netmsg_t msg) { struct netmsg_pru_listen *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_td)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so, nm->nm_td)); } -int -netmsg_pru_peeraddr(lwkt_msg_t msg) +void +netmsg_pru_peeraddr(netmsg_t msg) { struct netmsg_pru_peeraddr *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_nam)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so, nm->nm_nam)); } -int -netmsg_pru_rcvd(lwkt_msg_t msg) +void +netmsg_pru_rcvd(netmsg_t msg) { struct netmsg_pru_rcvd *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_flags)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so, nm->nm_flags)); } -int -netmsg_pru_rcvoob(lwkt_msg_t msg) +void +netmsg_pru_rcvoob(netmsg_t msg) { struct netmsg_pru_rcvoob *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_m, nm->nm_flags)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, + nm->nm_prufn(nm->nm_so, nm->nm_m, nm->nm_flags)); } -int -netmsg_pru_send(lwkt_msg_t msg) +void +netmsg_pru_send(netmsg_t msg) { struct netmsg_pru_send *nm = (void *)msg; int error; error = nm->nm_prufn(nm->nm_so, nm->nm_flags, nm->nm_m, nm->nm_addr, nm->nm_control, nm->nm_td); - lwkt_replymsg(msg, error); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, error); } -int -netmsg_pru_sense(lwkt_msg_t msg) +void +netmsg_pru_sense(netmsg_t msg) { struct netmsg_pru_sense *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_stat)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so, nm->nm_stat)); } -int -netmsg_pru_shutdown(lwkt_msg_t msg) +void +netmsg_pru_shutdown(netmsg_t msg) { struct netmsg_pru_shutdown *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so)); } -int -netmsg_pru_sockaddr(lwkt_msg_t msg) +void +netmsg_pru_sockaddr(netmsg_t msg) { struct netmsg_pru_sockaddr *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prufn(nm->nm_so, nm->nm_nam)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prufn(nm->nm_so, nm->nm_nam)); } -int -netmsg_pru_sopoll(lwkt_msg_t msg) +void +netmsg_pru_sopoll(netmsg_t msg) { struct netmsg_pru_sopoll *nm = (void *)msg; int error; error = nm->nm_prufn(nm->nm_so, nm->nm_events, nm->nm_cred, nm->nm_td); - lwkt_replymsg(msg, error); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, error); } -int -netmsg_pr_ctloutput(lwkt_msg_t msg) +void +netmsg_pr_ctloutput(netmsg_t msg) { struct netmsg_pr_ctloutput *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prfn(nm->nm_so, nm->nm_sopt)); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prfn(nm->nm_so, nm->nm_sopt)); } -int -netmsg_pr_timeout(lwkt_msg_t msg) +void +netmsg_pr_timeout(netmsg_t msg) { struct netmsg_pr_timeout *nm = (void *)msg; - lwkt_replymsg(msg, nm->nm_prfn()); - return(EASYNC); + lwkt_replymsg(&msg->nm_lmsg, nm->nm_prfn()); } /* * Handle a predicate event request. This function is only called once * when the predicate message queueing request is received. */ -int -netmsg_so_notify(lwkt_msg_t lmsg) +void +netmsg_so_notify(netmsg_t netmsg) { - struct netmsg_so_notify *msg = (void *)lmsg; + struct netmsg_so_notify *msg = (void *)netmsg; struct signalsockbuf *ssb; ssb = (msg->nm_etype & NM_REVENT) ? @@ -607,13 +592,31 @@ netmsg_so_notify(lwkt_msg_t lmsg) * Reply immediately if the event has occured, otherwise queue the * request. */ - if (msg->nm_predicate((struct netmsg *)msg)) { - lwkt_replymsg(lmsg, lmsg->ms_error); + if (msg->nm_predicate(&msg->nm_netmsg)) { + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, + msg->nm_netmsg.nm_lmsg.ms_error); } else { TAILQ_INSERT_TAIL(&ssb->ssb_sel.si_mlist, msg, nm_list); ssb->ssb_flags |= SSB_MEVENT; } - return(EASYNC); +} + +/* + * Called by doio when trying to abort a netmsg_so_notify message. + * Unlike the other functions this one is dispatched directly by + * the LWKT subsystem, so it takes a lwkt_msg_t as an argument. + */ +void +netmsg_so_notify_doabort(lwkt_msg_t lmsg) +{ + struct netmsg_so_notify_abort msg; + + if ((lmsg->ms_flags & MSGF_DONE) == 0) { + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + netmsg_so_notify_abort); + msg.nm_notifymsg = (void *)lmsg; + lwkt_domsg(lmsg->ms_target_port, &msg.nm_netmsg.nm_lmsg); + } } /* @@ -622,17 +625,28 @@ netmsg_so_notify(lwkt_msg_t lmsg) * occur on the same thread that controls the port where the abort is * requeued). */ -int -netmsg_so_notify_abort(lwkt_msg_t lmsg) +void +netmsg_so_notify_abort(netmsg_t netmsg) { - struct netmsg_so_notify *msg = (void *)lmsg; + struct netmsg_so_notify_abort *abrtmsg = (void *)netmsg; + struct netmsg_so_notify *msg = abrtmsg->nm_notifymsg; struct signalsockbuf *ssb; - ssb = (msg->nm_etype & NM_REVENT) ? - &msg->nm_so->so_rcv : - &msg->nm_so->so_snd; - TAILQ_REMOVE(&ssb->ssb_sel.si_mlist, msg, nm_list); - lwkt_replymsg(lmsg, EINTR); - return(EASYNC); + /* + * The original notify message is not destroyed until after the + * abort request is handled, so we can check its state. + */ + if ((msg->nm_netmsg.nm_lmsg.ms_flags & MSGF_DONE) == 0) { + ssb = (msg->nm_etype & NM_REVENT) ? + &msg->nm_so->so_rcv : + &msg->nm_so->so_snd; + TAILQ_REMOVE(&ssb->ssb_sel.si_mlist, msg, nm_list); + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, EINTR); + } + + /* + * Reply to the abort message + */ + lwkt_replymsg(&abrtmsg->nm_netmsg.nm_lmsg, 0); } diff --git a/sys/kern/uipc_socket2.c b/sys/kern/uipc_socket2.c index cc23f6bb02..0e758478c7 100644 --- a/sys/kern/uipc_socket2.c +++ b/sys/kern/uipc_socket2.c @@ -33,7 +33,7 @@ * * @(#)uipc_socket2.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/kern/uipc_socket2.c,v 1.55.2.17 2002/08/31 19:04:55 dwmalone Exp $ - * $DragonFly: src/sys/kern/uipc_socket2.c,v 1.28 2007/04/30 07:18:54 dillon Exp $ + * $DragonFly: src/sys/kern/uipc_socket2.c,v 1.29 2007/05/23 08:57:05 dillon Exp $ */ #include "opt_param.h" @@ -327,10 +327,10 @@ sowakeup(struct socket *so, struct signalsockbuf *ssb) struct netmsg_so_notify *msg, *nmsg; TAILQ_FOREACH_MUTABLE(msg, &selinfo->si_mlist, nm_list, nmsg) { - if (msg->nm_predicate((struct netmsg *)msg)) { + if (msg->nm_predicate(&msg->nm_netmsg)) { TAILQ_REMOVE(&selinfo->si_mlist, msg, nm_list); - lwkt_replymsg(&msg->nm_lmsg, - msg->nm_lmsg.ms_error); + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, + msg->nm_netmsg.nm_lmsg.ms_error); } } if (TAILQ_EMPTY(&ssb->ssb_sel.si_mlist)) diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index 95a862f4a7..a600a3f99b 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -35,7 +35,7 @@ * * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94 * $FreeBSD: src/sys/kern/uipc_syscalls.c,v 1.65.2.17 2003/04/04 17:11:16 tegge Exp $ - * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.80 2007/04/22 01:13:10 dillon Exp $ + * $DragonFly: src/sys/kern/uipc_syscalls.c,v 1.81 2007/05/23 08:57:05 dillon Exp $ */ #include "opt_ktrace.h" @@ -78,6 +78,7 @@ #include #include +#include #ifdef SCTP #include @@ -214,7 +215,7 @@ soaccept_predicate(struct netmsg *msg0) struct socket *head = msg->nm_so; if (head->so_error != 0) { - msg->nm_lmsg.ms_error = head->so_error; + msg->nm_netmsg.nm_lmsg.ms_error = head->so_error; return (TRUE); } if (!TAILQ_EMPTY(&head->so_comp)) { @@ -223,15 +224,15 @@ soaccept_predicate(struct netmsg *msg0) TAILQ_REMOVE(&head->so_comp, msg->nm_so, so_list); head->so_qlen--; - msg->nm_lmsg.ms_error = 0; + msg->nm_netmsg.nm_lmsg.ms_error = 0; return (TRUE); } if (head->so_state & SS_CANTRCVMORE) { - msg->nm_lmsg.ms_error = ECONNABORTED; + msg->nm_netmsg.nm_lmsg.ms_error = ECONNABORTED; return (TRUE); } if (msg->nm_fflags & FNONBLOCK) { - msg->nm_lmsg.ms_error = EWOULDBLOCK; + msg->nm_netmsg.nm_lmsg.ms_error = EWOULDBLOCK; return (TRUE); } @@ -287,15 +288,15 @@ kern_accept(int s, int fflags, struct sockaddr **name, int *namelen, int *res) /* optimize for uniprocessor case later XXX JH */ port = head->so_proto->pr_mport(head, NULL, PRU_PRED); - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, - MSGF_PCATCH | MSGF_ABORTABLE, - lwkt_cmd_func(netmsg_so_notify), - lwkt_cmd_func(netmsg_so_notify_abort)); + netmsg_init_abortable(&msg.nm_netmsg, &curthread->td_msgport, + MSGF_PCATCH, + netmsg_so_notify, + netmsg_so_notify_doabort); msg.nm_predicate = soaccept_predicate; msg.nm_fflags = fflags; msg.nm_so = head; msg.nm_etype = NM_REVENT; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); if (error) goto done; @@ -437,7 +438,7 @@ soconnected_predicate(struct netmsg *msg0) /* check predicate */ if (!(so->so_state & SS_ISCONNECTING) || so->so_error != 0) { - msg->nm_lmsg.ms_error = so->so_error; + msg->nm_netmsg.nm_lmsg.ms_error = so->so_error; return (TRUE); } @@ -481,15 +482,15 @@ kern_connect(int s, int fflags, struct sockaddr *sa) lwkt_port_t port; port = so->so_proto->pr_mport(so, sa, PRU_PRED); - lwkt_initmsg(&msg.nm_lmsg, - &curthread->td_msgport, - MSGF_PCATCH | MSGF_ABORTABLE, - lwkt_cmd_func(netmsg_so_notify), - lwkt_cmd_func(netmsg_so_notify_abort)); + netmsg_init_abortable(&msg.nm_netmsg, + &curthread->td_msgport, + MSGF_PCATCH, + netmsg_so_notify, + netmsg_so_notify_doabort); msg.nm_predicate = soconnected_predicate; msg.nm_so = so; msg.nm_etype = NM_REVENT; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); } if (error == 0) { error = so->so_error; diff --git a/sys/net/netisr.c b/sys/net/netisr.c index 1e800c9c17..213c092747 100644 --- a/sys/net/netisr.c +++ b/sys/net/netisr.c @@ -35,7 +35,7 @@ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $DragonFly: src/sys/net/netisr.c,v 1.30 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/net/netisr.c,v 1.31 2007/05/23 08:57:10 dillon Exp $ */ #include @@ -54,8 +54,9 @@ #include #include +#include -static int netmsg_sync_func(struct netmsg *msg); +static void netmsg_sync_func(struct netmsg *msg); struct netmsg_port_registration { TAILQ_ENTRY(netmsg_port_registration) npr_entry; @@ -104,13 +105,13 @@ netisr_autopanic_reply(lwkt_port_t port, lwkt_msg_t msg) static int netmsg_put_port(lwkt_port_t port, lwkt_msg_t lmsg) { - int error; + netmsg_t netmsg = (void *)lmsg; - if ((lmsg->ms_flags & MSGF_ASYNC) == 0 && port->mp_td == curthread) { - error = lmsg->ms_cmd.cm_func(lmsg); - if (error == EASYNC && (lmsg->ms_flags & MSGF_DONE) == 0) + if ((lmsg->ms_flags & MSGF_SYNC) && port->mp_td == curthread) { + netmsg->nm_dispatch(netmsg); + if ((lmsg->ms_flags & MSGF_DONE) == 0) panic("netmsg_put_port: self-referential deadlock on netport"); - return(error); + return(EASYNC); } else { return(lwkt_default_putport(port, lmsg)); } @@ -134,26 +135,16 @@ netmsg_put_port(lwkt_port_t port, lwkt_msg_t lmsg) static int netmsg_sync_putport(lwkt_port_t port, lwkt_msg_t lmsg) { + netmsg_t netmsg = (void *)lmsg; int error; lmsg->ms_flags &= ~MSGF_DONE; lmsg->ms_target_port = port; /* required for abort */ - error = lmsg->ms_cmd.cm_func(lmsg); - if (error == EASYNC) - error = lwkt_waitmsg(lmsg); - else - lmsg->ms_flags |= MSGF_DONE; + netmsg->nm_dispatch(netmsg); + error = lwkt_waitmsg(lmsg); return(error); } -static void -netmsg_sync_abortport(lwkt_port_t port, lwkt_msg_t lmsg) -{ - lmsg->ms_abort_port = lmsg->ms_reply_port; - lmsg->ms_flags |= MSGF_ABORTED; - lmsg->ms_abort.cm_func(lmsg); -} - static void netisr_init(void) { @@ -188,7 +179,6 @@ netisr_init(void) */ lwkt_initport(&netisr_sync_port, NULL); netisr_sync_port.mp_putport = netmsg_sync_putport; - netisr_sync_port.mp_abortport = netmsg_sync_abortport; } SYSINIT(netisr, SI_SUB_PROTO_BEGIN, SI_ORDER_FIRST, netisr_init, NULL); @@ -234,8 +224,7 @@ netmsg_service_sync(void) struct netmsg_port_registration *reg; struct netmsg smsg; - lwkt_initmsg(&smsg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func((void *)netmsg_sync_func), lwkt_cmd_op_none); + netmsg_init(&smsg, &curthread->td_msgport, 0, netmsg_sync_func); TAILQ_FOREACH(reg, &netreglist, npr_entry) { lwkt_domsg(reg->npr_port, &smsg.nm_lmsg); @@ -246,11 +235,10 @@ netmsg_service_sync(void) * The netmsg function simply replies the message. API semantics require * EASYNC to be returned if the netmsg function disposes of the message. */ -static int +static void netmsg_sync_func(struct netmsg *msg) { lwkt_replymsg(&msg->nm_lmsg, 0); - return(EASYNC); } /* @@ -263,7 +251,7 @@ netmsg_service_loop(void *arg) struct netmsg *msg; while ((msg = lwkt_waitport(&curthread->td_msgport, NULL))) { - msg->nm_lmsg.ms_cmd.cm_func(&msg->nm_lmsg); + msg->nm_dispatch(msg); } } @@ -304,11 +292,10 @@ netisr_queue(int num, struct mbuf *m) pmsg = &m->m_hdr.mh_netmsg; - lwkt_initmsg(&pmsg->nm_lmsg, &netisr_apanic_rport, 0, - lwkt_cmd_func((void *)ni->ni_handler), lwkt_cmd_op_none); + netmsg_init(&pmsg->nm_netmsg, &netisr_apanic_rport, 0, ni->ni_handler); pmsg->nm_packet = m; - pmsg->nm_lmsg.u.ms_result = num; - lwkt_sendmsg(port, &pmsg->nm_lmsg); + pmsg->nm_netmsg.nm_lmsg.u.ms_result = num; + lwkt_sendmsg(port, &pmsg->nm_netmsg.nm_lmsg); return (0); } @@ -317,8 +304,7 @@ netisr_register(int num, lwkt_portfn_t mportfn, netisr_fn_t handler) { KASSERT((num > 0 && num <= (sizeof(netisrs)/sizeof(netisrs[0]))), ("netisr_register: bad isr %d", num)); - lwkt_initmsg(&netisrs[num].ni_netmsg.nm_lmsg, &netisr_adone_rport, 0, - lwkt_cmd_op_none, lwkt_cmd_op_none); + netmsg_init(&netisrs[num].ni_netmsg, &netisr_adone_rport, 0, NULL); netisrs[num].ni_mport = mportfn; netisrs[num].ni_handler = handler; } @@ -386,8 +372,7 @@ schednetisr_remote(void *data) pmsg = &netisrs[num].ni_netmsg; crit_enter(); if (pmsg->nm_lmsg.ms_flags & MSGF_DONE) { - lwkt_initmsg(&pmsg->nm_lmsg, &netisr_adone_rport, 0, - lwkt_cmd_func((void *)ni->ni_handler), lwkt_cmd_op_none); + netmsg_init(pmsg, &netisr_adone_rport, 0, ni->ni_handler); pmsg->nm_lmsg.u.ms_result = num; lwkt_sendmsg(port, &pmsg->nm_lmsg); } diff --git a/sys/net/netisr.h b/sys/net/netisr.h index 77e6fde296..b7abf9d9be 100644 --- a/sys/net/netisr.h +++ b/sys/net/netisr.h @@ -65,7 +65,7 @@ * * @(#)netisr.h 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/net/netisr.h,v 1.21.2.5 2002/02/09 23:02:39 luigi Exp $ - * $DragonFly: src/sys/net/netisr.h,v 1.25 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/net/netisr.h,v 1.26 2007/05/23 08:57:10 dillon Exp $ */ #ifndef _NET_NETISR_H_ @@ -118,40 +118,37 @@ #ifndef _SYS_MSGPORT_H_ #include #endif +#ifndef _NET_NETMSG_H_ +#include +#endif TAILQ_HEAD(notifymsglist, netmsg_so_notify); -struct netmsg; - -typedef int (*netisr_fn_t)(struct netmsg *); typedef __boolean_t (*msg_predicate_fn_t)(struct netmsg *); /* * Base class. All net messages must start with the same fields. */ -struct netmsg { - struct lwkt_msg nm_lmsg; -}; struct netmsg_packet { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct mbuf *nm_packet; }; struct netmsg_pr_ctloutput { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; int (*nm_prfn) (struct socket *, struct sockopt *); struct socket *nm_so; struct sockopt *nm_sopt; }; struct netmsg_pr_timeout { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; int (*nm_prfn) (void); }; struct netmsg_so_notify { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; msg_predicate_fn_t nm_predicate; struct socket *nm_so; int nm_fflags; /* flags e.g. FNONBLOCK */ @@ -159,6 +156,11 @@ struct netmsg_so_notify { TAILQ_ENTRY(netmsg_so_notify) nm_list; }; +struct netmsg_so_notify_abort { + struct netmsg nm_netmsg; + struct netmsg_so_notify *nm_notifymsg; +}; + #define NM_REVENT 0x1 /* event on receive buffer */ #define NM_SEVENT 0x2 /* event on send buffer */ @@ -170,31 +172,32 @@ struct netmsg_so_notify { * for dispatching pr_ functions, * until they can be converted to message-passing */ -int netmsg_pru_abort(lwkt_msg_t); -int netmsg_pru_accept(lwkt_msg_t); -int netmsg_pru_attach(lwkt_msg_t); -int netmsg_pru_bind(lwkt_msg_t); -int netmsg_pru_connect(lwkt_msg_t); -int netmsg_pru_connect2(lwkt_msg_t); -int netmsg_pru_control(lwkt_msg_t); -int netmsg_pru_detach(lwkt_msg_t); -int netmsg_pru_disconnect(lwkt_msg_t); -int netmsg_pru_listen(lwkt_msg_t); -int netmsg_pru_peeraddr(lwkt_msg_t); -int netmsg_pru_rcvd(lwkt_msg_t); -int netmsg_pru_rcvoob(lwkt_msg_t); -int netmsg_pru_send(lwkt_msg_t); -int netmsg_pru_sense(lwkt_msg_t); -int netmsg_pru_shutdown(lwkt_msg_t); -int netmsg_pru_sockaddr(lwkt_msg_t); - -int netmsg_pru_sopoll(lwkt_msg_t); - -int netmsg_pr_ctloutput(lwkt_msg_t); -int netmsg_pr_timeout(lwkt_msg_t); - -int netmsg_so_notify(lwkt_msg_t); -int netmsg_so_notify_abort(lwkt_msg_t); +void netmsg_pru_abort(netmsg_t); +void netmsg_pru_accept(netmsg_t); +void netmsg_pru_attach(netmsg_t); +void netmsg_pru_bind(netmsg_t); +void netmsg_pru_connect(netmsg_t); +void netmsg_pru_connect2(netmsg_t); +void netmsg_pru_control(netmsg_t); +void netmsg_pru_detach(netmsg_t); +void netmsg_pru_disconnect(netmsg_t); +void netmsg_pru_listen(netmsg_t); +void netmsg_pru_peeraddr(netmsg_t); +void netmsg_pru_rcvd(netmsg_t); +void netmsg_pru_rcvoob(netmsg_t); +void netmsg_pru_send(netmsg_t); +void netmsg_pru_sense(netmsg_t); +void netmsg_pru_shutdown(netmsg_t); +void netmsg_pru_sockaddr(netmsg_t); + +void netmsg_pru_sopoll(netmsg_t); + +void netmsg_pr_ctloutput(netmsg_t); +void netmsg_pr_timeout(netmsg_t); + +void netmsg_so_notify(netmsg_t); +void netmsg_so_notify_abort(netmsg_t); +void netmsg_so_notify_doabort(lwkt_msg_t); #endif diff --git a/sys/net/netmsg.h b/sys/net/netmsg.h index fb424442cf..0b70334bdc 100644 --- a/sys/net/netmsg.h +++ b/sys/net/netmsg.h @@ -27,7 +27,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $DragonFly: src/sys/net/netmsg.h,v 1.5 2007/04/22 01:13:11 dillon Exp $ + * $DragonFly: src/sys/net/netmsg.h,v 1.6 2007/05/23 08:57:10 dillon Exp $ */ #ifndef _NET_NETMSG_H_ @@ -40,24 +40,36 @@ #include #endif +struct netmsg; + +typedef void (*netisr_fn_t)(struct netmsg *); + +/* + * Base netmsg + */ +typedef struct netmsg { + struct lwkt_msg nm_lmsg; + netisr_fn_t nm_dispatch; +} *netmsg_t; + /* * User protocol requests messages. */ struct netmsg_pru_abort { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_abort_fn_t nm_prufn; struct socket *nm_so; }; struct netmsg_pru_accept { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_accept_fn_t nm_prufn; struct socket *nm_so; struct sockaddr **nm_nam; }; struct netmsg_pru_attach { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_attach_fn_t nm_prufn; struct socket *nm_so; int nm_proto; @@ -65,7 +77,7 @@ struct netmsg_pru_attach { }; struct netmsg_pru_bind { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_bind_fn_t nm_prufn; struct socket *nm_so; struct sockaddr *nm_nam; @@ -73,7 +85,7 @@ struct netmsg_pru_bind { }; struct netmsg_pru_connect { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_connect_fn_t nm_prufn; struct socket *nm_so; struct sockaddr *nm_nam; @@ -81,14 +93,14 @@ struct netmsg_pru_connect { }; struct netmsg_pru_connect2 { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_connect2_fn_t nm_prufn; struct socket *nm_so1; struct socket *nm_so2; }; struct netmsg_pru_control { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_control_fn_t nm_prufn; struct socket *nm_so; u_long nm_cmd; @@ -98,40 +110,40 @@ struct netmsg_pru_control { }; struct netmsg_pru_detach { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_detach_fn_t nm_prufn; struct socket *nm_so; }; struct netmsg_pru_disconnect { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_disconnect_fn_t nm_prufn; struct socket *nm_so; }; struct netmsg_pru_listen { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_listen_fn_t nm_prufn; struct socket *nm_so; struct thread *nm_td; }; struct netmsg_pru_peeraddr { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_peeraddr_fn_t nm_prufn; struct socket *nm_so; struct sockaddr **nm_nam; }; struct netmsg_pru_rcvd { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_rcvd_fn_t nm_prufn; struct socket *nm_so; int nm_flags; }; struct netmsg_pru_rcvoob { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_rcvoob_fn_t nm_prufn; struct socket *nm_so; struct mbuf *nm_m; @@ -139,7 +151,7 @@ struct netmsg_pru_rcvoob { }; struct netmsg_pru_send { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_send_fn_t nm_prufn; struct socket *nm_so; int nm_flags; @@ -150,27 +162,27 @@ struct netmsg_pru_send { }; struct netmsg_pru_sense { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_sense_fn_t nm_prufn; struct socket *nm_so; struct stat *nm_stat; }; struct netmsg_pru_shutdown { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_shutdown_fn_t nm_prufn; struct socket *nm_so; }; struct netmsg_pru_sockaddr { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_sockaddr_fn_t nm_prufn; struct socket *nm_so; struct sockaddr **nm_nam; }; struct netmsg_pru_sosend { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_sosend_fn_t nm_prufn; struct socket *nm_so; struct sockaddr *nm_addr; @@ -182,8 +194,7 @@ struct netmsg_pru_sosend { }; struct netmsg_pru_soreceive { - struct lwkt_msg nm_lmsg; - pru_soreceive_fn_t nm_prufn; + struct netmsg nm_netmsg; struct sockaddr *nm_addr; struct socket *nm_so; struct sockaddr **nm_paddr; @@ -194,7 +205,7 @@ struct netmsg_pru_soreceive { }; struct netmsg_pru_sopoll { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; pru_sopoll_fn_t nm_prufn; struct socket *nm_so; int nm_events; diff --git a/sys/net/netmsg2.h b/sys/net/netmsg2.h new file mode 100644 index 0000000000..ce1d204abd --- /dev/null +++ b/sys/net/netmsg2.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2007 The DragonFly Project. All rights reserved. + * + * This code is derived from software contributed to The DragonFly Project + * by Matthew Dillon + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name of The DragonFly Project nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific, prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $DragonFly: src/sys/net/netmsg2.h,v 1.1 2007/05/23 08:57:10 dillon Exp $ + */ + +#ifndef _NET_NETMSG2_H_ + +#include +#include +#include + +/* + * Extended lwkt_initmsg() for netmsg's, also initializing the + * dispatch function + */ +static __inline void +netmsg_init(netmsg_t msg, lwkt_port_t rport, int flags, netisr_fn_t dispatch) +{ + lwkt_initmsg(&msg->nm_lmsg, rport, flags); + msg->nm_dispatch = dispatch; +} + +static __inline void +netmsg_init_abortable(netmsg_t msg, lwkt_port_t rport, int flags, + netisr_fn_t dispatch, void (*abortfn)(lwkt_msg_t)) +{ + lwkt_initmsg_abortable(&msg->nm_lmsg, rport, flags, abortfn); + msg->nm_dispatch = dispatch; +} + +#endif /* _NET_NETMSG2_H_ */ + diff --git a/sys/net/pf/pf.c b/sys/net/pf/pf.c index b95d974674..10a4fdd4cc 100644 --- a/sys/net/pf/pf.c +++ b/sys/net/pf/pf.c @@ -1,7 +1,7 @@ /* $FreeBSD: src/sys/contrib/pf/net/pf.c,v 1.19 2004/09/11 11:18:25 mlaier Exp $ */ /* $OpenBSD: pf.c,v 1.433.2.2 2004/07/17 03:22:34 brad Exp $ */ /* add $OpenBSD: pf.c,v 1.448 2004/05/11 07:34:11 dhartmei Exp $ */ -/* $DragonFly: src/sys/net/pf/pf.c,v 1.13 2006/12/22 23:44:57 swildner Exp $ */ +/* $DragonFly: src/sys/net/pf/pf.c,v 1.14 2007/05/23 08:57:10 dillon Exp $ */ /* * Copyright (c) 2004 The DragonFly Project. All rights reserved. @@ -62,6 +62,7 @@ #include #include #include +#include #include #include @@ -96,9 +97,10 @@ #endif /* INET6 */ #include +#include #include #include -#include +#include extern int ip_optcopy(struct ip *, struct ip *); @@ -2157,7 +2159,7 @@ pf_get_translation(struct pf_pdesc *pd, struct mbuf *m, int off, int direction, #ifdef SMP struct netmsg_hashlookup { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct inpcb **nm_pinp; struct inpcbinfo *nm_pcbinfo; struct pf_addr *nm_saddr; @@ -2167,8 +2169,8 @@ struct netmsg_hashlookup { sa_family_t nm_af; }; -static int -in_pcblookup_hash_handler(struct lwkt_msg *msg0) +static void +in_pcblookup_hash_handler(struct netmsg *msg0) { struct netmsg_hashlookup *msg = (struct netmsg_hashlookup *)msg0; @@ -2182,8 +2184,7 @@ in_pcblookup_hash_handler(struct lwkt_msg *msg0) &msg->nm_saddr->v6, msg->nm_sport, &msg->nm_daddr->v6, msg->nm_dport, INPLOOKUP_WILDCARD, NULL); #endif /* INET6 */ - lwkt_replymsg(&msg->nm_lmsg, 0); - return (EASYNC); + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, 0); } #endif /* SMP */ @@ -2228,9 +2229,8 @@ pf_socket_lookup(uid_t *uid, gid_t *gid, int direction, struct pf_pdesc *pd) */ if (pi_cpu != mycpu->gd_cpuid) { msg = kmalloc(sizeof(*msg), M_LWKTMSG, M_INTWAIT); - lwkt_initmsg(&msg->nm_lmsg, &netisr_afree_rport, 0, - lwkt_cmd_func(in_pcblookup_hash_handler), - lwkt_cmd_op_none); + netmsg_init(&msg->nm_netmsg, &netisr_afree_rport, 0, + in_pcblookup_hash_handler); msg->nm_pinp = &inp; msg->nm_pcbinfo = pi; msg->nm_saddr = saddr; @@ -2284,7 +2284,8 @@ pf_socket_lookup(uid_t *uid, gid_t *gid, int direction, struct pf_pdesc *pd) case AF_INET: #ifdef SMP if (msg != NULL) { - lwkt_sendmsg(tcp_cport(pi_cpu), &msg->nm_lmsg); + lwkt_sendmsg(tcp_cport(pi_cpu), + &msg->nm_netmsg.nm_lmsg); } else #endif /* SMP */ { diff --git a/sys/net/ppp/if_ppp.c b/sys/net/ppp/if_ppp.c index f388b7058c..2745a1544d 100644 --- a/sys/net/ppp/if_ppp.c +++ b/sys/net/ppp/if_ppp.c @@ -70,7 +70,7 @@ */ /* $FreeBSD: src/sys/net/if_ppp.c,v 1.67.2.4 2002/04/14 21:41:48 luigi Exp $ */ -/* $DragonFly: src/sys/net/ppp/if_ppp.c,v 1.34 2006/12/22 23:44:57 swildner Exp $ */ +/* $DragonFly: src/sys/net/ppp/if_ppp.c,v 1.35 2007/05/23 08:57:10 dillon Exp $ */ /* from if_sl.c,v 1.11 84/10/04 12:54:47 rick Exp */ /* from NetBSD: if_ppp.c,v 1.15.2.2 1994/07/28 05:17:58 cgd Exp */ @@ -196,7 +196,7 @@ static struct compressor *ppp_compressors[8] = { /* * Software interrupt routine, called at spl[soft]net. */ -static int +static void pppintr(struct netmsg *msg) { struct mbuf *m; @@ -226,7 +226,6 @@ pppintr(struct netmsg *msg) } lwkt_serialize_exit(sc->sc_if.if_serializer); } - return(EASYNC); } /* diff --git a/sys/net/route.c b/sys/net/route.c index af198d7483..26e8b1cef5 100644 --- a/sys/net/route.c +++ b/sys/net/route.c @@ -64,7 +64,7 @@ * * @(#)route.c 8.3 (Berkeley) 1/9/95 * $FreeBSD: src/sys/net/route.c,v 1.59.2.10 2003/01/17 08:04:00 ru Exp $ - * $DragonFly: src/sys/net/route.c,v 1.28 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/net/route.c,v 1.29 2007/05/23 08:57:10 dillon Exp $ */ #include "opt_inet.h" @@ -79,8 +79,6 @@ #include #include #include -#include -#include #include #include @@ -89,6 +87,10 @@ #include #include +#include +#include +#include + static struct rtstatistics rtstatistics_percpu[MAXCPU]; #ifdef SMP #define rtstat rtstatistics_percpu[mycpuid] @@ -107,8 +109,8 @@ static void rtinit_rtrequest_callback(int, int, struct rt_addrinfo *, struct rtentry *, void *); #ifdef SMP -static int rtredirect_msghandler(struct lwkt_msg *lmsg); -static int rtrequest1_msghandler(struct lwkt_msg *lmsg); +static void rtredirect_msghandler(struct netmsg *netmsg); +static void rtrequest1_msghandler(struct netmsg *netmsg); #endif SYSCTL_NODE(_net, OID_AUTO, route, CTLFLAG_RW, 0, "Routing"); @@ -169,11 +171,11 @@ rtable_init(void) static void rtable_service_loop(void *dummy __unused) { - struct lwkt_msg *lmsg; + struct netmsg *netmsg; thread_t td = curthread; - while ((lmsg = lwkt_waitport(&td->td_msgport, NULL)) != NULL) { - lmsg->ms_cmd.cm_func(lmsg); + while ((netmsg = lwkt_waitport(&td->td_msgport, NULL)) != NULL) { + netmsg->nm_dispatch(netmsg); } } @@ -426,7 +428,7 @@ out: #ifdef SMP struct netmsg_rtredirect { - struct lwkt_msg lmsg; + struct netmsg netmsg; struct sockaddr *dst; struct sockaddr *gateway; struct sockaddr *netmask; @@ -453,14 +455,14 @@ rtredirect(struct sockaddr *dst, struct sockaddr *gateway, #ifdef SMP struct netmsg_rtredirect msg; - lwkt_initmsg(&msg.lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(rtredirect_msghandler), lwkt_cmd_op_none); + netmsg_init(&msg.netmsg, &curthread->td_msgport, 0, + rtredirect_msghandler); msg.dst = dst; msg.gateway = gateway; msg.netmask = netmask; msg.flags = flags; msg.src = src; - error = lwkt_domsg(rtable_portfn(0), &msg.lmsg); + error = lwkt_domsg(rtable_portfn(0), &msg.netmsg.nm_lmsg); #else error = rtredirect_oncpu(dst, gateway, netmask, flags, src); #endif @@ -474,20 +476,19 @@ rtredirect(struct sockaddr *dst, struct sockaddr *gateway, #ifdef SMP -static int -rtredirect_msghandler(struct lwkt_msg *lmsg) +static void +rtredirect_msghandler(struct netmsg *netmsg) { - struct netmsg_rtredirect *msg = (void *)lmsg; + struct netmsg_rtredirect *msg = (void *)netmsg; int nextcpu; rtredirect_oncpu(msg->dst, msg->gateway, msg->netmask, msg->flags, msg->src); nextcpu = mycpuid + 1; if (nextcpu < ncpus) - lwkt_forwardmsg(rtable_portfn(nextcpu), &msg->lmsg); + lwkt_forwardmsg(rtable_portfn(nextcpu), &netmsg->nm_lmsg); else - lwkt_replymsg(&msg->lmsg, 0); - return (0); + lwkt_replymsg(&netmsg->nm_lmsg, 0); } #endif @@ -657,7 +658,7 @@ rtrequest_global( #ifdef SMP struct netmsg_rtq { - struct lwkt_msg lmsg; + struct netmsg netmsg; int req; struct rt_addrinfo *rtinfo; rtrequest1_callback_func_t callback; @@ -674,14 +675,14 @@ rtrequest1_global(int req, struct rt_addrinfo *rtinfo, #ifdef SMP struct netmsg_rtq msg; - lwkt_initmsg(&msg.lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(rtrequest1_msghandler), lwkt_cmd_op_none); - msg.lmsg.ms_error = -1; + netmsg_init(&msg.netmsg, &curthread->td_msgport, 0, + rtrequest1_msghandler); + msg.netmsg.nm_lmsg.ms_error = -1; msg.req = req; msg.rtinfo = rtinfo; msg.callback = callback; msg.arg = arg; - error = lwkt_domsg(rtable_portfn(0), &msg.lmsg); + error = lwkt_domsg(rtable_portfn(0), &msg.netmsg.nm_lmsg); #else struct rtentry *rt = NULL; @@ -701,10 +702,10 @@ rtrequest1_global(int req, struct rt_addrinfo *rtinfo, */ #ifdef SMP -static int -rtrequest1_msghandler(struct lwkt_msg *lmsg) +static void +rtrequest1_msghandler(struct netmsg *netmsg) { - struct netmsg_rtq *msg = (void *)lmsg; + struct netmsg_rtq *msg = (void *)netmsg; struct rtentry *rt = NULL; int nextcpu; int error; @@ -721,8 +722,8 @@ rtrequest1_msghandler(struct lwkt_msg *lmsg) * are not necessarily replicated. An overall error is returned * only if no cpus have the route in question. */ - if (msg->lmsg.ms_error < 0 || error == 0) - msg->lmsg.ms_error = error; + if (msg->netmsg.nm_lmsg.ms_error < 0 || error == 0) + msg->netmsg.nm_lmsg.ms_error = error; nextcpu = mycpuid + 1; if (error && msg->req != RTM_DELETE) { @@ -730,13 +731,13 @@ rtrequest1_msghandler(struct lwkt_msg *lmsg) panic("rtrequest1_msghandler: rtrequest table " "error was not on cpu #0: %p", msg->rtinfo); } - lwkt_replymsg(&msg->lmsg, error); + lwkt_replymsg(&msg->netmsg.nm_lmsg, error); } else if (nextcpu < ncpus) { - lwkt_forwardmsg(rtable_portfn(nextcpu), &msg->lmsg); + lwkt_forwardmsg(rtable_portfn(nextcpu), &msg->netmsg.nm_lmsg); } else { - lwkt_replymsg(&msg->lmsg, msg->lmsg.ms_error); + lwkt_replymsg(&msg->netmsg.nm_lmsg, + msg->netmsg.nm_lmsg.ms_error); } - return (0); } #endif diff --git a/sys/netgraph/netgraph/ng_base.c b/sys/netgraph/netgraph/ng_base.c index 134ddbaf62..39e2a001a3 100644 --- a/sys/netgraph/netgraph/ng_base.c +++ b/sys/netgraph/netgraph/ng_base.c @@ -38,7 +38,7 @@ * Archie Cobbs * * $FreeBSD: src/sys/netgraph/ng_base.c,v 1.11.2.17 2002/07/02 23:44:02 archie Exp $ - * $DragonFly: src/sys/netgraph/netgraph/ng_base.c,v 1.23 2006/12/22 23:44:57 swildner Exp $ + * $DragonFly: src/sys/netgraph/netgraph/ng_base.c,v 1.24 2007/05/23 08:57:09 dillon Exp $ * $Whistle: ng_base.c,v 1.39 1999/01/28 23:54:53 julian Exp $ */ @@ -88,7 +88,7 @@ static int ng_generic_msg(node_p here, struct ng_mesg *msg, const char *retaddr, struct ng_mesg ** resp); static ng_ID_t ng_decodeidname(const char *name); static int ngb_mod_event(module_t mod, int event, void *data); -static int ngintr(struct netmsg *); +static void ngintr(struct netmsg *); static int ng_load_module(const char *); static int ng_unload_module(const char *); @@ -2036,7 +2036,7 @@ ng_queue_msg(node_p here, struct ng_mesg *msg, const char *address) /* * Pick an item off the queue, process it, and dispose of the queue entry. */ -static int +static void ngintr(struct netmsg *pmsg) { hook_p hook; @@ -2093,7 +2093,7 @@ ngintr(struct netmsg *pmsg) } } out: - return(EASYNC); + ; } diff --git a/sys/netinet/if_ether.c b/sys/netinet/if_ether.c index b5c3410ae2..e785ccdf11 100644 --- a/sys/netinet/if_ether.c +++ b/sys/netinet/if_ether.c @@ -64,7 +64,7 @@ * * @(#)if_ether.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netinet/if_ether.c,v 1.64.2.23 2003/04/11 07:23:15 fjoe Exp $ - * $DragonFly: src/sys/netinet/if_ether.c,v 1.36 2007/03/04 18:51:59 swildner Exp $ + * $DragonFly: src/sys/netinet/if_ether.c,v 1.37 2007/05/23 08:57:09 dillon Exp $ */ /* @@ -85,9 +85,6 @@ #include #include -#include -#include - #include #include #include @@ -102,6 +99,11 @@ #include #include +#include +#include +#include + + #define SIN(s) ((struct sockaddr_in *)s) #define SDL(s) ((struct sockaddr_dl *)s) @@ -146,7 +148,7 @@ SYSCTL_INT(_net_link_ether_inet, OID_AUTO, proxyall, CTLFLAG_RW, static void arp_rtrequest (int, struct rtentry *, struct rt_addrinfo *); static void arprequest (struct ifnet *, struct in_addr *, struct in_addr *, u_char *); -static int arpintr(struct netmsg *); +static void arpintr(struct netmsg *); static void arptfree (struct llinfo_arp *); static void arptimer (void *); static struct llinfo_arp @@ -512,7 +514,7 @@ arpresolve( * Common length and type checks are done here, * then the protocol-specific routine is called. */ -static int +static void arpintr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -552,8 +554,8 @@ arpintr(struct netmsg *msg) out1: m_freem(m); out2: + ; /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } #ifdef INET @@ -707,13 +709,13 @@ arp_update_oncpu(struct mbuf *m, in_addr_t saddr, boolean_t create, #ifdef SMP struct netmsg_arp_update { - struct lwkt_msg lmsg; + struct netmsg netmsg; struct mbuf *m; in_addr_t saddr; boolean_t create; }; -static int arp_update_msghandler(struct lwkt_msg *lmsg); +static void arp_update_msghandler(struct netmsg *netmsg); #endif @@ -822,12 +824,12 @@ match: goto reply; } #ifdef SMP - lwkt_initmsg(&msg.lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(arp_update_msghandler), lwkt_cmd_op_none); + netmsg_init(&msg.netmsg, &curthread->td_msgport, 0, + arp_update_msghandler); msg.m = m; msg.saddr = isaddr.s_addr; msg.create = (itaddr.s_addr == myaddr.s_addr); - lwkt_domsg(rtable_portfn(0), &msg.lmsg); + lwkt_domsg(rtable_portfn(0), &msg.netmsg.nm_lmsg); #endif arp_update_oncpu(m, isaddr.s_addr, (itaddr.s_addr == myaddr.s_addr), TRUE); @@ -938,21 +940,20 @@ reply: #ifdef SMP static -int -arp_update_msghandler(struct lwkt_msg *lmsg) +void +arp_update_msghandler(struct netmsg *netmsg) { - struct netmsg_arp_update *msg = (struct netmsg_arp_update *)lmsg; + struct netmsg_arp_update *msg = (struct netmsg_arp_update *)netmsg; int nextcpu; arp_update_oncpu(msg->m, msg->saddr, msg->create, FALSE); nextcpu = mycpuid + 1; if (nextcpu < ncpus) { - lwkt_forwardmsg(rtable_portfn(nextcpu), &msg->lmsg); + lwkt_forwardmsg(rtable_portfn(nextcpu), &msg->netmsg.nm_lmsg); } else { - lwkt_replymsg(&msg->lmsg, 0); + lwkt_replymsg(&msg->netmsg.nm_lmsg, 0); } - return (0); } #endif diff --git a/sys/netinet/ip6.h b/sys/netinet/ip6.h index 3b505de4d9..f0f1857c70 100644 --- a/sys/netinet/ip6.h +++ b/sys/netinet/ip6.h @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet/ip6.h,v 1.2.2.2 2001/07/03 11:01:46 ume Exp $ */ -/* $DragonFly: src/sys/netinet/ip6.h,v 1.6 2006/05/20 02:42:12 dillon Exp $ */ +/* $DragonFly: src/sys/netinet/ip6.h,v 1.7 2007/05/23 08:57:09 dillon Exp $ */ /* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $ */ /* @@ -271,6 +271,9 @@ do { \ } \ } while (0) +#define IP6_EXTHDR_CHECK_VOIDRET(m, off, hlen) \ + IP6_EXTHDR_CHECK(m, off, hlen, ) + /* * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to * "len") is located in single mbuf, on contiguous memory region. diff --git a/sys/netinet/ip_input.c b/sys/netinet/ip_input.c index bb2bf8c8bd..c44a9c7aeb 100644 --- a/sys/netinet/ip_input.c +++ b/sys/netinet/ip_input.c @@ -65,7 +65,7 @@ * * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 * $FreeBSD: src/sys/netinet/ip_input.c,v 1.130.2.52 2003/03/07 07:01:28 silby Exp $ - * $DragonFly: src/sys/netinet/ip_input.c,v 1.66 2007/04/04 06:13:26 dillon Exp $ + * $DragonFly: src/sys/netinet/ip_input.c,v 1.67 2007/05/23 08:57:09 dillon Exp $ */ #define _IP_VHL @@ -94,9 +94,6 @@ #include #include -#include -#include - #include #include @@ -116,6 +113,9 @@ #include #include +#include +#include +#include #include @@ -307,7 +307,7 @@ static int ip_dooptions (struct mbuf *m, int, static void ip_forward (struct mbuf *m, boolean_t using_srcrt, struct sockaddr_in *next_hop); static void ip_freef (struct ipq *); -static int ip_input_handler (struct netmsg *); +static void ip_input_handler (struct netmsg *); static struct mbuf *ip_reass (struct mbuf *, struct ipq *, struct ipq *, u_int32_t *); @@ -406,35 +406,33 @@ transport_processing_oncpu(struct mbuf *m, int hlen, struct ip *ip, } struct netmsg_transport_packet { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct mbuf *nm_mbuf; int nm_hlen; boolean_t nm_hasnexthop; struct sockaddr_in nm_nexthop; }; -static int -transport_processing_handler(lwkt_msg_t lmsg) +static void +transport_processing_handler(netmsg_t netmsg) { - struct netmsg_transport_packet *msg = (void *)lmsg; + struct netmsg_transport_packet *msg = (void *)netmsg; struct sockaddr_in *nexthop; struct ip *ip; ip = mtod(msg->nm_mbuf, struct ip *); nexthop = msg->nm_hasnexthop ? &msg->nm_nexthop : NULL; transport_processing_oncpu(msg->nm_mbuf, msg->nm_hlen, ip, nexthop); - lwkt_replymsg(lmsg, 0); - return(EASYNC); + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, 0); } -static int +static void ip_input_handler(struct netmsg *msg0) { struct mbuf *m = ((struct netmsg_packet *)msg0)->nm_packet; ip_input(m); /* msg0 was embedded in the mbuf, do not reply! */ - return(EASYNC); } /* @@ -1087,9 +1085,8 @@ DPRINTF(("ip_input: no SP, packet discarded\n"));/*XXX*/ if (msg == NULL) goto bad; - lwkt_initmsg(&msg->nm_lmsg, &netisr_afree_rport, 0, - lwkt_cmd_func(transport_processing_handler), - lwkt_cmd_op_none); + netmsg_init(&msg->nm_netmsg, &netisr_afree_rport, 0, + transport_processing_handler); msg->nm_hlen = hlen; msg->nm_hasnexthop = (args.next_hop != NULL); if (msg->nm_hasnexthop) @@ -1099,7 +1096,7 @@ DPRINTF(("ip_input: no SP, packet discarded\n"));/*XXX*/ ip = mtod(m, struct ip *); ip->ip_len = ntohs(ip->ip_len); ip->ip_off = ntohs(ip->ip_off); - lwkt_sendmsg(port, &msg->nm_lmsg); + lwkt_sendmsg(port, &msg->nm_netmsg.nm_lmsg); } else { transport_processing_oncpu(m, hlen, ip, args.next_hop); } diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index f409e7fb6a..68427da973 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -65,7 +65,7 @@ * * @(#)tcp_subr.c 8.2 (Berkeley) 5/24/95 * $FreeBSD: src/sys/netinet/tcp_subr.c,v 1.73.2.31 2003/01/24 05:11:34 sam Exp $ - * $DragonFly: src/sys/netinet/tcp_subr.c,v 1.57 2007/04/22 01:13:14 dillon Exp $ + * $DragonFly: src/sys/netinet/tcp_subr.c,v 1.58 2007/05/23 08:57:09 dillon Exp $ */ #include "opt_compat.h" @@ -143,6 +143,8 @@ #include #include +#include + #if !defined(KTR_TCP) #define KTR_TCP KTR_ALL #endif @@ -380,7 +382,7 @@ tcpmsg_service_loop(void *dummy) while ((msg = lwkt_waitport(&curthread->td_msgport, NULL))) { do { logtcp(rxmsg); - msg->nm_lmsg.ms_cmd.cm_func(&msg->nm_lmsg); + msg->nm_dispatch(msg); } while ((msg = lwkt_getport(&curthread->td_msgport)) != NULL); logtcp(delayed); tcp_willblock(); @@ -720,7 +722,7 @@ tcp_drop(struct tcpcb *tp, int error) #ifdef SMP struct netmsg_remwildcard { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct inpcb *nm_inp; struct inpcbinfo *nm_pcbinfo; #if defined(INET6) @@ -735,8 +737,8 @@ struct netmsg_remwildcard { * inp can be detached. We do this by cycling through the cpus, ending up * on the cpu controlling the inp last and then doing the disconnect. */ -static int -in_pcbremwildcardhash_handler(struct lwkt_msg *msg0) +static void +in_pcbremwildcardhash_handler(struct netmsg *msg0) { struct netmsg_remwildcard *msg = (struct netmsg_remwildcard *)msg0; int cpu; @@ -751,14 +753,13 @@ in_pcbremwildcardhash_handler(struct lwkt_msg *msg0) else #endif in_pcbdetach(msg->nm_inp); - lwkt_replymsg(&msg->nm_lmsg, 0); + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, 0); } else { in_pcbremwildcardhash_oncpu(msg->nm_inp, msg->nm_pcbinfo); cpu = (cpu + 1) % ncpus2; msg->nm_pcbinfo = &tcbinfo[cpu]; - lwkt_forwardmsg(tcp_cport(cpu), &msg->nm_lmsg); + lwkt_forwardmsg(tcp_cport(cpu), &msg->nm_netmsg.nm_lmsg); } - return (EASYNC); } #endif @@ -942,16 +943,15 @@ no_valid_rt: cpu = (inp->inp_pcbinfo->cpu + 1) % ncpus2; msg = kmalloc(sizeof(struct netmsg_remwildcard), - M_LWKTMSG, M_INTWAIT); - lwkt_initmsg(&msg->nm_lmsg, &netisr_afree_rport, 0, - lwkt_cmd_func(in_pcbremwildcardhash_handler), - lwkt_cmd_op_none); + M_LWKTMSG, M_INTWAIT); + netmsg_init(&msg->nm_netmsg, &netisr_afree_rport, 0, + in_pcbremwildcardhash_handler); #ifdef INET6 msg->nm_isinet6 = isafinet6; #endif msg->nm_inp = inp; msg->nm_pcbinfo = &tcbinfo[cpu]; - lwkt_sendmsg(tcp_cport(cpu), &msg->nm_lmsg); + lwkt_sendmsg(tcp_cport(cpu), &msg->nm_netmsg.nm_lmsg); } else #endif { @@ -990,18 +990,17 @@ tcp_drain_oncpu(struct inpcbhead *head) #ifdef SMP struct netmsg_tcp_drain { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct inpcbhead *nm_head; }; -static int -tcp_drain_handler(lwkt_msg_t lmsg) +static void +tcp_drain_handler(netmsg_t netmsg) { - struct netmsg_tcp_drain *nm = (void *)lmsg; + struct netmsg_tcp_drain *nm = (void *)netmsg; tcp_drain_oncpu(nm->nm_head); - lwkt_replymsg(lmsg, 0); - return(EASYNC); + lwkt_replymsg(&nm->nm_netmsg.nm_lmsg, 0); } #endif @@ -1034,11 +1033,10 @@ tcp_drain(void) M_LWKTMSG, M_NOWAIT); if (msg == NULL) continue; - lwkt_initmsg(&msg->nm_lmsg, &netisr_afree_rport, 0, - lwkt_cmd_func(tcp_drain_handler), - lwkt_cmd_op_none); + netmsg_init(&msg->nm_netmsg, &netisr_afree_rport, 0, + tcp_drain_handler); msg->nm_head = &tcbinfo[cpu].pcblisthead; - lwkt_sendmsg(tcp_cport(cpu), &msg->nm_lmsg); + lwkt_sendmsg(tcp_cport(cpu), &msg->nm_netmsg.nm_lmsg); } } #else diff --git a/sys/netinet/tcp_syncache.c b/sys/netinet/tcp_syncache.c index fa199ef527..14eeab9cf5 100644 --- a/sys/netinet/tcp_syncache.c +++ b/sys/netinet/tcp_syncache.c @@ -69,7 +69,7 @@ * SUCH DAMAGE. * * $FreeBSD: src/sys/netinet/tcp_syncache.c,v 1.5.2.14 2003/02/24 04:02:27 silby Exp $ - * $DragonFly: src/sys/netinet/tcp_syncache.c,v 1.29 2007/04/22 01:13:14 dillon Exp $ + * $DragonFly: src/sys/netinet/tcp_syncache.c,v 1.30 2007/05/23 08:57:09 dillon Exp $ */ #include "opt_inet6.h" @@ -89,6 +89,7 @@ #include #include +#include #include #include @@ -160,7 +161,7 @@ static struct syncache *syncookie_lookup(struct in_conninfo *, #define TCP_SYNCACHE_BUCKETLIMIT 30 struct netmsg_sc_timer { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct msgrec *nm_mrec; /* back pointer to containing msgrec */ }; @@ -170,7 +171,7 @@ struct msgrec { int slot; /* constant after init */ }; -static int syncache_timer_handler(lwkt_msg_t); +static void syncache_timer_handler(netmsg_t); struct tcp_syncache { struct vm_zone *zone; @@ -333,10 +334,9 @@ syncache_init(void) syncache_percpu->mrec[i].port = tcp_cport(cpu); syncache_percpu->mrec[i].msg.nm_mrec = &syncache_percpu->mrec[i]; - lwkt_initmsg(&syncache_percpu->mrec[i].msg.nm_lmsg, - &syncache_null_rport, 0, - lwkt_cmd_func(syncache_timer_handler), - lwkt_cmd_op_none); + netmsg_init(&syncache_percpu->mrec[i].msg.nm_netmsg, + &syncache_null_rport, 0, + syncache_timer_handler); } } @@ -449,7 +449,7 @@ syncache_timer(void *p) { struct netmsg_sc_timer *msg = p; - lwkt_sendmsg(msg->nm_mrec->port, &msg->nm_lmsg); + lwkt_sendmsg(msg->nm_mrec->port, &msg->nm_netmsg.nm_lmsg); } /* @@ -463,15 +463,15 @@ syncache_timer(void *p) * are any entries still on the queue and deactivate it otherwise. Only after * a timer has been deactivated here can it be restarted by syncache_timeout(). */ -static int -syncache_timer_handler(lwkt_msg_t msg) +static void +syncache_timer_handler(netmsg_t netmsg) { struct tcp_syncache_percpu *syncache_percpu; struct syncache *sc, *nsc; struct inpcb *inp; int slot; - slot = ((struct netmsg_sc_timer *)msg)->nm_mrec->slot; + slot = ((struct netmsg_sc_timer *)netmsg)->nm_mrec->slot; syncache_percpu = &tcp_syncache_percpu[mycpu->gd_cpuid]; nsc = TAILQ_FIRST(&syncache_percpu->timerq[slot]); @@ -506,8 +506,7 @@ syncache_timer_handler(lwkt_msg_t msg) else callout_deactivate(&syncache_percpu->tt_timerq[slot]); - lwkt_replymsg(msg, 0); - return (EASYNC); + lwkt_replymsg(&netmsg->nm_lmsg, 0); } /* diff --git a/sys/netinet/tcp_usrreq.c b/sys/netinet/tcp_usrreq.c index 611d7237ed..6fa7fe8961 100644 --- a/sys/netinet/tcp_usrreq.c +++ b/sys/netinet/tcp_usrreq.c @@ -65,7 +65,7 @@ * * From: @(#)tcp_usrreq.c 8.2 (Berkeley) 1/3/94 * $FreeBSD: src/sys/netinet/tcp_usrreq.c,v 1.51.2.17 2002/10/11 11:46:44 ume Exp $ - * $DragonFly: src/sys/netinet/tcp_usrreq.c,v 1.42 2007/04/22 01:13:14 dillon Exp $ + * $DragonFly: src/sys/netinet/tcp_usrreq.c,v 1.43 2007/05/23 08:57:09 dillon Exp $ */ #include "opt_ipsec.h" @@ -95,6 +95,8 @@ #include #include +#include + #include #include #ifdef INET6 @@ -312,19 +314,18 @@ tcp6_usr_bind(struct socket *so, struct sockaddr *nam, struct thread *td) #ifdef SMP struct netmsg_inswildcard { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct inpcb *nm_inp; struct inpcbinfo *nm_pcbinfo; }; -static int -in_pcbinswildcardhash_handler(struct lwkt_msg *msg0) +static void +in_pcbinswildcardhash_handler(struct netmsg *msg0) { struct netmsg_inswildcard *msg = (struct netmsg_inswildcard *)msg0; in_pcbinswildcardhash_oncpu(msg->nm_inp, msg->nm_pcbinfo); - lwkt_replymsg(&msg->nm_lmsg, 0); - return (EASYNC); + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, 0); } #endif @@ -364,13 +365,12 @@ tcp_usr_listen(struct socket *so, struct thread *td) } msg = kmalloc(sizeof(struct netmsg_inswildcard), M_LWKTMSG, - M_INTWAIT); - lwkt_initmsg(&msg->nm_lmsg, &netisr_afree_rport, 0, - lwkt_cmd_func(in_pcbinswildcardhash_handler), - lwkt_cmd_op_none); + M_INTWAIT); + netmsg_init(&msg->nm_netmsg, &netisr_afree_rport, 0, + in_pcbinswildcardhash_handler); msg->nm_inp = inp; msg->nm_pcbinfo = &tcbinfo[cpu]; - lwkt_sendmsg(tcp_cport(cpu), &msg->nm_lmsg); + lwkt_sendmsg(tcp_cport(cpu), &msg->nm_netmsg.nm_lmsg); } #else in_pcbinswildcardhash(inp); @@ -414,13 +414,12 @@ tcp6_usr_listen(struct socket *so, struct thread *td) } msg = kmalloc(sizeof(struct netmsg_inswildcard), M_LWKTMSG, - M_INTWAIT); - lwkt_initmsg(&msg->nm_lmsg, &netisr_afree_rport, 0, - lwkt_cmd_func(in_pcbinswildcardhash_handler), - lwkt_cmd_op_none); + M_INTWAIT); + netmsg_init(&msg->nm_netmsg, &netisr_afree_rport, 0, + in_pcbinswildcardhash_handler); msg->nm_inp = inp; msg->nm_pcbinfo = &tcbinfo[cpu]; - lwkt_sendmsg(tcp_cport(cpu), &msg->nm_lmsg); + lwkt_sendmsg(tcp_cport(cpu), &msg->nm_netmsg.nm_lmsg); } #else in_pcbinswildcardhash(inp); @@ -921,21 +920,20 @@ tcp_connect_oncpu(struct tcpcb *tp, struct sockaddr_in *sin, #ifdef SMP struct netmsg_tcp_connect { - struct lwkt_msg nm_lmsg; + struct netmsg nm_netmsg; struct tcpcb *nm_tp; struct sockaddr_in *nm_sin; struct sockaddr_in *nm_ifsin; }; -static int -tcp_connect_handler(lwkt_msg_t lmsg) +static void +tcp_connect_handler(netmsg_t netmsg) { - struct netmsg_tcp_connect *msg = (void *)lmsg; + struct netmsg_tcp_connect *msg = (void *)netmsg; int error; error = tcp_connect_oncpu(msg->nm_tp, msg->nm_sin, msg->nm_ifsin); - lwkt_replymsg(lmsg, error); - return(EASYNC); + lwkt_replymsg(&msg->nm_netmsg.nm_lmsg, error); } #endif @@ -985,12 +983,12 @@ tcp_connect(struct tcpcb *tp, struct sockaddr *nam, struct thread *td) if (port->mp_td != curthread) { struct netmsg_tcp_connect msg; - lwkt_initmsg(&msg.nm_lmsg, &curthread->td_msgport, 0, - lwkt_cmd_func(tcp_connect_handler), lwkt_cmd_op_none); + netmsg_init(&msg.nm_netmsg, &curthread->td_msgport, 0, + tcp_connect_handler); msg.nm_tp = tp; msg.nm_sin = sin; msg.nm_ifsin = if_sin; - error = lwkt_domsg(port, &msg.nm_lmsg); + error = lwkt_domsg(port, &msg.nm_netmsg.nm_lmsg); } else #endif error = tcp_connect_oncpu(tp, sin, if_sin); diff --git a/sys/netinet6/ip6_input.c b/sys/netinet6/ip6_input.c index 7c413d30b3..05ea0a175a 100644 --- a/sys/netinet6/ip6_input.c +++ b/sys/netinet6/ip6_input.c @@ -1,5 +1,5 @@ /* $FreeBSD: src/sys/netinet6/ip6_input.c,v 1.11.2.15 2003/01/24 05:11:35 sam Exp $ */ -/* $DragonFly: src/sys/netinet6/ip6_input.c,v 1.33 2007/05/07 13:00:16 hasso Exp $ */ +/* $DragonFly: src/sys/netinet6/ip6_input.c,v 1.34 2007/05/23 08:57:09 dillon Exp $ */ /* $KAME: ip6_input.c,v 1.259 2002/01/21 04:58:09 jinmei Exp $ */ /* @@ -159,7 +159,7 @@ struct ip6stat ip6stat; static void ip6_init2 (void *); static struct ip6aux *ip6_setdstifaddr (struct mbuf *, struct in6_ifaddr *); static int ip6_hopopts_input (u_int32_t *, u_int32_t *, struct mbuf **, int *); -static int ip6_input(struct netmsg *msg); +static void ip6_input(struct netmsg *msg); #ifdef PULLDOWN_TEST static struct mbuf *ip6_pullexthdr (struct mbuf *, size_t, int); #endif @@ -237,7 +237,7 @@ SYSINIT(netinet6init2, SI_SUB_PROTO_DOMAIN, SI_ORDER_MIDDLE, ip6_init2, NULL); extern struct route_in6 ip6_forward_rt; static -int +void ip6_input(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -310,7 +310,7 @@ ip6_input(struct netmsg *msg) m_freem(m); m = n; } - IP6_EXTHDR_CHECK(m, 0, sizeof(struct ip6_hdr), EASYNC); + IP6_EXTHDR_CHECK_VOIDRET(m, 0, sizeof(struct ip6_hdr)); #endif if (m->m_len < sizeof(struct ip6_hdr)) { @@ -355,7 +355,7 @@ ip6_input(struct netmsg *msg) #ifdef ALTQ if (altq_input != NULL && (*altq_input)(m, AF_INET6) == 0) { /* packet is dropped by traffic conditioner */ - return (ENOBUFS); + return; } #endif @@ -839,8 +839,8 @@ hbhcheck: bad: m_freem(m); bad2: + ; /* msg was embedded in the mbuf, do not reply! */ - return (EASYNC); } /* diff --git a/sys/netproto/atalk/aarp.c b/sys/netproto/atalk/aarp.c index 31097d9a31..d850d07da5 100644 --- a/sys/netproto/atalk/aarp.c +++ b/sys/netproto/atalk/aarp.c @@ -3,7 +3,7 @@ * All Rights Reserved. * * $FreeBSD: src/sys/netatalk/aarp.c,v 1.12.2.2 2001/06/23 20:43:09 iedowse Exp $ - * $DragonFly: src/sys/netproto/atalk/aarp.c,v 1.20 2006/12/22 23:57:53 swildner Exp $ + * $DragonFly: src/sys/netproto/atalk/aarp.c,v 1.21 2007/05/23 08:57:06 dillon Exp $ */ #include "opt_atalk.h" @@ -245,7 +245,7 @@ aarpresolve(struct arpcom *ac, struct mbuf *m, struct sockaddr_at *destsat, return (0); } -int +void aarpintr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -282,8 +282,8 @@ aarpintr(struct netmsg *msg) out: m_freem(m); out2: + ; /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } static void diff --git a/sys/netproto/atalk/at_extern.h b/sys/netproto/atalk/at_extern.h index 6812460cf4..c1b9f3d170 100644 --- a/sys/netproto/atalk/at_extern.h +++ b/sys/netproto/atalk/at_extern.h @@ -1,5 +1,5 @@ /* - * $DragonFly: src/sys/netproto/atalk/at_extern.h,v 1.7 2004/06/03 15:04:51 joerg Exp $ + * $DragonFly: src/sys/netproto/atalk/at_extern.h,v 1.8 2007/05/23 08:57:06 dillon Exp $ */ struct mbuf; struct sockaddr_at; @@ -22,9 +22,9 @@ struct netmsg; struct proc; struct socket; -extern int aarpintr (struct netmsg *); -extern int at1intr (struct netmsg *); -extern int at2intr (struct netmsg *); +extern void aarpintr (struct netmsg *); +extern void at1intr (struct netmsg *); +extern void at2intr (struct netmsg *); extern void aarp_clean (void); extern int at_control ( struct socket *so, u_long cmd, diff --git a/sys/netproto/atalk/ddp_input.c b/sys/netproto/atalk/ddp_input.c index a7bbd8c6fb..3d730d21ac 100644 --- a/sys/netproto/atalk/ddp_input.c +++ b/sys/netproto/atalk/ddp_input.c @@ -3,7 +3,7 @@ * All Rights Reserved. See COPYRIGHT. * * $FreeBSD: src/sys/netatalk/ddp_input.c,v 1.12 2000/02/13 03:31:58 peter Exp $ - * $DragonFly: src/sys/netproto/atalk/ddp_input.c,v 1.13 2007/04/22 01:13:15 dillon Exp $ + * $DragonFly: src/sys/netproto/atalk/ddp_input.c,v 1.14 2007/05/23 08:57:06 dillon Exp $ */ #include @@ -39,7 +39,7 @@ static void ddp_input(struct mbuf *, struct ifnet *, struct elaphdr *, int); /* * Could probably merge these two code segments a little better... */ -int +void at2intr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -49,10 +49,9 @@ at2intr(struct netmsg *msg) */ ddp_input(m, m->m_pkthdr.rcvif, NULL, 2); /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } -int +void at1intr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -79,8 +78,8 @@ at1intr(struct netmsg *msg) ddp_input(m, m->m_pkthdr.rcvif, &elh, 1); } out: + ; /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } static void diff --git a/sys/netproto/atm/atm_subr.c b/sys/netproto/atm/atm_subr.c index 20048b238b..8be763b951 100644 --- a/sys/netproto/atm/atm_subr.c +++ b/sys/netproto/atm/atm_subr.c @@ -24,7 +24,7 @@ * notice must be reproduced on all copies. * * @(#) $FreeBSD: src/sys/netatm/atm_subr.c,v 1.7 2000/02/13 03:31:59 peter Exp $ - * @(#) $DragonFly: src/sys/netproto/atm/atm_subr.c,v 1.20 2006/12/22 23:57:53 swildner Exp $ + * @(#) $DragonFly: src/sys/netproto/atm/atm_subr.c,v 1.21 2007/05/23 08:57:07 dillon Exp $ */ /* @@ -71,7 +71,7 @@ static struct callout atm_timexp_ch; */ static void atm_compact (struct atm_time *); static KTimeout_ret atm_timexp (void *); -static int atm_intr(struct netmsg *); +static void atm_intr(struct netmsg *); /* * Local variables @@ -847,7 +847,7 @@ atm_stack_drain(void) * none * */ -static int +static void atm_intr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -879,7 +879,6 @@ atm_intr(struct netmsg *msg) */ STACK_DRAIN(); /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } /* diff --git a/sys/netproto/ipx/ipx_input.c b/sys/netproto/ipx/ipx_input.c index 68e1850e01..0035965813 100644 --- a/sys/netproto/ipx/ipx_input.c +++ b/sys/netproto/ipx/ipx_input.c @@ -34,7 +34,7 @@ * @(#)ipx_input.c * * $FreeBSD: src/sys/netipx/ipx_input.c,v 1.22.2.2 2001/02/22 09:44:18 bp Exp $ - * $DragonFly: src/sys/netproto/ipx/ipx_input.c,v 1.15 2006/12/22 23:57:54 swildner Exp $ + * $DragonFly: src/sys/netproto/ipx/ipx_input.c,v 1.16 2007/05/23 08:57:08 dillon Exp $ */ #include @@ -92,7 +92,7 @@ struct ipxpcb ipxrawpcb; long ipx_pexseq; -static int ipxintr(struct netmsg *); +static void ipxintr(struct netmsg *); static int ipx_do_route(struct ipx_addr *src, struct route *ro); static void ipx_undo_route(struct route *ro); static void ipx_forward(struct mbuf *m); @@ -124,7 +124,7 @@ ipx_init(void) /* * IPX input routine. Pass to next level. */ -static int +static void ipxintr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -269,8 +269,8 @@ ours: bad: m_freem(m); out: + ; /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } /* diff --git a/sys/netproto/natm/natm.c b/sys/netproto/natm/natm.c index 65ca96d40a..3e8ff7b61b 100644 --- a/sys/netproto/natm/natm.c +++ b/sys/netproto/natm/natm.c @@ -1,6 +1,6 @@ /* $NetBSD: natm.c,v 1.5 1996/11/09 03:26:26 chuck Exp $ */ /* $FreeBSD: src/sys/netnatm/natm.c,v 1.12 2000/02/13 03:32:03 peter Exp $ */ -/* $DragonFly: src/sys/netproto/natm/natm.c,v 1.26 2007/04/30 07:18:55 dillon Exp $ */ +/* $DragonFly: src/sys/netproto/natm/natm.c,v 1.27 2007/05/23 08:57:08 dillon Exp $ */ /* * @@ -742,7 +742,7 @@ natm5_sysctl(int *name, u_int namelen, void *oldp, size_t *oldlenp, return (ENOPROTOOPT); } -static int natmintr(struct netmsg *); +static void natmintr(struct netmsg *); #if defined(__DragonFly__) static void @@ -768,7 +768,7 @@ natm_init(void) * pointer. we can get the interface pointer from the so's PCB if * we really need it. */ -static int +static void natmintr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -823,7 +823,7 @@ m->m_pkthdr.rcvif = NULL; /* null it out to be safe */ m_freem(m); } out: + ; /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } diff --git a/sys/netproto/ns/ns_input.c b/sys/netproto/ns/ns_input.c index 306ea13571..b7c890b1bc 100644 --- a/sys/netproto/ns/ns_input.c +++ b/sys/netproto/ns/ns_input.c @@ -32,7 +32,7 @@ * * @(#)ns_input.c 8.1 (Berkeley) 6/10/93 * $FreeBSD: src/sys/netns/ns_input.c,v 1.13 2000/02/13 03:32:04 peter Exp $ - * $DragonFly: src/sys/netproto/ns/ns_input.c,v 1.19 2006/12/22 23:57:54 swildner Exp $ + * $DragonFly: src/sys/netproto/ns/ns_input.c,v 1.20 2007/05/23 08:57:08 dillon Exp $ */ #include @@ -81,7 +81,7 @@ struct nspcb nsrawpcb; int idpcksum = 1; long ns_pexseq; -static int nsintr(struct netmsg *msg); +static void nsintr(struct netmsg *msg); void ns_init(void) @@ -105,7 +105,7 @@ ns_init(void) int nsintr_getpck = 0; int nsintr_swtch = 0; -static int +static void nsintr(struct netmsg *msg) { struct mbuf *m = ((struct netmsg_packet *)msg)->nm_packet; @@ -232,8 +232,8 @@ nsintr(struct netmsg *msg) bad: m_freem(m); out: + ; /* msg was embedded in the mbuf, do not reply! */ - return(EASYNC); } u_char nsctlerrmap[PRC_NCMDS] = { diff --git a/sys/sys/msgport.h b/sys/sys/msgport.h index ee9c798605..985ec1e45b 100644 --- a/sys/sys/msgport.h +++ b/sys/sys/msgport.h @@ -3,7 +3,7 @@ * * Implements LWKT messages and ports. * - * $DragonFly: src/sys/sys/msgport.h,v 1.23 2007/05/23 02:09:41 dillon Exp $ + * $DragonFly: src/sys/sys/msgport.h,v 1.24 2007/05/23 08:56:59 dillon Exp $ */ #ifndef _SYS_MSGPORT_H_ @@ -33,55 +33,23 @@ typedef struct lwkt_port *lwkt_port_t; typedef TAILQ_HEAD(lwkt_msg_queue, lwkt_msg) lwkt_msg_queue; -/* - * LWKT command message operator type. This type holds a message's - * 'command'. The command format is opaque to the LWKT messaging system, - * meaning that it is specific to whatever convention the API chooses. - * By convention lwkt_cmd_t is passed by value and is expected to - * efficiently fit into a machine register. - */ -typedef union lwkt_cmd { - int cm_op; - int (*cm_func)(lwkt_msg_t msg); -} lwkt_cmd_t; - /* * The standard message and port structure for communications between * threads. See kern/lwkt_msgport.c for documentation on how messages and * ports work. * - * For the most part a message may only be manipulated by whomever currently - * owns it, which generally means the originating port if the message has + * A message may only be manipulated by whomever currently owns it, + * which generally means the originating port if the message has * not been sent yet or has been replied, and the target port if the message * has been sent and/or is undergoing processing. * - * The one exception to this rule is an abort. Aborts must be initiated - * by the originator and may 'chase' the target (especially if a message - * is being forwarded), potentially even 'chase' the message all the way - * back to the originator if it races against the target replying the - * message. The ms_abort_port field is the only field that may be modified - * by the originator or intermediate target (when the abort is chasing - * a forwarding or reply op). An abort may cause a reply to be delayed - * until the abort catches up to it. - * - * Messages which support an abort will have MSGF_ABORTABLE set, indicating - * that the ms_abort field has been initialized. An abort will cause a - * message to be requeued to the target port so the target sees the same - * message twice: once during initial processing of the message, and a - * second time to process the abort request. lwkt_getport() will detect - * the requeued abort and will copy ms_abort into ms_cmd before returning - * the requeued message the second time. This makes target processing a - * whole lot less complex. - * * NOTE! 64-bit-align this structure. */ typedef struct lwkt_msg { TAILQ_ENTRY(lwkt_msg) ms_node; /* link node */ lwkt_port_t ms_target_port; /* current target or relay port */ lwkt_port_t ms_reply_port; /* async replies returned here */ - lwkt_port_t ms_abort_port; /* abort chasing port */ - lwkt_cmd_t ms_cmd; /* message command operator */ - lwkt_cmd_t ms_abort; /* message abort operator */ + void (*ms_abortfn)(struct lwkt_msg *); int ms_flags; /* message flags */ int ms_error; /* positive error code or 0 */ union { @@ -96,15 +64,38 @@ typedef struct lwkt_msg { int ms_pad[2]; /* future use */ } lwkt_msg; -#define MSGF_DONE 0x0001 /* asynch message is complete */ -#define MSGF_REPLY1 0x0002 /* asynch message has been returned */ +/* + * Message state flags are manipulated by the current owner only. + * + * DONE Indicates completion of the reply. This flag is also set + * for unsent messages. + * + * REPLY Indicates message is being replied but may or may not + * have been queued or returned yet. This bit is left set + * when a message is retrieved from a reply port so the caller + * can distinguish between requests and replies. + * + * QUEUED Indicates message is queued on reply or target port, or + * some other port. + * + * SYNC Indicates that the originator is blocked directly on the + * message and that the message should be signaled on + * completion instead of queued. + * + * INTRANSIT Indicates that the message state is indeterminant (e.g. + * being passed through an IPI). + * + * PCATCH Static flag indicates blocking entity can be interrupted. + * + * ABORTABLE Static flag indicates that ms_abortfn is valid. + */ +#define MSGF_DONE 0x0001 /* message is complete */ +#define MSGF_REPLY 0x0002 /* asynch message has been returned */ #define MSGF_QUEUED 0x0004 /* message has been queued sanitychk */ -#define MSGF_ASYNC 0x0008 /* sync/async hint */ -#define MSGF_ABORTED 0x0010 /* indicate pending abort */ +#define MSGF_SYNC 0x0008 /* synchronous message operation */ +#define MSGF_INTRANSIT 0x0010 /* in-transit (IPI) */ #define MSGF_PCATCH 0x0020 /* catch proc signal while waiting */ -#define MSGF_REPLY2 0x0040 /* reply processed by rport cpu */ #define MSGF_ABORTABLE 0x0080 /* message supports abort */ -#define MSGF_RETRIEVED 0x0100 /* message retrieved on target */ #define MSG_CMD_CDEV 0x00010000 #define MSG_CMD_VFS 0x00020000 @@ -139,19 +130,6 @@ MALLOC_DECLARE(M_LWKTMSG); * supported, see lwkt_default_replyport(). Generally speaking * one sets MSGF_DONE. If MSGF_ASYNC is set the message is queued * to the port, else the port's thread is scheduled. - * - * mp_abortport(): - * - abort a message. The mp_abortport function for the message's - * ms_target_port is called. ms_target_port is basically where - * the message was sent to or last forwarded to. Aborting a message - * can be rather involved. Note that the lwkt_getmsg() code ensures - * that a message is returned non-abort before it is returned again - * with its ms_cmd set to ms_abort, even if the abort occurs before - * the initial retrieval of the message. The setting of ms_cmd to - * ms_abort is NOT handled by mp_abortport(). mp_abortport() is - * basically responsible for requeueing the message to the target - * port and setting the MSGF_ABORTED flag. - * */ typedef struct lwkt_port { lwkt_msg_queue mp_msgq; @@ -161,7 +139,6 @@ typedef struct lwkt_port { int (*mp_putport)(lwkt_port_t, lwkt_msg_t); void * (*mp_waitport)(lwkt_port_t, lwkt_msg_t); void (*mp_replyport)(lwkt_port_t, lwkt_msg_t); - void (*mp_abortport)(lwkt_port_t, lwkt_msg_t); } lwkt_port; #define MSGPORTF_WAITING 0x0001 diff --git a/sys/sys/msgport2.h b/sys/sys/msgport2.h index a3b9a905a8..63621d9955 100644 --- a/sys/sys/msgport2.h +++ b/sys/sys/msgport2.h @@ -3,7 +3,7 @@ * * Implements Inlines for LWKT messages and ports. * - * $DragonFly: src/sys/sys/msgport2.h,v 1.12 2007/05/23 02:09:41 dillon Exp $ + * $DragonFly: src/sys/sys/msgport2.h,v 1.13 2007/05/23 08:56:59 dillon Exp $ */ #ifndef _SYS_MSGPORT2_H_ @@ -19,69 +19,30 @@ #include #endif -#define lwkt_cmd_op_none lwkt_cmd_op(0) - -typedef int (*lwkt_cmd_func_t)(lwkt_msg_t); - /* * Initialize a LWKT message structure. Note that if the message supports - * an abort MSGF_ABORTABLE must be passed in flags and an abort command - * supplied. If abort is not supported then lwkt_cmd_op_none is passed as - * the abort command argument by convention. + * an abort MSGF_ABORTABLE must be passed in flags. * * Note that other areas of the LWKT msg may already be initialized, so we * do not zero the message here. + * + * Messages are marked as DONE until sent. */ static __inline void -lwkt_initmsg(lwkt_msg_t msg, lwkt_port_t rport, int flags, - lwkt_cmd_t cmd, lwkt_cmd_t abort) +lwkt_initmsg(lwkt_msg_t msg, lwkt_port_t rport, int flags) { - msg->ms_cmd = cmd; /* opaque */ - if (flags & MSGF_ABORTABLE) /* constant optimized conditional */ - msg->ms_abort = abort; /* opaque */ msg->ms_flags = MSGF_DONE | flags; msg->ms_reply_port = rport; } -/* - * These inlines convert specific types to the lwkt_cmd_t type. The compiler - * should be able to optimize this whole mess out. - */ -static __inline -lwkt_cmd_t -lwkt_cmd_op(int op) -{ - lwkt_cmd_t cmd; - - cmd.cm_op = op; - return(cmd); -} - -static __inline -lwkt_cmd_t -lwkt_cmd_func(int (*func)(lwkt_msg_t)) -{ - lwkt_cmd_t cmd; - - cmd.cm_func = func; - return(cmd); -} - -static __inline -void -lwkt_initmsg_simple(lwkt_msg_t msg, int op) -{ - lwkt_initmsg(msg, &curthread->td_msgport, 0, - lwkt_cmd_op(op), lwkt_cmd_op(0)); -} - static __inline void -lwkt_reinitmsg(lwkt_msg_t msg, lwkt_port_t rport) +lwkt_initmsg_abortable(lwkt_msg_t msg, lwkt_port_t rport, int flags, + void (*abortfn)(lwkt_msg_t)) { - msg->ms_flags = (msg->ms_flags & (MSGF_ASYNC | MSGF_ABORTABLE)) | MSGF_DONE; - msg->ms_reply_port = rport; + lwkt_initmsg(msg, rport, flags | MSGF_ABORTABLE); + msg->ms_abortfn = abortfn; } static __inline -- 2.41.0