automount-support.rst 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. .. SPDX-License-Identifier: GPL-2.0
  2. =================
  3. Automount Support
  4. =================
  5. Support is available for filesystems that wish to do automounting
  6. support (such as kAFS which can be found in fs/afs/ and NFS in
  7. fs/nfs/). This facility includes allowing in-kernel mounts to be
  8. performed and mountpoint degradation to be requested. The latter can
  9. also be requested by userspace.
  10. In-Kernel Automounting
  11. ======================
  12. See section "Mount Traps" of Documentation/filesystems/autofs.rst
  13. Then from userspace, you can just do something like::
  14. [root@andromeda root]# mount -t afs \#root.afs. /afs
  15. [root@andromeda root]# ls /afs
  16. asd cambridge cambridge.redhat.com grand.central.org
  17. [root@andromeda root]# ls /afs/cambridge
  18. afsdoc
  19. [root@andromeda root]# ls /afs/cambridge/afsdoc/
  20. ChangeLog html LICENSE pdf RELNOTES-1.2.2
  21. And then if you look in the mountpoint catalogue, you'll see something like::
  22. [root@andromeda root]# cat /proc/mounts
  23. ...
  24. #root.afs. /afs afs rw 0 0
  25. #root.cell. /afs/cambridge.redhat.com afs rw 0 0
  26. #afsdoc. /afs/cambridge.redhat.com/afsdoc afs rw 0 0
  27. Automatic Mountpoint Expiry
  28. ===========================
  29. Automatic expiration of mountpoints is easy, provided you've mounted the
  30. mountpoint to be expired in the automounting procedure outlined separately.
  31. To do expiration, you need to follow these steps:
  32. (1) Create at least one list off which the vfsmounts to be expired can be
  33. hung.
  34. (2) When a new mountpoint is created in the ->d_automount method, add
  35. the mnt to the list using mnt_set_expiry()::
  36. mnt_set_expiry(newmnt, &afs_vfsmounts);
  37. (3) When you want mountpoints to be expired, call mark_mounts_for_expiry()
  38. with a pointer to this list. This will process the list, marking every
  39. vfsmount thereon for potential expiry on the next call.
  40. If a vfsmount was already flagged for expiry, and if its usage count is 1
  41. (it's only referenced by its parent vfsmount), then it will be deleted
  42. from the namespace and thrown away (effectively unmounted).
  43. It may prove simplest to simply call this at regular intervals, using
  44. some sort of timed event to drive it.
  45. The expiration flag is cleared by calls to mntput. This means that expiration
  46. will only happen on the second expiration request after the last time the
  47. mountpoint was accessed.
  48. If a mountpoint is moved, it gets removed from the expiration list. If a bind
  49. mount is made on an expirable mount, the new vfsmount will not be on the
  50. expiration list and will not expire.
  51. If a namespace is copied, all mountpoints contained therein will be copied,
  52. and the copies of those that are on an expiration list will be added to the
  53. same expiration list.
  54. Userspace Driven Expiry
  55. =======================
  56. As an alternative, it is possible for userspace to request expiry of any
  57. mountpoint (though some will be rejected - the current process's idea of the
  58. rootfs for example). It does this by passing the MNT_EXPIRE flag to
  59. umount(). This flag is considered incompatible with MNT_FORCE and MNT_DETACH.
  60. If the mountpoint in question is in referenced by something other than
  61. umount() or its parent mountpoint, an EBUSY error will be returned and the
  62. mountpoint will not be marked for expiration or unmounted.
  63. If the mountpoint was not already marked for expiry at that time, an EAGAIN
  64. error will be given and it won't be unmounted.
  65. Otherwise if it was already marked and it wasn't referenced, unmounting will
  66. take place as usual.
  67. Again, the expiration flag is cleared every time anything other than umount()
  68. looks at a mountpoint.