Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 =================
0004 Automount Support
0005 =================
0006 
0007 
0008 Support is available for filesystems that wish to do automounting
0009 support (such as kAFS which can be found in fs/afs/ and NFS in
0010 fs/nfs/). This facility includes allowing in-kernel mounts to be
0011 performed and mountpoint degradation to be requested. The latter can
0012 also be requested by userspace.
0013 
0014 
0015 In-Kernel Automounting
0016 ======================
0017 
0018 See section "Mount Traps" of  Documentation/filesystems/autofs.rst
0019 
0020 Then from userspace, you can just do something like::
0021 
0022         [root@andromeda root]# mount -t afs \#root.afs. /afs
0023         [root@andromeda root]# ls /afs
0024         asd  cambridge  cambridge.redhat.com  grand.central.org
0025         [root@andromeda root]# ls /afs/cambridge
0026         afsdoc
0027         [root@andromeda root]# ls /afs/cambridge/afsdoc/
0028         ChangeLog  html  LICENSE  pdf  RELNOTES-1.2.2
0029 
0030 And then if you look in the mountpoint catalogue, you'll see something like::
0031 
0032         [root@andromeda root]# cat /proc/mounts
0033         ...
0034         #root.afs. /afs afs rw 0 0
0035         #root.cell. /afs/cambridge.redhat.com afs rw 0 0
0036         #afsdoc. /afs/cambridge.redhat.com/afsdoc afs rw 0 0
0037 
0038 
0039 Automatic Mountpoint Expiry
0040 ===========================
0041 
0042 Automatic expiration of mountpoints is easy, provided you've mounted the
0043 mountpoint to be expired in the automounting procedure outlined separately.
0044 
0045 To do expiration, you need to follow these steps:
0046 
0047  (1) Create at least one list off which the vfsmounts to be expired can be
0048      hung.
0049 
0050  (2) When a new mountpoint is created in the ->d_automount method, add
0051      the mnt to the list using mnt_set_expiry()::
0052 
0053              mnt_set_expiry(newmnt, &afs_vfsmounts);
0054 
0055  (3) When you want mountpoints to be expired, call mark_mounts_for_expiry()
0056      with a pointer to this list. This will process the list, marking every
0057      vfsmount thereon for potential expiry on the next call.
0058 
0059      If a vfsmount was already flagged for expiry, and if its usage count is 1
0060      (it's only referenced by its parent vfsmount), then it will be deleted
0061      from the namespace and thrown away (effectively unmounted).
0062 
0063      It may prove simplest to simply call this at regular intervals, using
0064      some sort of timed event to drive it.
0065 
0066 The expiration flag is cleared by calls to mntput. This means that expiration
0067 will only happen on the second expiration request after the last time the
0068 mountpoint was accessed.
0069 
0070 If a mountpoint is moved, it gets removed from the expiration list. If a bind
0071 mount is made on an expirable mount, the new vfsmount will not be on the
0072 expiration list and will not expire.
0073 
0074 If a namespace is copied, all mountpoints contained therein will be copied,
0075 and the copies of those that are on an expiration list will be added to the
0076 same expiration list.
0077 
0078 
0079 Userspace Driven Expiry
0080 =======================
0081 
0082 As an alternative, it is possible for userspace to request expiry of any
0083 mountpoint (though some will be rejected - the current process's idea of the
0084 rootfs for example). It does this by passing the MNT_EXPIRE flag to
0085 umount(). This flag is considered incompatible with MNT_FORCE and MNT_DETACH.
0086 
0087 If the mountpoint in question is in referenced by something other than
0088 umount() or its parent mountpoint, an EBUSY error will be returned and the
0089 mountpoint will not be marked for expiration or unmounted.
0090 
0091 If the mountpoint was not already marked for expiry at that time, an EAGAIN
0092 error will be given and it won't be unmounted.
0093 
0094 Otherwise if it was already marked and it wasn't referenced, unmounting will
0095 take place as usual.
0096 
0097 Again, the expiration flag is cleared every time anything other than umount()
0098 looks at a mountpoint.