Simplify vn_lock(), VOP_LOCK(), and VOP_UNLOCK() by removing the thread_t
[dragonfly.git] / sys / vfs / fifofs / fifo_vnops.c
CommitLineData
984263bc
MD
1/*
2 * Copyright (c) 1990, 1993, 1995
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)fifo_vnops.c 8.10 (Berkeley) 5/27/95
34 * $FreeBSD: src/sys/miscfs/fifofs/fifo_vnops.c,v 1.45.2.4 2003/04/22 10:11:24 bde Exp $
ca466bae 35 * $DragonFly: src/sys/vfs/fifofs/fifo_vnops.c,v 1.27 2006/05/05 21:15:09 dillon Exp $
984263bc
MD
36 */
37
38#include <sys/param.h>
39#include <sys/systm.h>
40#include <sys/unistd.h>
41#include <sys/kernel.h>
42#include <sys/lock.h>
43#include <sys/malloc.h>
44#include <sys/vnode.h>
45#include <sys/socket.h>
46#include <sys/socketvar.h>
47#include <sys/filio.h>
48#include <sys/fcntl.h>
49#include <sys/file.h>
50#include <sys/event.h>
51#include <sys/poll.h>
52#include <sys/un.h>
1f2de5d4 53#include "fifo.h"
984263bc
MD
54
55/*
56 * This structure is associated with the FIFO vnode and stores
57 * the state associated with the FIFO.
58 */
59struct fifoinfo {
60 struct socket *fi_readsock;
61 struct socket *fi_writesock;
62 long fi_readers;
63 long fi_writers;
64};
65
a6ee311a
RG
66static int fifo_badop (void);
67static int fifo_print (struct vop_print_args *);
e62afb5f 68static int fifo_lookup (struct vop_old_lookup_args *);
a6ee311a
RG
69static int fifo_open (struct vop_open_args *);
70static int fifo_close (struct vop_close_args *);
71static int fifo_read (struct vop_read_args *);
72static int fifo_write (struct vop_write_args *);
73static int fifo_ioctl (struct vop_ioctl_args *);
74static int fifo_poll (struct vop_poll_args *);
75static int fifo_kqfilter (struct vop_kqfilter_args *);
76static int fifo_inactive (struct vop_inactive_args *);
77static int fifo_bmap (struct vop_bmap_args *);
78static int fifo_pathconf (struct vop_pathconf_args *);
79static int fifo_advlock (struct vop_advlock_args *);
984263bc
MD
80
81static void filt_fifordetach(struct knote *kn);
82static int filt_fiforead(struct knote *kn, long hint);
83static void filt_fifowdetach(struct knote *kn);
84static int filt_fifowrite(struct knote *kn, long hint);
85
86static struct filterops fiforead_filtops =
87 { 1, NULL, filt_fifordetach, filt_fiforead };
88static struct filterops fifowrite_filtops =
89 { 1, NULL, filt_fifowdetach, filt_fifowrite };
90
2d3e977e 91struct vop_ops *fifo_vnode_vops;
984263bc 92static struct vnodeopv_entry_desc fifo_vnodeop_entries[] = {
625ddaba
JS
93 { &vop_default_desc, (vnodeopv_entry_t) vop_defaultop },
94 { &vop_access_desc, (vnodeopv_entry_t) vop_ebadf },
95 { &vop_advlock_desc, (vnodeopv_entry_t) fifo_advlock },
96 { &vop_bmap_desc, (vnodeopv_entry_t) fifo_bmap },
97 { &vop_close_desc, (vnodeopv_entry_t) fifo_close },
e62afb5f 98 { &vop_old_create_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba
JS
99 { &vop_getattr_desc, (vnodeopv_entry_t) vop_ebadf },
100 { &vop_inactive_desc, (vnodeopv_entry_t) fifo_inactive },
101 { &vop_ioctl_desc, (vnodeopv_entry_t) fifo_ioctl },
102 { &vop_kqfilter_desc, (vnodeopv_entry_t) fifo_kqfilter },
e62afb5f
MD
103 { &vop_old_link_desc, (vnodeopv_entry_t) fifo_badop },
104 { &vop_old_lookup_desc, (vnodeopv_entry_t) fifo_lookup },
105 { &vop_old_mkdir_desc, (vnodeopv_entry_t) fifo_badop },
106 { &vop_old_mknod_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba
JS
107 { &vop_open_desc, (vnodeopv_entry_t) fifo_open },
108 { &vop_pathconf_desc, (vnodeopv_entry_t) fifo_pathconf },
109 { &vop_poll_desc, (vnodeopv_entry_t) fifo_poll },
110 { &vop_print_desc, (vnodeopv_entry_t) fifo_print },
111 { &vop_read_desc, (vnodeopv_entry_t) fifo_read },
112 { &vop_readdir_desc, (vnodeopv_entry_t) fifo_badop },
113 { &vop_readlink_desc, (vnodeopv_entry_t) fifo_badop },
114 { &vop_reallocblks_desc, (vnodeopv_entry_t) fifo_badop },
115 { &vop_reclaim_desc, (vnodeopv_entry_t) vop_null },
e62afb5f
MD
116 { &vop_old_remove_desc, (vnodeopv_entry_t) fifo_badop },
117 { &vop_old_rename_desc, (vnodeopv_entry_t) fifo_badop },
118 { &vop_old_rmdir_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba 119 { &vop_setattr_desc, (vnodeopv_entry_t) vop_ebadf },
e62afb5f 120 { &vop_old_symlink_desc, (vnodeopv_entry_t) fifo_badop },
625ddaba 121 { &vop_write_desc, (vnodeopv_entry_t) fifo_write },
984263bc
MD
122 { NULL, NULL }
123};
124static struct vnodeopv_desc fifo_vnodeop_opv_desc =
dc1be39c 125 { &fifo_vnode_vops, fifo_vnodeop_entries, 0 };
984263bc
MD
126
127VNODEOP_SET(fifo_vnodeop_opv_desc);
128
5fd012e0
MD
129static MALLOC_DEFINE(M_FIFOINFO, "Fifo info", "Fifo info entries");
130
b5f12e21
CP
131/*
132 * fifo_vnoperate(struct vnodeop_desc *a_desc, ...)
133 */
984263bc 134int
b5f12e21 135fifo_vnoperate(struct vop_generic_args *ap)
984263bc 136{
0961aa92 137 return (VOCALL(fifo_vnode_vops, ap));
984263bc
MD
138}
139
140/*
141 * Trivial lookup routine that always fails.
b5f12e21
CP
142 *
143 * fifo_lookup(struct vnode *a_dvp, struct vnode **a_vpp,
144 * struct componentname *a_cnp)
984263bc
MD
145 */
146/* ARGSUSED */
147static int
e62afb5f 148fifo_lookup(struct vop_old_lookup_args *ap)
984263bc 149{
984263bc
MD
150 *ap->a_vpp = NULL;
151 return (ENOTDIR);
152}
153
154/*
155 * Open called to set up a new instance of a fifo or
156 * to find an active instance of a fifo.
b5f12e21
CP
157 *
158 * fifo_open(struct vnode *a_vp, int a_mode, struct ucred *a_cred,
159 * struct thread *a_td)
984263bc
MD
160 */
161/* ARGSUSED */
162static int
b5f12e21 163fifo_open(struct vop_open_args *ap)
984263bc
MD
164{
165 struct vnode *vp = ap->a_vp;
166 struct fifoinfo *fip;
984263bc
MD
167 struct socket *rso, *wso;
168 int error;
169
170 if ((fip = vp->v_fifoinfo) == NULL) {
5fd012e0 171 MALLOC(fip, struct fifoinfo *, sizeof(*fip), M_FIFOINFO, M_WAITOK);
984263bc 172 vp->v_fifoinfo = fip;
dadab5e9 173 error = socreate(AF_LOCAL, &rso, SOCK_STREAM, 0, ap->a_td);
984263bc 174 if (error) {
5fd012e0 175 free(fip, M_FIFOINFO);
984263bc
MD
176 vp->v_fifoinfo = NULL;
177 return (error);
178 }
179 fip->fi_readsock = rso;
dadab5e9 180 error = socreate(AF_LOCAL, &wso, SOCK_STREAM, 0, ap->a_td);
984263bc 181 if (error) {
b1ce5639 182 soclose(rso);
5fd012e0 183 free(fip, M_FIFOINFO);
984263bc
MD
184 vp->v_fifoinfo = NULL;
185 return (error);
186 }
187 fip->fi_writesock = wso;
188 error = unp_connect2(wso, rso);
189 if (error) {
b1ce5639
SW
190 soclose(wso);
191 soclose(rso);
5fd012e0 192 free(fip, M_FIFOINFO);
984263bc
MD
193 vp->v_fifoinfo = NULL;
194 return (error);
195 }
196 fip->fi_readers = fip->fi_writers = 0;
197 wso->so_snd.sb_lowat = PIPE_BUF;
198 rso->so_state |= SS_CANTRCVMORE;
199 }
200 if (ap->a_mode & FREAD) {
201 fip->fi_readers++;
202 if (fip->fi_readers == 1) {
203 fip->fi_writesock->so_state &= ~SS_CANTSENDMORE;
204 if (fip->fi_writers > 0) {
205 wakeup((caddr_t)&fip->fi_writers);
206 sowwakeup(fip->fi_writesock);
207 }
208 }
209 }
210 if (ap->a_mode & FWRITE) {
211 fip->fi_writers++;
212 if (fip->fi_writers == 1) {
213 fip->fi_readsock->so_state &= ~SS_CANTRCVMORE;
214 if (fip->fi_readers > 0) {
215 wakeup((caddr_t)&fip->fi_readers);
216 sorwakeup(fip->fi_writesock);
217 }
218 }
219 }
220 if ((ap->a_mode & FREAD) && (ap->a_mode & O_NONBLOCK) == 0) {
221 if (fip->fi_writers == 0) {
ca466bae 222 VOP_UNLOCK(vp, 0);
984263bc 223 error = tsleep((caddr_t)&fip->fi_readers,
377d4740 224 PCATCH, "fifoor", 0);
ca466bae 225 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
226 if (error)
227 goto bad;
228 /*
229 * We must have got woken up because we had a writer.
230 * That (and not still having one) is the condition
231 * that we must wait for.
232 */
233 }
234 }
235 if (ap->a_mode & FWRITE) {
236 if (ap->a_mode & O_NONBLOCK) {
237 if (fip->fi_readers == 0) {
238 error = ENXIO;
239 goto bad;
240 }
241 } else {
242 if (fip->fi_readers == 0) {
ca466bae 243 VOP_UNLOCK(vp, 0);
984263bc 244 error = tsleep((caddr_t)&fip->fi_writers,
377d4740 245 PCATCH, "fifoow", 0);
ca466bae 246 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
247 if (error)
248 goto bad;
249 /*
250 * We must have got woken up because we had
251 * a reader. That (and not still having one)
252 * is the condition that we must wait for.
253 */
254 }
255 }
256 }
8ddc6004 257 return (vop_stdopen(ap));
984263bc 258bad:
cbeb1f72 259 vop_stdopen(ap); /* bump opencount/writecount as appropriate */
3b568787 260 VOP_CLOSE(vp, ap->a_mode, ap->a_td);
984263bc
MD
261 return (error);
262}
263
264/*
265 * Vnode op for read
b5f12e21
CP
266 *
267 * fifo_read(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
268 * struct ucred *a_cred)
984263bc
MD
269 */
270/* ARGSUSED */
271static int
b5f12e21 272fifo_read(struct vop_read_args *ap)
984263bc
MD
273{
274 struct uio *uio = ap->a_uio;
275 struct socket *rso = ap->a_vp->v_fifoinfo->fi_readsock;
984263bc
MD
276 int error, startresid;
277
278#ifdef DIAGNOSTIC
279 if (uio->uio_rw != UIO_READ)
280 panic("fifo_read mode");
281#endif
282 if (uio->uio_resid == 0)
283 return (0);
284 if (ap->a_ioflag & IO_NDELAY)
285 rso->so_state |= SS_NBIO;
286 startresid = uio->uio_resid;
ca466bae 287 VOP_UNLOCK(ap->a_vp, 0);
984263bc
MD
288 error = soreceive(rso, (struct sockaddr **)0, uio, (struct mbuf **)0,
289 (struct mbuf **)0, (int *)0);
ca466bae 290 vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
291 if (ap->a_ioflag & IO_NDELAY)
292 rso->so_state &= ~SS_NBIO;
293 return (error);
294}
295
296/*
297 * Vnode op for write
b5f12e21
CP
298 *
299 * fifo_write(struct vnode *a_vp, struct uio *a_uio, int a_ioflag,
300 * struct ucred *a_cred)
984263bc
MD
301 */
302/* ARGSUSED */
303static int
b5f12e21 304fifo_write(struct vop_write_args *ap)
984263bc
MD
305{
306 struct socket *wso = ap->a_vp->v_fifoinfo->fi_writesock;
dadab5e9 307 struct thread *td = ap->a_uio->uio_td;
984263bc
MD
308 int error;
309
310#ifdef DIAGNOSTIC
311 if (ap->a_uio->uio_rw != UIO_WRITE)
312 panic("fifo_write mode");
313#endif
314 if (ap->a_ioflag & IO_NDELAY)
315 wso->so_state |= SS_NBIO;
ca466bae 316 VOP_UNLOCK(ap->a_vp, 0);
984263bc 317 error = sosend(wso, (struct sockaddr *)0, ap->a_uio, 0,
dadab5e9 318 (struct mbuf *)0, 0, td);
ca466bae 319 vn_lock(ap->a_vp, LK_EXCLUSIVE | LK_RETRY);
984263bc
MD
320 if (ap->a_ioflag & IO_NDELAY)
321 wso->so_state &= ~SS_NBIO;
322 return (error);
323}
324
325/*
326 * Device ioctl operation.
b5f12e21
CP
327 *
328 * fifo_ioctl(struct vnode *a_vp, int a_command, caddr_t a_data, int a_fflag,
329 * struct ucred *a_cred, struct thread *a_td)
984263bc
MD
330 */
331/* ARGSUSED */
332static int
b5f12e21 333fifo_ioctl(struct vop_ioctl_args *ap)
984263bc 334{
9443ca22 335 struct file filetmp; /* Local */
984263bc
MD
336 int error;
337
338 if (ap->a_command == FIONBIO)
339 return (0);
340 if (ap->a_fflag & FREAD) {
fbb4eeab 341 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_readsock;
dadab5e9 342 error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_td);
984263bc
MD
343 if (error)
344 return (error);
345 }
346 if (ap->a_fflag & FWRITE) {
fbb4eeab 347 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_writesock;
dadab5e9 348 error = soo_ioctl(&filetmp, ap->a_command, ap->a_data, ap->a_td);
984263bc
MD
349 if (error)
350 return (error);
351 }
352 return (0);
353}
354
b5f12e21
CP
355/*
356 * fifo_kqfilter(struct vnode *a_vp, struct knote *a_kn)
357 */
984263bc
MD
358/* ARGSUSED */
359static int
b5f12e21 360fifo_kqfilter(struct vop_kqfilter_args *ap)
984263bc
MD
361{
362 struct fifoinfo *fi = ap->a_vp->v_fifoinfo;
363 struct socket *so;
364 struct sockbuf *sb;
365
366 switch (ap->a_kn->kn_filter) {
367 case EVFILT_READ:
368 ap->a_kn->kn_fop = &fiforead_filtops;
369 so = fi->fi_readsock;
370 sb = &so->so_rcv;
371 break;
372 case EVFILT_WRITE:
373 ap->a_kn->kn_fop = &fifowrite_filtops;
374 so = fi->fi_writesock;
375 sb = &so->so_snd;
376 break;
377 default:
378 return (1);
379 }
380
381 ap->a_kn->kn_hook = (caddr_t)so;
382
383 SLIST_INSERT_HEAD(&sb->sb_sel.si_note, ap->a_kn, kn_selnext);
384 sb->sb_flags |= SB_KNOTE;
385
386 return (0);
387}
388
389static void
390filt_fifordetach(struct knote *kn)
391{
392 struct socket *so = (struct socket *)kn->kn_hook;
393
394 SLIST_REMOVE(&so->so_rcv.sb_sel.si_note, kn, knote, kn_selnext);
395 if (SLIST_EMPTY(&so->so_rcv.sb_sel.si_note))
396 so->so_rcv.sb_flags &= ~SB_KNOTE;
397}
398
399static int
400filt_fiforead(struct knote *kn, long hint)
401{
402 struct socket *so = (struct socket *)kn->kn_hook;
403
404 kn->kn_data = so->so_rcv.sb_cc;
405 if (so->so_state & SS_CANTRCVMORE) {
406 kn->kn_flags |= EV_EOF;
407 return (1);
408 }
409 kn->kn_flags &= ~EV_EOF;
410 return (kn->kn_data > 0);
411}
412
413static void
414filt_fifowdetach(struct knote *kn)
415{
416 struct socket *so = (struct socket *)kn->kn_hook;
417
418 SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext);
419 if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note))
420 so->so_snd.sb_flags &= ~SB_KNOTE;
421}
422
423static int
424filt_fifowrite(struct knote *kn, long hint)
425{
426 struct socket *so = (struct socket *)kn->kn_hook;
427
428 kn->kn_data = sbspace(&so->so_snd);
429 if (so->so_state & SS_CANTSENDMORE) {
430 kn->kn_flags |= EV_EOF;
431 return (1);
432 }
433 kn->kn_flags &= ~EV_EOF;
434 return (kn->kn_data >= so->so_snd.sb_lowat);
435}
436
b5f12e21
CP
437/*
438 * fifo_poll(struct vnode *a_vp, int a_events, struct ucred *a_cred,
439 * struct thread *a_td)
440 */
984263bc
MD
441/* ARGSUSED */
442static int
b5f12e21 443fifo_poll(struct vop_poll_args *ap)
984263bc
MD
444{
445 struct file filetmp;
d08a3c4d
HP
446 int events, revents = 0;
447
630a348c 448 events = ap->a_events &
9443ca22 449 (POLLIN | POLLINIGNEOF | POLLPRI | POLLRDNORM | POLLRDBAND);
d08a3c4d
HP
450 if (events) {
451 /*
9443ca22
HP
452 * If POLLIN or POLLRDNORM is requested and POLLINIGNEOF is
453 * not, then convert the first two to the last one. This
454 * tells the socket poll function to ignore EOF so that we
455 * block if there is no writer (and no data). Callers can
456 * set POLLINIGNEOF to get non-blocking behavior.
d08a3c4d 457 */
ad4bd3a5
HP
458 if (events & (POLLIN | POLLRDNORM) &&
459 !(events & POLLINIGNEOF)) {
d08a3c4d
HP
460 events &= ~(POLLIN | POLLRDNORM);
461 events |= POLLINIGNEOF;
462 }
9443ca22 463
fbb4eeab 464 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_readsock;
984263bc 465 if (filetmp.f_data)
d08a3c4d 466 revents |= soo_poll(&filetmp, events, ap->a_cred,
dadab5e9 467 ap->a_td);
d08a3c4d 468
9443ca22
HP
469 /* Reverse the above conversion. */
470 if ((revents & POLLINIGNEOF) &&
471 !(ap->a_events & POLLINIGNEOF)) {
472 revents |= (ap->a_events & (POLLIN | POLLRDNORM));
d08a3c4d 473 revents &= ~POLLINIGNEOF;
d08a3c4d 474 }
984263bc 475 }
d08a3c4d
HP
476 events = ap->a_events & (POLLOUT | POLLWRNORM | POLLWRBAND);
477 if (events) {
fbb4eeab 478 filetmp.f_data = ap->a_vp->v_fifoinfo->fi_writesock;
984263bc 479 if (filetmp.f_data)
d08a3c4d 480 revents |= soo_poll(&filetmp, events, ap->a_cred,
dadab5e9 481 ap->a_td);
984263bc
MD
482 }
483 return (revents);
484}
485
b5f12e21
CP
486/*
487 * fifo_inactive(struct vnode *a_vp, struct thread *a_td)
488 */
984263bc 489static int
b5f12e21 490fifo_inactive(struct vop_inactive_args *ap)
984263bc 491{
984263bc
MD
492 return (0);
493}
494
495/*
496 * This is a noop, simply returning what one has been given.
b5f12e21 497 *
54078292
MD
498 * fifo_bmap(struct vnode *a_vp, off_t a_loffset, struct vnode **a_vpp,
499 * off_t *a_doffsetp, int *a_runp, int *a_runb)
984263bc
MD
500 */
501static int
b5f12e21 502fifo_bmap(struct vop_bmap_args *ap)
984263bc 503{
984263bc
MD
504 if (ap->a_vpp != NULL)
505 *ap->a_vpp = ap->a_vp;
54078292
MD
506 if (ap->a_doffsetp != NULL)
507 *ap->a_doffsetp = ap->a_loffset;
984263bc
MD
508 if (ap->a_runp != NULL)
509 *ap->a_runp = 0;
510 if (ap->a_runb != NULL)
511 *ap->a_runb = 0;
512 return (0);
513}
514
515/*
516 * Device close routine
b5f12e21
CP
517 *
518 * fifo_close(struct vnode *a_vp, int a_fflag, struct ucred *a_cred,
519 * struct thread *a_td)
984263bc
MD
520 */
521/* ARGSUSED */
522static int
b5f12e21 523fifo_close(struct vop_close_args *ap)
984263bc 524{
0e99e805
RG
525 struct vnode *vp = ap->a_vp;
526 struct fifoinfo *fip = vp->v_fifoinfo;
984263bc
MD
527 int error1, error2;
528
529 if (ap->a_fflag & FREAD) {
530 fip->fi_readers--;
531 if (fip->fi_readers == 0)
532 socantsendmore(fip->fi_writesock);
533 }
534 if (ap->a_fflag & FWRITE) {
535 fip->fi_writers--;
536 if (fip->fi_writers == 0)
537 socantrcvmore(fip->fi_readsock);
538 }
8ddc6004
MD
539 if (vp->v_usecount > 1) {
540 vop_stdclose(ap);
984263bc 541 return (0);
8ddc6004 542 }
984263bc
MD
543 error1 = soclose(fip->fi_readsock);
544 error2 = soclose(fip->fi_writesock);
5fd012e0 545 FREE(fip, M_FIFOINFO);
984263bc
MD
546 vp->v_fifoinfo = NULL;
547 if (error1)
548 return (error1);
8ddc6004 549 vop_stdclose(ap);
984263bc
MD
550 return (error2);
551}
552
553
554/*
555 * Print out internal contents of a fifo vnode.
556 */
557int
b5f12e21 558fifo_printinfo(struct vnode *vp)
984263bc 559{
0e99e805 560 struct fifoinfo *fip = vp->v_fifoinfo;
984263bc
MD
561
562 printf(", fifo with %ld readers and %ld writers",
563 fip->fi_readers, fip->fi_writers);
564 return (0);
565}
566
567/*
568 * Print out the contents of a fifo vnode.
b5f12e21
CP
569 *
570 * fifo_print(struct vnode *a_vp)
984263bc
MD
571 */
572static int
b5f12e21 573fifo_print(struct vop_print_args *ap)
984263bc 574{
984263bc
MD
575 printf("tag VT_NON");
576 fifo_printinfo(ap->a_vp);
577 printf("\n");
578 return (0);
579}
580
581/*
582 * Return POSIX pathconf information applicable to fifo's.
b5f12e21
CP
583 *
584 * fifo_pathconf(struct vnode *a_vp, int a_name, int *a_retval)
984263bc
MD
585 */
586int
b5f12e21 587fifo_pathconf(struct vop_pathconf_args *ap)
984263bc 588{
984263bc
MD
589 switch (ap->a_name) {
590 case _PC_LINK_MAX:
591 *ap->a_retval = LINK_MAX;
592 return (0);
593 case _PC_PIPE_BUF:
594 *ap->a_retval = PIPE_BUF;
595 return (0);
596 case _PC_CHOWN_RESTRICTED:
597 *ap->a_retval = 1;
598 return (0);
599 default:
600 return (EINVAL);
601 }
602 /* NOTREACHED */
603}
604
605/*
606 * Fifo advisory byte-level locks.
b5f12e21
CP
607 *
608 * fifo_advlock(struct vnode *a_vp, caddr_t a_id, int a_op, struct flock *a_fl,
609 * int a_flags)
984263bc
MD
610 */
611/* ARGSUSED */
612static int
b5f12e21 613fifo_advlock(struct vop_advlock_args *ap)
984263bc 614{
984263bc
MD
615 return (ap->a_flags & F_FLOCK ? EOPNOTSUPP : EINVAL);
616}
617
618/*
619 * Fifo bad operation
620 */
621static int
b5f12e21 622fifo_badop(void)
984263bc 623{
984263bc
MD
624 panic("fifo_badop called");
625 /* NOTREACHED */
626}