diff options
author | rwatson <rwatson@FreeBSD.org> | 2006-06-10 14:34:07 +0000 |
---|---|---|
committer | rwatson <rwatson@FreeBSD.org> | 2006-06-10 14:34:07 +0000 |
commit | 120490c1a53b9a5e5df4f242c0ea5afd571503e5 (patch) | |
tree | 65b5fe3647642c3e72f5e3350d9d16a351075639 /sys/kern/uipc_sockbuf.c | |
parent | 1a50da1db5b6e916c2426726bb89218851beefe1 (diff) | |
download | FreeBSD-src-120490c1a53b9a5e5df4f242c0ea5afd571503e5.zip FreeBSD-src-120490c1a53b9a5e5df4f242c0ea5afd571503e5.tar.gz |
Move some functions and definitions from uipc_socket2.c to uipc_socket.c:
- Move sonewconn(), which creates new sockets for incoming connections on
listen sockets, so that all socket allocate code is together in
uipc_socket.c.
- Move 'maxsockets' and associated sysctls to uipc_socket.c with the
socket allocation code.
- Move kern.ipc sysctl node to uipc_socket.c, add a SYSCTL_DECL() for it
to sysctl.h and remove lots of scattered implementations in various
IPC modules.
- Sort sodealloc() after soalloc() in uipc_socket.c for dependency order
reasons. Statisticize soalloc() and sodealloc() as they are now
required only in uipc_socket.c, and are internal to the socket
implementation.
After this change, socket allocation and deallocation is entirely
centralized in one file, and uipc_socket2.c consists entirely of socket
buffer manipulation and default protocol switch functions.
MFC after: 1 month
Diffstat (limited to 'sys/kern/uipc_sockbuf.c')
-rw-r--r-- | sys/kern/uipc_sockbuf.c | 138 |
1 files changed, 0 insertions, 138 deletions
diff --git a/sys/kern/uipc_sockbuf.c b/sys/kern/uipc_sockbuf.c index b18ff4a..a39c685 100644 --- a/sys/kern/uipc_sockbuf.c +++ b/sys/kern/uipc_sockbuf.c @@ -57,8 +57,6 @@ __FBSDID("$FreeBSD$"); #include <sys/sysctl.h> #include <sys/systm.h> -int maxsockets; - void (*aio_swake)(struct socket *, struct sockbuf *); /* @@ -71,12 +69,6 @@ static u_long sb_max_adj = static u_long sb_efficiency = 8; /* parameter for sbreserve() */ -#ifdef REGRESSION -static int regression_sonewconn_earlytest = 1; -SYSCTL_INT(_regression, OID_AUTO, sonewconn_earlytest, CTLFLAG_RW, - ®ression_sonewconn_earlytest, 0, "Perform early sonewconn limit test"); -#endif - /* * Procedures to manipulate state flags of socket * and do appropriate wakeups. Normal sequence from the @@ -202,97 +194,6 @@ soisdisconnected(so) } /* - * When an attempt at a new connection is noted on a socket - * which accepts connections, sonewconn is called. If the - * connection is possible (subject to space constraints, etc.) - * then we allocate a new structure, propoerly linked into the - * data structure of the original socket, and return this. - * Connstatus may be 0, or SO_ISCONFIRMING, or SO_ISCONNECTED. - * - * note: the ref count on the socket is 0 on return - */ -struct socket * -sonewconn(head, connstatus) - register struct socket *head; - int connstatus; -{ - register struct socket *so; - int over; - - ACCEPT_LOCK(); - over = (head->so_qlen > 3 * head->so_qlimit / 2); - ACCEPT_UNLOCK(); -#ifdef REGRESSION - if (regression_sonewconn_earlytest && over) -#else - if (over) -#endif - return (NULL); - so = soalloc(M_NOWAIT); - if (so == NULL) - return (NULL); - if ((head->so_options & SO_ACCEPTFILTER) != 0) - connstatus = 0; - so->so_head = head; - so->so_type = head->so_type; - so->so_options = head->so_options &~ SO_ACCEPTCONN; - so->so_linger = head->so_linger; - so->so_state = head->so_state | SS_NOFDREF; - so->so_proto = head->so_proto; - so->so_timeo = head->so_timeo; - so->so_cred = crhold(head->so_cred); -#ifdef MAC - SOCK_LOCK(head); - mac_create_socket_from_socket(head, so); - SOCK_UNLOCK(head); -#endif - knlist_init(&so->so_rcv.sb_sel.si_note, SOCKBUF_MTX(&so->so_rcv), - NULL, NULL, NULL); - knlist_init(&so->so_snd.sb_sel.si_note, SOCKBUF_MTX(&so->so_snd), - NULL, NULL, NULL); - if (soreserve(so, head->so_snd.sb_hiwat, head->so_rcv.sb_hiwat) || - (*so->so_proto->pr_usrreqs->pru_attach)(so, 0, NULL)) { - sodealloc(so); - return (NULL); - } - so->so_state |= connstatus; - ACCEPT_LOCK(); - if (connstatus) { - TAILQ_INSERT_TAIL(&head->so_comp, so, so_list); - so->so_qstate |= SQ_COMP; - head->so_qlen++; - } else { - /* - * Keep removing sockets from the head until there's room for - * us to insert on the tail. In pre-locking revisions, this - * was a simple if(), but as we could be racing with other - * threads and soabort() requires dropping locks, we must - * loop waiting for the condition to be true. - */ - while (head->so_incqlen > head->so_qlimit) { - struct socket *sp; - sp = TAILQ_FIRST(&head->so_incomp); - TAILQ_REMOVE(&head->so_incomp, sp, so_list); - head->so_incqlen--; - sp->so_qstate &= ~SQ_INCOMP; - sp->so_head = NULL; - ACCEPT_UNLOCK(); - soabort(sp); - ACCEPT_LOCK(); - } - TAILQ_INSERT_TAIL(&head->so_incomp, so, so_list); - so->so_qstate |= SQ_INCOMP; - head->so_incqlen++; - } - ACCEPT_UNLOCK(); - if (connstatus) { - sorwakeup(head); - wakeup_one(&head->so_timeo); - } - return (so); -} - -/* * Socantsendmore indicates that no more data will be sent on the * socket; it would normally be applied to a socket when the user * informs the system that no more data is to be sent, by the protocol @@ -1498,49 +1399,10 @@ sbtoxsockbuf(struct sockbuf *sb, struct xsockbuf *xsb) xsb->sb_timeo = sb->sb_timeo; } -/* - * Here is the definition of some of the basic objects in the kern.ipc - * branch of the MIB. - */ -SYSCTL_NODE(_kern, KERN_IPC, ipc, CTLFLAG_RW, 0, "IPC"); - /* This takes the place of kern.maxsockbuf, which moved to kern.ipc. */ static int dummy; SYSCTL_INT(_kern, KERN_DUMMY, dummy, CTLFLAG_RW, &dummy, 0, ""); SYSCTL_OID(_kern_ipc, KIPC_MAXSOCKBUF, maxsockbuf, CTLTYPE_ULONG|CTLFLAG_RW, &sb_max, 0, sysctl_handle_sb_max, "LU", "Maximum socket buffer size"); -static int -sysctl_maxsockets(SYSCTL_HANDLER_ARGS) -{ - int error, newmaxsockets; - - newmaxsockets = maxsockets; - error = sysctl_handle_int(oidp, &newmaxsockets, sizeof(int), req); - if (error == 0 && req->newptr) { - if (newmaxsockets > maxsockets) { - maxsockets = newmaxsockets; - if (maxsockets > ((maxfiles / 4) * 3)) { - maxfiles = (maxsockets * 5) / 4; - maxfilesperproc = (maxfiles * 9) / 10; - } - EVENTHANDLER_INVOKE(maxsockets_change); - } else - error = EINVAL; - } - return (error); -} -SYSCTL_PROC(_kern_ipc, OID_AUTO, maxsockets, CTLTYPE_INT|CTLFLAG_RW, - &maxsockets, 0, sysctl_maxsockets, "IU", - "Maximum number of sockets avaliable"); SYSCTL_ULONG(_kern_ipc, KIPC_SOCKBUF_WASTE, sockbuf_waste_factor, CTLFLAG_RW, &sb_efficiency, 0, ""); - -/* - * Initialise maxsockets - */ -static void init_maxsockets(void *ignored) -{ - TUNABLE_INT_FETCH("kern.ipc.maxsockets", &maxsockets); - maxsockets = imax(maxsockets, imax(maxfiles, nmbclusters)); -} -SYSINIT(param, SI_SUB_TUNABLES, SI_ORDER_ANY, init_maxsockets, NULL); |