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.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)vfs_vnops.c 8.2 (Berkeley) 1/21/94
37 #include <sys/cdefs.h>
38 __FBSDID("$FreeBSD$");
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/fcntl.h>
49 #include <sys/limits.h>
52 #include <sys/mount.h>
53 #include <sys/mutex.h>
54 #include <sys/namei.h>
55 #include <sys/vnode.h>
58 #include <sys/filio.h>
60 #include <sys/ttycom.h>
62 #include <sys/syslog.h>
63 #include <sys/unistd.h>
65 static fo_rdwr_t vn_read;
66 static fo_rdwr_t vn_write;
67 static fo_ioctl_t vn_ioctl;
68 static fo_poll_t vn_poll;
69 static fo_kqfilter_t vn_kqfilter;
70 static fo_stat_t vn_statfile;
71 static fo_close_t vn_closefile;
73 struct fileops vnops = {
78 .fo_kqfilter = vn_kqfilter,
79 .fo_stat = vn_statfile,
80 .fo_close = vn_closefile,
81 .fo_flags = DFLAG_PASSABLE | DFLAG_SEEKABLE
85 vn_open(ndp, flagp, cmode, fdidx)
86 struct nameidata *ndp;
87 int *flagp, cmode, fdidx;
89 struct thread *td = ndp->ni_cnd.cn_thread;
91 return (vn_open_cred(ndp, flagp, cmode, td->td_ucred, fdidx));
95 * Common code for vnode open operations.
96 * Check permissions, and call the VOP_OPEN or VOP_CREATE routine.
98 * Note that this does NOT free nameidata for the successful case,
99 * due to the NDINIT being done elsewhere.
102 vn_open_cred(ndp, flagp, cmode, cred, fdidx)
103 struct nameidata *ndp;
110 struct thread *td = ndp->ni_cnd.cn_thread;
112 struct vattr *vap = &vat;
113 int mode, fmode, error;
119 if (fmode & O_CREAT) {
120 ndp->ni_cnd.cn_nameiop = CREATE;
121 ndp->ni_cnd.cn_flags = ISOPEN | LOCKPARENT | LOCKLEAF |
122 MPSAFE | AUDITVNODE1;
123 if ((fmode & O_EXCL) == 0 && (fmode & O_NOFOLLOW) == 0)
124 ndp->ni_cnd.cn_flags |= FOLLOW;
126 if ((error = namei(ndp)) != 0)
128 vfslocked = (ndp->ni_cnd.cn_flags & GIANTHELD) != 0;
129 ndp->ni_cnd.cn_flags &= ~MPSAFE;
130 if (ndp->ni_vp == NULL) {
133 vap->va_mode = cmode;
135 vap->va_vaflags |= VA_EXCLUSIVE;
136 if (vn_start_write(ndp->ni_dvp, &mp, V_NOWAIT) != 0) {
137 NDFREE(ndp, NDF_ONLY_PNBUF);
139 VFS_UNLOCK_GIANT(vfslocked);
140 if ((error = vn_start_write(NULL, &mp,
141 V_XSLEEP | PCATCH)) != 0)
146 error = mac_check_vnode_create(cred, ndp->ni_dvp,
150 VOP_LEASE(ndp->ni_dvp, td, cred, LEASE_WRITE);
151 error = VOP_CREATE(ndp->ni_dvp, &ndp->ni_vp,
157 vn_finished_write(mp);
159 VFS_UNLOCK_GIANT(vfslocked);
160 NDFREE(ndp, NDF_ONLY_PNBUF);
166 if (ndp->ni_dvp == ndp->ni_vp)
172 if (fmode & O_EXCL) {
179 ndp->ni_cnd.cn_nameiop = LOOKUP;
180 ndp->ni_cnd.cn_flags = ISOPEN |
181 ((fmode & O_NOFOLLOW) ? NOFOLLOW : FOLLOW) |
182 LOCKSHARED | LOCKLEAF | MPSAFE | AUDITVNODE1;
183 if ((error = namei(ndp)) != 0)
185 ndp->ni_cnd.cn_flags &= ~MPSAFE;
186 vfslocked = (ndp->ni_cnd.cn_flags & GIANTHELD) != 0;
189 if (vp->v_type == VLNK) {
193 if (vp->v_type == VSOCK) {
198 if (fmode & (FWRITE | O_TRUNC)) {
199 if (vp->v_type == VDIR) {
207 if (fmode & O_APPEND)
210 error = mac_check_vnode_open(cred, vp, mode);
214 if ((fmode & O_CREAT) == 0) {
216 error = vn_writechk(vp);
221 error = VOP_ACCESS(vp, mode, cred, td);
226 if ((error = VOP_OPEN(vp, fmode, cred, td, fdidx)) != 0)
232 ASSERT_VOP_LOCKED(vp, "vn_open_cred");
234 VFS_UNLOCK_GIANT(vfslocked);
237 NDFREE(ndp, NDF_ONLY_PNBUF);
239 VFS_UNLOCK_GIANT(vfslocked);
246 * Check for write permissions on the specified vnode.
247 * Prototype text segments cannot be written.
251 register struct vnode *vp;
254 ASSERT_VOP_LOCKED(vp, "vn_writechk");
256 * If there's shared text associated with
257 * the vnode, try to free it up once. If
258 * we fail, we can't allow writing.
260 if (vp->v_vflag & VV_TEXT)
270 vn_close(vp, flags, file_cred, td)
271 register struct vnode *vp;
273 struct ucred *file_cred;
279 VFS_ASSERT_GIANT(vp->v_mount);
281 vn_start_write(vp, &mp, V_WAIT);
282 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
285 error = VOP_CLOSE(vp, flags, file_cred, td);
287 vn_finished_write(mp);
292 * Sequential heuristic - detect sequential operation
296 sequential_heuristic(struct uio *uio, struct file *fp)
299 if ((uio->uio_offset == 0 && fp->f_seqcount > 0) ||
300 uio->uio_offset == fp->f_nextoff) {
302 * XXX we assume that the filesystem block size is
303 * the default. Not true, but still gives us a pretty
304 * good indicator of how sequential the read operations
307 fp->f_seqcount += (uio->uio_resid + BKVASIZE - 1) / BKVASIZE;
308 if (fp->f_seqcount > IO_SEQMAX)
309 fp->f_seqcount = IO_SEQMAX;
310 return(fp->f_seqcount << IO_SEQSHIFT);
314 * Not sequential, quick draw-down of seqcount
316 if (fp->f_seqcount > 1)
324 * Package up an I/O request on a vnode into a uio and do it.
327 vn_rdwr(rw, vp, base, len, offset, segflg, ioflg, active_cred, file_cred,
336 struct ucred *active_cred;
337 struct ucred *file_cred;
347 VFS_ASSERT_GIANT(vp->v_mount);
349 if ((ioflg & IO_NODELOCKED) == 0) {
351 if (rw == UIO_WRITE) {
352 if (vp->v_type != VCHR &&
353 (error = vn_start_write(vp, &mp, V_WAIT | PCATCH))
356 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
359 * XXX This should be LK_SHARED but I don't trust VFS
360 * enough to leave it like that until it has been
363 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
367 ASSERT_VOP_LOCKED(vp, "IO_NODELOCKED with no vp lock held");
368 auio.uio_iov = &aiov;
370 aiov.iov_base = base;
372 auio.uio_resid = len;
373 auio.uio_offset = offset;
374 auio.uio_segflg = segflg;
379 if ((ioflg & IO_NOMACCHECK) == 0) {
381 error = mac_check_vnode_read(active_cred, file_cred,
384 error = mac_check_vnode_write(active_cred, file_cred,
394 error = VOP_READ(vp, &auio, ioflg, cred);
396 error = VOP_WRITE(vp, &auio, ioflg, cred);
399 *aresid = auio.uio_resid;
401 if (auio.uio_resid && error == 0)
403 if ((ioflg & IO_NODELOCKED) == 0) {
405 vn_finished_write(mp);
406 VOP_UNLOCK(vp, 0, td);
412 * Package up an I/O request on a vnode into a uio and do it. The I/O
413 * request is split up into smaller chunks and we try to avoid saturating
414 * the buffer cache while potentially holding a vnode locked, so we
415 * check bwillwrite() before calling vn_rdwr(). We also call uio_yield()
416 * to give other processes a chance to lock the vnode (either other processes
417 * core'ing the same binary, or unrelated processes scanning the directory).
420 vn_rdwr_inchunks(rw, vp, base, len, offset, segflg, ioflg, active_cred,
421 file_cred, aresid, td)
429 struct ucred *active_cred;
430 struct ucred *file_cred;
437 VFS_ASSERT_GIANT(vp->v_mount);
443 * Force `offset' to a multiple of MAXBSIZE except possibly
444 * for the first chunk, so that filesystems only need to
445 * write full blocks except possibly for the first and last
448 chunk = MAXBSIZE - (uoff_t)offset % MAXBSIZE;
452 if (rw != UIO_READ && vp->v_type == VREG)
455 error = vn_rdwr(rw, vp, base, chunk, offset, segflg,
456 ioflg, active_cred, file_cred, &iaresid, td);
457 len -= chunk; /* aresid calc already includes length */
461 base = (char *)base + chunk;
465 *aresid = len + iaresid;
470 * File table vnode read routine.
473 vn_read(fp, uio, active_cred, flags, td)
476 struct ucred *active_cred;
484 KASSERT(uio->uio_td == td, ("uio_td %p is not td %p",
488 if (fp->f_flag & FNONBLOCK)
490 if (fp->f_flag & O_DIRECT)
492 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
493 VOP_LEASE(vp, td, fp->f_cred, LEASE_READ);
495 * According to McKusick the vn lock is protecting f_offset here.
496 * Once this field has it's own lock we can acquire this shared.
498 if ((flags & FOF_OFFSET) == 0) {
499 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
500 uio->uio_offset = fp->f_offset;
502 vn_lock(vp, LK_SHARED | LK_RETRY, td);
504 ioflag |= sequential_heuristic(uio, fp);
507 error = mac_check_vnode_read(active_cred, fp->f_cred, vp);
510 error = VOP_READ(vp, uio, ioflag, fp->f_cred);
511 if ((flags & FOF_OFFSET) == 0)
512 fp->f_offset = uio->uio_offset;
513 fp->f_nextoff = uio->uio_offset;
514 VOP_UNLOCK(vp, 0, td);
515 VFS_UNLOCK_GIANT(vfslocked);
520 * File table vnode write routine.
523 vn_write(fp, uio, active_cred, flags, td)
526 struct ucred *active_cred;
535 KASSERT(uio->uio_td == td, ("uio_td %p is not td %p",
538 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
539 if (vp->v_type == VREG)
542 if (vp->v_type == VREG && (fp->f_flag & O_APPEND))
544 if (fp->f_flag & FNONBLOCK)
546 if (fp->f_flag & O_DIRECT)
548 if ((fp->f_flag & O_FSYNC) ||
549 (vp->v_mount && (vp->v_mount->mnt_flag & MNT_SYNCHRONOUS)))
552 if (vp->v_type != VCHR &&
553 (error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
555 VOP_LEASE(vp, td, fp->f_cred, LEASE_WRITE);
556 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
557 if ((flags & FOF_OFFSET) == 0)
558 uio->uio_offset = fp->f_offset;
559 ioflag |= sequential_heuristic(uio, fp);
561 error = mac_check_vnode_write(active_cred, fp->f_cred, vp);
564 error = VOP_WRITE(vp, uio, ioflag, fp->f_cred);
565 if ((flags & FOF_OFFSET) == 0)
566 fp->f_offset = uio->uio_offset;
567 fp->f_nextoff = uio->uio_offset;
568 VOP_UNLOCK(vp, 0, td);
569 vn_finished_write(mp);
571 VFS_UNLOCK_GIANT(vfslocked);
576 * File table vnode stat routine.
579 vn_statfile(fp, sb, active_cred, td)
582 struct ucred *active_cred;
585 struct vnode *vp = fp->f_vnode;
589 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
590 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
591 error = vn_stat(vp, sb, active_cred, fp->f_cred, td);
592 VOP_UNLOCK(vp, 0, td);
593 VFS_UNLOCK_GIANT(vfslocked);
599 * Stat a vnode; implementation for the stat syscall
602 vn_stat(vp, sb, active_cred, file_cred, td)
604 register struct stat *sb;
605 struct ucred *active_cred;
606 struct ucred *file_cred;
610 register struct vattr *vap;
615 error = mac_check_vnode_stat(active_cred, file_cred, vp);
621 error = VOP_GETATTR(vp, vap, active_cred, td);
626 * Zero the spare stat fields
628 bzero(sb, sizeof *sb);
631 * Copy from vattr table
633 if (vap->va_fsid != VNOVAL)
634 sb->st_dev = vap->va_fsid;
636 sb->st_dev = vp->v_mount->mnt_stat.f_fsid.val[0];
637 sb->st_ino = vap->va_fileid;
639 switch (vap->va_type) {
654 /* This is a cosmetic change, symlinks do not have a mode. */
655 if (vp->v_mount->mnt_flag & MNT_NOSYMFOLLOW)
656 sb->st_mode &= ~ACCESSPERMS; /* 0000 */
658 sb->st_mode |= ACCESSPERMS; /* 0777 */
670 sb->st_nlink = vap->va_nlink;
671 sb->st_uid = vap->va_uid;
672 sb->st_gid = vap->va_gid;
673 sb->st_rdev = vap->va_rdev;
674 if (vap->va_size > OFF_MAX)
676 sb->st_size = vap->va_size;
677 sb->st_atimespec = vap->va_atime;
678 sb->st_mtimespec = vap->va_mtime;
679 sb->st_ctimespec = vap->va_ctime;
680 sb->st_birthtimespec = vap->va_birthtime;
683 * According to www.opengroup.org, the meaning of st_blksize is
684 * "a filesystem-specific preferred I/O block size for this
685 * object. In some filesystem types, this may vary from file
687 * Default to PAGE_SIZE after much discussion.
688 * XXX: min(PAGE_SIZE, vp->v_bufobj.bo_bsize) may be more correct.
691 sb->st_blksize = PAGE_SIZE;
693 sb->st_flags = vap->va_flags;
697 sb->st_gen = vap->va_gen;
699 #if (S_BLKSIZE == 512)
700 /* Optimize this case */
701 sb->st_blocks = vap->va_bytes >> 9;
703 sb->st_blocks = vap->va_bytes / S_BLKSIZE;
709 * File table vnode ioctl routine.
712 vn_ioctl(fp, com, data, active_cred, td)
716 struct ucred *active_cred;
719 struct vnode *vp = fp->f_vnode;
724 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
726 switch (vp->v_type) {
729 if (com == FIONREAD) {
730 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
731 error = VOP_GETATTR(vp, &vattr, active_cred, td);
732 VOP_UNLOCK(vp, 0, td);
734 *(int *)data = vattr.va_size - fp->f_offset;
736 if (com == FIONBIO || com == FIOASYNC) /* XXX */
739 error = VOP_IOCTL(vp, com, data, fp->f_flag,
746 VFS_UNLOCK_GIANT(vfslocked);
751 * File table vnode poll routine.
754 vn_poll(fp, events, active_cred, td)
757 struct ucred *active_cred;
767 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
768 error = mac_check_vnode_poll(active_cred, fp->f_cred, vp);
769 VOP_UNLOCK(vp, 0, td);
773 error = VOP_POLL(vp, events, fp->f_cred, td);
779 * Check that the vnode is still valid, and if so
780 * acquire requested lock.
783 vn_lock(vp, flags, td)
791 if ((flags & LK_INTERLOCK) == 0)
793 if ((flags & LK_NOWAIT || (flags & LK_TYPE_MASK) == 0) &&
794 vp->v_iflag & VI_DOOMED) {
799 * Just polling to check validity.
801 if ((flags & LK_TYPE_MASK) == 0) {
806 * lockmgr drops interlock before it will return for
807 * any reason. So force the code above to relock it.
809 error = VOP_LOCK(vp, flags | LK_INTERLOCK, td);
810 flags &= ~LK_INTERLOCK;
811 KASSERT((flags & LK_RETRY) == 0 || error == 0,
812 ("LK_RETRY set with incompatible flags %d\n", flags));
814 * Callers specify LK_RETRY if they wish to get dead vnodes.
815 * If RETRY is not set, we return ENOENT instead.
817 if (error == 0 && vp->v_iflag & VI_DOOMED &&
818 (flags & LK_RETRY) == 0) {
819 VOP_UNLOCK(vp, 0, td);
823 } while (flags & LK_RETRY && error != 0);
828 * File table vnode close routine.
842 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
843 if (fp->f_type == DTYPE_VNODE && fp->f_flag & FHASLOCK) {
844 lf.l_whence = SEEK_SET;
848 (void) VOP_ADVLOCK(vp, fp, F_UNLCK, &lf, F_FLOCK);
851 fp->f_ops = &badfileops;
853 error = vn_close(vp, fp->f_flag, fp->f_cred, td);
854 VFS_UNLOCK_GIANT(vfslocked);
859 * Preparing to start a filesystem write operation. If the operation is
860 * permitted, then we bump the count of operations in progress and
861 * proceed. If a suspend request is in progress, we wait until the
862 * suspension is over, and then proceed.
865 vn_start_write(vp, mpp, flags)
875 * If a vnode is provided, get and return the mount point that
876 * to which it will write.
879 if ((error = VOP_GETWRITEMOUNT(vp, mpp)) != 0) {
881 if (error != EOPNOTSUPP)
886 if ((mp = *mpp) == NULL)
890 * Check on status of suspension.
892 while ((mp->mnt_kern_flag & MNTK_SUSPEND) != 0) {
893 if (flags & V_NOWAIT) {
897 error = msleep(&mp->mnt_flag, MNT_MTX(mp),
898 (PUSER - 1) | (flags & PCATCH), "suspfs", 0);
902 if (flags & V_XSLEEP)
904 mp->mnt_writeopcount++;
911 * Secondary suspension. Used by operations such as vop_inactive
912 * routines that are needed by the higher level functions. These
913 * are allowed to proceed until all the higher level functions have
914 * completed (indicated by mnt_writeopcount dropping to zero). At that
915 * time, these operations are halted until the suspension is over.
918 vn_write_suspend_wait(vp, mp, flags)
926 if ((error = VOP_GETWRITEMOUNT(vp, &mp)) != 0) {
927 if (error != EOPNOTSUPP)
933 * If we are not suspended or have not yet reached suspended
934 * mode, then let the operation proceed.
939 if ((mp->mnt_kern_flag & MNTK_SUSPENDED) == 0) {
943 if (flags & V_NOWAIT) {
945 return (EWOULDBLOCK);
948 * Wait for the suspension to finish.
950 return (msleep(&mp->mnt_flag, MNT_MTX(mp),
951 (PUSER - 1) | (flags & PCATCH) | PDROP, "suspfs", 0));
955 * Secondary suspension. Used by operations such as vop_inactive
956 * routines that are needed by the higher level functions. These
957 * are allowed to proceed until all the higher level functions have
958 * completed (indicated by mnt_writeopcount dropping to zero). At that
959 * time, these operations are halted until the suspension is over.
962 vn_start_secondary_write(vp, mpp, flags)
972 if ((error = VOP_GETWRITEMOUNT(vp, mpp)) != 0) {
974 if (error != EOPNOTSUPP)
980 * If we are not suspended or have not yet reached suspended
981 * mode, then let the operation proceed.
983 if ((mp = *mpp) == NULL)
986 if ((mp->mnt_kern_flag & (MNTK_SUSPENDED | MNTK_SUSPEND2)) == 0) {
987 mp->mnt_secondary_writes++;
988 mp->mnt_secondary_accwrites++;
992 if (flags & V_NOWAIT) {
994 return (EWOULDBLOCK);
997 * Wait for the suspension to finish.
999 error = msleep(&mp->mnt_flag, MNT_MTX(mp),
1000 (PUSER - 1) | (flags & PCATCH) | PDROP, "suspfs", 0);
1007 * Filesystem write operation has completed. If we are suspending and this
1008 * operation is the last one, notify the suspender that the suspension is
1012 vn_finished_write(mp)
1018 mp->mnt_writeopcount--;
1019 if (mp->mnt_writeopcount < 0)
1020 panic("vn_finished_write: neg cnt");
1021 if ((mp->mnt_kern_flag & MNTK_SUSPEND) != 0 &&
1022 mp->mnt_writeopcount <= 0)
1023 wakeup(&mp->mnt_writeopcount);
1029 * Filesystem secondary write operation has completed. If we are
1030 * suspending and this operation is the last one, notify the suspender
1031 * that the suspension is now in effect.
1034 vn_finished_secondary_write(mp)
1040 mp->mnt_secondary_writes--;
1041 if (mp->mnt_secondary_writes < 0)
1042 panic("vn_finished_secondary_write: neg cnt");
1043 if ((mp->mnt_kern_flag & MNTK_SUSPEND) != 0 &&
1044 mp->mnt_secondary_writes <= 0)
1045 wakeup(&mp->mnt_secondary_writes);
1052 * Request a filesystem to suspend write operations.
1055 vfs_write_suspend(mp)
1058 struct thread *td = curthread;
1063 if (mp->mnt_kern_flag & MNTK_SUSPEND)
1065 mp->mnt_kern_flag |= MNTK_SUSPEND;
1066 if (mp->mnt_writeopcount > 0)
1067 (void) msleep(&mp->mnt_writeopcount,
1068 MNT_MTX(mp), (PUSER - 1)|PDROP, "suspwt", 0);
1071 if ((error = VFS_SYNC(mp, MNT_SUSPEND, td)) != 0) {
1072 vfs_write_resume(mp);
1082 * Request a filesystem to resume write operations.
1085 vfs_write_resume(mp)
1090 if ((mp->mnt_kern_flag & MNTK_SUSPEND) != 0) {
1091 mp->mnt_kern_flag &= ~(MNTK_SUSPEND | MNTK_SUSPEND2 |
1093 wakeup(&mp->mnt_writeopcount);
1094 wakeup(&mp->mnt_flag);
1100 * Implement kqueues for files by translating it to vnode operation.
1103 vn_kqfilter(struct file *fp, struct knote *kn)
1108 error = VOP_KQFILTER(fp->f_vnode, kn);
1115 * Simplified in-kernel wrapper calls for extended attribute access.
1116 * Both calls pass in a NULL credential, authorizing as "kernel" access.
1117 * Set IO_NODELOCKED in ioflg if the vnode is already locked.
1120 vn_extattr_get(struct vnode *vp, int ioflg, int attrnamespace,
1121 const char *attrname, int *buflen, char *buf, struct thread *td)
1127 iov.iov_len = *buflen;
1130 auio.uio_iov = &iov;
1131 auio.uio_iovcnt = 1;
1132 auio.uio_rw = UIO_READ;
1133 auio.uio_segflg = UIO_SYSSPACE;
1135 auio.uio_offset = 0;
1136 auio.uio_resid = *buflen;
1138 if ((ioflg & IO_NODELOCKED) == 0)
1139 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
1141 ASSERT_VOP_LOCKED(vp, "IO_NODELOCKED with no vp lock held");
1143 /* authorize attribute retrieval as kernel */
1144 error = VOP_GETEXTATTR(vp, attrnamespace, attrname, &auio, NULL, NULL,
1147 if ((ioflg & IO_NODELOCKED) == 0)
1148 VOP_UNLOCK(vp, 0, td);
1151 *buflen = *buflen - auio.uio_resid;
1158 * XXX failure mode if partially written?
1161 vn_extattr_set(struct vnode *vp, int ioflg, int attrnamespace,
1162 const char *attrname, int buflen, char *buf, struct thread *td)
1169 iov.iov_len = buflen;
1172 auio.uio_iov = &iov;
1173 auio.uio_iovcnt = 1;
1174 auio.uio_rw = UIO_WRITE;
1175 auio.uio_segflg = UIO_SYSSPACE;
1177 auio.uio_offset = 0;
1178 auio.uio_resid = buflen;
1180 if ((ioflg & IO_NODELOCKED) == 0) {
1181 if ((error = vn_start_write(vp, &mp, V_WAIT)) != 0)
1183 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
1186 ASSERT_VOP_LOCKED(vp, "IO_NODELOCKED with no vp lock held");
1188 /* authorize attribute setting as kernel */
1189 error = VOP_SETEXTATTR(vp, attrnamespace, attrname, &auio, NULL, td);
1191 if ((ioflg & IO_NODELOCKED) == 0) {
1192 vn_finished_write(mp);
1193 VOP_UNLOCK(vp, 0, td);
1200 vn_extattr_rm(struct vnode *vp, int ioflg, int attrnamespace,
1201 const char *attrname, struct thread *td)
1206 if ((ioflg & IO_NODELOCKED) == 0) {
1207 if ((error = vn_start_write(vp, &mp, V_WAIT)) != 0)
1209 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
1212 ASSERT_VOP_LOCKED(vp, "IO_NODELOCKED with no vp lock held");
1214 /* authorize attribute removal as kernel */
1215 error = VOP_DELETEEXTATTR(vp, attrnamespace, attrname, NULL, td);
1216 if (error == EOPNOTSUPP)
1217 error = VOP_SETEXTATTR(vp, attrnamespace, attrname, NULL,
1220 if ((ioflg & IO_NODELOCKED) == 0) {
1221 vn_finished_write(mp);
1222 VOP_UNLOCK(vp, 0, td);