xref: /freebsd/sbin/mount_nullfs/mount_nullfs.8 (revision df21a004be237a1dccd03c7b47254625eea62fa9)
1.\"
2.\" Copyright (c) 1992, 1993, 1994
3.\"	The Regents of the University of California.  All rights reserved.
4.\"
5.\" This code is derived from software donated to Berkeley by
6.\" John Heidemann of the UCLA Ficus project.
7.\"
8.\"
9.\" Redistribution and use in source and binary forms, with or without
10.\" modification, are permitted provided that the following conditions
11.\" are met:
12.\" 1. Redistributions of source code must retain the above copyright
13.\"    notice, this list of conditions and the following disclaimer.
14.\" 2. Redistributions in binary form must reproduce the above copyright
15.\"    notice, this list of conditions and the following disclaimer in the
16.\"    documentation and/or other materials provided with the distribution.
17.\" 3. Neither the name of the University nor the names of its contributors
18.\"    may be used to endorse or promote products derived from this software
19.\"    without specific prior written permission.
20.\"
21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31.\" SUCH DAMAGE.
32.\"
33.Dd March 24, 2024
34.Dt MOUNT_NULLFS 8
35.Os
36.Sh NAME
37.Nm mount_nullfs
38.Nd "mount a loopback file system sub-tree; demonstrate the use of a null file system layer"
39.Sh SYNOPSIS
40.Nm
41.Op Fl o Ar options
42.Ar target
43.Ar mount-point
44.Sh DESCRIPTION
45The
46.Nm
47utility creates a
48.Xr nullfs 4
49layer, duplicating a sub-tree of the file system
50name space under another part of the global file system namespace.
51This allows existing files and directories to be accessed
52using a different pathname.
53.Pp
54The primary differences between a virtual copy of the file system
55and a symbolic link are that the
56.Xr getcwd 3
57functions work correctly in the virtual copy, and that other file systems
58may be mounted on the virtual copy without affecting the original.
59A different device number for the virtual copy is returned by
60.Xr stat 2 ,
61but in other respects it is indistinguishable from the original.
62.Pp
63The
64.Nm
65utility supports mounting both directories and single files.
66Both
67.Ar target
68and
69.Ar mount_point
70must be the same type.
71Mounting directories to files or files to
72directories is not supported.
73.Pp
74The
75.Nm
76file system differs from a traditional
77loopback file system in two respects: it is implemented using
78a stackable layers techniques, and its
79.Do null-node Dc Ns s
80stack above
81all lower-layer vnodes, not just over directory vnodes.
82.Pp
83The options are as follows:
84.Bl -tag -width indent
85.It Fl o
86Options are specified with a
87.Fl o
88flag followed by a comma separated string of options.
89See the
90.Xr mount 8
91man page for possible options and their meanings.
92Additionally the following option is supported:
93.Bl -tag -width nounixbypass
94.It Cm nocache
95Disable metadata caching in the null layer.
96Some lower-layer file systems may force this option.
97Depending on the access pattern,
98this may result in increased lock contention.
99.It Cm cache
100Force enable metadata caching.
101.It Cm nounixbypass
102Disable bypassing
103.Xr unix 4
104socket files used for
105.Xr bind 2
106and
107.Xr connect 2 ,
108to the lower (mounted-from) filesystem layer.
109.Pp
110The effect is that lower and upper (bypassed) unix sockets
111are separate.
112.It Cm unixbypass
113Enable the bypass of unix socket file to lower filesystem layer.
114This is default.
115.Pp
116The effect is that
117.Xr bind 2
118and
119.Xr connect 2
120operations on a unix socket done from either the upper (nullfs) or lower
121layer path are performed on same unix socket.
122For instance, if a server
123.Xr bind 2
124is done on a socket in the lower layer, then
125.Xr connect 2
126on the socket file accessed via the nullfs mount, connects to the server.
127.El
128.El
129.Pp
130The
131.Dv vfs.nullfs.cache_vnodes
132sysctl specifies global default for mount-specific cache/nocache option.
133.Pp
134The null layer has two purposes.
135First, it serves as a demonstration of layering by providing a layer
136which does nothing.
137(It actually does everything the loopback file system does,
138which is slightly more than nothing.)
139Second, the null layer can serve as a prototype layer.
140Since it provides all necessary layer framework,
141new file system layers can be created very easily by starting
142with a null layer.
143.Pp
144The remainder of this man page examines the null layer as a basis
145for constructing new layers.
146.\"
147.\"
148.Sh INSTANTIATING NEW NULL LAYERS
149New null layers are created with
150.Nm .
151The
152.Nm
153utility takes two arguments, the pathname
154of the lower vfs (target-pn) and the pathname where the null
155layer will appear in the namespace (mount-point-pn).
156After
157the null layer is put into place, the contents
158of target-pn subtree will be aliased under mount-point-pn.
159.\"
160.\"
161.Sh OPERATION OF A NULL LAYER
162The null layer is the minimum file system layer,
163simply bypassing all possible operations to the lower layer
164for processing there.
165The majority of its activity centers
166on the bypass routine, through which nearly all vnode operations
167pass.
168.Pp
169The bypass routine accepts arbitrary vnode operations for
170handling by the lower layer.
171It begins by examining vnode
172operation arguments and replacing any null-nodes by their
173lower-layer equivalents.
174It then invokes the operation
175on the lower layer.
176Finally, it replaces the null-nodes
177in the arguments and, if a vnode is returned by the operation,
178stacks a null-node on top of the returned vnode.
179.Pp
180Although bypass handles most operations,
181.Em vop_getattr ,
182.Em vop_inactive ,
183.Em vop_reclaim ,
184and
185.Em vop_print
186are not bypassed.
187.Em Vop_getattr
188must change the fsid being returned.
189.Em Vop_inactive
190and
191.Em vop_reclaim
192are not bypassed so that
193they can handle freeing null-layer specific data.
194.Em Vop_print
195is not bypassed to avoid excessive debugging
196information.
197.\"
198.\"
199.Sh INSTANTIATING VNODE STACKS
200Mounting associates the null layer with a lower layer,
201in effect stacking two VFSes.
202Vnode stacks are instead
203created on demand as files are accessed.
204.Pp
205The initial mount creates a single vnode stack for the
206root of the new null layer.
207All other vnode stacks
208are created as a result of vnode operations on
209this or other null vnode stacks.
210.Pp
211New vnode stacks come into existence as a result of
212an operation which returns a vnode.
213The bypass routine stacks a null-node above the new
214vnode before returning it to the caller.
215.Pp
216For example, imagine mounting a null layer with
217.Bd -literal -offset indent
218mount_nullfs /usr/include /dev/layer/null
219.Ed
220.Pp
221Changing directory to
222.Pa /dev/layer/null
223will assign
224the root null-node (which was created when the null layer was mounted).
225Now consider opening
226.Pa sys .
227A vop_lookup would be
228done on the root null-node.
229This operation would bypass through
230to the lower layer which would return a vnode representing
231the UFS
232.Pa sys .
233Null_bypass then builds a null-node
234aliasing the UFS
235.Pa sys
236and returns this to the caller.
237Later operations on the null-node
238.Pa sys
239will repeat this
240process when constructing other vnode stacks.
241.\"
242.\"
243.Sh CREATING OTHER FILE SYSTEM LAYERS
244One of the easiest ways to construct new file system layers is to make
245a copy of the null layer, rename all files and variables, and
246then begin modifying the copy.
247The
248.Xr sed 1
249utility can be used to easily rename
250all variables.
251.Pp
252The umap layer is an example of a layer descended from the
253null layer.
254.\"
255.\"
256.Sh INVOKING OPERATIONS ON LOWER LAYERS
257There are two techniques to invoke operations on a lower layer
258when the operation cannot be completely bypassed.
259Each method
260is appropriate in different situations.
261In both cases,
262it is the responsibility of the aliasing layer to make
263the operation arguments "correct" for the lower layer
264by mapping a vnode argument to the lower layer.
265.Pp
266The first approach is to call the aliasing layer's bypass routine.
267This method is most suitable when you wish to invoke the operation
268currently being handled on the lower layer.
269It has the advantage that
270the bypass routine already must do argument mapping.
271An example of this is
272.Em null_getattrs
273in the null layer.
274.Pp
275A second approach is to directly invoke vnode operations on
276the lower layer with the
277.Em VOP_OPERATIONNAME
278interface.
279The advantage of this method is that it is easy to invoke
280arbitrary operations on the lower layer.
281The disadvantage
282is that vnode arguments must be manually mapped.
283.\"
284.\"
285.Sh SEE ALSO
286.Xr nullfs 4 ,
287.Xr mount 8
288.Pp
289UCLA Technical Report CSD-910056,
290.Em "Stackable Layers: an Architecture for File System Development" .
291.Sh HISTORY
292The
293.Nm mount_null
294utility first appeared in
295.Bx 4.4 .
296It was renamed to
297.Nm
298in
299.Fx 5.0 .
300