--- //depot/projects/smpng/sys/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c 2008/09/24 21:56:18 +++ //depot/user/jhb/socket/dev/cxgb/ulp/iw_cxgb/iw_cxgb_cm.c 2009/05/26 18:20:36 @@ -141,7 +141,7 @@ static void ep_timeout(void *arg); static void connect_reply_upcall(struct iwch_ep *ep, int status); -static void iwch_so_upcall(struct socket *so, void *arg, int waitflag); +static int iwch_so_upcall(struct socket *so, void *arg, int waitflag); /* * Cruft to offload socket upcalls onto thread. @@ -335,9 +335,7 @@ { CTR4(KTR_IW_CXGB, "%s ep %p so %p state %s", __FUNCTION__, epc, epc->so, states[epc->state]); SOCK_LOCK(epc->so); - epc->so->so_upcall = NULL; - epc->so->so_upcallarg = NULL; - epc->so->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(epc->so, SO_RCV); SOCK_UNLOCK(epc->so); soshutdown(epc->so, SHUT_WR|SHUT_RD); epc->so = NULL; @@ -1108,7 +1106,7 @@ { struct toepcb *toep = (struct toepcb *)ctx; struct socket *so = toeptoso(toep); - struct iwch_ep *ep = so->so_upcallarg; + struct iwch_ep *ep = so->so_rcv.sb_upcallarg; CTR2(KTR_IW_CXGB, "%s ep %p", __FUNCTION__, ep); m_adj(m, sizeof(struct cpl_rdma_terminate)); @@ -1129,7 +1127,7 @@ struct iwch_qp_attributes attrs; int release = 0; - ep = so->so_upcallarg; + ep = so->so_rcv.sb_upcallarg; CTR5(KTR_IW_CXGB, "%s ep %p so %p state %s ec_status %d", __FUNCTION__, ep, ep->com.so, states[ep->com.state], rep->status); if (!so || !ep) { panic("bogosity ep %p state %d, so %p state %x\n", ep, ep ? ep->com.state : -1, so, so ? so->so_state : -1); @@ -1309,10 +1307,10 @@ struct sockopt sopt; int on=1; - epc->so->so_upcall = iwch_so_upcall; - epc->so->so_upcallarg = epc; - epc->so->so_rcv.sb_flags |= SB_UPCALL; + SOCK_LOCK(epc->so); + soupcall_set(epc->so, SO_RCV, iwch_so_upcall, epc); epc->so->so_state |= SS_NBIO; + SOCK_UNLOCK(epc->so); sopt.sopt_dir = SOPT_SET; sopt.sopt_level = SOL_SOCKET; sopt.sopt_name = SO_NO_DDP; @@ -1611,10 +1609,8 @@ so->so_qstate &= ~SQ_COMP; so->so_head = NULL; soref(so); - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, iwch_so_upcall, child_ep); so->so_state |= SS_NBIO; - so->so_upcall = iwch_so_upcall; - so->so_upcallarg = child_ep; PANIC_IF(!(so->so_state & SS_ISCONNECTED)); PANIC_IF(so->so_error); SOCK_UNLOCK(so); @@ -1661,7 +1657,7 @@ process_mpa_request(child_ep); } -static void +static int iwch_so_upcall(struct socket *so, void *arg, int waitflag) { struct iwch_ep *ep = arg; @@ -1674,6 +1670,7 @@ taskqueue_enqueue(iw_cxgb_taskq, &iw_cxgb_task); } mtx_unlock(&req_lock); + return (SU_OK); } static void --- //depot/projects/smpng/sys/kern/uipc_sockbuf.c 2009/05/08 11:53:25 +++ //depot/user/jhb/socket/kern/uipc_sockbuf.c 2009/05/26 18:34:25 @@ -175,6 +175,7 @@ void sowakeup(struct socket *so, struct sockbuf *sb) { + int ret; SOCKBUF_LOCK_ASSERT(sb); @@ -186,13 +187,17 @@ wakeup(&sb->sb_cc); } KNOTE_LOCKED(&sb->sb_sel.si_note, 0); + if (sb->sb_upcall != NULL) + ret = sb->sb_upcall(so, sb->sb_upcallarg, M_DONTWAIT); + else + ret = SU_OK; + if (sb->sb_flags & SB_AIO) + aio_swake(so, sb); SOCKBUF_UNLOCK(sb); + if (ret == SU_ISCONNECTED) + soisconnected(so); if ((so->so_state & SS_ASYNC) && so->so_sigio != NULL) pgsigio(&so->so_sigio, SIGIO, 0); - if (sb->sb_flags & SB_UPCALL) - (*so->so_upcall)(so, so->so_upcallarg, M_DONTWAIT); - if (sb->sb_flags & SB_AIO) - aio_swake(so, sb); mtx_assert(SOCKBUF_MTX(sb), MA_NOTOWNED); } --- //depot/projects/smpng/sys/kern/uipc_socket.c 2009/05/13 13:56:17 +++ //depot/user/jhb/socket/kern/uipc_socket.c 2009/05/26 18:20:36 @@ -3054,8 +3054,10 @@ void soisconnected(struct socket *so) { - struct socket *head; + struct socket *head; + int ret; +restart: ACCEPT_LOCK(); SOCK_LOCK(so); so->so_state &= ~(SS_ISCONNECTING|SS_ISDISCONNECTING|SS_ISCONFIRMING); @@ -3075,13 +3077,15 @@ wakeup_one(&head->so_timeo); } else { ACCEPT_UNLOCK(); - so->so_upcall = - head->so_accf->so_accept_filter->accf_callback; - so->so_upcallarg = head->so_accf->so_accept_filter_arg; - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, + head->so_accf->so_accept_filter->accf_callback, + head->so_accf->so_accept_filter_arg); so->so_options &= ~SO_ACCEPTFILTER; + ret = head->so_accf->so_accept_filter->accf_callback(so, + head->so_accf->so_accept_filter_arg, M_DONTWAIT); SOCK_UNLOCK(so); - so->so_upcall(so, so->so_upcallarg, M_DONTWAIT); + if (ret == SU_ISCONNECTED) + goto restart; } return; } @@ -3146,6 +3150,57 @@ } /* + * Register per-socket buffer upcalls. + */ +void +soupcall_set(struct socket *so, int which, + int (*func)(struct socket *, void *, int), void *arg) +{ + struct sockbuf *sb; + + switch (which) { + case SO_RCV: + sb = &so->so_rcv; + break; + case SO_SND: + sb = &so->so_snd; + break; + default: + panic("soupcall_set: bad which"); + } + SOCKBUF_LOCK_ASSERT(sb); +#if 0 + /* XXX: accf_http actually wants to do this on purpose. */ + KASSERT(sb->sb_upcall == NULL, ("soupcall_set: overwriting upcall")); +#endif + sb->sb_upcall = func; + sb->sb_upcallarg = arg; + sb->sb_flags |= SB_UPCALL; +} + +void +soupcall_clear(struct socket *so, int which) +{ + struct sockbuf *sb; + + switch (which) { + case SO_RCV: + sb = &so->so_rcv; + break; + case SO_SND: + sb = &so->so_snd; + break; + default: + panic("soupcall_clear: bad which"); + } + SOCKBUF_LOCK_ASSERT(sb); + KASSERT(sb->sb_upcall != NULL, ("soupcall_clear: no upcall to clear")); + sb->sb_upcall = NULL; + sb->sb_upcallarg = NULL; + sb->sb_flags &= ~SB_UPCALL; +} + +/* * Create an external-format (``xsocket'') structure using the information in * the kernel-format socket structure pointed to by so. This is done to * reduce the spew of irrelevant information over this interface, to isolate --- //depot/projects/smpng/sys/kern/vfs_aio.c 2009/01/23 22:58:19 +++ //depot/user/jhb/socket/kern/vfs_aio.c 2009/05/26 18:34:25 @@ -1313,12 +1313,12 @@ struct aiocblist *cb, *cbn; int opcode; + SOCKBUF_LOCK_ASSERT(sb); if (sb == &so->so_snd) opcode = LIO_WRITE; else opcode = LIO_READ; - SOCKBUF_LOCK(sb); sb->sb_flags &= ~SB_AIO; mtx_lock(&aio_job_mtx); TAILQ_FOREACH_SAFE(cb, &so->so_aiojobq, list, cbn) { @@ -1336,7 +1336,6 @@ } } mtx_unlock(&aio_job_mtx); - SOCKBUF_UNLOCK(sb); } static int --- //depot/projects/smpng/sys/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c 2009/02/11 15:04:28 +++ //depot/user/jhb/socket/netgraph/bluetooth/socket/ng_btsocket_rfcomm.c 2009/05/26 18:20:36 @@ -93,7 +93,7 @@ #define ALOT 0x7fff /* Local prototypes */ -static void ng_btsocket_rfcomm_upcall +static int ng_btsocket_rfcomm_upcall (struct socket *so, void *arg, int waitflag); static void ng_btsocket_rfcomm_sessions_task (void *ctx, int pending); @@ -1007,7 +1007,7 @@ * Upcall function for L2CAP sockets. Enqueue RFCOMM task. */ -static void +static int ng_btsocket_rfcomm_upcall(struct socket *so, void *arg, int waitflag) { int error; @@ -1018,6 +1018,7 @@ if ((error = ng_btsocket_rfcomm_task_wakeup()) != 0) NG_BTSOCKET_RFCOMM_ALERT( "%s: Could not enqueue RFCOMM task, error=%d\n", __func__, error); + return (SU_OK); } /* ng_btsocket_rfcomm_upcall */ /* @@ -1047,13 +1048,11 @@ panic("%s: DLC list is not empty\n", __func__); /* Close L2CAP socket */ - s->l2so->so_upcallarg = NULL; - s->l2so->so_upcall = NULL; SOCKBUF_LOCK(&s->l2so->so_rcv); - s->l2so->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(s->l2so, SO_RCV); SOCKBUF_UNLOCK(&s->l2so->so_rcv); SOCKBUF_LOCK(&s->l2so->so_snd); - s->l2so->so_snd.sb_flags &= ~SB_UPCALL; + soupcall_clear(s->l2so, SO_SND); SOCKBUF_UNLOCK(&s->l2so->so_snd); soclose(s->l2so); @@ -1286,13 +1285,11 @@ LIST_INIT(&s->dlcs); /* Prepare L2CAP socket */ - l2so->so_upcallarg = NULL; - l2so->so_upcall = ng_btsocket_rfcomm_upcall; SOCKBUF_LOCK(&l2so->so_rcv); - l2so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(l2so, SO_RCV, ng_btsocket_rfcomm_upcall, NULL); SOCKBUF_UNLOCK(&l2so->so_rcv); SOCKBUF_LOCK(&l2so->so_snd); - l2so->so_snd.sb_flags |= SB_UPCALL; + soupcall_set(l2so, SO_SND, ng_btsocket_rfcomm_upcall, NULL); SOCKBUF_UNLOCK(&l2so->so_snd); l2so->so_state |= SS_NBIO; s->l2so = l2so; @@ -1370,13 +1367,11 @@ mtx_unlock(&s->session_mtx); /* Return L2CAP socket back to its original state */ - l2so->so_upcallarg = NULL; - l2so->so_upcall = NULL; SOCKBUF_LOCK(&l2so->so_rcv); - l2so->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(s->l2so, SO_RCV); SOCKBUF_UNLOCK(&l2so->so_rcv); SOCKBUF_LOCK(&l2so->so_snd); - l2so->so_snd.sb_flags &= ~SB_UPCALL; + soupcall_clear(s->l2so, SO_SND); SOCKBUF_UNLOCK(&l2so->so_snd); l2so->so_state &= ~SS_NBIO; --- //depot/projects/smpng/sys/netgraph/ng_ksocket.c 2008/11/03 21:11:59 +++ //depot/user/jhb/socket/netgraph/ng_ksocket.c 2009/05/26 18:20:36 @@ -158,7 +158,7 @@ /* Helper functions */ static int ng_ksocket_check_accept(priv_p); static void ng_ksocket_finish_accept(priv_p); -static void ng_ksocket_incoming(struct socket *so, void *arg, int waitflag); +static int ng_ksocket_incoming(struct socket *so, void *arg, int waitflag); static int ng_ksocket_parse(const struct ng_ksocket_alias *aliases, const char *s, int family); static void ng_ksocket_incoming2(node_p node, hook_p hook, @@ -616,13 +616,11 @@ struct socket *const so = priv->so; /* Add our hook for incoming data and other events */ - priv->so->so_upcallarg = (caddr_t)node; - priv->so->so_upcall = ng_ksocket_incoming; SOCKBUF_LOCK(&priv->so->so_rcv); - priv->so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(priv->so, SO_RCV, ng_ksocket_incoming, node); SOCKBUF_UNLOCK(&priv->so->so_rcv); SOCKBUF_LOCK(&priv->so->so_snd); - priv->so->so_snd.sb_flags |= SB_UPCALL; + soupcall_set(priv->so, SO_SND, ng_ksocket_incoming, node); SOCKBUF_UNLOCK(&priv->so->so_snd); SOCK_LOCK(priv->so); priv->so->so_state |= SS_NBIO; @@ -941,12 +939,11 @@ /* Close our socket (if any) */ if (priv->so != NULL) { SOCKBUF_LOCK(&priv->so->so_rcv); - priv->so->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(priv->so, SO_RCV); SOCKBUF_UNLOCK(&priv->so->so_rcv); SOCKBUF_LOCK(&priv->so->so_snd); - priv->so->so_snd.sb_flags &= ~SB_UPCALL; + soupcall_clear(priv->so, SO_SND); SOCKBUF_UNLOCK(&priv->so->so_snd); - priv->so->so_upcall = NULL; soclose(priv->so); priv->so = NULL; } @@ -1000,7 +997,7 @@ * To decouple stack, we use queue version of ng_send_fn(). */ -static void +static int ng_ksocket_incoming(struct socket *so, void *arg, int waitflag) { const node_p node = arg; @@ -1017,6 +1014,7 @@ ng_send_fn1(node, NULL, &ng_ksocket_incoming2, so, 0, wait)) { atomic_store_rel_int(&priv->fn_sent, 0); } + return (SU_OK); } @@ -1258,13 +1256,11 @@ */ LIST_INSERT_HEAD(&priv->embryos, priv2, siblings); - so->so_upcallarg = (caddr_t)node; - so->so_upcall = ng_ksocket_incoming; SOCKBUF_LOCK(&so->so_rcv); - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, ng_ksocket_incoming, node); SOCKBUF_UNLOCK(&so->so_rcv); SOCKBUF_LOCK(&so->so_snd); - so->so_snd.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, ng_ksocket_incoming, node); SOCKBUF_UNLOCK(&so->so_snd); /* Fill in the response data and send it or return it to the caller */ --- //depot/projects/smpng/sys/netinet/accf_data.c 2007/12/20 22:29:11 +++ //depot/user/jhb/socket/netinet/accf_data.c 2009/05/26 18:20:36 @@ -38,7 +38,7 @@ /* accept filter that holds a socket until data arrives */ -static void sohasdata(struct socket *so, void *arg, int waitflag); +static int sohasdata(struct socket *so, void *arg, int waitflag); static struct accept_filter accf_data_filter = { "dataready", @@ -55,15 +55,13 @@ DECLARE_MODULE(accf_data, accf_data_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); -static void +static int sohasdata(struct socket *so, void *arg, int waitflag) { if (!soreadable(so)) - return; + return (SU_OK); - so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected(so); - return; + soupcall_clear(so, SO_RCV); + return (SU_ISCONNECTED); } --- //depot/projects/smpng/sys/netinet/accf_dns.c 2008/07/25 18:20:23 +++ //depot/user/jhb/socket/netinet/accf_dns.c 2009/05/26 18:20:36 @@ -37,7 +37,7 @@ #include /* check for full DNS request */ -static void sohasdns(struct socket *so, void *arg, int waitflag); +static int sohasdns(struct socket *so, void *arg, int waitflag); struct packet { struct mbuf *m; /* Current mbuf. */ @@ -69,7 +69,7 @@ DECLARE_MODULE(accf_dns, accf_dns_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE); -static void +static int sohasdns(struct socket *so, void *arg, int waitflag) { struct sockbuf *sb = &so->so_rcv; @@ -78,15 +78,13 @@ if (sb->sb_cc >= sb->sb_hiwat || sb->sb_mbcnt >= sb->sb_mbmax) goto ready; - /* Check and see if we have a request. */ + /* Check to see if we have a request. */ if (skippacket(sb) == DNS_WAIT) - return; + return (SU_OK); ready: - so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected(so); - return; + soupcall_clear(so, SO_RCV); + return (SU_ISCONNECTED); } #define GET8(p, val) do { \ @@ -128,7 +126,7 @@ q.len = sb->sb_cc; GET16(p, packlen); - if (packlen + 2 < q.len) + if (packlen + 2 > q.len) return DNS_WAIT; return DNS_OK; --- //depot/projects/smpng/sys/netinet/accf_http.c 2007/12/20 22:29:11 +++ //depot/user/jhb/socket/netinet/accf_http.c 2009/05/26 18:20:36 @@ -39,11 +39,11 @@ #include /* check for GET/HEAD */ -static void sohashttpget(struct socket *so, void *arg, int waitflag); +static int sohashttpget(struct socket *so, void *arg, int waitflag); /* check for HTTP/1.0 or HTTP/1.1 */ -static void soparsehttpvers(struct socket *so, void *arg, int waitflag); +static int soparsehttpvers(struct socket *so, void *arg, int waitflag); /* check for end of HTTP/1.x request */ -static void soishttpconnected(struct socket *so, void *arg, int waitflag); +static int soishttpconnected(struct socket *so, void *arg, int waitflag); /* strcmp on an mbuf chain */ static int mbufstrcmp(struct mbuf *m, struct mbuf *npkt, int offset, char *cmp); /* strncmp on an mbuf chain */ @@ -158,7 +158,7 @@ slen = sizeof(str) - 1; \ } while(0) -static void +static int sohashttpget(struct socket *so, void *arg, int waitflag) { @@ -170,7 +170,7 @@ m = so->so_rcv.sb_mb; cc = so->so_rcv.sb_cc - 1; if (cc < 1) - return; + return (SU_OK); switch (*mtod(m, char *)) { case 'G': STRSETUP(cmp, cmplen, "ET "); @@ -184,7 +184,7 @@ if (cc < cmplen) { if (mbufstrncmp(m, m->m_nextpkt, 1, cc, cmp) == 1) { DPRINT("short cc (%d) but mbufstrncmp ok", cc); - return; + return (SU_OK); } else { DPRINT("short cc (%d) mbufstrncmp failed", cc); goto fallout; @@ -193,23 +193,20 @@ if (mbufstrcmp(m, m->m_nextpkt, 1, cmp) == 1) { DPRINT("mbufstrcmp ok"); if (parse_http_version == 0) - soishttpconnected(so, arg, waitflag); + return (soishttpconnected(so, arg, waitflag)); else - soparsehttpvers(so, arg, waitflag); - return; + return (soparsehttpvers(so, arg, waitflag)); } DPRINT("mbufstrcmp bad"); } fallout: DPRINT("fallout"); - so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected(so); - return; + soupcall_clear(so, SO_RCV); + return (SU_ISCONNECTED); } -static void +static int soparsehttpvers(struct socket *so, void *arg, int waitflag) { struct mbuf *m, *n; @@ -262,9 +259,9 @@ mbufstrcmp(m, n, i, "HTTP/1.0") || mbufstrcmp(m, n, i, "HTTP/1.1")) { DPRINT("ok"); - soishttpconnected(so, - arg, waitflag); - return; + return ( + soishttpconnected(so, + arg, waitflag)); } else { DPRINT("bad"); goto fallout; @@ -279,22 +276,19 @@ * if we hit here we haven't hit something * we don't understand or a newline, so try again */ - so->so_upcall = soparsehttpvers; - so->so_rcv.sb_flags |= SB_UPCALL; - return; + soupcall_set(so, SO_RCV, soparsehttpvers, arg); + return (SU_OK); fallout: DPRINT("fallout"); - so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected(so); - return; + soupcall_clear(so, SO_RCV); + return (SU_ISCONNECTED); } #define NCHRS 3 -static void +static int soishttpconnected(struct socket *so, void *arg, int waitflag) { char a, b, c; @@ -350,13 +344,10 @@ } readmore: - so->so_upcall = soishttpconnected; - so->so_rcv.sb_flags |= SB_UPCALL; - return; + soupcall_set(so, SO_RCV, soishttpconnected, arg); + return (SU_OK); gotit: - so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; - soisconnected(so); - return; + soupcall_clear(so, SO_RCV); + return (SU_ISCONNECTED); } --- //depot/projects/smpng/sys/netsmb/smb_trantcp.c 2008/11/03 21:11:59 +++ //depot/user/jhb/socket/netsmb/smb_trantcp.c 2009/05/26 18:20:36 @@ -100,14 +100,15 @@ return 0; } -static void +static int nb_upcall(struct socket *so, void *arg, int waitflag) { struct nbpcb *nbp = arg; if (arg == NULL || nbp->nbp_selectid == NULL) - return; + return (SU_OK); wakeup(nbp->nbp_selectid); + return (SU_OK); } static int @@ -152,10 +153,8 @@ if (error) return error; nbp->nbp_tso = so; - so->so_upcallarg = (caddr_t)nbp; - so->so_upcall = nb_upcall; SOCKBUF_LOCK(&so->so_rcv); - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, nb_upcall, nbp); SOCKBUF_UNLOCK(&so->so_rcv); so->so_rcv.sb_timeo = (5 * hz); so->so_snd.sb_timeo = (5 * hz); --- //depot/projects/smpng/sys/nfsclient/nfs_socket.c 2009/04/14 19:06:19 +++ //depot/user/jhb/socket/nfsclient/nfs_socket.c 2009/05/26 18:20:36 @@ -126,8 +126,8 @@ static int nfs_reply(struct nfsreq *); static void nfs_softterm(struct nfsreq *rep); static int nfs_reconnect(struct nfsreq *rep); -static void nfs_clnt_tcp_soupcall(struct socket *so, void *arg, int waitflag); -static void nfs_clnt_udp_soupcall(struct socket *so, void *arg, int waitflag); +static int nfs_clnt_tcp_soupcall(struct socket *so, void *arg, int waitflag); +static int nfs_clnt_udp_soupcall(struct socket *so, void *arg, int waitflag); extern struct mtx nfs_reqq_mtx; @@ -461,12 +461,10 @@ goto bad; SOCKBUF_LOCK(&so->so_rcv); so->so_rcv.sb_flags |= SB_NOINTR; - so->so_upcallarg = (caddr_t)nmp; if (so->so_type == SOCK_STREAM) - so->so_upcall = nfs_clnt_tcp_soupcall; - else - so->so_upcall = nfs_clnt_udp_soupcall; - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, nfs_clnt_tcp_soupcall, nmp); + else + soupcall_set(so, SO_RCV, nfs_clnt_udp_soupcall, nmp); SOCKBUF_UNLOCK(&so->so_rcv); SOCKBUF_LOCK(&so->so_snd); so->so_snd.sb_flags |= SB_NOINTR; @@ -604,9 +602,7 @@ nmp->nm_so = NULL; mtx_unlock(&nmp->nm_mtx); SOCKBUF_LOCK(&so->so_rcv); - so->so_upcallarg = NULL; - so->so_upcall = NULL; - so->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(so, SO_RCV); SOCKBUF_UNLOCK(&so->so_rcv); soshutdown(so, SHUT_WR); soclose(so); @@ -815,7 +811,7 @@ * XXX TO DO * Make nfs_realign() non-blocking. Also make nfsm_dissect() nonblocking. */ -static void +static int nfs_clnt_match_xid(struct socket *so, struct nfsmount *nmp, struct mbuf *mrep) @@ -932,11 +928,10 @@ { int retval; - SOCKBUF_LOCK(&so->so_rcv); + SOCKBUF_LOCK_ASSERT(&so->so_rcv); retval = (so->so_rcv.sb_cc >= (bytes) || (so->so_rcv.sb_state & SBS_CANTRCVMORE) || so->so_error); - SOCKBUF_UNLOCK(&so->so_rcv); return (retval); } @@ -973,7 +968,7 @@ mtx_lock(&nmp->nm_mtx); if (nmp->nm_nfstcpstate.flags & NFS_TCP_FORCE_RECONNECT) { mtx_unlock(&nmp->nm_mtx); - return; + return (SU_OK); } else mtx_unlock(&nmp->nm_mtx); auio.uio_td = curthread; @@ -987,8 +982,9 @@ mtx_unlock(&nmp->nm_mtx); if (!nfstcp_marker_readable(so)) { /* Marker is not readable */ - return; + return (SU_OK); } + SOCKBUF_UNLOCK(&so->so_rcv); auio.uio_resid = sizeof(u_int32_t); auio.uio_iov = NULL; auio.uio_iovcnt = 0; @@ -996,6 +992,7 @@ rcvflg = (MSG_DONTWAIT | MSG_SOCALLBCK); error = soreceive(so, (struct sockaddr **)0, &auio, &mp, (struct mbuf **)0, &rcvflg); + SOCKBUF_LOCK(&so->so_rcv); /* * We've already tested that the socket is readable. 2 cases * here, we either read 0 bytes (client closed connection), @@ -1056,8 +1053,9 @@ mtx_unlock(&nmp->nm_mtx); if (!nfstcp_readable(so, nmp->nm_nfstcpstate.rpcresid)) { /* All data not readable */ - return; + return (SU_OK); } + SOCKBUF_UNLOCK(&so->so_rcv); auio.uio_resid = nmp->nm_nfstcpstate.rpcresid; auio.uio_iov = NULL; auio.uio_iovcnt = 0; @@ -1065,6 +1063,7 @@ rcvflg = (MSG_DONTWAIT | MSG_SOCALLBCK); error = soreceive(so, (struct sockaddr **)0, &auio, &mp, (struct mbuf **)0, &rcvflg); + SOCKBUF_LOCK(&so->so_rcv); if (error || auio.uio_resid > 0) { if (error && error != ECONNRESET) { log(LOG_ERR, @@ -1087,6 +1086,7 @@ mark_reconnect: nfs_mark_for_reconnect(nmp); + return (SU_OK); } static void @@ -1098,6 +1098,7 @@ struct mbuf *control = NULL; int error, rcvflag; + SOCKBUF_UNLOCK(&so->so_rcv); auio.uio_resid = 1000000; auio.uio_td = curthread; rcvflag = MSG_DONTWAIT; @@ -1110,6 +1111,8 @@ if (mp) nfs_clnt_match_xid(so, nmp, mp); } while (mp && !error); + SOCKBUF_LOCK(&so->so_rcv); + return (SU_OK); } /* --- //depot/projects/smpng/sys/nfsserver/nfs.h 2009/04/14 19:06:19 +++ //depot/user/jhb/socket/nfsserver/nfs.h 2009/05/20 20:44:04 @@ -367,7 +367,7 @@ int nfsrv_getcache(struct nfsrv_descript *, struct mbuf **); void nfsrv_updatecache(struct nfsrv_descript *, int, struct mbuf *); void nfsrv_cleancache(void); -void nfsrv_rcv(struct socket *so, void *arg, int waitflag); +int nfsrv_rcv(struct socket *so, void *arg, int waitflag); void nfsrv_slpderef(struct nfssvc_sock *slp); void nfsrv_wakenfsd(struct nfssvc_sock *slp); int nfsrv_writegather(struct nfsrv_descript **, struct nfssvc_sock *, --- //depot/projects/smpng/sys/nfsserver/nfs_srvsock.c 2008/11/03 21:11:59 +++ //depot/user/jhb/socket/nfsserver/nfs_srvsock.c 2009/05/20 20:44:04 @@ -405,7 +405,7 @@ * Essentially do as much as possible non-blocking, else punt and it will * be called with M_WAIT from an nfsd. */ -void +int nfsrv_rcv(struct socket *so, void *arg, int waitflag) { struct nfssvc_sock *slp = (struct nfssvc_sock *)arg; @@ -419,7 +419,7 @@ /* XXXRW: Unlocked read. */ if ((slp->ns_flag & SLP_VALID) == 0) - return; + return (SU_OK); /* * We can't do this in the context of a socket callback --- //depot/projects/smpng/sys/nfsserver/nfs_syscalls.c 2009/04/14 19:06:19 +++ //depot/user/jhb/socket/nfsserver/nfs_syscalls.c 2009/05/26 18:20:36 @@ -263,11 +263,11 @@ slp->ns_nam = mynam; fhold(fp); slp->ns_fp = fp; + NFSD_UNLOCK(); SOCKBUF_LOCK(&so->so_rcv); - so->so_upcallarg = (caddr_t)slp; - so->so_upcall = nfsrv_rcv; - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, nfsrv_rcv, slp); SOCKBUF_UNLOCK(&so->so_rcv); + NFSD_LOCK(); slp->ns_flag = (SLP_VALID | SLP_NEEDQ); nfsrv_wakenfsd(slp); NFSD_UNLOCK(); @@ -585,9 +585,7 @@ slp->ns_fp = NULL; so = slp->ns_so; SOCKBUF_LOCK(&so->so_rcv); - so->so_rcv.sb_flags &= ~SB_UPCALL; - so->so_upcall = NULL; - so->so_upcallarg = NULL; + soupcall_clear(so, SO_RCV); SOCKBUF_UNLOCK(&so->so_rcv); soshutdown(so, SHUT_RDWR); closef(fp, NULL); --- //depot/projects/smpng/sys/notes 2009/02/18 22:05:55 +++ //depot/user/jhb/socket/notes 2009/05/20 20:44:04 @@ -73,3 +73,46 @@ - jhb_socket - socket hacking Space reserved for child branches: +- Try to cleanup the so_upcall mess + - There are three "types" of upcalls: one for each socket buffer, and one + for accept (soisconnected). + - There isn't any locking for any of them. + - Accept upcalls can recurse which is really ugly. + - First, add an API to set/unset upcalls: + - sosetupcall(so, SU_(RCV|SND|ACCEPT), func, arg) + - soclearupcall(so, SU_(RCV|SND|ACCEPT), func, arg) + - Second, change locking for rcv/snd upcalls so that they are called with + the socket buffer lock held (and then close set/clear races) + - Third, the accept locking I have no idea on, maybe use ACCEPT_LOCK? + Also, to fix the recursion, perhaps the ACCEPT_LOCK upcall should have + a return value that lets the calling code make the next state transition + instead of recursing inside the upcall. This probably is not MFC'able + and perhaps is a second round. + - An MFC candidate might include the non-accept changes and use a flag + set by sosetupcall() to enable new locking semantics to try and + preserve the ABI. + - So, after further reading, some of the above is quite wrong. There + are really only two upcalls, one for each socket buffer. I think what + I am going to do is have the upcalls return a value to indicate if + soisconnected() needs to be called. + - Possibly add a MSG_LOCKED for the RPC/NFS upcalls to use so they can + hold the socket buffer lock over soreceive(). Can we use MSG_SOCALLBCK + for this? + +- List of upcalls + - iwch_so_upcall (SO_RCV), sb lock ok + - ng_btsocket_rfcomm_upcall (SO_RCV, SO_SND), sb lock ok + - ng_ksocket_incoming (SO_RCV, SO_SND), sb lock ok + - sohasdata (SO_RCV), sb lock ok + - sohasdns (SO_RCV), sb lock ok + - sohashttpget (SO_RCV), sb lock ok + - soparsehttpvers (SO_RCV), sb lock ok + - soishttpconnected (SO_RCV), sb lock ok + - nb_upcall (SO_RCV), sb lock ok + - nfs_clnt_tcp_soupcall (SO_RCV), hacked + - nfs_clnt_udp_soupcall (SO_RCV), hacked + - nfsrv_rcv (SO_RCV), sb lock ok only b/c it skips most work when an upcall + - clnt_dg_soupcall (SO_RCV), hacked + - clnt_vc_soupcall (SO_RCV), hacked + - svc_dg_soupcall (SO_RCV), sb lock ok + - svc_vc_upcall (SO_RCV), sb lock ok --- //depot/projects/smpng/sys/rpc/clnt_dg.c 2008/11/03 21:11:59 +++ //depot/user/jhb/socket/rpc/clnt_dg.c 2009/05/26 18:20:36 @@ -79,7 +79,7 @@ static bool_t clnt_dg_control(CLIENT *, u_int, void *); static void clnt_dg_close(CLIENT *); static void clnt_dg_destroy(CLIENT *); -static void clnt_dg_soupcall(struct socket *so, void *arg, int waitflag); +static int clnt_dg_soupcall(struct socket *so, void *arg, int waitflag); static struct clnt_ops clnt_dg_ops = { .cl_call = clnt_dg_call, @@ -112,7 +112,7 @@ #define MCALL_MSG_SIZE 24 /* - * This structure is pointed to by the socket's so_upcallarg + * This structure is pointed to by the socket buffer's sb_upcallarg * member. It is separate from the client private data to facilitate * multiple clients sharing the same socket. The cs_lock mutex is used * to protect all fields of this structure, the socket's receive @@ -183,6 +183,7 @@ CLIENT *cl = NULL; /* client handle */ struct cu_data *cu = NULL; /* private data */ struct cu_socket *cs = NULL; + struct sockbuf *sb; struct timeval now; struct rpc_msg call_msg; struct __rpc_sockinfo si; @@ -260,15 +261,16 @@ cu->cu_socket = so; soreserve(so, 256*1024, 256*1024); + sb = &so->so_rcv; SOCKBUF_LOCK(&so->so_rcv); recheck_socket: - if (so->so_upcall) { - if (so->so_upcall != clnt_dg_soupcall) { + if (sb->sb_upcall) { + if (sb->sb_upcall != clnt_dg_soupcall) { SOCKBUF_UNLOCK(&so->so_rcv); printf("clnt_dg_create(): socket already has an incompatible upcall\n"); goto err2; } - cs = (struct cu_socket *) so->so_upcallarg; + cs = (struct cu_socket *) sb->sb_upcallarg; mtx_lock(&cs->cs_lock); cs->cs_refs++; mtx_unlock(&cs->cs_lock); @@ -277,10 +279,10 @@ * We are the first on this socket - allocate the * structure and install it in the socket. */ - SOCKBUF_UNLOCK(&cu->cu_socket->so_rcv); + SOCKBUF_UNLOCK(&so->so_rcv); cs = mem_alloc(sizeof(*cs)); - SOCKBUF_LOCK(&cu->cu_socket->so_rcv); - if (so->so_upcall) { + SOCKBUF_LOCK(&so->so_rcv); + if (sb->sb_upcall) { /* * We have lost a race with some other client. */ @@ -290,9 +292,7 @@ mtx_init(&cs->cs_lock, "cs->cs_lock", NULL, MTX_DEF); cs->cs_refs = 1; TAILQ_INIT(&cs->cs_pending); - so->so_upcallarg = cs; - so->so_upcall = clnt_dg_soupcall; - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, clnt_dg_soupcall, cs); } SOCKBUF_UNLOCK(&so->so_rcv); @@ -322,7 +322,7 @@ struct timeval utimeout) /* seconds to wait before giving up */ { struct cu_data *cu = (struct cu_data *)cl->cl_private; - struct cu_socket *cs = (struct cu_socket *) cu->cu_socket->so_upcallarg; + struct cu_socket *cs; struct rpc_timers *rt; AUTH *auth; struct rpc_err *errp; @@ -343,6 +343,7 @@ struct cu_request *cr; int error; + cs = cu->cu_socket->so_rcv.sb_upcallarg; cr = malloc(sizeof(struct cu_request), M_RPC, M_WAITOK); mtx_lock(&cs->cs_lock); @@ -797,9 +798,10 @@ clnt_dg_control(CLIENT *cl, u_int request, void *info) { struct cu_data *cu = (struct cu_data *)cl->cl_private; - struct cu_socket *cs = (struct cu_socket *) cu->cu_socket->so_upcallarg; + struct cu_socket *cs; struct sockaddr *addr; + cs = cu->cu_socket->so_rcv.sb_upcallarg; mtx_lock(&cs->cs_lock); switch (request) { @@ -929,9 +931,10 @@ clnt_dg_close(CLIENT *cl) { struct cu_data *cu = (struct cu_data *)cl->cl_private; - struct cu_socket *cs = (struct cu_socket *) cu->cu_socket->so_upcallarg; + struct cu_socket *cs; struct cu_request *cr; + cs = cu->cu_socket->so_rcv.sb_upcallarg; mtx_lock(&cs->cs_lock); if (cu->cu_closed) { @@ -974,10 +977,11 @@ clnt_dg_destroy(CLIENT *cl) { struct cu_data *cu = (struct cu_data *)cl->cl_private; - struct cu_socket *cs = (struct cu_socket *) cu->cu_socket->so_upcallarg; + struct cu_socket *cs; struct socket *so = NULL; bool_t lastsocketref; + cs = cu->cu_socket->so_rcv.sb_upcallarg; clnt_dg_close(cl); mtx_lock(&cs->cs_lock); @@ -986,9 +990,7 @@ if (cs->cs_refs == 0) { mtx_destroy(&cs->cs_lock); SOCKBUF_LOCK(&cu->cu_socket->so_rcv); - cu->cu_socket->so_upcallarg = NULL; - cu->cu_socket->so_upcall = NULL; - cu->cu_socket->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(cu->cu_socket, SO_RCV); SOCKBUF_UNLOCK(&cu->cu_socket->so_rcv); mem_free(cs, sizeof(*cs)); lastsocketref = TRUE; @@ -1023,7 +1025,7 @@ t->tv_usec < -1 || t->tv_usec > 1000000); } -void +int clnt_dg_soupcall(struct socket *so, void *arg, int waitflag) { struct cu_socket *cs = (struct cu_socket *) arg; @@ -1037,12 +1039,14 @@ uio.uio_resid = 1000000000; uio.uio_td = curthread; do { + SOCKBUF_UNLOCK(&so->so_rcv); m = NULL; control = NULL; rcvflag = MSG_DONTWAIT; error = soreceive(so, NULL, &uio, &m, &control, &rcvflag); if (control) m_freem(control); + SOCKBUF_LOCK(&so->so_rcv); if (error == EWOULDBLOCK) break; @@ -1107,5 +1111,6 @@ if (!foundreq) m_freem(m); } while (m); + return (SU_OK); } --- //depot/projects/smpng/sys/rpc/clnt_vc.c 2008/11/18 23:25:45 +++ //depot/user/jhb/socket/rpc/clnt_vc.c 2009/05/26 18:20:36 @@ -91,7 +91,7 @@ static void clnt_vc_close(CLIENT *); static void clnt_vc_destroy(CLIENT *); static bool_t time_not_ok(struct timeval *); -static void clnt_vc_soupcall(struct socket *so, void *arg, int waitflag); +static int clnt_vc_soupcall(struct socket *so, void *arg, int waitflag); static struct clnt_ops clnt_vc_ops = { .cl_call = clnt_vc_call, @@ -286,9 +286,7 @@ soreserve(ct->ct_socket, sendsz, recvsz); SOCKBUF_LOCK(&ct->ct_socket->so_rcv); - ct->ct_socket->so_upcallarg = ct; - ct->ct_socket->so_upcall = clnt_vc_soupcall; - ct->ct_socket->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(ct->ct_socket, SO_RCV, clnt_vc_soupcall, ct); SOCKBUF_UNLOCK(&ct->ct_socket->so_rcv); ct->ct_record = NULL; @@ -750,17 +748,18 @@ } if (ct->ct_socket) { + ct->ct_closing = TRUE; + mtx_unlock(&ct->ct_lock); + SOCKBUF_LOCK(&ct->ct_socket->so_rcv); - ct->ct_socket->so_upcallarg = NULL; - ct->ct_socket->so_upcall = NULL; - ct->ct_socket->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(ct->ct_socket, SO_RCV); SOCKBUF_UNLOCK(&ct->ct_socket->so_rcv); /* * Abort any pending requests and wait until everyone * has finished with clnt_vc_call. */ - ct->ct_closing = TRUE; + mtx_lock(&ct->ct_lock); TAILQ_FOREACH(cr, &ct->ct_pending, cr_link) { cr->cr_xid = 0; cr->cr_error = ESHUTDOWN; @@ -815,7 +814,7 @@ t->tv_usec <= -1 || t->tv_usec > 1000000); } -void +int clnt_vc_soupcall(struct socket *so, void *arg, int waitflag) { struct ct_data *ct = (struct ct_data *) arg; @@ -840,20 +839,20 @@ * error condition */ do_read = FALSE; - SOCKBUF_LOCK(&so->so_rcv); if (so->so_rcv.sb_cc >= sizeof(uint32_t) || (so->so_rcv.sb_state & SBS_CANTRCVMORE) || so->so_error) do_read = TRUE; - SOCKBUF_UNLOCK(&so->so_rcv); if (!do_read) - return; + return (SU_OK); + SOCKBUF_UNLOCK(&so->so_rcv); uio.uio_resid = sizeof(uint32_t); m = NULL; rcvflag = MSG_DONTWAIT | MSG_SOCALLBCK; error = soreceive(so, NULL, &uio, &m, NULL, &rcvflag); + SOCKBUF_LOCK(&so->so_rcv); if (error == EWOULDBLOCK) break; @@ -893,25 +892,25 @@ * buffered. */ do_read = FALSE; - SOCKBUF_LOCK(&so->so_rcv); if (so->so_rcv.sb_cc >= ct->ct_record_resid || (so->so_rcv.sb_state & SBS_CANTRCVMORE) || so->so_error) do_read = TRUE; - SOCKBUF_UNLOCK(&so->so_rcv); if (!do_read) - return; + return (SU_OK); /* * We have the record mark. Read as much as * the socket has buffered up to the end of * this record. */ + SOCKBUF_UNLOCK(&so->so_rcv); uio.uio_resid = ct->ct_record_resid; m = NULL; rcvflag = MSG_DONTWAIT | MSG_SOCALLBCK; error = soreceive(so, NULL, &uio, &m, NULL, &rcvflag); + SOCKBUF_LOCK(&so->so_rcv); if (error == EWOULDBLOCK) break; @@ -980,4 +979,5 @@ } } } while (m); + return (SU_OK); } --- //depot/projects/smpng/sys/rpc/svc_dg.c 2008/11/03 21:11:59 +++ //depot/user/jhb/socket/rpc/svc_dg.c 2009/05/26 18:20:36 @@ -68,7 +68,7 @@ struct sockaddr *, struct mbuf *); static void svc_dg_destroy(SVCXPRT *); static bool_t svc_dg_control(SVCXPRT *, const u_int, void *); -static void svc_dg_soupcall(struct socket *so, void *arg, int waitflag); +static int svc_dg_soupcall(struct socket *so, void *arg, int waitflag); static struct xp_ops svc_dg_ops = { .xp_recv = svc_dg_recv, @@ -133,9 +133,7 @@ xprt_register(xprt); SOCKBUF_LOCK(&so->so_rcv); - so->so_upcallarg = xprt; - so->so_upcall = svc_dg_soupcall; - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, svc_dg_soupcall, xprt); SOCKBUF_UNLOCK(&so->so_rcv); return (xprt); @@ -205,9 +203,7 @@ if (error) { SOCKBUF_LOCK(&xprt->xp_socket->so_rcv); - xprt->xp_socket->so_upcallarg = NULL; - xprt->xp_socket->so_upcall = NULL; - xprt->xp_socket->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(xprt->xp_socket, SO_RCV); SOCKBUF_UNLOCK(&xprt->xp_socket->so_rcv); xprt_inactive(xprt); sx_xunlock(&xprt->xp_lock); @@ -275,9 +271,7 @@ { SOCKBUF_LOCK(&xprt->xp_socket->so_rcv); - xprt->xp_socket->so_upcallarg = NULL; - xprt->xp_socket->so_upcall = NULL; - xprt->xp_socket->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(xprt->xp_socket, SO_RCV); SOCKBUF_UNLOCK(&xprt->xp_socket->so_rcv); sx_destroy(&xprt->xp_lock); @@ -300,10 +294,11 @@ return (FALSE); } -static void +static int svc_dg_soupcall(struct socket *so, void *arg, int waitflag) { SVCXPRT *xprt = (SVCXPRT *) arg; xprt_active(xprt); + return (SU_OK); } --- //depot/projects/smpng/sys/rpc/svc_vc.c 2008/11/03 21:11:59 +++ //depot/user/jhb/socket/rpc/svc_vc.c 2009/05/26 18:20:36 @@ -80,7 +80,7 @@ static SVCXPRT *svc_vc_create_conn(SVCPOOL *pool, struct socket *so, struct sockaddr *raddr); static int svc_vc_accept(struct socket *head, struct socket **sop); -static void svc_vc_soupcall(struct socket *so, void *arg, int waitflag); +static int svc_vc_soupcall(struct socket *so, void *arg, int waitflag); static struct xp_ops svc_vc_rendezvous_ops = { .xp_recv = svc_vc_rendezvous_recv, @@ -160,9 +160,7 @@ solisten(so, SOMAXCONN, curthread); SOCKBUF_LOCK(&so->so_rcv); - so->so_upcallarg = xprt; - so->so_upcall = svc_vc_soupcall; - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, svc_vc_soupcall, xprt); SOCKBUF_UNLOCK(&so->so_rcv); return (xprt); @@ -236,9 +234,7 @@ xprt_register(xprt); SOCKBUF_LOCK(&so->so_rcv); - so->so_upcallarg = xprt; - so->so_upcall = svc_vc_soupcall; - so->so_rcv.sb_flags |= SB_UPCALL; + soupcall_set(so, SO_RCV, svc_vc_soupcall, xprt); SOCKBUF_UNLOCK(&so->so_rcv); /* @@ -358,9 +354,7 @@ if (error) { SOCKBUF_LOCK(&xprt->xp_socket->so_rcv); - xprt->xp_socket->so_upcallarg = NULL; - xprt->xp_socket->so_upcall = NULL; - xprt->xp_socket->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(xprt->xp_socket, SO_RCV); SOCKBUF_UNLOCK(&xprt->xp_socket->so_rcv); xprt_inactive(xprt); sx_xunlock(&xprt->xp_lock); @@ -405,9 +399,7 @@ svc_vc_destroy_common(SVCXPRT *xprt) { SOCKBUF_LOCK(&xprt->xp_socket->so_rcv); - xprt->xp_socket->so_upcallarg = NULL; - xprt->xp_socket->so_upcall = NULL; - xprt->xp_socket->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(xprt->xp_socket, SO_RCV); SOCKBUF_UNLOCK(&xprt->xp_socket->so_rcv); sx_destroy(&xprt->xp_lock); @@ -642,9 +634,7 @@ if (error) { SOCKBUF_LOCK(&xprt->xp_socket->so_rcv); - xprt->xp_socket->so_upcallarg = NULL; - xprt->xp_socket->so_upcall = NULL; - xprt->xp_socket->so_rcv.sb_flags &= ~SB_UPCALL; + soupcall_clear(xprt->xp_socket, SO_RCV); SOCKBUF_UNLOCK(&xprt->xp_socket->so_rcv); xprt_inactive(xprt); cd->strm_stat = XPRT_DIED; @@ -729,12 +719,13 @@ return (FALSE); } -static void +static int svc_vc_soupcall(struct socket *so, void *arg, int waitflag) { SVCXPRT *xprt = (SVCXPRT *) arg; xprt_active(xprt); + return (SU_OK); } #if 0 --- //depot/projects/smpng/sys/sys/sockbuf.h 2008/08/05 21:26:01 +++ //depot/user/jhb/socket/sys/sockbuf.h 2009/02/18 22:05:13 @@ -99,6 +99,8 @@ int sb_lowat; /* (c/d) low water mark */ int sb_timeo; /* (c/d) timeout for read/write */ short sb_flags; /* (c/d) flags, see below */ + int (*sb_upcall)(struct socket *, void *, int); /* (c/d) */ + void *sb_upcallarg; /* (c/d) */ }; #ifdef _KERNEL --- //depot/projects/smpng/sys/sys/socketvar.h 2009/05/08 11:53:25 +++ //depot/user/jhb/socket/sys/socketvar.h 2009/05/26 18:20:36 @@ -55,6 +55,8 @@ */ typedef u_quad_t so_gen_t; +struct socket; + /*- * Locking key to struct socket: * (a) constant after allocation, no locking required. @@ -104,8 +106,6 @@ struct sockbuf so_rcv, so_snd; - void (*so_upcall)(struct socket *, void *, int); - void *so_upcallarg; struct ucred *so_cred; /* (a) user credentials */ struct label *so_label; /* (b) MAC label for socket */ struct label *so_peerlabel; /* (b) cached MAC label for peer */ @@ -280,7 +280,7 @@ struct accept_filter { char accf_name[16]; - void (*accf_callback) + int (*accf_callback) (struct socket *so, void *arg, int waitflag); void * (*accf_create) (struct socket *so, char *arg); @@ -305,6 +305,14 @@ struct ucred; struct uio; +/* 'which' values for socket upcalls. */ +#define SO_RCV 1 +#define SO_SND 2 + +/* Return values for socket upcalls. */ +#define SU_OK 0 +#define SU_ISCONNECTED 1 + /* * From uipc_socket and friends */ @@ -356,6 +364,9 @@ int flags, struct thread *td); int soshutdown(struct socket *so, int how); void sotoxsocket(struct socket *so, struct xsocket *xso); +void soupcall_clear(struct socket *so, int which); +void soupcall_set(struct socket *so, int which, + int (*func)(struct socket *, void *, int), void *arg); void sowakeup(struct socket *so, struct sockbuf *sb); int selsocket(struct socket *so, int events, struct timeval *tv, struct thread *td);