2 * SPDX-License-Identifier: BSD-2-Clause
4 * Copyright (c) 2020 Netflix, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
24 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 #include <sys/param.h>
32 #include <sys/mount.h>
33 #include <sys/vnode.h>
36 * The "mntfs" VCHR vnodes implemented here provide a safe way for file systems
37 * to access their disk devices. Using the normal devfs vnode has the problem
38 * that if the device disappears, the devfs vnode is vgone'd as part of
39 * removing it from the application-visible namespace, and some file systems
40 * (notably FFS with softdep) get very unhappy if their dirty buffers are
41 * invalidated out from under them. By using a separate, private vnode,
42 * file systems are able to clean up their buffer state in a controlled fashion
43 * when the underlying device disappears.
47 mntfs_reclaim(struct vop_reclaim_args *ap)
49 struct vnode *vp = ap->a_vp;
55 struct vop_vector mntfs_vnodeops = {
56 .vop_default = &default_vnodeops,
58 .vop_fsync = vop_stdfsync,
59 .vop_strategy = VOP_PANIC,
60 .vop_reclaim = mntfs_reclaim,
62 VFS_VOP_VECTOR_REGISTER(mntfs_vnodeops);
65 * Allocate a private VCHR vnode for use by a mounted fs.
66 * The underlying device will be the same as for the given vnode.
67 * This mntfs vnode must be freed with mntfs_freevp() rather than just
68 * releasing the reference.
71 mntfs_allocvp(struct mount *mp, struct vnode *ovp)
76 ASSERT_VOP_ELOCKED(ovp, __func__);
80 getnewvnode("mntfs", mp, &mntfs_vnodeops, &vp);
87 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
88 vn_set_state(vp, VSTATE_CONSTRUCTED);
93 mntfs_freevp(struct vnode *vp)
95 ASSERT_VOP_ELOCKED(vp, "mntfs_freevp");