7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24
25 /*
26 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
27 * Copyright (c) 2014, Joyent, Inc. All rights reserved.
28 */
29
30 #include <sys/types.h>
31 #include <sys/sysmacros.h>
32 #include <sys/param.h>
33 #include <sys/errno.h>
34 #include <sys/signal.h>
35 #include <sys/stat.h>
36 #include <sys/proc.h>
37 #include <sys/cred.h>
38 #include <sys/user.h>
39 #include <sys/vnode.h>
40 #include <sys/file.h>
41 #include <sys/stream.h>
42 #include <sys/strsubr.h>
43 #include <sys/stropts.h>
44 #include <sys/tihdr.h>
45 #include <sys/var.h>
46 #include <sys/poll.h>
47 #include <sys/termio.h>
60 #include <sys/vtrace.h>
61 #include <sys/debug.h>
62 #include <sys/strredir.h>
63 #include <sys/fs/fifonode.h>
64 #include <sys/fs/snode.h>
65 #include <sys/strlog.h>
66 #include <sys/strsun.h>
67 #include <sys/project.h>
68 #include <sys/kbio.h>
69 #include <sys/msio.h>
70 #include <sys/tty.h>
71 #include <sys/ptyvar.h>
72 #include <sys/vuid_event.h>
73 #include <sys/modctl.h>
74 #include <sys/sunddi.h>
75 #include <sys/sunldi_impl.h>
76 #include <sys/autoconf.h>
77 #include <sys/policy.h>
78 #include <sys/dld.h>
79 #include <sys/zone.h>
80 #include <c2/audit.h>
81
82 /*
83 * This define helps improve the readability of streams code while
84 * still maintaining a very old streams performance enhancement. The
85 * performance enhancement basically involved having all callers
86 * of straccess() perform the first check that straccess() will do
87 * locally before actually calling straccess(). (There by reducing
88 * the number of unnecessary calls to straccess().)
89 */
90 #define i_straccess(x, y) ((stp->sd_sidp == NULL) ? 0 : \
91 (stp->sd_vnode->v_type == VFIFO) ? 0 : \
92 straccess((x), (y)))
93
94 /*
95 * what is mblk_pull_len?
96 *
97 * If a streams message consists of many short messages,
98 * a performance degradation occurs from copyout overhead.
99 * To decrease the per mblk overhead, messages that are
968 strget(struct stdata *stp, queue_t *q, struct uio *uiop, int first,
969 int *errorp)
970 {
971 mblk_t *bp;
972 int error;
973 ssize_t rbytes = 0;
974
975 /* Holding sd_lock prevents the read queue from changing */
976 ASSERT(MUTEX_HELD(&stp->sd_lock));
977
978 if (uiop != NULL && stp->sd_struiordq != NULL &&
979 q->q_first == NULL &&
980 (!first || (stp->sd_wakeq & RSLEEP))) {
981 /*
982 * Stream supports rwnext() for the read side.
983 * If this is the first time we're called by e.g. strread
984 * only do the downcall if there is a deferred wakeup
985 * (registered in sd_wakeq).
986 */
987 struiod_t uiod;
988
989 if (first)
990 stp->sd_wakeq &= ~RSLEEP;
991
992 (void) uiodup(uiop, &uiod.d_uio, uiod.d_iov,
993 sizeof (uiod.d_iov) / sizeof (*uiod.d_iov));
994 uiod.d_mp = 0;
995 /*
996 * Mark that a thread is in rwnext on the read side
997 * to prevent strrput from nacking ioctls immediately.
998 * When the last concurrent rwnext returns
999 * the ioctls are nack'ed.
1000 */
1001 ASSERT(MUTEX_HELD(&stp->sd_lock));
1002 stp->sd_struiodnak++;
1003 /*
1004 * Note: rwnext will drop sd_lock.
1005 */
1006 error = rwnext(q, &uiod);
1007 ASSERT(MUTEX_NOT_HELD(&stp->sd_lock));
1008 mutex_enter(&stp->sd_lock);
1009 stp->sd_struiodnak--;
1010 while (stp->sd_struiodnak == 0 &&
1011 ((bp = stp->sd_struionak) != NULL)) {
1012 stp->sd_struionak = bp->b_next;
1013 bp->b_next = NULL;
1014 bp->b_datap->db_type = M_IOCNAK;
1015 /*
1016 * Protect against the driver passing up
1017 * messages after it has done a qprocsoff.
1018 */
1019 if (_OTHERQ(q)->q_next == NULL)
1020 freemsg(bp);
1021 else {
1022 mutex_exit(&stp->sd_lock);
1023 qreply(q, bp);
1024 mutex_enter(&stp->sd_lock);
1025 }
1026 }
1027 ASSERT(MUTEX_HELD(&stp->sd_lock));
1028 if (error == 0 || error == EWOULDBLOCK) {
1029 if ((bp = uiod.d_mp) != NULL) {
1030 *errorp = 0;
1031 ASSERT(MUTEX_HELD(&stp->sd_lock));
1032 return (bp);
1033 }
1034 error = 0;
1035 } else if (error == EINVAL) {
1036 /*
1037 * The stream plumbing must have
1038 * changed while we were away, so
1039 * just turn off rwnext()s.
1040 */
1041 error = 0;
1042 } else if (error == EBUSY) {
1043 /*
1044 * The module might have data in transit using putnext
1045 * Fall back on waiting + getq.
1046 */
1047 error = 0;
1048 } else {
1049 *errorp = error;
1050 ASSERT(MUTEX_HELD(&stp->sd_lock));
1051 return (NULL);
1052 }
1053 /*
1054 * Try a getq in case a rwnext() generated mblk
1055 * has bubbled up via strrput().
1056 */
1057 }
1058 *errorp = 0;
1059 ASSERT(MUTEX_HELD(&stp->sd_lock));
1060
1061 /*
1062 * If we have a valid uio, try and use this as a guide for how
1063 * many bytes to retrieve from the queue via getq_noenab().
1064 * Doing this can avoid unneccesary counting of overlong
1065 * messages in putback(). We currently only do this for sockets
1066 * and only if there is no sd_rputdatafunc hook.
1067 *
1068 * The sd_rputdatafunc hook transforms the entire message
1069 * before any bytes in it can be given to a client. So, rbytes
1070 * must be 0 if there is a hook.
1071 */
1072 if ((uiop != NULL) && (stp->sd_vnode->v_type == VSOCK) &&
2527 *
2528 * Caller should *not* hold sd_lock.
2529 * When EWOULDBLOCK is returned the caller has to redo the canputnext
2530 * under sd_lock in order to avoid missing a backenabling wakeup.
2531 *
2532 * Use iosize = -1 to not send any M_DATA. iosize = 0 sends zero-length M_DATA.
2533 *
2534 * Set MSG_IGNFLOW in flags to ignore flow control for hipri messages.
2535 * For sync streams we can only ignore flow control by reverting to using
2536 * putnext.
2537 *
2538 * If sd_maxblk is less than *iosize this routine might return without
2539 * transferring all of *iosize. In all cases, on return *iosize will contain
2540 * the amount of data that was transferred.
2541 */
2542 static int
2543 strput(struct stdata *stp, mblk_t *mctl, struct uio *uiop, ssize_t *iosize,
2544 int b_flag, int pri, int flags)
2545 {
2546 struiod_t uiod;
2547 mblk_t *mp;
2548 queue_t *wqp = stp->sd_wrq;
2549 int error = 0;
2550 ssize_t count = *iosize;
2551
2552 ASSERT(MUTEX_NOT_HELD(&stp->sd_lock));
2553
2554 if (uiop != NULL && count >= 0)
2555 flags |= stp->sd_struiowrq ? STRUIO_POSTPONE : 0;
2556
2557 if (!(flags & STRUIO_POSTPONE)) {
2558 /*
2559 * Use regular canputnext, strmakedata, putnext sequence.
2560 */
2561 if (pri == 0) {
2562 if (!canputnext(wqp) && !(flags & MSG_IGNFLOW)) {
2563 freemsg(mctl);
2564 return (EWOULDBLOCK);
2565 }
2566 } else {
2618 if ((error = strmakedata(iosize, uiop, stp, flags, &mp)) != 0) {
2619 freemsg(mctl);
2620 /*
2621 * map EAGAIN to ENOMEM since EAGAIN means "flow controlled".
2622 */
2623 return (error == EAGAIN ? ENOMEM : error);
2624 }
2625 if (mctl != NULL) {
2626 if (mctl->b_cont == NULL)
2627 mctl->b_cont = mp;
2628 else if (mp != NULL)
2629 linkb(mctl, mp);
2630 mp = mctl;
2631 } else if (mp == NULL) {
2632 return (0);
2633 }
2634
2635 mp->b_flag |= b_flag;
2636 mp->b_band = (uchar_t)pri;
2637
2638 (void) uiodup(uiop, &uiod.d_uio, uiod.d_iov,
2639 sizeof (uiod.d_iov) / sizeof (*uiod.d_iov));
2640 uiod.d_uio.uio_offset = 0;
2641 uiod.d_mp = mp;
2642 error = rwnext(wqp, &uiod);
2643 if (! uiod.d_mp) {
2644 uioskip(uiop, *iosize);
2645 return (error);
2646 }
2647 ASSERT(mp == uiod.d_mp);
2648 if (error == EINVAL) {
2649 /*
2650 * The stream plumbing must have changed while
2651 * we were away, so just turn off rwnext()s.
2652 */
2653 error = 0;
2654 } else if (error == EBUSY || error == EWOULDBLOCK) {
2655 /*
2656 * Couldn't enter a perimeter or took a page fault,
2657 * so fall-back to putnext().
2658 */
2659 error = 0;
2660 } else {
2661 freemsg(mp);
2662 return (error);
2663 }
2664 /* Have to check canput before consuming data from the uio */
2665 if (pri == 0) {
2666 if (!canputnext(wqp) && !(flags & MSG_IGNFLOW)) {
2667 freemsg(mp);
2668 return (EWOULDBLOCK);
2669 }
2670 } else {
2671 if (!bcanputnext(wqp, pri) && !(flags & MSG_IGNFLOW)) {
2672 freemsg(mp);
2673 return (EWOULDBLOCK);
2674 }
2675 }
2676 ASSERT(mp == uiod.d_mp);
2677 /* Copyin data from the uio */
2678 if ((error = struioget(wqp, mp, &uiod, 0)) != 0) {
2679 freemsg(mp);
2680 return (error);
2681 }
2682 uioskip(uiop, *iosize);
2683 if (flags & MSG_IGNFLOW) {
2684 /*
2685 * XXX Hack: Don't get stuck running service procedures.
2686 * This is needed for sockfs when sending the unbind message
2687 * out of the rput procedure - we don't want a put procedure
2688 * to run service procedures.
2689 */
2690 putnext(wqp, mp);
2691 } else {
2692 stream_willservice(stp);
2693 putnext(wqp, mp);
2694 stream_runservice(stp);
2695 }
2696 return (0);
2697 }
2698
2699 /*
2700 * Write attempts to break the write request into messages conforming
2701 * with the minimum and maximum packet sizes set downstream.
2702 *
2703 * Write will not block if downstream queue is full and
2704 * O_NDELAY is set, otherwise it will block waiting for the queue to get room.
2705 *
2706 * A write of zero bytes gets packaged into a zero length message and sent
2707 * downstream like any other message.
2708 *
2709 * If buffers of the requested sizes are not available, the write will
2710 * sleep until the buffers become available.
2711 *
2712 * Write (if specified) will supply a write offset in a message if it
2713 * makes sense. This can be specified by downstream modules as part of
2714 * a M_SETOPTS message. Write will not supply the write offset if it
2715 * cannot supply any data in a buffer. In other words, write will never
3161 case LDSMAP: /* Obsolete */
3162 case DIOCSETP:
3163 case I_FLUSH:
3164 case I_SRDOPT:
3165 case I_SETSIG:
3166 case I_SWROPT:
3167 case I_FLUSHBAND:
3168 case I_SETCLTIME:
3169 case I_SERROPT:
3170 case I_ESETSIG:
3171 case FIONBIO:
3172 case FIOASYNC:
3173 case FIOSETOWN:
3174 case JBOOT: /* Obsolete */
3175 case JTERM: /* Obsolete */
3176 case JTIMOM: /* Obsolete */
3177 case JZOMBOOT: /* Obsolete */
3178 case JAGENT: /* Obsolete */
3179 case JTRUN: /* Obsolete */
3180 case JXTPROTO: /* Obsolete */
3181 return (JCSETP);
3182 }
3183
3184 return (JCGETP);
3185 }
3186
3187 /*
3188 * ioctl for streams
3189 */
3190 int
3191 strioctl(struct vnode *vp, int cmd, intptr_t arg, int flag, int copyflag,
3192 cred_t *crp, int *rvalp)
3193 {
3194 struct stdata *stp;
3195 struct strcmd *scp;
3196 struct strioctl strioc;
3197 struct uio uio;
3198 struct iovec iov;
3199 int access;
3200 mblk_t *mp;
|
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
22 /* All Rights Reserved */
23
24
25 /*
26 * Copyright (c) 1988, 2010, Oracle and/or its affiliates. All rights reserved.
27 * Copyright 2015, Joyent, Inc. All rights reserved.
28 */
29
30 #include <sys/types.h>
31 #include <sys/sysmacros.h>
32 #include <sys/param.h>
33 #include <sys/errno.h>
34 #include <sys/signal.h>
35 #include <sys/stat.h>
36 #include <sys/proc.h>
37 #include <sys/cred.h>
38 #include <sys/user.h>
39 #include <sys/vnode.h>
40 #include <sys/file.h>
41 #include <sys/stream.h>
42 #include <sys/strsubr.h>
43 #include <sys/stropts.h>
44 #include <sys/tihdr.h>
45 #include <sys/var.h>
46 #include <sys/poll.h>
47 #include <sys/termio.h>
60 #include <sys/vtrace.h>
61 #include <sys/debug.h>
62 #include <sys/strredir.h>
63 #include <sys/fs/fifonode.h>
64 #include <sys/fs/snode.h>
65 #include <sys/strlog.h>
66 #include <sys/strsun.h>
67 #include <sys/project.h>
68 #include <sys/kbio.h>
69 #include <sys/msio.h>
70 #include <sys/tty.h>
71 #include <sys/ptyvar.h>
72 #include <sys/vuid_event.h>
73 #include <sys/modctl.h>
74 #include <sys/sunddi.h>
75 #include <sys/sunldi_impl.h>
76 #include <sys/autoconf.h>
77 #include <sys/policy.h>
78 #include <sys/dld.h>
79 #include <sys/zone.h>
80 #include <sys/limits.h>
81 #include <c2/audit.h>
82
83 /*
84 * This define helps improve the readability of streams code while
85 * still maintaining a very old streams performance enhancement. The
86 * performance enhancement basically involved having all callers
87 * of straccess() perform the first check that straccess() will do
88 * locally before actually calling straccess(). (There by reducing
89 * the number of unnecessary calls to straccess().)
90 */
91 #define i_straccess(x, y) ((stp->sd_sidp == NULL) ? 0 : \
92 (stp->sd_vnode->v_type == VFIFO) ? 0 : \
93 straccess((x), (y)))
94
95 /*
96 * what is mblk_pull_len?
97 *
98 * If a streams message consists of many short messages,
99 * a performance degradation occurs from copyout overhead.
100 * To decrease the per mblk overhead, messages that are
969 strget(struct stdata *stp, queue_t *q, struct uio *uiop, int first,
970 int *errorp)
971 {
972 mblk_t *bp;
973 int error;
974 ssize_t rbytes = 0;
975
976 /* Holding sd_lock prevents the read queue from changing */
977 ASSERT(MUTEX_HELD(&stp->sd_lock));
978
979 if (uiop != NULL && stp->sd_struiordq != NULL &&
980 q->q_first == NULL &&
981 (!first || (stp->sd_wakeq & RSLEEP))) {
982 /*
983 * Stream supports rwnext() for the read side.
984 * If this is the first time we're called by e.g. strread
985 * only do the downcall if there is a deferred wakeup
986 * (registered in sd_wakeq).
987 */
988 struiod_t uiod;
989 struct iovec buf[IOV_MAX_STACK];
990 int iovlen = 0;
991
992 if (first)
993 stp->sd_wakeq &= ~RSLEEP;
994
995 if (uiop->uio_iovcnt > IOV_MAX_STACK) {
996 iovlen = uiop->uio_iovcnt * sizeof (iovec_t);
997 uiod.d_iov = kmem_alloc(iovlen, KM_SLEEP);
998 } else {
999 uiod.d_iov = buf;
1000 }
1001
1002 (void) uiodup(uiop, &uiod.d_uio, uiod.d_iov, uiop->uio_iovcnt);
1003 uiod.d_mp = 0;
1004 /*
1005 * Mark that a thread is in rwnext on the read side
1006 * to prevent strrput from nacking ioctls immediately.
1007 * When the last concurrent rwnext returns
1008 * the ioctls are nack'ed.
1009 */
1010 ASSERT(MUTEX_HELD(&stp->sd_lock));
1011 stp->sd_struiodnak++;
1012 /*
1013 * Note: rwnext will drop sd_lock.
1014 */
1015 error = rwnext(q, &uiod);
1016 ASSERT(MUTEX_NOT_HELD(&stp->sd_lock));
1017 mutex_enter(&stp->sd_lock);
1018 stp->sd_struiodnak--;
1019 while (stp->sd_struiodnak == 0 &&
1020 ((bp = stp->sd_struionak) != NULL)) {
1021 stp->sd_struionak = bp->b_next;
1022 bp->b_next = NULL;
1023 bp->b_datap->db_type = M_IOCNAK;
1024 /*
1025 * Protect against the driver passing up
1026 * messages after it has done a qprocsoff.
1027 */
1028 if (_OTHERQ(q)->q_next == NULL)
1029 freemsg(bp);
1030 else {
1031 mutex_exit(&stp->sd_lock);
1032 qreply(q, bp);
1033 mutex_enter(&stp->sd_lock);
1034 }
1035 }
1036 ASSERT(MUTEX_HELD(&stp->sd_lock));
1037 if (error == 0 || error == EWOULDBLOCK) {
1038 if ((bp = uiod.d_mp) != NULL) {
1039 *errorp = 0;
1040 ASSERT(MUTEX_HELD(&stp->sd_lock));
1041 if (iovlen != 0)
1042 kmem_free(uiod.d_iov, iovlen);
1043 return (bp);
1044 }
1045 error = 0;
1046 } else if (error == EINVAL) {
1047 /*
1048 * The stream plumbing must have
1049 * changed while we were away, so
1050 * just turn off rwnext()s.
1051 */
1052 error = 0;
1053 } else if (error == EBUSY) {
1054 /*
1055 * The module might have data in transit using putnext
1056 * Fall back on waiting + getq.
1057 */
1058 error = 0;
1059 } else {
1060 *errorp = error;
1061 ASSERT(MUTEX_HELD(&stp->sd_lock));
1062 if (iovlen != 0)
1063 kmem_free(uiod.d_iov, iovlen);
1064 return (NULL);
1065 }
1066
1067 if (iovlen != 0)
1068 kmem_free(uiod.d_iov, iovlen);
1069
1070 /*
1071 * Try a getq in case a rwnext() generated mblk
1072 * has bubbled up via strrput().
1073 */
1074 }
1075 *errorp = 0;
1076 ASSERT(MUTEX_HELD(&stp->sd_lock));
1077
1078 /*
1079 * If we have a valid uio, try and use this as a guide for how
1080 * many bytes to retrieve from the queue via getq_noenab().
1081 * Doing this can avoid unneccesary counting of overlong
1082 * messages in putback(). We currently only do this for sockets
1083 * and only if there is no sd_rputdatafunc hook.
1084 *
1085 * The sd_rputdatafunc hook transforms the entire message
1086 * before any bytes in it can be given to a client. So, rbytes
1087 * must be 0 if there is a hook.
1088 */
1089 if ((uiop != NULL) && (stp->sd_vnode->v_type == VSOCK) &&
2544 *
2545 * Caller should *not* hold sd_lock.
2546 * When EWOULDBLOCK is returned the caller has to redo the canputnext
2547 * under sd_lock in order to avoid missing a backenabling wakeup.
2548 *
2549 * Use iosize = -1 to not send any M_DATA. iosize = 0 sends zero-length M_DATA.
2550 *
2551 * Set MSG_IGNFLOW in flags to ignore flow control for hipri messages.
2552 * For sync streams we can only ignore flow control by reverting to using
2553 * putnext.
2554 *
2555 * If sd_maxblk is less than *iosize this routine might return without
2556 * transferring all of *iosize. In all cases, on return *iosize will contain
2557 * the amount of data that was transferred.
2558 */
2559 static int
2560 strput(struct stdata *stp, mblk_t *mctl, struct uio *uiop, ssize_t *iosize,
2561 int b_flag, int pri, int flags)
2562 {
2563 struiod_t uiod;
2564 struct iovec buf[IOV_MAX_STACK];
2565 int iovlen = 0;
2566 mblk_t *mp;
2567 queue_t *wqp = stp->sd_wrq;
2568 int error = 0;
2569 ssize_t count = *iosize;
2570
2571 ASSERT(MUTEX_NOT_HELD(&stp->sd_lock));
2572
2573 if (uiop != NULL && count >= 0)
2574 flags |= stp->sd_struiowrq ? STRUIO_POSTPONE : 0;
2575
2576 if (!(flags & STRUIO_POSTPONE)) {
2577 /*
2578 * Use regular canputnext, strmakedata, putnext sequence.
2579 */
2580 if (pri == 0) {
2581 if (!canputnext(wqp) && !(flags & MSG_IGNFLOW)) {
2582 freemsg(mctl);
2583 return (EWOULDBLOCK);
2584 }
2585 } else {
2637 if ((error = strmakedata(iosize, uiop, stp, flags, &mp)) != 0) {
2638 freemsg(mctl);
2639 /*
2640 * map EAGAIN to ENOMEM since EAGAIN means "flow controlled".
2641 */
2642 return (error == EAGAIN ? ENOMEM : error);
2643 }
2644 if (mctl != NULL) {
2645 if (mctl->b_cont == NULL)
2646 mctl->b_cont = mp;
2647 else if (mp != NULL)
2648 linkb(mctl, mp);
2649 mp = mctl;
2650 } else if (mp == NULL) {
2651 return (0);
2652 }
2653
2654 mp->b_flag |= b_flag;
2655 mp->b_band = (uchar_t)pri;
2656
2657 if (uiop->uio_iovcnt > IOV_MAX_STACK) {
2658 iovlen = uiop->uio_iovcnt * sizeof (iovec_t);
2659 uiod.d_iov = (struct iovec *)kmem_alloc(iovlen, KM_SLEEP);
2660 } else {
2661 uiod.d_iov = buf;
2662 }
2663
2664 (void) uiodup(uiop, &uiod.d_uio, uiod.d_iov, uiop->uio_iovcnt);
2665 uiod.d_uio.uio_offset = 0;
2666 uiod.d_mp = mp;
2667 error = rwnext(wqp, &uiod);
2668 if (! uiod.d_mp) {
2669 uioskip(uiop, *iosize);
2670 if (iovlen != 0)
2671 kmem_free(uiod.d_iov, iovlen);
2672 return (error);
2673 }
2674 ASSERT(mp == uiod.d_mp);
2675 if (error == EINVAL) {
2676 /*
2677 * The stream plumbing must have changed while
2678 * we were away, so just turn off rwnext()s.
2679 */
2680 error = 0;
2681 } else if (error == EBUSY || error == EWOULDBLOCK) {
2682 /*
2683 * Couldn't enter a perimeter or took a page fault,
2684 * so fall-back to putnext().
2685 */
2686 error = 0;
2687 } else {
2688 freemsg(mp);
2689 if (iovlen != 0)
2690 kmem_free(uiod.d_iov, iovlen);
2691 return (error);
2692 }
2693 /* Have to check canput before consuming data from the uio */
2694 if (pri == 0) {
2695 if (!canputnext(wqp) && !(flags & MSG_IGNFLOW)) {
2696 freemsg(mp);
2697 if (iovlen != 0)
2698 kmem_free(uiod.d_iov, iovlen);
2699 return (EWOULDBLOCK);
2700 }
2701 } else {
2702 if (!bcanputnext(wqp, pri) && !(flags & MSG_IGNFLOW)) {
2703 freemsg(mp);
2704 if (iovlen != 0)
2705 kmem_free(uiod.d_iov, iovlen);
2706 return (EWOULDBLOCK);
2707 }
2708 }
2709 ASSERT(mp == uiod.d_mp);
2710 /* Copyin data from the uio */
2711 if ((error = struioget(wqp, mp, &uiod, 0)) != 0) {
2712 freemsg(mp);
2713 if (iovlen != 0)
2714 kmem_free(uiod.d_iov, iovlen);
2715 return (error);
2716 }
2717 uioskip(uiop, *iosize);
2718 if (flags & MSG_IGNFLOW) {
2719 /*
2720 * XXX Hack: Don't get stuck running service procedures.
2721 * This is needed for sockfs when sending the unbind message
2722 * out of the rput procedure - we don't want a put procedure
2723 * to run service procedures.
2724 */
2725 putnext(wqp, mp);
2726 } else {
2727 stream_willservice(stp);
2728 putnext(wqp, mp);
2729 stream_runservice(stp);
2730 }
2731 if (iovlen != 0)
2732 kmem_free(uiod.d_iov, iovlen);
2733 return (0);
2734 }
2735
2736 /*
2737 * Write attempts to break the write request into messages conforming
2738 * with the minimum and maximum packet sizes set downstream.
2739 *
2740 * Write will not block if downstream queue is full and
2741 * O_NDELAY is set, otherwise it will block waiting for the queue to get room.
2742 *
2743 * A write of zero bytes gets packaged into a zero length message and sent
2744 * downstream like any other message.
2745 *
2746 * If buffers of the requested sizes are not available, the write will
2747 * sleep until the buffers become available.
2748 *
2749 * Write (if specified) will supply a write offset in a message if it
2750 * makes sense. This can be specified by downstream modules as part of
2751 * a M_SETOPTS message. Write will not supply the write offset if it
2752 * cannot supply any data in a buffer. In other words, write will never
3198 case LDSMAP: /* Obsolete */
3199 case DIOCSETP:
3200 case I_FLUSH:
3201 case I_SRDOPT:
3202 case I_SETSIG:
3203 case I_SWROPT:
3204 case I_FLUSHBAND:
3205 case I_SETCLTIME:
3206 case I_SERROPT:
3207 case I_ESETSIG:
3208 case FIONBIO:
3209 case FIOASYNC:
3210 case FIOSETOWN:
3211 case JBOOT: /* Obsolete */
3212 case JTERM: /* Obsolete */
3213 case JTIMOM: /* Obsolete */
3214 case JZOMBOOT: /* Obsolete */
3215 case JAGENT: /* Obsolete */
3216 case JTRUN: /* Obsolete */
3217 case JXTPROTO: /* Obsolete */
3218 case TIOCSETLD:
3219 return (JCSETP);
3220 }
3221
3222 return (JCGETP);
3223 }
3224
3225 /*
3226 * ioctl for streams
3227 */
3228 int
3229 strioctl(struct vnode *vp, int cmd, intptr_t arg, int flag, int copyflag,
3230 cred_t *crp, int *rvalp)
3231 {
3232 struct stdata *stp;
3233 struct strcmd *scp;
3234 struct strioctl strioc;
3235 struct uio uio;
3236 struct iovec iov;
3237 int access;
3238 mblk_t *mp;
|