sockcommon.c revision 0f1702c5201310f0529cd5abb77652e5e9b241b6
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER START
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * The contents of this file are subject to the terms of the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Common Development and Distribution License (the "License").
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You may not use this file except in compliance with the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * See the License for the specific language governing permissions
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and limitations under the License.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * When distributing Covered Code, include this CDDL HEADER in each
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If applicable, add the following below this CDDL HEADER, with the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * fields enclosed by brackets "[]" replaced with your own identifying
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * information: Portions Copyright [yyyy] [name of copyright owner]
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * CDDL HEADER END
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Use is subject to license terms.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningextern int xnet_skip_checks, xnet_check_print, xnet_truncate_print;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Common socket access functions.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Instead of accessing the sonode switch directly (i.e., SOP_xxx()),
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * the socket_xxx() function should be used.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Try to create a new sonode of the requested <family, type, protocol>.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/* ARGSUSED */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_create(int family, int type, int protocol, char *devpath, char *mod,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int flags, int version, struct cred *cr, int *errorp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Look for a sockparams entry that match the given criteria.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * solookup() returns with the entry held.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning *errorp = solookup(family, type, protocol, &sp);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning int kmflags = (flags == SOCKET_SLEEP) ? KM_SLEEP : KM_NOSLEEP;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * There is no matching sockparams entry. An ephemeral entry is
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * created if the caller specifies a device or a socket module.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sp = sockparams_hold_ephemeral_bydev(family, type,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sp = sockparams_hold_ephemeral_bymod(family, type,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(flags == SOCKET_SLEEP || flags == SOCKET_NOSLEEP);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so = sp->sp_smod_info->smod_sock_create_func(sp, family, type,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((*errorp = SOP_INIT(so, NULL, cr, flags)) == 0) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Cannot fail, only bumps so_count */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) VOP_OPEN(&SOTOV(so), FREAD|FWRITE, cr, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_newconn(struct sonode *parent, sock_lower_handle_t lh,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so = sp->sp_smod_info->smod_sock_create_func(sp, parent->so_family,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning parent->so_type, parent->so_protocol, parent->so_version, flags,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function may be called in interrupt context, and CRED()
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * will be NULL. In this case, pass in kcred.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if ((*errorp = SOP_INIT(so, parent, cr, flags)) == 0) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Cannot fail, only bumps so_count */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning (void) VOP_OPEN(&SOTOV(so), FREAD|FWRITE, cr, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Bind local endpoint.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_bind(struct sonode *so, struct sockaddr *name, socklen_t namelen,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_BIND(so, name, namelen, flags, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Turn socket into a listen socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_listen(struct sonode *so, int backlog, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Use the same qlimit as in BSD. BSD checks the qlimit
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * before queuing the next connection implying that a
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * listen(sock, 0) allows one connection to be queued.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * BSD also uses 1.5 times the requested backlog.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * XNS Issue 4 required a strict interpretation of the backlog.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This has been waived subsequently for Issue 4 and the change
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * incorporated in XNS Issue 5. So we aren't required to do
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * anything special for XPG apps.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Accept incoming connection.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_accept(struct sonode *lso, int fflag, cred_t *cr, struct sonode **nsop)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Active open.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_connect(struct sonode *so, const struct sockaddr *name,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t namelen, int fflag, int flags, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Handle a connect to a name parameter of type AF_UNSPEC like a
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * connect to a null address. This is the portable method to
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * unconnect a socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning error = SOP_CONNECT(so, name, namelen, fflag, flags, cr);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (error == EHOSTUNREACH && flags & _SOCONNECT_XPG4_2) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * X/Open specification contains a requirement that
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * ENETUNREACH be returned but does not require
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * EHOSTUNREACH. In order to keep the test suite
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * happy we mess with the errno here.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Get address of remote node.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_getpeername(struct sonode *so, struct sockaddr *addr,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning socklen_t *addrlen, boolean_t accept, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_GETPEERNAME(so, addr, addrlen, accept, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Get local address.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_getsockname(struct sonode *so, struct sockaddr *addr,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_GETSOCKNAME(so, addr, addrlen, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Called from shutdown().
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_shutdown(struct sonode *so, int how, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Get socket options.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_getsockopt(struct sonode *so, int level, int option_name,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning void *optval, socklen_t *optlenp, int flags, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_GETSOCKOPT(so, level, option_name, optval,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Set socket options
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_setsockopt(struct sonode *so, int level, int option_name,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning const void *optval, t_uscalar_t optlen, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Caller allocates aligned optval, or passes null */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(((uintptr_t)optval & (sizeof (t_scalar_t) - 1)) == 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* If optval is null optlen is 0, and vice-versa */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* No options should be zero-length */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_SETSOCKOPT(so, level, option_name, optval, optlen, cr));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_sendmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Do not bypass the cache if we are doing a local (AF_UNIX) write.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* We did a partial send */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_sendmblk(struct sonode *so, struct nmsghdr *msg, int fflag,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_recvmsg(struct sonode *so, struct nmsghdr *msg, struct uio *uiop,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Do not bypass the cache when reading data, as the application
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * is likely to access the data shortly.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* We did a partial read */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_ioctl(struct sonode *so, int cmd, intptr_t arg, int mode,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_IOCTL(so, cmd, arg, mode, cr, rvalp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_poll(struct sonode *so, short events, int anyyet, short *reventsp,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (SOP_POLL(so, events, anyyet, reventsp, phpp));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_close(struct sonode *so, int flag, struct cred *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (VOP_CLOSE(SOTOV(so), flag, 1, 0, cr, NULL));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_close_internal(struct sonode *so, int flag, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning/* ARGSUSED */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsocket_destroy_internal(struct sonode *so, cred_t *cr)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * TODO Once the common vnode ops is available, then the vnops argument
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * should be removed.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsonode_constructor(void *buf, void *cdrarg, int kmflags)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning return (-1);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_rcv_timer_interval = SOCKET_NO_RCVTIMER;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_init(&so->so_lock, NULL, MUTEX_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning mutex_init(&so->so_acceptq_lock, NULL, MUTEX_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning rw_init(&so->so_fallback_rwlock, NULL, RW_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_state_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_want_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_acceptq_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_snd_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_rcv_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_copy_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning cv_init(&so->so_closing_cv, NULL, CV_DEFAULT, NULL);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_tail == &so->so_acceptq_head);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsonode_init(struct sonode *so, struct sockparams *sp, int family,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(so->so_acceptq_tail == &so->so_acceptq_head);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&so->so_poll_list, sizeof (so->so_poll_list));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&so->so_proto_props, sizeof (struct sock_proto_props));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning bzero(&(so->so_ksock_callbacks), sizeof (ksocket_callbacks_t));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_max_addr_len = sizeof (struct sockaddr_storage);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning#endif /* DEBUG */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning so->so_state &= ~(SS_OOBPEND|SS_HAVEOOBDATA|SS_HADOOBDATA|
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function is called at the beginning of recvmsg().
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If I/OAT is enabled on this sonode, initialize the uioa state machine
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * with state UIOA_ALLOC.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_rcv_init(struct sonode *so, int flags, struct uio **uiopp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp != NULL && (sodp->sod_state & SOD_ENABLED) &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Big enough I/O for uioa min setup and an sodirect socket
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and sodirect enabled and uioa enabled and I/O will be done
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and not EOF so initialize the sodirect_t uioa_t with "uiop".
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Successful uioainit() so the uio_t part of the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * uioa_t will be used for all uio_t work to follow,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * we return the original "uiop" in "suiop".
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Before returning to the caller the passed in uio_t
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * "uiop" will be updated via a call to uioafini()
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Note, the uioa.uioa_state isn't set to UIOA_ENABLED
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * here as first we have to uioamove() any currently
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * queued M_DATA mblk_t(s) so it will be done later.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * In either uioainit() success or not case note the number
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * of uio bytes the caller wants for sod framework and/or
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * transport (e.g. TCP) strategy.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning } else if (sodp != NULL && (sodp->sod_state & SOD_ENABLED)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * No uioa but still using sodirect so note the number of
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * uio bytes the caller wants for sodirect framework and/or
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * transport (e.g. TCP) strategy.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function is called at the end of recvmsg(), it finializes all the I/OAT
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * operations, and reset the uioa state to UIOA_ALLOC.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_rcv_done(struct sonode *so, struct uio *suiop, struct uio *uiop)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Finish any sodirect and uioa processing */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Finish any uioa_t processing */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Last, clear sod_want value */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Schedule a uioamove() on a mblk. This is ususally called from
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * protocols (e.g. TCP) on a I/OAT enabled sonode.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_uioa_mblk_init(struct sodirect_s *sodp, mblk_t *mp, size_t msg_size)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Caller must have lock held */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Uioa is enabled */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * There isn't enough uio space for the mblk_t chain
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * so disable uioa such that this and any additional
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * mblk_t data is handled by the socket and schedule
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * the socket for wakeup to finish this uioa.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (!uioamove(mp1->b_rptr, len, UIO_READ, uioap)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Scheduled, mark dblk_t as such */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Error, turn off async processing */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Not all mblk_t(s) uioamoved (error) or all uio
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * space has been consumed so schedule the socket
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * for wakeup to finish this uio.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Break the mblk chain if neccessary. */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * This function is called on a mblk that thas been successfully uioamoved().
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_uioa_mblk_done(sodirect_t *sodp, mblk_t *bp)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (bp != NULL && (bp->b_datap->db_flags & DBLK_UIOA)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * A uioa flaged mblk_t chain, already uio processed,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * add it to the sodirect uioa pending free list.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Note, a b_cont chain headed by a DBLK_UIOA enable
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * mblk_t must have all mblk_t(s) DBLK_UIOA enabled.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Add first mblk_t of "bp" chain to current sodirect uioa
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * free list tail mblk_t, if any, else empty list so new head.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Walk mblk_t "bp" chain to find tail and adjust rptr of
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * each to reflect that uioamove() has consumed all data.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* New sodirect uioa free list tail */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Only dequeue once with data returned per uioa_t */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (sodp->sod_uioa.uioa_state & UIOA_ENABLED) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * When transit from UIOA_INIT state to UIOA_ENABLE state in recvmsg(), call
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * this function on a non-STREAMS socket to schedule uioamove() on the data
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * that has already queued in this socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_uioa_so_init(struct sonode *so, struct sodirect_s *sodp, struct uio *uiop)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Walk first b_cont chain in sod_q
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * and schedule any M_DATA mblk_t's for uio asynchronous move.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Walk the chain */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Not M_DATA, no more uioa */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Have a M_DATA mblk_t with data */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (len > uioap->uio_resid || (so->so_oobmark > 0 &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Not enough uio sapce, or beyond oobmark */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Scheduled, mark dblk_t as such */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Break the mblk chain */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Save last wbp processed */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (in_rcv_q && (bp == NULL || bp->b_next == NULL)) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * We get here only once to process the sonode dump area
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * if so_rcv_q_head is NULL or all the mblks have been
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * successfully uioamoved()ed.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* move to dump area */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* No more uioa */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * If we processed 1 or more mblk_t(s) then we need to split the
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * current mblk_t chain in 2 so that all the uioamove()ed mblk_t(s)
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * are in the current chain and the rest are in the following new
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* New end of current chain */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Insert new chain wbp after bp */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * No need to grab so_lock, since sod_lockp
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * points to so_lock.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Initialize sodirect data structures on a socket.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangningsod_sock_init(struct sonode *so, struct stdata *stp, sod_enq_func enq_func,
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp = kmem_cache_alloc(sock_sod_cache, KM_SLEEP);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sodp->sod_q = (stp != NULL) ? RD(stp->sd_wrq) : NULL;
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Remainder of the sod_uioa members are left uninitialized
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * but will be initialized later by uioainit() before uioa
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * is enabled.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning * Init the sodirect kmem cache while sockfs is loading.
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* Allocate sodirect_t kmem_cache */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sock_sod_cache = kmem_cache_create("sock_sod_cache",
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning sizeof (sodirect_t), 0, NULL, NULL, NULL, NULL, NULL, 0);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp->sod_uioa.uioa_state != (UIOA_ALLOC|UIOA_INIT));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning ASSERT(sodp->sod_uioa.uioa_state & (UIOA_ENABLED|UIOA_FINI));
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning if (so->so_rcv_q_head == NULL && so->so_rcv_head != NULL &&
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning /* more arrived */
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning while (m != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning " in so_rcv_q_head.\n", (void *)m);
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning while (m != NULL) {
0f1702c5201310f0529cd5abb77652e5e9b241b6Yu Xiangning " in so_rcv_head.\n", (void *)m);