device switch 1/many: Remove d_autoq, add d_clone (where d_autoq was).
[dragonfly.git] / sys / kern / vfs_vnops.c
1 /*
2  * Copyright (c) 1982, 1986, 1989, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  * (c) UNIX System Laboratories, Inc.
5  * All or some portions of this file are derived from material licensed
6  * to the University of California by American Telephone and Telegraph
7  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8  * the permission of UNIX System Laboratories, Inc.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *      This product includes software developed by the University of
21  *      California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *      @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94
39  * $FreeBSD: src/sys/kern/vfs_vnops.c,v 1.87.2.13 2002/12/29 18:19:53 dillon Exp $
40  * $DragonFly: src/sys/kern/vfs_vnops.c,v 1.19 2004/05/13 23:49:23 dillon Exp $
41  */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/fcntl.h>
46 #include <sys/file.h>
47 #include <sys/stat.h>
48 #include <sys/proc.h>
49 #include <sys/mount.h>
50 #include <sys/namei.h>
51 #include <sys/vnode.h>
52 #include <sys/buf.h>
53 #include <sys/filio.h>
54 #include <sys/ttycom.h>
55 #include <sys/conf.h>
56 #include <sys/syslog.h>
57
58 static int vn_closefile (struct file *fp, struct thread *td);
59 static int vn_ioctl (struct file *fp, u_long com, caddr_t data, 
60                 struct thread *td);
61 static int vn_read (struct file *fp, struct uio *uio, 
62                 struct ucred *cred, int flags, struct thread *td);
63 static int vn_poll (struct file *fp, int events, struct ucred *cred,
64                 struct thread *td);
65 static int vn_kqfilter (struct file *fp, struct knote *kn);
66 static int vn_statfile (struct file *fp, struct stat *sb, struct thread *td);
67 static int vn_write (struct file *fp, struct uio *uio, 
68                 struct ucred *cred, int flags, struct thread *td);
69
70 struct  fileops vnops = {
71         NULL,   /* port */
72         NULL,   /* clone */
73         vn_read, vn_write, vn_ioctl, vn_poll, vn_kqfilter,
74         vn_statfile, vn_closefile
75 };
76
77 /*
78  * Common code for vnode open operations.
79  * Check permissions, and call the VOP_OPEN or VOP_CREATE routine.
80  * 
81  * Note that this does NOT free nameidata for the successful case,
82  * due to the NDINIT being done elsewhere.
83  */
84 int
85 vn_open(ndp, fmode, cmode)
86         struct nameidata *ndp;
87         int fmode, cmode;
88 {
89         struct vnode *vp;
90         struct thread *td = ndp->ni_cnd.cn_td;
91         struct ucred *cred = ndp->ni_cnd.cn_cred;
92         struct vattr vat;
93         struct vattr *vap = &vat;
94         int mode, error;
95
96         KKASSERT(cred == td->td_proc->p_ucred);
97
98         if (fmode & O_CREAT) {
99                 ndp->ni_cnd.cn_nameiop = NAMEI_CREATE;
100                 ndp->ni_cnd.cn_flags = CNP_LOCKPARENT | CNP_LOCKLEAF;
101                 if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0)
102                         ndp->ni_cnd.cn_flags |= CNP_FOLLOW;
103                 bwillwrite();
104                 error = namei(ndp);
105                 if (error)
106                         return (error);
107                 if (ndp->ni_vp == NULL) {
108                         VATTR_NULL(vap);
109                         vap->va_type = VREG;
110                         vap->va_mode = cmode;
111                         if (fmode & O_EXCL)
112                                 vap->va_vaflags |= VA_EXCLUSIVE;
113                         VOP_LEASE(ndp->ni_dvp, td, cred, LEASE_WRITE);
114                         error = VOP_CREATE(ndp->ni_dvp, NCPNULL, &ndp->ni_vp,
115                                            &ndp->ni_cnd, vap);
116                         if (error) {
117                                 NDFREE(ndp, NDF_ONLY_PNBUF);
118                                 vput(ndp->ni_dvp);
119                                 return (error);
120                         }
121                         vput(ndp->ni_dvp);
122                         ASSERT_VOP_UNLOCKED(ndp->ni_dvp, "create");
123                         ASSERT_VOP_LOCKED(ndp->ni_vp, "create");
124                         fmode &= ~O_TRUNC;
125                         vp = ndp->ni_vp;
126                 } else {
127                         if (ndp->ni_dvp == ndp->ni_vp)
128                                 vrele(ndp->ni_dvp);
129                         else
130                                 vput(ndp->ni_dvp);
131                         ndp->ni_dvp = NULL;
132                         vp = ndp->ni_vp;
133                         if (fmode & O_EXCL) {
134                                 error = EEXIST;
135                                 goto bad;
136                         }
137                         fmode &= ~O_CREAT;
138                 }
139         } else {
140                 ndp->ni_cnd.cn_nameiop = NAMEI_LOOKUP;
141                 ndp->ni_cnd.cn_flags = CNP_LOCKLEAF |
142                     ((fmode & O_NOFOLLOW) ? 0 : CNP_FOLLOW);
143                 error = namei(ndp);
144                 if (error)
145                         return (error);
146                 vp = ndp->ni_vp;
147         }
148         if (vp->v_type == VLNK) {
149                 error = EMLINK;
150                 goto bad;
151         }
152         if (vp->v_type == VSOCK) {
153                 error = EOPNOTSUPP;
154                 goto bad;
155         }
156         if ((fmode & O_CREAT) == 0) {
157                 mode = 0;
158                 if (fmode & (FWRITE | O_TRUNC)) {
159                         if (vp->v_type == VDIR) {
160                                 error = EISDIR;
161                                 goto bad;
162                         }
163                         error = vn_writechk(vp);
164                         if (error)
165                                 goto bad;
166                         mode |= VWRITE;
167                 }
168                 if (fmode & FREAD)
169                         mode |= VREAD;
170                 if (mode) {
171                         error = VOP_ACCESS(vp, mode, cred, td);
172                         if (error)
173                                 goto bad;
174                 }
175         }
176         if (fmode & O_TRUNC) {
177                 VOP_UNLOCK(vp, NULL, 0, td);                    /* XXX */
178                 VOP_LEASE(vp, td, cred, LEASE_WRITE);
179                 vn_lock(vp, NULL, LK_EXCLUSIVE | LK_RETRY, td); /* XXX */
180                 VATTR_NULL(vap);
181                 vap->va_size = 0;
182                 error = VOP_SETATTR(vp, vap, cred, td);
183                 if (error)
184                         goto bad;
185         }
186         error = VOP_OPEN(vp, fmode, cred, td);
187         if (error)
188                 goto bad;
189         /*
190          * Make sure that a VM object is created for VMIO support.
191          */
192         if (vn_canvmio(vp) == TRUE) {
193                 if ((error = vfs_object_create(vp, td)) != 0)
194                         goto bad;
195         }
196
197         if (fmode & FWRITE)
198                 vp->v_writecount++;
199         return (0);
200 bad:
201         NDFREE(ndp, NDF_ONLY_PNBUF);
202         vput(vp);
203         return (error);
204 }
205
206 /*
207  * Check for write permissions on the specified vnode.
208  * Prototype text segments cannot be written.
209  */
210 int
211 vn_writechk(vp)
212         struct vnode *vp;
213 {
214
215         /*
216          * If there's shared text associated with
217          * the vnode, try to free it up once.  If
218          * we fail, we can't allow writing.
219          */
220         if (vp->v_flag & VTEXT)
221                 return (ETXTBSY);
222         return (0);
223 }
224
225 /*
226  * Vnode close call
227  */
228 int
229 vn_close(struct vnode *vp, int flags, struct thread *td)
230 {
231         int error;
232
233         if (flags & FWRITE)
234                 vp->v_writecount--;
235         error = VOP_CLOSE(vp, flags, td);
236         vrele(vp);
237         return (error);
238 }
239
240 static __inline
241 int
242 sequential_heuristic(struct uio *uio, struct file *fp)
243 {
244         /*
245          * Sequential heuristic - detect sequential operation
246          */
247         if ((uio->uio_offset == 0 && fp->f_seqcount > 0) ||
248             uio->uio_offset == fp->f_nextoff) {
249                 int tmpseq = fp->f_seqcount;
250                 /*
251                  * XXX we assume that the filesystem block size is
252                  * the default.  Not true, but still gives us a pretty
253                  * good indicator of how sequential the read operations
254                  * are.
255                  */
256                 tmpseq += (uio->uio_resid + BKVASIZE - 1) / BKVASIZE;
257                 if (tmpseq > IO_SEQMAX)
258                         tmpseq = IO_SEQMAX;
259                 fp->f_seqcount = tmpseq;
260                 return(fp->f_seqcount << IO_SEQSHIFT);
261         }
262
263         /*
264          * Not sequential, quick draw-down of seqcount
265          */
266         if (fp->f_seqcount > 1)
267                 fp->f_seqcount = 1;
268         else
269                 fp->f_seqcount = 0;
270         return(0);
271 }
272
273 /*
274  * Package up an I/O request on a vnode into a uio and do it.
275  */
276 int
277 vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, cred, aresid, td)
278         enum uio_rw rw;
279         struct vnode *vp;
280         caddr_t base;
281         int len;
282         off_t offset;
283         enum uio_seg segflg;
284         int ioflg;
285         struct ucred *cred;
286         int *aresid;
287         struct thread *td;
288 {
289         struct uio auio;
290         struct iovec aiov;
291         int error;
292
293         if ((ioflg & IO_NODELOCKED) == 0)
294                 vn_lock(vp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
295         auio.uio_iov = &aiov;
296         auio.uio_iovcnt = 1;
297         aiov.iov_base = base;
298         aiov.iov_len = len;
299         auio.uio_resid = len;
300         auio.uio_offset = offset;
301         auio.uio_segflg = segflg;
302         auio.uio_rw = rw;
303         auio.uio_td = td;
304         if (rw == UIO_READ) {
305                 error = VOP_READ(vp, &auio, ioflg, cred);
306         } else {
307                 error = VOP_WRITE(vp, &auio, ioflg, cred);
308         }
309         if (aresid)
310                 *aresid = auio.uio_resid;
311         else
312                 if (auio.uio_resid && error == 0)
313                         error = EIO;
314         if ((ioflg & IO_NODELOCKED) == 0)
315                 VOP_UNLOCK(vp, NULL, 0, td);
316         return (error);
317 }
318
319 /*
320  * Package up an I/O request on a vnode into a uio and do it.  The I/O
321  * request is split up into smaller chunks and we try to avoid saturating
322  * the buffer cache while potentially holding a vnode locked, so we 
323  * check bwillwrite() before calling vn_rdwr().  We also call uio_yield()
324  * to give other processes a chance to lock the vnode (either other processes
325  * core'ing the same binary, or unrelated processes scanning the directory).
326  */
327 int
328 vn_rdwr_inchunks(rw, vp, base, len, offset, segflg, ioflg, cred, aresid, td)
329         enum uio_rw rw;
330         struct vnode *vp;
331         caddr_t base;
332         int len;
333         off_t offset;
334         enum uio_seg segflg;
335         int ioflg;
336         struct ucred *cred;
337         int *aresid;
338         struct thread *td;
339 {
340         int error = 0;
341
342         do {
343                 int chunk;
344
345                 /*
346                  * Force `offset' to a multiple of MAXBSIZE except possibly
347                  * for the first chunk, so that filesystems only need to
348                  * write full blocks except possibly for the first and last
349                  * chunks.
350                  */
351                 chunk = MAXBSIZE - (uoff_t)offset % MAXBSIZE;
352
353                 if (chunk > len)
354                         chunk = len;
355                 if (rw != UIO_READ && vp->v_type == VREG)
356                         bwillwrite();
357                 error = vn_rdwr(rw, vp, base, chunk, offset, segflg,
358                             ioflg, cred, aresid, td);
359                 len -= chunk;   /* aresid calc already includes length */
360                 if (error)
361                         break;
362                 offset += chunk;
363                 base += chunk;
364                 uio_yield();
365         } while (len);
366         if (aresid)
367                 *aresid += len;
368         return (error);
369 }
370
371 /*
372  * File table vnode read routine.
373  */
374 static int
375 vn_read(fp, uio, cred, flags, td)
376         struct file *fp;
377         struct uio *uio;
378         struct ucred *cred;
379         struct thread *td;
380         int flags;
381 {
382         struct vnode *vp;
383         int error, ioflag;
384
385         KASSERT(uio->uio_td == td, ("uio_td %p is not td %p", uio->uio_td, td));
386         vp = (struct vnode *)fp->f_data;
387         ioflag = 0;
388         if (fp->f_flag & FNONBLOCK)
389                 ioflag |= IO_NDELAY;
390         if (fp->f_flag & O_DIRECT)
391                 ioflag |= IO_DIRECT;
392         VOP_LEASE(vp, td, cred, LEASE_READ);
393         vn_lock(vp, NULL, LK_SHARED | LK_NOPAUSE | LK_RETRY, td);
394         if ((flags & FOF_OFFSET) == 0)
395                 uio->uio_offset = fp->f_offset;
396
397         ioflag |= sequential_heuristic(uio, fp);
398
399         error = VOP_READ(vp, uio, ioflag, cred);
400         if ((flags & FOF_OFFSET) == 0)
401                 fp->f_offset = uio->uio_offset;
402         fp->f_nextoff = uio->uio_offset;
403         VOP_UNLOCK(vp, NULL, 0, td);
404         return (error);
405 }
406
407 /*
408  * File table vnode write routine.
409  */
410 static int
411 vn_write(fp, uio, cred, flags, td)
412         struct file *fp;
413         struct uio *uio;
414         struct ucred *cred;
415         struct thread *td;
416         int flags;
417 {
418         struct vnode *vp;
419         int error, ioflag;
420
421         KASSERT(uio->uio_td == td, ("uio_procp %p is not p %p", 
422             uio->uio_td, td));
423         vp = (struct vnode *)fp->f_data;
424         if (vp->v_type == VREG)
425                 bwillwrite();
426         vp = (struct vnode *)fp->f_data;        /* XXX needed? */
427         ioflag = IO_UNIT;
428         if (vp->v_type == VREG && (fp->f_flag & O_APPEND))
429                 ioflag |= IO_APPEND;
430         if (fp->f_flag & FNONBLOCK)
431                 ioflag |= IO_NDELAY;
432         if (fp->f_flag & O_DIRECT)
433                 ioflag |= IO_DIRECT;
434         if ((fp->f_flag & O_FSYNC) ||
435             (vp->v_mount && (vp->v_mount->mnt_flag & MNT_SYNCHRONOUS)))
436                 ioflag |= IO_SYNC;
437         VOP_LEASE(vp, td, cred, LEASE_WRITE);
438         vn_lock(vp, NULL, LK_EXCLUSIVE | LK_RETRY, td);
439         if ((flags & FOF_OFFSET) == 0)
440                 uio->uio_offset = fp->f_offset;
441         ioflag |= sequential_heuristic(uio, fp);
442         error = VOP_WRITE(vp, uio, ioflag, cred);
443         if ((flags & FOF_OFFSET) == 0)
444                 fp->f_offset = uio->uio_offset;
445         fp->f_nextoff = uio->uio_offset;
446         VOP_UNLOCK(vp, NULL, 0, td);
447         return (error);
448 }
449
450 /*
451  * File table vnode stat routine.
452  */
453 static int
454 vn_statfile(struct file *fp, struct stat *sb, struct thread *td)
455 {
456         struct vnode *vp = (struct vnode *)fp->f_data;
457
458         return vn_stat(vp, sb, td);
459 }
460
461 int
462 vn_stat(struct vnode *vp, struct stat *sb, struct thread *td)
463 {
464         struct vattr vattr;
465         struct vattr *vap;
466         int error;
467         u_short mode;
468
469         vap = &vattr;
470         error = VOP_GETATTR(vp, vap, td);
471         if (error)
472                 return (error);
473
474         /*
475          * Zero the spare stat fields
476          */
477         sb->st_lspare = 0;
478         sb->st_qspare[0] = 0;
479         sb->st_qspare[1] = 0;
480
481         /*
482          * Copy from vattr table
483          */
484         if (vap->va_fsid != VNOVAL)
485                 sb->st_dev = vap->va_fsid;
486         else
487                 sb->st_dev = vp->v_mount->mnt_stat.f_fsid.val[0];
488         sb->st_ino = vap->va_fileid;
489         mode = vap->va_mode;
490         switch (vap->va_type) {
491         case VREG:
492                 mode |= S_IFREG;
493                 break;
494         case VDIR:
495                 mode |= S_IFDIR;
496                 break;
497         case VBLK:
498                 mode |= S_IFBLK;
499                 break;
500         case VCHR:
501                 mode |= S_IFCHR;
502                 break;
503         case VLNK:
504                 mode |= S_IFLNK;
505                 /* This is a cosmetic change, symlinks do not have a mode. */
506                 if (vp->v_mount->mnt_flag & MNT_NOSYMFOLLOW)
507                         sb->st_mode &= ~ACCESSPERMS;    /* 0000 */
508                 else
509                         sb->st_mode |= ACCESSPERMS;     /* 0777 */
510                 break;
511         case VSOCK:
512                 mode |= S_IFSOCK;
513                 break;
514         case VFIFO:
515                 mode |= S_IFIFO;
516                 break;
517         default:
518                 return (EBADF);
519         };
520         sb->st_mode = mode;
521         sb->st_nlink = vap->va_nlink;
522         sb->st_uid = vap->va_uid;
523         sb->st_gid = vap->va_gid;
524         sb->st_rdev = vap->va_rdev;
525         sb->st_size = vap->va_size;
526         sb->st_atimespec = vap->va_atime;
527         sb->st_mtimespec = vap->va_mtime;
528         sb->st_ctimespec = vap->va_ctime;
529
530         /*
531          * According to www.opengroup.org, the meaning of st_blksize is 
532          *   "a filesystem-specific preferred I/O block size for this 
533          *    object.  In some filesystem types, this may vary from file
534          *    to file"
535          * Default to PAGE_SIZE after much discussion.
536          */
537
538         if (vap->va_type == VREG) {
539                 sb->st_blksize = vap->va_blocksize;
540         } else if (vn_isdisk(vp, NULL)) {
541                 sb->st_blksize = vp->v_rdev->si_bsize_best;
542                 if (sb->st_blksize < vp->v_rdev->si_bsize_phys)
543                         sb->st_blksize = vp->v_rdev->si_bsize_phys;
544                 if (sb->st_blksize < BLKDEV_IOSIZE)
545                         sb->st_blksize = BLKDEV_IOSIZE;
546         } else {
547                 sb->st_blksize = PAGE_SIZE;
548         }
549         
550         sb->st_flags = vap->va_flags;
551         if (suser(td))
552                 sb->st_gen = 0;
553         else
554                 sb->st_gen = vap->va_gen;
555
556 #if (S_BLKSIZE == 512)
557         /* Optimize this case */
558         sb->st_blocks = vap->va_bytes >> 9;
559 #else
560         sb->st_blocks = vap->va_bytes / S_BLKSIZE;
561 #endif
562         return (0);
563 }
564
565 /*
566  * File table vnode ioctl routine.
567  */
568 static int
569 vn_ioctl(struct file *fp, u_long com, caddr_t data, struct thread *td)
570 {
571         struct vnode *vp = ((struct vnode *)fp->f_data);
572         struct ucred *ucred;
573         struct vattr vattr;
574         int error;
575
576         KKASSERT(td->td_proc != NULL);
577         ucred = td->td_proc->p_ucred;
578
579         switch (vp->v_type) {
580         case VREG:
581         case VDIR:
582                 if (com == FIONREAD) {
583                         error = VOP_GETATTR(vp, &vattr, td);
584                         if (error)
585                                 return (error);
586                         *(int *)data = vattr.va_size - fp->f_offset;
587                         return (0);
588                 }
589                 if (com == FIONBIO || com == FIOASYNC)  /* XXX */
590                         return (0);                     /* XXX */
591                 /* fall into ... */
592         default:
593 #if 0
594                 return (ENOTTY);
595 #endif
596         case VFIFO:
597         case VCHR:
598         case VBLK:
599                 if (com == FIODTYPE) {
600                         if (vp->v_type != VCHR && vp->v_type != VBLK)
601                                 return (ENOTTY);
602                         *(int *)data = dev_dflags(vp->v_rdev) & D_TYPEMASK;
603                         return (0);
604                 }
605                 error = VOP_IOCTL(vp, com, data, fp->f_flag, ucred, td);
606                 if (error == 0 && com == TIOCSCTTY) {
607                         struct session *sess = td->td_proc->p_session;
608
609                         /* Do nothing if reassigning same control tty */
610                         if (sess->s_ttyvp == vp)
611                                 return (0);
612
613                         /* Get rid of reference to old control tty */
614                         if (sess->s_ttyvp)
615                                 vrele(sess->s_ttyvp);
616
617                         sess->s_ttyvp = vp;
618                         vref(vp);
619                 }
620                 return (error);
621         }
622 }
623
624 /*
625  * File table vnode poll routine.
626  */
627 static int
628 vn_poll(struct file *fp, int events, struct ucred *cred, struct thread *td)
629 {
630         return (VOP_POLL(((struct vnode *)fp->f_data), events, cred, td));
631 }
632
633 /*
634  * Check that the vnode is still valid, and if so
635  * acquire requested lock.
636  */
637 int
638 #ifndef DEBUG_LOCKS
639 vn_lock(struct vnode *vp, lwkt_tokref_t vlock, int flags, struct thread *td)
640 #else
641 debug_vn_lock(struct vnode *vp, lwkt_tokref_t vlock, int flags, 
642                 struct thread *td, const char *filename, int line)
643 #endif
644 {
645         int error;
646         lwkt_tokref vvlock;
647         
648         do {
649                 if ((flags & LK_INTERLOCK) == 0) {
650                         lwkt_gettoken(&vvlock, vp->v_interlock);
651                         vlock = &vvlock;
652                 }
653                 if ((vp->v_flag & VXLOCK) && vp->v_vxthread != curthread) {
654                         vp->v_flag |= VXWANT;
655                         lwkt_reltoken(vlock);
656                         tsleep((caddr_t)vp, 0, "vn_lock", 0);
657                         error = ENOENT;
658                 } else {
659 #if 0
660                         /* this can now occur in normal operation */
661                         if (vp->v_vxthread != NULL)
662                                 log(LOG_INFO, "VXLOCK interlock avoided in vn_lock\n");
663 #endif
664 #ifdef  DEBUG_LOCKS
665                         vp->filename = filename;
666                         vp->line = line;
667 #endif
668                         error = VOP_LOCK(vp, vlock,
669                                     flags | LK_NOPAUSE | LK_INTERLOCK, td);
670                         if (error == 0)
671                                 return (0);
672                 }
673                 flags &= ~LK_INTERLOCK;
674         } while (flags & LK_RETRY);
675         return (error);
676 }
677
678 /*
679  * File table vnode close routine.
680  */
681 static int
682 vn_closefile(struct file *fp, struct thread *td)
683 {
684         int err;
685
686         fp->f_ops = &badfileops;
687         err = vn_close(((struct vnode *)fp->f_data), fp->f_flag, td);
688         return(err);
689 }
690
691 static int
692 vn_kqfilter(struct file *fp, struct knote *kn)
693 {
694
695         return (VOP_KQFILTER(((struct vnode *)fp->f_data), kn));
696 }