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