xref: /openbmc/linux/Documentation/filesystems/automount-support.rst (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
1*41defb4dSMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0
2*41defb4dSMauro Carvalho Chehab
3*41defb4dSMauro Carvalho Chehab=================
4*41defb4dSMauro Carvalho ChehabAutomount Support
5*41defb4dSMauro Carvalho Chehab=================
6*41defb4dSMauro Carvalho Chehab
7*41defb4dSMauro Carvalho Chehab
8*41defb4dSMauro Carvalho ChehabSupport is available for filesystems that wish to do automounting
9*41defb4dSMauro Carvalho Chehabsupport (such as kAFS which can be found in fs/afs/ and NFS in
10*41defb4dSMauro Carvalho Chehabfs/nfs/). This facility includes allowing in-kernel mounts to be
11*41defb4dSMauro Carvalho Chehabperformed and mountpoint degradation to be requested. The latter can
12*41defb4dSMauro Carvalho Chehabalso be requested by userspace.
13*41defb4dSMauro Carvalho Chehab
14*41defb4dSMauro Carvalho Chehab
15*41defb4dSMauro Carvalho ChehabIn-Kernel Automounting
16*41defb4dSMauro Carvalho Chehab======================
17*41defb4dSMauro Carvalho Chehab
18*41defb4dSMauro Carvalho ChehabSee section "Mount Traps" of  Documentation/filesystems/autofs.rst
19*41defb4dSMauro Carvalho Chehab
20*41defb4dSMauro Carvalho ChehabThen from userspace, you can just do something like::
21*41defb4dSMauro Carvalho Chehab
22*41defb4dSMauro Carvalho Chehab	[root@andromeda root]# mount -t afs \#root.afs. /afs
23*41defb4dSMauro Carvalho Chehab	[root@andromeda root]# ls /afs
24*41defb4dSMauro Carvalho Chehab	asd  cambridge  cambridge.redhat.com  grand.central.org
25*41defb4dSMauro Carvalho Chehab	[root@andromeda root]# ls /afs/cambridge
26*41defb4dSMauro Carvalho Chehab	afsdoc
27*41defb4dSMauro Carvalho Chehab	[root@andromeda root]# ls /afs/cambridge/afsdoc/
28*41defb4dSMauro Carvalho Chehab	ChangeLog  html  LICENSE  pdf  RELNOTES-1.2.2
29*41defb4dSMauro Carvalho Chehab
30*41defb4dSMauro Carvalho ChehabAnd then if you look in the mountpoint catalogue, you'll see something like::
31*41defb4dSMauro Carvalho Chehab
32*41defb4dSMauro Carvalho Chehab	[root@andromeda root]# cat /proc/mounts
33*41defb4dSMauro Carvalho Chehab	...
34*41defb4dSMauro Carvalho Chehab	#root.afs. /afs afs rw 0 0
35*41defb4dSMauro Carvalho Chehab	#root.cell. /afs/cambridge.redhat.com afs rw 0 0
36*41defb4dSMauro Carvalho Chehab	#afsdoc. /afs/cambridge.redhat.com/afsdoc afs rw 0 0
37*41defb4dSMauro Carvalho Chehab
38*41defb4dSMauro Carvalho Chehab
39*41defb4dSMauro Carvalho ChehabAutomatic Mountpoint Expiry
40*41defb4dSMauro Carvalho Chehab===========================
41*41defb4dSMauro Carvalho Chehab
42*41defb4dSMauro Carvalho ChehabAutomatic expiration of mountpoints is easy, provided you've mounted the
43*41defb4dSMauro Carvalho Chehabmountpoint to be expired in the automounting procedure outlined separately.
44*41defb4dSMauro Carvalho Chehab
45*41defb4dSMauro Carvalho ChehabTo do expiration, you need to follow these steps:
46*41defb4dSMauro Carvalho Chehab
47*41defb4dSMauro Carvalho Chehab (1) Create at least one list off which the vfsmounts to be expired can be
48*41defb4dSMauro Carvalho Chehab     hung.
49*41defb4dSMauro Carvalho Chehab
50*41defb4dSMauro Carvalho Chehab (2) When a new mountpoint is created in the ->d_automount method, add
51*41defb4dSMauro Carvalho Chehab     the mnt to the list using mnt_set_expiry()::
52*41defb4dSMauro Carvalho Chehab
53*41defb4dSMauro Carvalho Chehab             mnt_set_expiry(newmnt, &afs_vfsmounts);
54*41defb4dSMauro Carvalho Chehab
55*41defb4dSMauro Carvalho Chehab (3) When you want mountpoints to be expired, call mark_mounts_for_expiry()
56*41defb4dSMauro Carvalho Chehab     with a pointer to this list. This will process the list, marking every
57*41defb4dSMauro Carvalho Chehab     vfsmount thereon for potential expiry on the next call.
58*41defb4dSMauro Carvalho Chehab
59*41defb4dSMauro Carvalho Chehab     If a vfsmount was already flagged for expiry, and if its usage count is 1
60*41defb4dSMauro Carvalho Chehab     (it's only referenced by its parent vfsmount), then it will be deleted
61*41defb4dSMauro Carvalho Chehab     from the namespace and thrown away (effectively unmounted).
62*41defb4dSMauro Carvalho Chehab
63*41defb4dSMauro Carvalho Chehab     It may prove simplest to simply call this at regular intervals, using
64*41defb4dSMauro Carvalho Chehab     some sort of timed event to drive it.
65*41defb4dSMauro Carvalho Chehab
66*41defb4dSMauro Carvalho ChehabThe expiration flag is cleared by calls to mntput. This means that expiration
67*41defb4dSMauro Carvalho Chehabwill only happen on the second expiration request after the last time the
68*41defb4dSMauro Carvalho Chehabmountpoint was accessed.
69*41defb4dSMauro Carvalho Chehab
70*41defb4dSMauro Carvalho ChehabIf a mountpoint is moved, it gets removed from the expiration list. If a bind
71*41defb4dSMauro Carvalho Chehabmount is made on an expirable mount, the new vfsmount will not be on the
72*41defb4dSMauro Carvalho Chehabexpiration list and will not expire.
73*41defb4dSMauro Carvalho Chehab
74*41defb4dSMauro Carvalho ChehabIf a namespace is copied, all mountpoints contained therein will be copied,
75*41defb4dSMauro Carvalho Chehaband the copies of those that are on an expiration list will be added to the
76*41defb4dSMauro Carvalho Chehabsame expiration list.
77*41defb4dSMauro Carvalho Chehab
78*41defb4dSMauro Carvalho Chehab
79*41defb4dSMauro Carvalho ChehabUserspace Driven Expiry
80*41defb4dSMauro Carvalho Chehab=======================
81*41defb4dSMauro Carvalho Chehab
82*41defb4dSMauro Carvalho ChehabAs an alternative, it is possible for userspace to request expiry of any
83*41defb4dSMauro Carvalho Chehabmountpoint (though some will be rejected - the current process's idea of the
84*41defb4dSMauro Carvalho Chehabrootfs for example). It does this by passing the MNT_EXPIRE flag to
85*41defb4dSMauro Carvalho Chehabumount(). This flag is considered incompatible with MNT_FORCE and MNT_DETACH.
86*41defb4dSMauro Carvalho Chehab
87*41defb4dSMauro Carvalho ChehabIf the mountpoint in question is in referenced by something other than
88*41defb4dSMauro Carvalho Chehabumount() or its parent mountpoint, an EBUSY error will be returned and the
89*41defb4dSMauro Carvalho Chehabmountpoint will not be marked for expiration or unmounted.
90*41defb4dSMauro Carvalho Chehab
91*41defb4dSMauro Carvalho ChehabIf the mountpoint was not already marked for expiry at that time, an EAGAIN
92*41defb4dSMauro Carvalho Chehaberror will be given and it won't be unmounted.
93*41defb4dSMauro Carvalho Chehab
94*41defb4dSMauro Carvalho ChehabOtherwise if it was already marked and it wasn't referenced, unmounting will
95*41defb4dSMauro Carvalho Chehabtake place as usual.
96*41defb4dSMauro Carvalho Chehab
97*41defb4dSMauro Carvalho ChehabAgain, the expiration flag is cleared every time anything other than umount()
98*41defb4dSMauro Carvalho Chehablooks at a mountpoint.
99