141defb4dSMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0 241defb4dSMauro Carvalho Chehab 341defb4dSMauro Carvalho Chehab================= 441defb4dSMauro Carvalho ChehabAutomount Support 541defb4dSMauro Carvalho Chehab================= 641defb4dSMauro Carvalho Chehab 741defb4dSMauro Carvalho Chehab 841defb4dSMauro Carvalho ChehabSupport is available for filesystems that wish to do automounting 941defb4dSMauro Carvalho Chehabsupport (such as kAFS which can be found in fs/afs/ and NFS in 1041defb4dSMauro Carvalho Chehabfs/nfs/). This facility includes allowing in-kernel mounts to be 1141defb4dSMauro Carvalho Chehabperformed and mountpoint degradation to be requested. The latter can 1241defb4dSMauro Carvalho Chehabalso be requested by userspace. 1341defb4dSMauro Carvalho Chehab 1441defb4dSMauro Carvalho Chehab 1541defb4dSMauro Carvalho ChehabIn-Kernel Automounting 1641defb4dSMauro Carvalho Chehab====================== 1741defb4dSMauro Carvalho Chehab 1841defb4dSMauro Carvalho ChehabSee section "Mount Traps" of Documentation/filesystems/autofs.rst 1941defb4dSMauro Carvalho Chehab 2041defb4dSMauro Carvalho ChehabThen from userspace, you can just do something like:: 2141defb4dSMauro Carvalho Chehab 2241defb4dSMauro Carvalho Chehab [root@andromeda root]# mount -t afs \#root.afs. /afs 2341defb4dSMauro Carvalho Chehab [root@andromeda root]# ls /afs 2441defb4dSMauro Carvalho Chehab asd cambridge cambridge.redhat.com grand.central.org 2541defb4dSMauro Carvalho Chehab [root@andromeda root]# ls /afs/cambridge 2641defb4dSMauro Carvalho Chehab afsdoc 2741defb4dSMauro Carvalho Chehab [root@andromeda root]# ls /afs/cambridge/afsdoc/ 2841defb4dSMauro Carvalho Chehab ChangeLog html LICENSE pdf RELNOTES-1.2.2 2941defb4dSMauro Carvalho Chehab 3041defb4dSMauro Carvalho ChehabAnd then if you look in the mountpoint catalogue, you'll see something like:: 3141defb4dSMauro Carvalho Chehab 3241defb4dSMauro Carvalho Chehab [root@andromeda root]# cat /proc/mounts 3341defb4dSMauro Carvalho Chehab ... 3441defb4dSMauro Carvalho Chehab #root.afs. /afs afs rw 0 0 3541defb4dSMauro Carvalho Chehab #root.cell. /afs/cambridge.redhat.com afs rw 0 0 3641defb4dSMauro Carvalho Chehab #afsdoc. /afs/cambridge.redhat.com/afsdoc afs rw 0 0 3741defb4dSMauro Carvalho Chehab 3841defb4dSMauro Carvalho Chehab 3941defb4dSMauro Carvalho ChehabAutomatic Mountpoint Expiry 4041defb4dSMauro Carvalho Chehab=========================== 4141defb4dSMauro Carvalho Chehab 4241defb4dSMauro Carvalho ChehabAutomatic expiration of mountpoints is easy, provided you've mounted the 4341defb4dSMauro Carvalho Chehabmountpoint to be expired in the automounting procedure outlined separately. 4441defb4dSMauro Carvalho Chehab 4541defb4dSMauro Carvalho ChehabTo do expiration, you need to follow these steps: 4641defb4dSMauro Carvalho Chehab 4741defb4dSMauro Carvalho Chehab (1) Create at least one list off which the vfsmounts to be expired can be 4841defb4dSMauro Carvalho Chehab hung. 4941defb4dSMauro Carvalho Chehab 5041defb4dSMauro Carvalho Chehab (2) When a new mountpoint is created in the ->d_automount method, add 5141defb4dSMauro Carvalho Chehab the mnt to the list using mnt_set_expiry():: 5241defb4dSMauro Carvalho Chehab 5341defb4dSMauro Carvalho Chehab mnt_set_expiry(newmnt, &afs_vfsmounts); 5441defb4dSMauro Carvalho Chehab 5541defb4dSMauro Carvalho Chehab (3) When you want mountpoints to be expired, call mark_mounts_for_expiry() 5641defb4dSMauro Carvalho Chehab with a pointer to this list. This will process the list, marking every 5741defb4dSMauro Carvalho Chehab vfsmount thereon for potential expiry on the next call. 5841defb4dSMauro Carvalho Chehab 5941defb4dSMauro Carvalho Chehab If a vfsmount was already flagged for expiry, and if its usage count is 1 6041defb4dSMauro Carvalho Chehab (it's only referenced by its parent vfsmount), then it will be deleted 6141defb4dSMauro Carvalho Chehab from the namespace and thrown away (effectively unmounted). 6241defb4dSMauro Carvalho Chehab 6341defb4dSMauro Carvalho Chehab It may prove simplest to simply call this at regular intervals, using 6441defb4dSMauro Carvalho Chehab some sort of timed event to drive it. 6541defb4dSMauro Carvalho Chehab 6641defb4dSMauro Carvalho ChehabThe expiration flag is cleared by calls to mntput. This means that expiration 6741defb4dSMauro Carvalho Chehabwill only happen on the second expiration request after the last time the 6841defb4dSMauro Carvalho Chehabmountpoint was accessed. 6941defb4dSMauro Carvalho Chehab 7041defb4dSMauro Carvalho ChehabIf a mountpoint is moved, it gets removed from the expiration list. If a bind 7141defb4dSMauro Carvalho Chehabmount is made on an expirable mount, the new vfsmount will not be on the 7241defb4dSMauro Carvalho Chehabexpiration list and will not expire. 7341defb4dSMauro Carvalho Chehab 7441defb4dSMauro Carvalho ChehabIf a namespace is copied, all mountpoints contained therein will be copied, 7541defb4dSMauro Carvalho Chehaband the copies of those that are on an expiration list will be added to the 7641defb4dSMauro Carvalho Chehabsame expiration list. 7741defb4dSMauro Carvalho Chehab 7841defb4dSMauro Carvalho Chehab 7941defb4dSMauro Carvalho ChehabUserspace Driven Expiry 8041defb4dSMauro Carvalho Chehab======================= 8141defb4dSMauro Carvalho Chehab 8241defb4dSMauro Carvalho ChehabAs an alternative, it is possible for userspace to request expiry of any 8341defb4dSMauro Carvalho Chehabmountpoint (though some will be rejected - the current process's idea of the 8441defb4dSMauro Carvalho Chehabrootfs for example). It does this by passing the MNT_EXPIRE flag to 8541defb4dSMauro Carvalho Chehabumount(). This flag is considered incompatible with MNT_FORCE and MNT_DETACH. 8641defb4dSMauro Carvalho Chehab 8741defb4dSMauro Carvalho ChehabIf the mountpoint in question is in referenced by something other than 8841defb4dSMauro Carvalho Chehabumount() or its parent mountpoint, an EBUSY error will be returned and the 8941defb4dSMauro Carvalho Chehabmountpoint will not be marked for expiration or unmounted. 9041defb4dSMauro Carvalho Chehab 9141defb4dSMauro Carvalho ChehabIf the mountpoint was not already marked for expiry at that time, an EAGAIN 9241defb4dSMauro Carvalho Chehaberror will be given and it won't be unmounted. 9341defb4dSMauro Carvalho Chehab 9441defb4dSMauro Carvalho ChehabOtherwise if it was already marked and it wasn't referenced, unmounting will 9541defb4dSMauro Carvalho Chehabtake place as usual. 9641defb4dSMauro Carvalho Chehab 9741defb4dSMauro Carvalho ChehabAgain, the expiration flag is cleared every time anything other than umount() 9841defb4dSMauro Carvalho Chehablooks at a mountpoint. 99