2 * Copyright (c) 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 * 3. 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_subr.c 8.31 (Berkeley) 5/26/95
35 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $
39 * External virtual filesystem routines
43 #include "opt_inet6.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
49 #include <sys/dirent.h>
50 #include <sys/eventhandler.h>
51 #include <sys/fcntl.h>
53 #include <sys/kernel.h>
54 #include <sys/kthread.h>
55 #include <sys/malloc.h>
57 #include <sys/mount.h>
60 #include <sys/reboot.h>
61 #include <sys/socket.h>
63 #include <sys/sysctl.h>
64 #include <sys/syslog.h>
65 #include <sys/unistd.h>
66 #include <sys/vmmeter.h>
67 #include <sys/vnode.h>
69 #include <machine/limits.h>
72 #include <vm/vm_object.h>
73 #include <vm/vm_extern.h>
74 #include <vm/vm_kern.h>
76 #include <vm/vm_map.h>
77 #include <vm/vm_page.h>
78 #include <vm/vm_pager.h>
79 #include <vm/vnode_pager.h>
80 #include <vm/vm_zone.h>
83 #include <sys/thread2.h>
84 #include <sys/mplock2.h>
85 #include <vm/vm_page2.h>
87 #include <netinet/in.h>
89 static MALLOC_DEFINE(M_NETCRED
, "Export Host", "Export host address structure");
92 SYSCTL_INT(_debug
, OID_AUTO
, numvnodes
, CTLFLAG_RD
, &numvnodes
, 0,
93 "Number of vnodes allocated");
95 SYSCTL_INT(_debug
, OID_AUTO
, verbose_reclaims
, CTLFLAG_RD
, &verbose_reclaims
, 0,
96 "Output filename of reclaimed vnode(s)");
98 enum vtype iftovt_tab
[16] = {
99 VNON
, VFIFO
, VCHR
, VNON
, VDIR
, VNON
, VBLK
, VNON
,
100 VREG
, VNON
, VLNK
, VNON
, VSOCK
, VNON
, VNON
, VBAD
,
102 int vttoif_tab
[9] = {
103 0, S_IFREG
, S_IFDIR
, S_IFBLK
, S_IFCHR
, S_IFLNK
,
104 S_IFSOCK
, S_IFIFO
, S_IFMT
,
107 static int reassignbufcalls
;
108 SYSCTL_INT(_vfs
, OID_AUTO
, reassignbufcalls
, CTLFLAG_RW
, &reassignbufcalls
,
109 0, "Number of times buffers have been reassigned to the proper list");
111 static int check_buf_overlap
= 2; /* invasive check */
112 SYSCTL_INT(_vfs
, OID_AUTO
, check_buf_overlap
, CTLFLAG_RW
, &check_buf_overlap
,
113 0, "Enable overlapping buffer checks");
115 int nfs_mount_type
= -1;
116 static struct lwkt_token spechash_token
;
117 struct nfs_public nfs_pub
; /* publicly exported FS */
120 SYSCTL_INT(_kern
, KERN_MAXVNODES
, maxvnodes
, CTLFLAG_RW
,
121 &maxvnodes
, 0, "Maximum number of vnodes");
123 static struct radix_node_head
*vfs_create_addrlist_af(int af
,
124 struct netexport
*nep
);
125 static void vfs_free_addrlist (struct netexport
*nep
);
126 static int vfs_free_netcred (struct radix_node
*rn
, void *w
);
127 static void vfs_free_addrlist_af (struct radix_node_head
**prnh
);
128 static int vfs_hang_addrlist (struct mount
*mp
, struct netexport
*nep
,
129 const struct export_args
*argp
);
131 int prtactive
= 0; /* 1 => print out reclaim of active vnodes */
134 * Red black tree functions
136 static int rb_buf_compare(struct buf
*b1
, struct buf
*b2
);
137 RB_GENERATE2(buf_rb_tree
, buf
, b_rbnode
, rb_buf_compare
, off_t
, b_loffset
);
138 RB_GENERATE2(buf_rb_hash
, buf
, b_rbhash
, rb_buf_compare
, off_t
, b_loffset
);
141 rb_buf_compare(struct buf
*b1
, struct buf
*b2
)
143 if (b1
->b_loffset
< b2
->b_loffset
)
145 if (b1
->b_loffset
> b2
->b_loffset
)
151 * Initialize the vnode management data structures.
153 * Called from vfsinit()
162 * Desiredvnodes is kern.maxvnodes. We want to scale it
163 * according to available system memory but we may also have
164 * to limit it based on available KVM.
166 * WARNING! For machines with 64-256M of ram we have to be sure
167 * that the default limit scales down well due to HAMMER
168 * taking up significantly more memory per-vnode vs UFS.
169 * We want around ~5800 on a 128M machine.
171 * WARNING! Now that KVM is substantially larger (e.g. 8TB+),
172 * also limit maxvnodes based on a 128GB metric. This
173 * gives us something like ~3 millon vnodes. sysctl
174 * can be used to increase it further if desired.
176 * For disk cachhing purposes, filesystems like HAMMER1
177 * and HAMMER2 will or can be told to cache file data
178 * via the block device instead of excessively in vnodes.
180 factor1
= 25 * (sizeof(struct vm_object
) + sizeof(struct vnode
));
181 factor2
= 30 * (sizeof(struct vm_object
) + sizeof(struct vnode
));
182 maxvnodes
= imin((int64_t)vmstats
.v_page_count
* PAGE_SIZE
/ factor1
,
184 maxvnodes
= imax(maxvnodes
, maxproc
* 8);
185 maxvnodes
= imin(maxvnodes
, 64LL*1024*1024*1024 / factor2
);
187 lwkt_token_init(&spechash_token
, "spechash");
191 * Knob to control the precision of file timestamps:
193 * 0 = seconds only; nanoseconds zeroed.
194 * 1 = seconds and nanoseconds, accurate within 1/HZ.
195 * 2 = seconds and nanoseconds, truncated to microseconds.
196 * >=3 = seconds and nanoseconds, maximum precision.
198 enum { TSP_SEC
, TSP_HZ
, TSP_USEC
, TSP_NSEC
};
200 static int timestamp_precision
= TSP_SEC
;
201 SYSCTL_INT(_vfs
, OID_AUTO
, timestamp_precision
, CTLFLAG_RW
,
202 ×tamp_precision
, 0, "Precision of file timestamps");
205 * Get a current timestamp.
210 vfs_timestamp(struct timespec
*tsp
)
214 switch (timestamp_precision
) {
216 tsp
->tv_sec
= time_second
;
224 TIMEVAL_TO_TIMESPEC(&tv
, tsp
);
234 * Set vnode attributes to VNOVAL
237 vattr_null(struct vattr
*vap
)
240 vap
->va_size
= VNOVAL
;
241 vap
->va_bytes
= VNOVAL
;
242 vap
->va_mode
= VNOVAL
;
243 vap
->va_nlink
= VNOVAL
;
244 vap
->va_uid
= VNOVAL
;
245 vap
->va_gid
= VNOVAL
;
246 vap
->va_fsid
= VNOVAL
;
247 vap
->va_fileid
= VNOVAL
;
248 vap
->va_blocksize
= VNOVAL
;
249 vap
->va_rmajor
= VNOVAL
;
250 vap
->va_rminor
= VNOVAL
;
251 vap
->va_atime
.tv_sec
= VNOVAL
;
252 vap
->va_atime
.tv_nsec
= VNOVAL
;
253 vap
->va_mtime
.tv_sec
= VNOVAL
;
254 vap
->va_mtime
.tv_nsec
= VNOVAL
;
255 vap
->va_ctime
.tv_sec
= VNOVAL
;
256 vap
->va_ctime
.tv_nsec
= VNOVAL
;
257 vap
->va_flags
= VNOVAL
;
258 vap
->va_gen
= VNOVAL
;
260 /* va_*_uuid fields are only valid if related flags are set */
264 * Flush out and invalidate all buffers associated with a vnode.
268 static int vinvalbuf_bp(struct buf
*bp
, void *data
);
270 struct vinvalbuf_bp_info
{
279 vinvalbuf(struct vnode
*vp
, int flags
, int slpflag
, int slptimeo
)
281 struct vinvalbuf_bp_info info
;
285 lwkt_gettoken(&vp
->v_token
);
288 * If we are being asked to save, call fsync to ensure that the inode
291 if (flags
& V_SAVE
) {
292 error
= bio_track_wait(&vp
->v_track_write
, slpflag
, slptimeo
);
295 if (!RB_EMPTY(&vp
->v_rbdirty_tree
)) {
296 if ((error
= VOP_FSYNC(vp
, MNT_WAIT
, 0)) != 0)
300 * Dirty bufs may be left or generated via races
301 * in circumstances where vinvalbuf() is called on
302 * a vnode not undergoing reclamation. Only
303 * panic if we are trying to reclaim the vnode.
305 if ((vp
->v_flag
& VRECLAIMED
) &&
306 (bio_track_active(&vp
->v_track_write
) ||
307 !RB_EMPTY(&vp
->v_rbdirty_tree
))) {
308 panic("vinvalbuf: dirty bufs");
313 info
.slptimeo
= slptimeo
;
314 info
.lkflags
= LK_EXCLUSIVE
| LK_SLEEPFAIL
;
315 if (slpflag
& PCATCH
)
316 info
.lkflags
|= LK_PCATCH
;
321 * Flush the buffer cache until nothing is left, wait for all I/O
322 * to complete. At least one pass is required. We might block
323 * in the pip code so we have to re-check. Order is important.
329 if (!RB_EMPTY(&vp
->v_rbclean_tree
)) {
331 error
= RB_SCAN(buf_rb_tree
, &vp
->v_rbclean_tree
,
332 NULL
, vinvalbuf_bp
, &info
);
334 if (!RB_EMPTY(&vp
->v_rbdirty_tree
)) {
336 error
= RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
,
337 NULL
, vinvalbuf_bp
, &info
);
341 * Wait for I/O completion.
343 bio_track_wait(&vp
->v_track_write
, 0, 0);
344 if ((object
= vp
->v_object
) != NULL
)
345 refcount_wait(&object
->paging_in_progress
, "vnvlbx");
346 } while (bio_track_active(&vp
->v_track_write
) ||
347 !RB_EMPTY(&vp
->v_rbclean_tree
) ||
348 !RB_EMPTY(&vp
->v_rbdirty_tree
));
351 * Destroy the copy in the VM cache, too.
353 if ((object
= vp
->v_object
) != NULL
) {
354 vm_object_page_remove(object
, 0, 0,
355 (flags
& V_SAVE
) ? TRUE
: FALSE
);
358 if (!RB_EMPTY(&vp
->v_rbdirty_tree
) || !RB_EMPTY(&vp
->v_rbclean_tree
))
359 panic("vinvalbuf: flush failed");
360 if (!RB_EMPTY(&vp
->v_rbhash_tree
))
361 panic("vinvalbuf: flush failed, buffers still present");
364 lwkt_reltoken(&vp
->v_token
);
369 vinvalbuf_bp(struct buf
*bp
, void *data
)
371 struct vinvalbuf_bp_info
*info
= data
;
374 if (BUF_LOCK(bp
, LK_EXCLUSIVE
| LK_NOWAIT
)) {
375 atomic_add_int(&bp
->b_refs
, 1);
376 error
= BUF_TIMELOCK(bp
, info
->lkflags
,
377 "vinvalbuf", info
->slptimeo
);
378 atomic_subtract_int(&bp
->b_refs
, 1);
387 KKASSERT(bp
->b_vp
== info
->vp
);
390 * Must check clean/dirty status after successfully locking as
393 if ((info
->clean
&& (bp
->b_flags
& B_DELWRI
)) ||
394 (info
->clean
== 0 && (bp
->b_flags
& B_DELWRI
) == 0)) {
400 * NOTE: NO B_LOCKED CHECK. Also no buf_checkwrite()
401 * check. This code will write out the buffer, period.
404 if (((bp
->b_flags
& (B_DELWRI
| B_INVAL
)) == B_DELWRI
) &&
405 (info
->flags
& V_SAVE
)) {
407 } else if (info
->flags
& V_SAVE
) {
409 * Cannot set B_NOCACHE on a clean buffer as this will
410 * destroy the VM backing store which might actually
411 * be dirty (and unsynchronized).
413 bp
->b_flags
|= (B_INVAL
| B_RELBUF
);
416 bp
->b_flags
|= (B_INVAL
| B_NOCACHE
| B_RELBUF
);
423 * Truncate a file's buffer and pages to a specified length. This
424 * is in lieu of the old vinvalbuf mechanism, which performed unneeded
427 * The vnode must be locked.
429 static int vtruncbuf_bp_trunc_cmp(struct buf
*bp
, void *data
);
430 static int vtruncbuf_bp_trunc(struct buf
*bp
, void *data
);
431 static int vtruncbuf_bp_metasync_cmp(struct buf
*bp
, void *data
);
432 static int vtruncbuf_bp_metasync(struct buf
*bp
, void *data
);
434 struct vtruncbuf_info
{
441 vtruncbuf(struct vnode
*vp
, off_t length
, int blksize
)
443 struct vtruncbuf_info info
;
444 const char *filename
;
448 * Round up to the *next* block, then destroy the buffers in question.
449 * Since we are only removing some of the buffers we must rely on the
450 * scan count to determine whether a loop is necessary.
452 if ((count
= (int)(length
% blksize
)) != 0)
453 info
.truncloffset
= length
+ (blksize
- count
);
455 info
.truncloffset
= length
;
458 lwkt_gettoken(&vp
->v_token
);
461 count
= RB_SCAN(buf_rb_tree
, &vp
->v_rbclean_tree
,
462 vtruncbuf_bp_trunc_cmp
,
463 vtruncbuf_bp_trunc
, &info
);
465 count
+= RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
,
466 vtruncbuf_bp_trunc_cmp
,
467 vtruncbuf_bp_trunc
, &info
);
471 * For safety, fsync any remaining metadata if the file is not being
472 * truncated to 0. Since the metadata does not represent the entire
473 * dirty list we have to rely on the hit count to ensure that we get
478 count
= RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
,
479 vtruncbuf_bp_metasync_cmp
,
480 vtruncbuf_bp_metasync
, &info
);
485 * Clean out any left over VM backing store.
487 * It is possible to have in-progress I/O from buffers that were
488 * not part of the truncation. This should not happen if we
489 * are truncating to 0-length.
491 vnode_pager_setsize(vp
, length
);
492 bio_track_wait(&vp
->v_track_write
, 0, 0);
497 spin_lock(&vp
->v_spin
);
498 filename
= TAILQ_FIRST(&vp
->v_namecache
) ?
499 TAILQ_FIRST(&vp
->v_namecache
)->nc_name
: "?";
500 spin_unlock(&vp
->v_spin
);
503 * Make sure no buffers were instantiated while we were trying
504 * to clean out the remaining VM pages. This could occur due
505 * to busy dirty VM pages being flushed out to disk.
509 count
= RB_SCAN(buf_rb_tree
, &vp
->v_rbclean_tree
,
510 vtruncbuf_bp_trunc_cmp
,
511 vtruncbuf_bp_trunc
, &info
);
513 count
+= RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
,
514 vtruncbuf_bp_trunc_cmp
,
515 vtruncbuf_bp_trunc
, &info
);
517 kprintf("Warning: vtruncbuf(): Had to re-clean %d "
518 "left over buffers in %s\n", count
, filename
);
522 lwkt_reltoken(&vp
->v_token
);
528 * The callback buffer is beyond the new file EOF and must be destroyed.
529 * Note that the compare function must conform to the RB_SCAN's requirements.
533 vtruncbuf_bp_trunc_cmp(struct buf
*bp
, void *data
)
535 struct vtruncbuf_info
*info
= data
;
537 if (bp
->b_loffset
>= info
->truncloffset
)
544 vtruncbuf_bp_trunc(struct buf
*bp
, void *data
)
546 struct vtruncbuf_info
*info
= data
;
549 * Do not try to use a buffer we cannot immediately lock, but sleep
550 * anyway to prevent a livelock. The code will loop until all buffers
553 * We must always revalidate the buffer after locking it to deal
556 if (BUF_LOCK(bp
, LK_EXCLUSIVE
| LK_NOWAIT
)) {
557 atomic_add_int(&bp
->b_refs
, 1);
558 if (BUF_LOCK(bp
, LK_EXCLUSIVE
|LK_SLEEPFAIL
) == 0)
560 atomic_subtract_int(&bp
->b_refs
, 1);
561 } else if ((info
->clean
&& (bp
->b_flags
& B_DELWRI
)) ||
562 (info
->clean
== 0 && (bp
->b_flags
& B_DELWRI
) == 0) ||
563 bp
->b_vp
!= info
->vp
||
564 vtruncbuf_bp_trunc_cmp(bp
, data
)) {
568 bp
->b_flags
|= (B_INVAL
| B_RELBUF
| B_NOCACHE
);
575 * Fsync all meta-data after truncating a file to be non-zero. Only metadata
576 * blocks (with a negative loffset) are scanned.
577 * Note that the compare function must conform to the RB_SCAN's requirements.
580 vtruncbuf_bp_metasync_cmp(struct buf
*bp
, void *data __unused
)
582 if (bp
->b_loffset
< 0)
588 vtruncbuf_bp_metasync(struct buf
*bp
, void *data
)
590 struct vtruncbuf_info
*info
= data
;
592 if (BUF_LOCK(bp
, LK_EXCLUSIVE
| LK_NOWAIT
)) {
593 atomic_add_int(&bp
->b_refs
, 1);
594 if (BUF_LOCK(bp
, LK_EXCLUSIVE
|LK_SLEEPFAIL
) == 0)
596 atomic_subtract_int(&bp
->b_refs
, 1);
597 } else if ((bp
->b_flags
& B_DELWRI
) == 0 ||
598 bp
->b_vp
!= info
->vp
||
599 vtruncbuf_bp_metasync_cmp(bp
, data
)) {
603 if (bp
->b_vp
== info
->vp
)
612 * vfsync - implements a multipass fsync on a file which understands
613 * dependancies and meta-data. The passed vnode must be locked. The
614 * waitfor argument may be MNT_WAIT or MNT_NOWAIT, or MNT_LAZY.
616 * When fsyncing data asynchronously just do one consolidated pass starting
617 * with the most negative block number. This may not get all the data due
620 * When fsyncing data synchronously do a data pass, then a metadata pass,
621 * then do additional data+metadata passes to try to get all the data out.
623 * Caller must ref the vnode but does not have to lock it.
625 static int vfsync_wait_output(struct vnode
*vp
,
626 int (*waitoutput
)(struct vnode
*, struct thread
*));
627 static int vfsync_dummy_cmp(struct buf
*bp __unused
, void *data __unused
);
628 static int vfsync_data_only_cmp(struct buf
*bp
, void *data
);
629 static int vfsync_meta_only_cmp(struct buf
*bp
, void *data
);
630 static int vfsync_lazy_range_cmp(struct buf
*bp
, void *data
);
631 static int vfsync_bp(struct buf
*bp
, void *data
);
641 int (*checkdef
)(struct buf
*);
642 int (*cmpfunc
)(struct buf
*, void *);
646 vfsync(struct vnode
*vp
, int waitfor
, int passes
,
647 int (*checkdef
)(struct buf
*),
648 int (*waitoutput
)(struct vnode
*, struct thread
*))
650 struct vfsync_info info
;
653 bzero(&info
, sizeof(info
));
655 if ((info
.checkdef
= checkdef
) == NULL
)
658 lwkt_gettoken(&vp
->v_token
);
661 case MNT_LAZY
| MNT_NOWAIT
:
664 * Lazy (filesystem syncer typ) Asynchronous plus limit the
665 * number of data (not meta) pages we try to flush to 1MB.
666 * A non-zero return means that lazy limit was reached.
668 info
.lazylimit
= 1024 * 1024;
670 info
.cmpfunc
= vfsync_lazy_range_cmp
;
671 error
= RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
,
672 vfsync_lazy_range_cmp
, vfsync_bp
, &info
);
673 info
.cmpfunc
= vfsync_meta_only_cmp
;
674 RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
,
675 vfsync_meta_only_cmp
, vfsync_bp
, &info
);
678 else if (!RB_EMPTY(&vp
->v_rbdirty_tree
))
679 vn_syncer_add(vp
, 1);
684 * Asynchronous. Do a data-only pass and a meta-only pass.
687 info
.cmpfunc
= vfsync_data_only_cmp
;
688 RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
, vfsync_data_only_cmp
,
690 info
.cmpfunc
= vfsync_meta_only_cmp
;
691 RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
, vfsync_meta_only_cmp
,
697 * Synchronous. Do a data-only pass, then a meta-data+data
698 * pass, then additional integrated passes to try to get
699 * all the dependancies flushed.
701 info
.cmpfunc
= vfsync_data_only_cmp
;
703 RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
, vfsync_data_only_cmp
,
706 error
= vfsync_wait_output(vp
, waitoutput
);
708 info
.skippedbufs
= 0;
709 info
.cmpfunc
= vfsync_dummy_cmp
;
710 RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
, NULL
,
712 error
= vfsync_wait_output(vp
, waitoutput
);
713 if (info
.skippedbufs
) {
714 kprintf("Warning: vfsync skipped %d dirty "
717 ((info
.skippedbufs
> 1) ? "s" : ""));
720 while (error
== 0 && passes
> 0 &&
721 !RB_EMPTY(&vp
->v_rbdirty_tree
)
723 info
.skippedbufs
= 0;
725 info
.synchronous
= 1;
728 info
.cmpfunc
= vfsync_dummy_cmp
;
729 error
= RB_SCAN(buf_rb_tree
, &vp
->v_rbdirty_tree
, NULL
,
735 error
= vfsync_wait_output(vp
, waitoutput
);
736 if (info
.skippedbufs
&& passes
== 0) {
737 kprintf("Warning: vfsync skipped %d dirty "
738 "buf%s in final pass!\n",
740 ((info
.skippedbufs
> 1) ? "s" : ""));
745 * This case can occur normally because vnode lock might
748 if (!RB_EMPTY(&vp
->v_rbdirty_tree
))
749 kprintf("dirty bufs left after final pass\n");
753 lwkt_reltoken(&vp
->v_token
);
759 vfsync_wait_output(struct vnode
*vp
,
760 int (*waitoutput
)(struct vnode
*, struct thread
*))
764 error
= bio_track_wait(&vp
->v_track_write
, 0, 0);
766 error
= waitoutput(vp
, curthread
);
771 vfsync_dummy_cmp(struct buf
*bp __unused
, void *data __unused
)
777 vfsync_data_only_cmp(struct buf
*bp
, void *data
)
779 if (bp
->b_loffset
< 0)
785 vfsync_meta_only_cmp(struct buf
*bp
, void *data
)
787 if (bp
->b_loffset
< 0)
793 vfsync_lazy_range_cmp(struct buf
*bp
, void *data
)
795 struct vfsync_info
*info
= data
;
797 if (bp
->b_loffset
< info
->vp
->v_lazyw
)
803 vfsync_bp(struct buf
*bp
, void *data
)
805 struct vfsync_info
*info
= data
;
806 struct vnode
*vp
= info
->vp
;
809 if (info
->fastpass
) {
811 * Ignore buffers that we cannot immediately lock.
813 if (BUF_LOCK(bp
, LK_EXCLUSIVE
| LK_NOWAIT
)) {
815 * Removed BUF_TIMELOCK(..., 1), even a 1-tick
816 * delay can mess up performance
818 * Another reason is that during a dirty-buffer
819 * scan a clustered write can start I/O on buffers
820 * ahead of the scan, causing the scan to not
821 * get a lock here. Usually this means the write
822 * is already in progress so, in fact, we *want*
823 * to skip the buffer.
828 } else if (info
->synchronous
== 0) {
830 * Normal pass, give the buffer a little time to become
833 if (BUF_TIMELOCK(bp
, LK_EXCLUSIVE
, "bflst2", hz
/ 10)) {
839 * Synchronous pass, give the buffer a lot of time before
842 if (BUF_TIMELOCK(bp
, LK_EXCLUSIVE
, "bflst3", hz
* 10)) {
849 * We must revalidate the buffer after locking.
851 if ((bp
->b_flags
& B_DELWRI
) == 0 ||
852 bp
->b_vp
!= info
->vp
||
853 info
->cmpfunc(bp
, data
)) {
859 * If syncdeps is not set we do not try to write buffers which have
862 if (!info
->synchronous
&& info
->syncdeps
== 0 && info
->checkdef(bp
)) {
868 * B_NEEDCOMMIT (primarily used by NFS) is a state where the buffer
869 * has been written but an additional handshake with the device
870 * is required before we can dispose of the buffer. We have no idea
871 * how to do this so we have to skip these buffers.
873 if (bp
->b_flags
& B_NEEDCOMMIT
) {
879 * Ask bioops if it is ok to sync. If not the VFS may have
880 * set B_LOCKED so we have to cycle the buffer.
882 if (LIST_FIRST(&bp
->b_dep
) != NULL
&& buf_checkwrite(bp
)) {
888 if (info
->synchronous
) {
890 * Synchronous flush. An error may be returned and will
897 * Asynchronous flush. We use the error return to support
900 * In low-memory situations we revert to synchronous
901 * operation. This should theoretically prevent the I/O
902 * path from exhausting memory in a non-recoverable way.
904 vp
->v_lazyw
= bp
->b_loffset
;
906 if (vm_page_count_min(0)) {
908 info
->lazycount
+= bp
->b_bufsize
;
912 info
->lazycount
+= cluster_awrite(bp
);
913 waitrunningbufspace();
914 /*vm_wait_nominal();*/
916 if (info
->lazylimit
&& info
->lazycount
>= info
->lazylimit
)
925 * Associate a buffer with a vnode.
930 bgetvp(struct vnode
*vp
, struct buf
*bp
, int testsize
)
932 KASSERT(bp
->b_vp
== NULL
, ("bgetvp: not free"));
933 KKASSERT((bp
->b_flags
& (B_HASHED
|B_DELWRI
|B_VNCLEAN
|B_VNDIRTY
)) == 0);
936 * Insert onto list for new vnode.
938 lwkt_gettoken(&vp
->v_token
);
940 if (buf_rb_hash_RB_INSERT(&vp
->v_rbhash_tree
, bp
)) {
941 lwkt_reltoken(&vp
->v_token
);
946 * Diagnostics (mainly for HAMMER debugging). Check for
947 * overlapping buffers.
949 if (check_buf_overlap
) {
951 bx
= buf_rb_hash_RB_PREV(bp
);
953 if (bx
->b_loffset
+ bx
->b_bufsize
> bp
->b_loffset
) {
954 kprintf("bgetvp: overlapl %016jx/%d %016jx "
956 (intmax_t)bx
->b_loffset
,
958 (intmax_t)bp
->b_loffset
,
960 if (check_buf_overlap
> 1)
961 panic("bgetvp - overlapping buffer");
964 bx
= buf_rb_hash_RB_NEXT(bp
);
966 if (bp
->b_loffset
+ testsize
> bx
->b_loffset
) {
967 kprintf("bgetvp: overlapr %016jx/%d %016jx "
969 (intmax_t)bp
->b_loffset
,
971 (intmax_t)bx
->b_loffset
,
973 if (check_buf_overlap
> 1)
974 panic("bgetvp - overlapping buffer");
979 bp
->b_flags
|= B_HASHED
;
980 bp
->b_flags
|= B_VNCLEAN
;
981 if (buf_rb_tree_RB_INSERT(&vp
->v_rbclean_tree
, bp
))
982 panic("reassignbuf: dup lblk/clean vp %p bp %p", vp
, bp
);
984 lwkt_reltoken(&vp
->v_token
);
989 * Disassociate a buffer from a vnode.
994 brelvp(struct buf
*bp
)
998 KASSERT(bp
->b_vp
!= NULL
, ("brelvp: NULL"));
1001 * Delete from old vnode list, if on one.
1004 lwkt_gettoken(&vp
->v_token
);
1005 if (bp
->b_flags
& (B_VNDIRTY
| B_VNCLEAN
)) {
1006 if (bp
->b_flags
& B_VNDIRTY
)
1007 buf_rb_tree_RB_REMOVE(&vp
->v_rbdirty_tree
, bp
);
1009 buf_rb_tree_RB_REMOVE(&vp
->v_rbclean_tree
, bp
);
1010 bp
->b_flags
&= ~(B_VNDIRTY
| B_VNCLEAN
);
1012 if (bp
->b_flags
& B_HASHED
) {
1013 buf_rb_hash_RB_REMOVE(&vp
->v_rbhash_tree
, bp
);
1014 bp
->b_flags
&= ~B_HASHED
;
1018 * Only remove from synclist when no dirty buffers are left AND
1019 * the VFS has not flagged the vnode's inode as being dirty.
1021 if ((vp
->v_flag
& (VONWORKLST
| VISDIRTY
| VOBJDIRTY
)) == VONWORKLST
&&
1022 RB_EMPTY(&vp
->v_rbdirty_tree
)) {
1023 vn_syncer_remove(vp
, 0);
1027 lwkt_reltoken(&vp
->v_token
);
1033 * Reassign the buffer to the proper clean/dirty list based on B_DELWRI.
1034 * This routine is called when the state of the B_DELWRI bit is changed.
1036 * Must be called with vp->v_token held.
1040 reassignbuf(struct buf
*bp
)
1042 struct vnode
*vp
= bp
->b_vp
;
1045 ASSERT_LWKT_TOKEN_HELD(&vp
->v_token
);
1049 * B_PAGING flagged buffers cannot be reassigned because their vp
1050 * is not fully linked in.
1052 if (bp
->b_flags
& B_PAGING
)
1053 panic("cannot reassign paging buffer");
1055 if (bp
->b_flags
& B_DELWRI
) {
1057 * Move to the dirty list, add the vnode to the worklist
1059 if (bp
->b_flags
& B_VNCLEAN
) {
1060 buf_rb_tree_RB_REMOVE(&vp
->v_rbclean_tree
, bp
);
1061 bp
->b_flags
&= ~B_VNCLEAN
;
1063 if ((bp
->b_flags
& B_VNDIRTY
) == 0) {
1064 if (buf_rb_tree_RB_INSERT(&vp
->v_rbdirty_tree
, bp
)) {
1065 panic("reassignbuf: dup lblk vp %p bp %p",
1068 bp
->b_flags
|= B_VNDIRTY
;
1070 if ((vp
->v_flag
& VONWORKLST
) == 0) {
1071 switch (vp
->v_type
) {
1078 vp
->v_rdev
->si_mountpoint
!= NULL
) {
1086 vn_syncer_add(vp
, delay
);
1090 * Move to the clean list, remove the vnode from the worklist
1091 * if no dirty blocks remain.
1093 if (bp
->b_flags
& B_VNDIRTY
) {
1094 buf_rb_tree_RB_REMOVE(&vp
->v_rbdirty_tree
, bp
);
1095 bp
->b_flags
&= ~B_VNDIRTY
;
1097 if ((bp
->b_flags
& B_VNCLEAN
) == 0) {
1098 if (buf_rb_tree_RB_INSERT(&vp
->v_rbclean_tree
, bp
)) {
1099 panic("reassignbuf: dup lblk vp %p bp %p",
1102 bp
->b_flags
|= B_VNCLEAN
;
1106 * Only remove from synclist when no dirty buffers are left
1107 * AND the VFS has not flagged the vnode's inode as being
1110 if ((vp
->v_flag
& (VONWORKLST
| VISDIRTY
| VOBJDIRTY
)) ==
1112 RB_EMPTY(&vp
->v_rbdirty_tree
)) {
1113 vn_syncer_remove(vp
, 0);
1119 * Create a vnode for a block device. Used for mounting the root file
1122 * A vref()'d vnode is returned.
1124 extern struct vop_ops
*devfs_vnode_dev_vops_p
;
1126 bdevvp(cdev_t dev
, struct vnode
**vpp
)
1136 error
= getspecialvnode(VT_NON
, NULL
, &devfs_vnode_dev_vops_p
,
1147 v_associate_rdev(vp
, dev
);
1148 vp
->v_umajor
= dev
->si_umajor
;
1149 vp
->v_uminor
= dev
->si_uminor
;
1156 v_associate_rdev(struct vnode
*vp
, cdev_t dev
)
1160 if (dev_is_good(dev
) == 0)
1162 KKASSERT(vp
->v_rdev
== NULL
);
1163 vp
->v_rdev
= reference_dev(dev
);
1164 lwkt_gettoken(&spechash_token
);
1165 SLIST_INSERT_HEAD(&dev
->si_hlist
, vp
, v_cdevnext
);
1166 lwkt_reltoken(&spechash_token
);
1171 v_release_rdev(struct vnode
*vp
)
1175 if ((dev
= vp
->v_rdev
) != NULL
) {
1176 lwkt_gettoken(&spechash_token
);
1177 SLIST_REMOVE(&dev
->si_hlist
, vp
, vnode
, v_cdevnext
);
1180 lwkt_reltoken(&spechash_token
);
1185 * Add a vnode to the alias list hung off the cdev_t. We only associate
1186 * the device number with the vnode. The actual device is not associated
1187 * until the vnode is opened (usually in spec_open()), and will be
1188 * disassociated on last close.
1191 addaliasu(struct vnode
*nvp
, int x
, int y
)
1193 if (nvp
->v_type
!= VBLK
&& nvp
->v_type
!= VCHR
)
1194 panic("addaliasu on non-special vnode");
1200 * Simple call that a filesystem can make to try to get rid of a
1201 * vnode. It will fail if anyone is referencing the vnode (including
1204 * The filesystem can check whether its in-memory inode structure still
1205 * references the vp on return.
1207 * May only be called if the vnode is in a known state (i.e. being prevented
1208 * from being deallocated by some other condition such as a vfs inode hold).
1211 vclean_unlocked(struct vnode
*vp
)
1214 if (VREFCNT(vp
) <= 1)
1220 * Disassociate a vnode from its underlying filesystem.
1222 * The vnode must be VX locked and referenced. In all normal situations
1223 * there are no active references. If vclean_vxlocked() is called while
1224 * there are active references, the vnode is being ripped out and we have
1225 * to call VOP_CLOSE() as appropriate before we can reclaim it.
1228 vclean_vxlocked(struct vnode
*vp
, int flags
)
1233 struct namecache
*ncp
;
1236 * If the vnode has already been reclaimed we have nothing to do.
1238 if (vp
->v_flag
& VRECLAIMED
)
1242 * Set flag to interlock operation, flag finalization to ensure
1243 * that the vnode winds up on the inactive list, and set v_act to 0.
1245 vsetflags(vp
, VRECLAIMED
);
1246 atomic_set_int(&vp
->v_refcnt
, VREF_FINALIZE
);
1249 if (verbose_reclaims
) {
1250 if ((ncp
= TAILQ_FIRST(&vp
->v_namecache
)) != NULL
)
1251 kprintf("Debug: reclaim %p %s\n", vp
, ncp
->nc_name
);
1255 * Scrap the vfs cache
1257 while (cache_inval_vp(vp
, 0) != 0) {
1258 kprintf("Warning: vnode %p clean/cache_resolution "
1259 "race detected\n", vp
);
1260 tsleep(vp
, 0, "vclninv", 2);
1264 * Check to see if the vnode is in use. If so we have to reference it
1265 * before we clean it out so that its count cannot fall to zero and
1266 * generate a race against ourselves to recycle it.
1268 active
= (VREFCNT(vp
) > 0);
1271 * Clean out any buffers associated with the vnode and destroy its
1272 * object, if it has one.
1274 vinvalbuf(vp
, V_SAVE
, 0, 0);
1277 * If purging an active vnode (typically during a forced unmount
1278 * or reboot), it must be closed and deactivated before being
1279 * reclaimed. This isn't really all that safe, but what can
1282 * Note that neither of these routines unlocks the vnode.
1284 if (active
&& (flags
& DOCLOSE
)) {
1285 while ((n
= vp
->v_opencount
) != 0) {
1286 if (vp
->v_writecount
)
1287 VOP_CLOSE(vp
, FWRITE
|FNONBLOCK
, NULL
);
1289 VOP_CLOSE(vp
, FNONBLOCK
, NULL
);
1290 if (vp
->v_opencount
== n
) {
1291 kprintf("Warning: unable to force-close"
1299 * If the vnode has not been deactivated, deactivated it. Deactivation
1300 * can create new buffers and VM pages so we have to call vinvalbuf()
1301 * again to make sure they all get flushed.
1303 * This can occur if a file with a link count of 0 needs to be
1306 * If the vnode is already dead don't try to deactivate it.
1308 if ((vp
->v_flag
& VINACTIVE
) == 0) {
1309 vsetflags(vp
, VINACTIVE
);
1312 vinvalbuf(vp
, V_SAVE
, 0, 0);
1316 * If the vnode has an object, destroy it.
1318 while ((object
= vp
->v_object
) != NULL
) {
1319 vm_object_hold(object
);
1320 if (object
== vp
->v_object
)
1322 vm_object_drop(object
);
1325 if (object
!= NULL
) {
1326 if (object
->ref_count
== 0) {
1327 if ((object
->flags
& OBJ_DEAD
) == 0)
1328 vm_object_terminate(object
);
1329 vm_object_drop(object
);
1330 vclrflags(vp
, VOBJBUF
);
1332 vm_pager_deallocate(object
);
1333 vclrflags(vp
, VOBJBUF
);
1334 vm_object_drop(object
);
1337 KKASSERT((vp
->v_flag
& VOBJBUF
) == 0);
1339 if (vp
->v_flag
& VOBJDIRTY
)
1343 * Reclaim the vnode if not already dead.
1345 if (vp
->v_mount
&& VOP_RECLAIM(vp
))
1346 panic("vclean: cannot reclaim");
1349 * Done with purge, notify sleepers of the grim news.
1351 vp
->v_ops
= &dead_vnode_vops_p
;
1356 * If we are destroying an active vnode, reactivate it now that
1357 * we have reassociated it with deadfs. This prevents the system
1358 * from crashing on the vnode due to it being unexpectedly marked
1359 * as inactive or reclaimed.
1361 if (active
&& (flags
& DOCLOSE
)) {
1362 vclrflags(vp
, VINACTIVE
| VRECLAIMED
);
1367 * Eliminate all activity associated with the requested vnode
1368 * and with all vnodes aliased to the requested vnode.
1370 * The vnode must be referenced but should not be locked.
1373 vrevoke(struct vnode
*vp
, struct ucred
*cred
)
1381 * If the vnode has a device association, scrap all vnodes associated
1382 * with the device. Don't let the device disappear on us while we
1383 * are scrapping the vnodes.
1385 * The passed vp will probably show up in the list, do not VX lock
1388 * Releasing the vnode's rdev here can mess up specfs's call to
1389 * device close, so don't do it. The vnode has been disassociated
1390 * and the device will be closed after the last ref on the related
1391 * fp goes away (if not still open by e.g. the kernel).
1393 if (vp
->v_type
!= VCHR
) {
1394 error
= fdrevoke(vp
, DTYPE_VNODE
, cred
);
1397 if ((dev
= vp
->v_rdev
) == NULL
) {
1401 lwkt_gettoken(&spechash_token
);
1404 vqn
= SLIST_FIRST(&dev
->si_hlist
);
1407 while ((vq
= vqn
) != NULL
) {
1408 if (VREFCNT(vq
) > 0) {
1410 fdrevoke(vq
, DTYPE_VNODE
, cred
);
1411 /*v_release_rdev(vq);*/
1413 if (vq
->v_rdev
!= dev
) {
1418 vqn
= SLIST_NEXT(vq
, v_cdevnext
);
1423 lwkt_reltoken(&spechash_token
);
1430 * This is called when the object underlying a vnode is being destroyed,
1431 * such as in a remove(). Try to recycle the vnode immediately if the
1432 * only active reference is our reference.
1434 * Directory vnodes in the namecache with children cannot be immediately
1435 * recycled because numerous VOP_N*() ops require them to be stable.
1437 * To avoid recursive recycling from VOP_INACTIVE implemenetations this
1438 * function is a NOP if VRECLAIMED is already set.
1441 vrecycle(struct vnode
*vp
)
1443 if (VREFCNT(vp
) <= 1 && (vp
->v_flag
& VRECLAIMED
) == 0) {
1444 if (cache_inval_vp_nonblock(vp
))
1453 * Return the maximum I/O size allowed for strategy calls on VP.
1455 * If vp is VCHR or VBLK we dive the device, otherwise we use
1456 * the vp's mount info.
1458 * The returned value is clamped at MAXPHYS as most callers cannot use
1459 * buffers larger than that size.
1462 vmaxiosize(struct vnode
*vp
)
1466 if (vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
)
1467 maxiosize
= vp
->v_rdev
->si_iosize_max
;
1469 maxiosize
= vp
->v_mount
->mnt_iosize_max
;
1471 if (maxiosize
> MAXPHYS
)
1472 maxiosize
= MAXPHYS
;
1477 * Eliminate all activity associated with a vnode in preparation for
1480 * The vnode must be VX locked and refd and will remain VX locked and refd
1481 * on return. This routine may be called with the vnode in any state, as
1482 * long as it is VX locked. The vnode will be cleaned out and marked
1483 * VRECLAIMED but will not actually be reused until all existing refs and
1486 * NOTE: This routine may be called on a vnode which has not yet been
1487 * already been deactivated (VOP_INACTIVE), or on a vnode which has
1488 * already been reclaimed.
1490 * This routine is not responsible for placing us back on the freelist.
1491 * Instead, it happens automatically when the caller releases the VX lock
1492 * (assuming there aren't any other references).
1495 vgone_vxlocked(struct vnode
*vp
)
1498 * assert that the VX lock is held. This is an absolute requirement
1499 * now for vgone_vxlocked() to be called.
1501 KKASSERT(lockinuse(&vp
->v_lock
));
1504 * Clean out the filesystem specific data and set the VRECLAIMED
1505 * bit. Also deactivate the vnode if necessary.
1507 * The vnode should have automatically been removed from the syncer
1508 * list as syncer/dirty flags cleared during the cleaning.
1510 vclean_vxlocked(vp
, DOCLOSE
);
1513 * Normally panic if the vnode is still dirty, unless we are doing
1514 * a forced unmount (tmpfs typically).
1516 if (vp
->v_flag
& VONWORKLST
) {
1517 if (vp
->v_mount
->mnt_kern_flag
& MNTK_UNMOUNTF
) {
1519 vn_syncer_remove(vp
, 1);
1521 panic("vp %p still dirty in vgone after flush", vp
);
1526 * Delete from old mount point vnode list, if on one.
1528 if (vp
->v_mount
!= NULL
) {
1529 KKASSERT(vp
->v_data
== NULL
);
1530 insmntque(vp
, NULL
);
1534 * If special device, remove it from special device alias list
1535 * if it is on one. This should normally only occur if a vnode is
1536 * being revoked as the device should otherwise have been released
1539 if ((vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
) && vp
->v_rdev
!= NULL
) {
1550 * Lookup a vnode by device number.
1552 * Returns non-zero and *vpp set to a vref'd vnode on success.
1553 * Returns zero on failure.
1556 vfinddev(cdev_t dev
, enum vtype type
, struct vnode
**vpp
)
1560 lwkt_gettoken(&spechash_token
);
1561 SLIST_FOREACH(vp
, &dev
->si_hlist
, v_cdevnext
) {
1562 if (type
== vp
->v_type
) {
1565 lwkt_reltoken(&spechash_token
);
1569 lwkt_reltoken(&spechash_token
);
1574 * Calculate the total number of references to a special device. This
1575 * routine may only be called for VBLK and VCHR vnodes since v_rdev is
1576 * an overloaded field. Since udev2dev can now return NULL, we have
1577 * to check for a NULL v_rdev.
1580 count_dev(cdev_t dev
)
1585 if (SLIST_FIRST(&dev
->si_hlist
)) {
1586 lwkt_gettoken(&spechash_token
);
1587 SLIST_FOREACH(vp
, &dev
->si_hlist
, v_cdevnext
) {
1588 count
+= vp
->v_opencount
;
1590 lwkt_reltoken(&spechash_token
);
1596 vcount(struct vnode
*vp
)
1598 if (vp
->v_rdev
== NULL
)
1600 return(count_dev(vp
->v_rdev
));
1604 * Initialize VMIO for a vnode. This routine MUST be called before a
1605 * VFS can issue buffer cache ops on a vnode. It is typically called
1606 * when a vnode is initialized from its inode.
1609 vinitvmio(struct vnode
*vp
, off_t filesize
, int blksize
, int boff
)
1614 object
= vp
->v_object
;
1616 vm_object_hold(object
);
1617 KKASSERT(vp
->v_object
== object
);
1620 if (object
== NULL
) {
1621 object
= vnode_pager_alloc(vp
, filesize
, 0, 0, blksize
, boff
);
1624 * Dereference the reference we just created. This assumes
1625 * that the object is associated with the vp. Allow it to
1626 * have zero refs. It cannot be destroyed as long as it
1627 * is associated with the vnode.
1629 vm_object_hold(object
);
1630 atomic_add_int(&object
->ref_count
, -1);
1633 KKASSERT((object
->flags
& OBJ_DEAD
) == 0);
1635 KASSERT(vp
->v_object
!= NULL
, ("vinitvmio: NULL object"));
1636 vsetflags(vp
, VOBJBUF
);
1637 vm_object_drop(object
);
1644 * Print out a description of a vnode.
1646 static char *typename
[] =
1647 {"VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"};
1650 vprint(char *label
, struct vnode
*vp
)
1655 kprintf("%s: %p: ", label
, (void *)vp
);
1657 kprintf("%p: ", (void *)vp
);
1658 kprintf("type %s, refcnt %08x, writecount %d, holdcnt %d,",
1659 typename
[vp
->v_type
],
1660 vp
->v_refcnt
, vp
->v_writecount
, vp
->v_auxrefs
);
1662 if (vp
->v_flag
& VROOT
)
1663 strcat(buf
, "|VROOT");
1664 if (vp
->v_flag
& VPFSROOT
)
1665 strcat(buf
, "|VPFSROOT");
1666 if (vp
->v_flag
& VTEXT
)
1667 strcat(buf
, "|VTEXT");
1668 if (vp
->v_flag
& VSYSTEM
)
1669 strcat(buf
, "|VSYSTEM");
1670 if (vp
->v_flag
& VOBJBUF
)
1671 strcat(buf
, "|VOBJBUF");
1673 kprintf(" flags (%s)", &buf
[1]);
1674 if (vp
->v_data
== NULL
) {
1683 * Do the usual access checking.
1684 * file_mode, uid and gid are from the vnode in question,
1685 * while acc_mode and cred are from the VOP_ACCESS parameter list
1688 vaccess(enum vtype type
, mode_t file_mode
, uid_t uid
, gid_t gid
,
1689 mode_t acc_mode
, struct ucred
*cred
)
1695 * Super-user always gets read/write access, but execute access depends
1696 * on at least one execute bit being set.
1698 if (priv_check_cred(cred
, PRIV_ROOT
, 0) == 0) {
1699 if ((acc_mode
& VEXEC
) && type
!= VDIR
&&
1700 (file_mode
& (S_IXUSR
|S_IXGRP
|S_IXOTH
)) == 0)
1707 /* Otherwise, check the owner. */
1708 if (cred
->cr_uid
== uid
) {
1709 if (acc_mode
& VEXEC
)
1711 if (acc_mode
& VREAD
)
1713 if (acc_mode
& VWRITE
)
1715 return ((file_mode
& mask
) == mask
? 0 : EACCES
);
1718 /* Otherwise, check the groups. */
1719 ismember
= groupmember(gid
, cred
);
1720 if (cred
->cr_svgid
== gid
|| ismember
) {
1721 if (acc_mode
& VEXEC
)
1723 if (acc_mode
& VREAD
)
1725 if (acc_mode
& VWRITE
)
1727 return ((file_mode
& mask
) == mask
? 0 : EACCES
);
1730 /* Otherwise, check everyone else. */
1731 if (acc_mode
& VEXEC
)
1733 if (acc_mode
& VREAD
)
1735 if (acc_mode
& VWRITE
)
1737 return ((file_mode
& mask
) == mask
? 0 : EACCES
);
1741 #include <ddb/ddb.h>
1743 static int db_show_locked_vnodes(struct mount
*mp
, void *data
);
1746 * List all of the locked vnodes in the system.
1747 * Called when debugging the kernel.
1749 DB_SHOW_COMMAND(lockedvnodes
, lockedvnodes
)
1751 kprintf("Locked vnodes\n");
1752 mountlist_scan(db_show_locked_vnodes
, NULL
,
1753 MNTSCAN_FORWARD
|MNTSCAN_NOBUSY
);
1757 db_show_locked_vnodes(struct mount
*mp
, void *data __unused
)
1761 TAILQ_FOREACH(vp
, &mp
->mnt_nvnodelist
, v_nmntvnodes
) {
1762 if (vn_islocked(vp
))
1770 * Top level filesystem related information gathering.
1772 static int sysctl_ovfs_conf (SYSCTL_HANDLER_ARGS
);
1775 vfs_sysctl(SYSCTL_HANDLER_ARGS
)
1777 int *name
= (int *)arg1
- 1; /* XXX */
1778 u_int namelen
= arg2
+ 1; /* XXX */
1779 struct vfsconf
*vfsp
;
1782 #if 1 || defined(COMPAT_PRELITE2)
1783 /* Resolve ambiguity between VFS_VFSCONF and VFS_GENERIC. */
1785 return (sysctl_ovfs_conf(oidp
, arg1
, arg2
, req
));
1789 /* all sysctl names at this level are at least name and field */
1791 return (ENOTDIR
); /* overloaded */
1792 if (name
[0] != VFS_GENERIC
) {
1793 vfsp
= vfsconf_find_by_typenum(name
[0]);
1795 return (EOPNOTSUPP
);
1796 return ((*vfsp
->vfc_vfsops
->vfs_sysctl
)(&name
[1], namelen
- 1,
1797 oldp
, oldlenp
, newp
, newlen
, p
));
1801 case VFS_MAXTYPENUM
:
1804 maxtypenum
= vfsconf_get_maxtypenum();
1805 return (SYSCTL_OUT(req
, &maxtypenum
, sizeof(maxtypenum
)));
1808 return (ENOTDIR
); /* overloaded */
1809 vfsp
= vfsconf_find_by_typenum(name
[2]);
1811 return (EOPNOTSUPP
);
1812 return (SYSCTL_OUT(req
, vfsp
, sizeof *vfsp
));
1814 return (EOPNOTSUPP
);
1817 SYSCTL_NODE(_vfs
, VFS_GENERIC
, generic
, CTLFLAG_RD
, vfs_sysctl
,
1818 "Generic filesystem");
1820 #if 1 || defined(COMPAT_PRELITE2)
1823 sysctl_ovfs_conf_iter(struct vfsconf
*vfsp
, void *data
)
1826 struct ovfsconf ovfs
;
1827 struct sysctl_req
*req
= (struct sysctl_req
*) data
;
1829 bzero(&ovfs
, sizeof(ovfs
));
1830 ovfs
.vfc_vfsops
= vfsp
->vfc_vfsops
; /* XXX used as flag */
1831 strcpy(ovfs
.vfc_name
, vfsp
->vfc_name
);
1832 ovfs
.vfc_index
= vfsp
->vfc_typenum
;
1833 ovfs
.vfc_refcount
= vfsp
->vfc_refcount
;
1834 ovfs
.vfc_flags
= vfsp
->vfc_flags
;
1835 error
= SYSCTL_OUT(req
, &ovfs
, sizeof ovfs
);
1837 return error
; /* abort iteration with error code */
1839 return 0; /* continue iterating with next element */
1843 sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS
)
1845 return vfsconf_each(sysctl_ovfs_conf_iter
, (void*)req
);
1848 #endif /* 1 || COMPAT_PRELITE2 */
1851 * Check to see if a filesystem is mounted on a block device.
1854 vfs_mountedon(struct vnode
*vp
)
1858 if ((dev
= vp
->v_rdev
) == NULL
) {
1859 /* if (vp->v_type != VBLK)
1860 dev = get_dev(vp->v_uminor, vp->v_umajor); */
1862 if (dev
!= NULL
&& dev
->si_mountpoint
)
1868 * Unmount all filesystems. The list is traversed in reverse order
1869 * of mounting to avoid dependencies.
1871 * We want the umountall to be able to break out of its loop if a
1872 * failure occurs, after scanning all possible mounts, so the callback
1873 * returns 0 on error.
1875 * NOTE: Do not call mountlist_remove(mp) on error any more, this will
1876 * confuse mountlist_scan()'s unbusy check.
1878 static int vfs_umountall_callback(struct mount
*mp
, void *data
);
1881 vfs_unmountall(int halting
)
1886 count
= mountlist_scan(vfs_umountall_callback
, &halting
,
1887 MNTSCAN_REVERSE
|MNTSCAN_NOBUSY
);
1893 vfs_umountall_callback(struct mount
*mp
, void *data
)
1896 int halting
= *(int *)data
;
1899 * NOTE: When halting, dounmount will disconnect but leave
1900 * certain mount points intact. e.g. devfs.
1902 error
= dounmount(mp
, MNT_FORCE
, halting
);
1904 kprintf("unmount of filesystem mounted from %s failed (",
1905 mp
->mnt_stat
.f_mntfromname
);
1909 kprintf("%d)\n", error
);
1917 * Checks the mount flags for parameter mp and put the names comma-separated
1918 * into a string buffer buf with a size limit specified by len.
1920 * It returns the number of bytes written into buf, and (*errorp) will be
1921 * set to 0, EINVAL (if passed length is 0), or ENOSPC (supplied buffer was
1922 * not large enough). The buffer will be 0-terminated if len was not 0.
1925 vfs_flagstostr(int flags
, const struct mountctl_opt
*optp
,
1926 char *buf
, size_t len
, int *errorp
)
1928 static const struct mountctl_opt optnames
[] = {
1929 { MNT_RDONLY
, "read-only" },
1930 { MNT_SYNCHRONOUS
, "synchronous" },
1931 { MNT_NOEXEC
, "noexec" },
1932 { MNT_NOSUID
, "nosuid" },
1933 { MNT_NODEV
, "nodev" },
1934 { MNT_AUTOMOUNTED
, "automounted" },
1935 { MNT_ASYNC
, "asynchronous" },
1936 { MNT_SUIDDIR
, "suiddir" },
1937 { MNT_SOFTDEP
, "soft-updates" },
1938 { MNT_NOSYMFOLLOW
, "nosymfollow" },
1939 { MNT_TRIM
, "trim" },
1940 { MNT_NOATIME
, "noatime" },
1941 { MNT_NOCLUSTERR
, "noclusterr" },
1942 { MNT_NOCLUSTERW
, "noclusterw" },
1943 { MNT_EXRDONLY
, "NFS read-only" },
1944 { MNT_EXPORTED
, "NFS exported" },
1945 /* Remaining NFS flags could come here */
1946 { MNT_LOCAL
, "local" },
1947 { MNT_QUOTA
, "with-quotas" },
1948 /* { MNT_ROOTFS, "rootfs" }, */
1949 /* { MNT_IGNORE, "ignore" }, */
1959 bleft
= len
- 1; /* leave room for trailing \0 */
1962 * Checks the size of the string. If it contains
1963 * any data, then we will append the new flags to
1966 actsize
= strlen(buf
);
1970 /* Default flags if no flags passed */
1974 if (bleft
< 0) { /* degenerate case, 0-length buffer */
1979 for (; flags
&& optp
->o_opt
; ++optp
) {
1980 if ((flags
& optp
->o_opt
) == 0)
1982 optlen
= strlen(optp
->o_name
);
1983 if (bwritten
|| actsize
> 0) {
1988 buf
[bwritten
++] = ',';
1989 buf
[bwritten
++] = ' ';
1992 if (bleft
< optlen
) {
1996 bcopy(optp
->o_name
, buf
+ bwritten
, optlen
);
1999 flags
&= ~optp
->o_opt
;
2003 * Space already reserved for trailing \0
2010 * Build hash lists of net addresses and hang them off the mount point.
2011 * Called by ufs_mount() to set up the lists of export addresses.
2014 vfs_hang_addrlist(struct mount
*mp
, struct netexport
*nep
,
2015 const struct export_args
*argp
)
2018 struct radix_node_head
*rnh
;
2020 struct radix_node
*rn
;
2021 struct sockaddr
*saddr
, *smask
= NULL
;
2024 if (argp
->ex_addrlen
== 0) {
2025 if (mp
->mnt_flag
& MNT_DEFEXPORTED
)
2027 np
= &nep
->ne_defexported
;
2028 np
->netc_exflags
= argp
->ex_flags
;
2029 np
->netc_anon
= argp
->ex_anon
;
2030 np
->netc_anon
.cr_ref
= 1;
2031 mp
->mnt_flag
|= MNT_DEFEXPORTED
;
2035 if (argp
->ex_addrlen
< 0 || argp
->ex_addrlen
> MLEN
)
2037 if (argp
->ex_masklen
< 0 || argp
->ex_masklen
> MLEN
)
2040 i
= sizeof(struct netcred
) + argp
->ex_addrlen
+ argp
->ex_masklen
;
2041 np
= (struct netcred
*)kmalloc(i
, M_NETCRED
, M_WAITOK
| M_ZERO
);
2042 saddr
= (struct sockaddr
*) (np
+ 1);
2043 if ((error
= copyin(argp
->ex_addr
, (caddr_t
) saddr
, argp
->ex_addrlen
)))
2045 if (saddr
->sa_len
> argp
->ex_addrlen
)
2046 saddr
->sa_len
= argp
->ex_addrlen
;
2047 if (argp
->ex_masklen
) {
2048 smask
= (struct sockaddr
*)((caddr_t
)saddr
+ argp
->ex_addrlen
);
2049 error
= copyin(argp
->ex_mask
, (caddr_t
)smask
, argp
->ex_masklen
);
2052 if (smask
->sa_len
> argp
->ex_masklen
)
2053 smask
->sa_len
= argp
->ex_masklen
;
2056 if (nep
->ne_maskhead
== NULL
) {
2057 if (!rn_inithead((void **)&nep
->ne_maskhead
, NULL
, 0)) {
2062 if ((rnh
= vfs_create_addrlist_af(saddr
->sa_family
, nep
)) == NULL
) {
2066 rn
= (*rnh
->rnh_addaddr
)((char *)saddr
, (char *)smask
, rnh
,
2069 if (rn
== NULL
|| np
!= (struct netcred
*)rn
) { /* already exists */
2073 np
->netc_exflags
= argp
->ex_flags
;
2074 np
->netc_anon
= argp
->ex_anon
;
2075 np
->netc_anon
.cr_ref
= 1;
2079 kfree(np
, M_NETCRED
);
2084 * Free netcred structures installed in the netexport
2087 vfs_free_netcred(struct radix_node
*rn
, void *w
)
2089 struct radix_node_head
*rnh
= (struct radix_node_head
*)w
;
2091 (*rnh
->rnh_deladdr
) (rn
->rn_key
, rn
->rn_mask
, rnh
);
2092 kfree(rn
, M_NETCRED
);
2098 * callback to free an element of the mask table installed in the
2099 * netexport. These may be created indirectly and are not netcred
2103 vfs_free_netcred_mask(struct radix_node
*rn
, void *w
)
2105 struct radix_node_head
*rnh
= (struct radix_node_head
*)w
;
2107 (*rnh
->rnh_deladdr
) (rn
->rn_key
, rn
->rn_mask
, rnh
);
2108 kfree(rn
, M_RTABLE
);
2113 static struct radix_node_head
*
2114 vfs_create_addrlist_af(int af
, struct netexport
*nep
)
2116 struct radix_node_head
*rnh
= NULL
;
2117 #if defined(INET) || defined(INET6)
2118 struct radix_node_head
*maskhead
= nep
->ne_maskhead
;
2122 NE_ASSERT_LOCKED(nep
);
2123 #if defined(INET) || defined(INET6)
2124 KKASSERT(maskhead
!= NULL
);
2129 if ((rnh
= nep
->ne_inethead
) == NULL
) {
2130 off
= offsetof(struct sockaddr_in
, sin_addr
) << 3;
2131 if (!rn_inithead((void **)&rnh
, maskhead
, off
))
2133 nep
->ne_inethead
= rnh
;
2139 if ((rnh
= nep
->ne_inet6head
) == NULL
) {
2140 off
= offsetof(struct sockaddr_in6
, sin6_addr
) << 3;
2141 if (!rn_inithead((void **)&rnh
, maskhead
, off
))
2143 nep
->ne_inet6head
= rnh
;
2152 * helper function for freeing netcred elements
2155 vfs_free_addrlist_af(struct radix_node_head
**prnh
)
2157 struct radix_node_head
*rnh
= *prnh
;
2159 (*rnh
->rnh_walktree
) (rnh
, vfs_free_netcred
, rnh
);
2160 kfree(rnh
, M_RTABLE
);
2165 * helper function for freeing mask elements
2168 vfs_free_addrlist_masks(struct radix_node_head
**prnh
)
2170 struct radix_node_head
*rnh
= *prnh
;
2172 (*rnh
->rnh_walktree
) (rnh
, vfs_free_netcred_mask
, rnh
);
2173 kfree(rnh
, M_RTABLE
);
2178 * Free the net address hash lists that are hanging off the mount points.
2181 vfs_free_addrlist(struct netexport
*nep
)
2184 if (nep
->ne_inethead
!= NULL
)
2185 vfs_free_addrlist_af(&nep
->ne_inethead
);
2186 if (nep
->ne_inet6head
!= NULL
)
2187 vfs_free_addrlist_af(&nep
->ne_inet6head
);
2188 if (nep
->ne_maskhead
)
2189 vfs_free_addrlist_masks(&nep
->ne_maskhead
);
2194 vfs_export(struct mount
*mp
, struct netexport
*nep
,
2195 const struct export_args
*argp
)
2199 if (argp
->ex_flags
& MNT_DELEXPORT
) {
2200 if (mp
->mnt_flag
& MNT_EXPUBLIC
) {
2201 vfs_setpublicfs(NULL
, NULL
, NULL
);
2202 mp
->mnt_flag
&= ~MNT_EXPUBLIC
;
2204 vfs_free_addrlist(nep
);
2205 mp
->mnt_flag
&= ~(MNT_EXPORTED
| MNT_DEFEXPORTED
);
2207 if (argp
->ex_flags
& MNT_EXPORTED
) {
2208 if (argp
->ex_flags
& MNT_EXPUBLIC
) {
2209 if ((error
= vfs_setpublicfs(mp
, nep
, argp
)) != 0)
2211 mp
->mnt_flag
|= MNT_EXPUBLIC
;
2213 if ((error
= vfs_hang_addrlist(mp
, nep
, argp
)))
2215 mp
->mnt_flag
|= MNT_EXPORTED
;
2222 * Set the publicly exported filesystem (WebNFS). Currently, only
2223 * one public filesystem is possible in the spec (RFC 2054 and 2055)
2226 vfs_setpublicfs(struct mount
*mp
, struct netexport
*nep
,
2227 const struct export_args
*argp
)
2234 * mp == NULL -> invalidate the current info, the FS is
2235 * no longer exported. May be called from either vfs_export
2236 * or unmount, so check if it hasn't already been done.
2239 if (nfs_pub
.np_valid
) {
2240 nfs_pub
.np_valid
= 0;
2241 if (nfs_pub
.np_index
!= NULL
) {
2242 kfree(nfs_pub
.np_index
, M_TEMP
);
2243 nfs_pub
.np_index
= NULL
;
2250 * Only one allowed at a time.
2252 if (nfs_pub
.np_valid
!= 0 && mp
!= nfs_pub
.np_mount
)
2256 * Get real filehandle for root of exported FS.
2258 bzero((caddr_t
)&nfs_pub
.np_handle
, sizeof(nfs_pub
.np_handle
));
2259 nfs_pub
.np_handle
.fh_fsid
= mp
->mnt_stat
.f_fsid
;
2261 if ((error
= VFS_ROOT(mp
, &rvp
)))
2264 if ((error
= VFS_VPTOFH(rvp
, &nfs_pub
.np_handle
.fh_fid
)))
2270 * If an indexfile was specified, pull it in.
2272 if (argp
->ex_indexfile
!= NULL
) {
2275 error
= vn_get_namelen(rvp
, &namelen
);
2278 nfs_pub
.np_index
= kmalloc(namelen
, M_TEMP
, M_WAITOK
);
2279 error
= copyinstr(argp
->ex_indexfile
, nfs_pub
.np_index
,
2283 * Check for illegal filenames.
2285 for (cp
= nfs_pub
.np_index
; *cp
; cp
++) {
2293 kfree(nfs_pub
.np_index
, M_TEMP
);
2298 nfs_pub
.np_mount
= mp
;
2299 nfs_pub
.np_valid
= 1;
2304 vfs_export_lookup(struct mount
*mp
, struct netexport
*nep
,
2305 struct sockaddr
*nam
)
2308 struct radix_node_head
*rnh
;
2309 struct sockaddr
*saddr
;
2312 if (mp
->mnt_flag
& MNT_EXPORTED
) {
2314 * Lookup in the export list first.
2319 switch (saddr
->sa_family
) {
2322 rnh
= nep
->ne_inethead
;
2327 rnh
= nep
->ne_inet6head
;
2334 np
= (struct netcred
*)
2335 (*rnh
->rnh_matchaddr
)((char *)saddr
,
2337 if (np
&& np
->netc_rnodes
->rn_flags
& RNF_ROOT
)
2343 * If no address match, use the default if it exists.
2345 if (np
== NULL
&& mp
->mnt_flag
& MNT_DEFEXPORTED
)
2346 np
= &nep
->ne_defexported
;
2352 * perform msync on all vnodes under a mount point. The mount point must
2353 * be locked. This code is also responsible for lazy-freeing unreferenced
2354 * vnodes whos VM objects no longer contain pages.
2356 * NOTE: MNT_WAIT still skips vnodes in the VXLOCK state.
2358 * NOTE: XXX VOP_PUTPAGES and friends requires that the vnode be locked,
2359 * but vnode_pager_putpages() doesn't lock the vnode. We have to do it
2360 * way up in this high level function.
2362 static int vfs_msync_scan1(struct mount
*mp
, struct vnode
*vp
, void *data
);
2363 static int vfs_msync_scan2(struct mount
*mp
, struct vnode
*vp
, void *data
);
2366 vfs_msync(struct mount
*mp
, int flags
)
2371 * tmpfs sets this flag to prevent msync(), sync, and the
2372 * filesystem periodic syncer from trying to flush VM pages
2373 * to swap. Only pure memory pressure flushes tmpfs VM pages
2376 if (mp
->mnt_kern_flag
& MNTK_NOMSYNC
)
2380 * Ok, scan the vnodes for work. If the filesystem is using the
2381 * syncer thread feature we can use vsyncscan() instead of
2382 * vmntvnodescan(), which is much faster.
2384 vmsc_flags
= VMSC_GETVP
;
2385 if (flags
!= MNT_WAIT
)
2386 vmsc_flags
|= VMSC_NOWAIT
;
2388 if (mp
->mnt_kern_flag
& MNTK_THR_SYNC
) {
2389 vsyncscan(mp
, vmsc_flags
, vfs_msync_scan2
,
2390 (void *)(intptr_t)flags
);
2392 vmntvnodescan(mp
, vmsc_flags
,
2393 vfs_msync_scan1
, vfs_msync_scan2
,
2394 (void *)(intptr_t)flags
);
2399 * scan1 is a fast pre-check. There could be hundreds of thousands of
2400 * vnodes, we cannot afford to do anything heavy weight until we have a
2401 * fairly good indication that there is work to do.
2405 vfs_msync_scan1(struct mount
*mp
, struct vnode
*vp
, void *data
)
2407 int flags
= (int)(intptr_t)data
;
2409 if ((vp
->v_flag
& VRECLAIMED
) == 0) {
2410 if (vp
->v_auxrefs
== 0 && VREFCNT(vp
) <= 0 &&
2412 return(0); /* call scan2 */
2414 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0 &&
2415 (vp
->v_flag
& VOBJDIRTY
) &&
2416 (flags
== MNT_WAIT
|| vn_islocked(vp
) == 0)) {
2417 return(0); /* call scan2 */
2422 * do not call scan2, continue the loop
2428 * This callback is handed a locked vnode.
2432 vfs_msync_scan2(struct mount
*mp
, struct vnode
*vp
, void *data
)
2435 int flags
= (int)(intptr_t)data
;
2437 if (vp
->v_flag
& VRECLAIMED
)
2440 if ((mp
->mnt_flag
& MNT_RDONLY
) == 0 && (vp
->v_flag
& VOBJDIRTY
)) {
2441 if ((obj
= vp
->v_object
) != NULL
) {
2442 vm_object_page_clean(obj
, 0, 0,
2443 flags
== MNT_WAIT
? OBJPC_SYNC
: OBJPC_NOSYNC
);
2450 * Wake up anyone interested in vp because it is being revoked.
2453 vn_gone(struct vnode
*vp
)
2455 lwkt_gettoken(&vp
->v_token
);
2456 KNOTE(&vp
->v_pollinfo
.vpi_kqinfo
.ki_note
, NOTE_REVOKE
);
2457 lwkt_reltoken(&vp
->v_token
);
2461 * extract the cdev_t from a VBLK or VCHR. The vnode must have been opened
2462 * (or v_rdev might be NULL).
2465 vn_todev(struct vnode
*vp
)
2467 if (vp
->v_type
!= VBLK
&& vp
->v_type
!= VCHR
)
2469 KKASSERT(vp
->v_rdev
!= NULL
);
2470 return (vp
->v_rdev
);
2474 * Check if vnode represents a disk device. The vnode does not need to be
2480 vn_isdisk(struct vnode
*vp
, int *errp
)
2484 if (vp
->v_type
!= VCHR
) {
2497 if (dev_is_good(dev
) == 0) {
2502 if ((dev_dflags(dev
) & D_DISK
) == 0) {
2513 vn_get_namelen(struct vnode
*vp
, int *namelen
)
2516 register_t retval
[2];
2518 error
= VOP_PATHCONF(vp
, _PC_NAME_MAX
, retval
);
2521 *namelen
= (int)retval
[0];
2526 vop_write_dirent(int *error
, struct uio
*uio
, ino_t d_ino
, uint8_t d_type
,
2527 uint16_t d_namlen
, const char *d_name
)
2532 len
= _DIRENT_RECLEN(d_namlen
);
2533 if (len
> uio
->uio_resid
)
2536 dp
= kmalloc(len
, M_TEMP
, M_WAITOK
| M_ZERO
);
2539 dp
->d_namlen
= d_namlen
;
2540 dp
->d_type
= d_type
;
2541 bcopy(d_name
, dp
->d_name
, d_namlen
);
2543 *error
= uiomove((caddr_t
)dp
, len
, uio
);
2551 vn_mark_atime(struct vnode
*vp
, struct thread
*td
)
2553 struct proc
*p
= td
->td_proc
;
2554 struct ucred
*cred
= p
? p
->p_ucred
: proc0
.p_ucred
;
2556 if ((vp
->v_mount
->mnt_flag
& (MNT_NOATIME
| MNT_RDONLY
)) == 0) {
2557 VOP_MARKATIME(vp
, cred
);
2562 * Calculate the number of entries in an inode-related chained hash table.
2563 * With today's memory sizes, maxvnodes can wind up being a very large
2564 * number. There is no reason to waste memory, so tolerate some stacking.
2567 vfs_inodehashsize(void)
2572 while (hsize
< maxvnodes
)
2574 while (hsize
> maxvnodes
* 2)
2575 hsize
>>= 1; /* nominal 2x stacking */
2577 if (maxvnodes
> 1024 * 1024)
2578 hsize
>>= 1; /* nominal 8x stacking */
2580 if (maxvnodes
> 128 * 1024)
2581 hsize
>>= 1; /* nominal 4x stacking */