automount-support.txt 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. Support is available for filesystems that wish to do automounting support (such
  2. as kAFS which can be found in fs/afs/). This facility includes allowing
  3. in-kernel mounts to be performed and mountpoint degradation to be
  4. requested. The latter can also be requested by userspace.
  5. ======================
  6. IN-KERNEL AUTOMOUNTING
  7. ======================
  8. A filesystem can now mount another filesystem on one of its directories by the
  9. following procedure:
  10. (1) Give the directory a follow_link() operation.
  11. When the directory is accessed, the follow_link op will be called, and
  12. it will be provided with the location of the mountpoint in the nameidata
  13. structure (vfsmount and dentry).
  14. (2) Have the follow_link() op do the following steps:
  15. (a) Call vfs_kern_mount() to call the appropriate filesystem to set up a
  16. superblock and gain a vfsmount structure representing it.
  17. (b) Copy the nameidata provided as an argument and substitute the dentry
  18. argument into it the copy.
  19. (c) Call do_add_mount() to install the new vfsmount into the namespace's
  20. mountpoint tree, thus making it accessible to userspace. Use the
  21. nameidata set up in (b) as the destination.
  22. If the mountpoint will be automatically expired, then do_add_mount()
  23. should also be given the location of an expiration list (see further
  24. down).
  25. (d) Release the path in the nameidata argument and substitute in the new
  26. vfsmount and its root dentry. The ref counts on these will need
  27. incrementing.
  28. Then from userspace, you can just do something like:
  29. [root@andromeda root]# mount -t afs \#root.afs. /afs
  30. [root@andromeda root]# ls /afs
  31. asd cambridge cambridge.redhat.com grand.central.org
  32. [root@andromeda root]# ls /afs/cambridge
  33. afsdoc
  34. [root@andromeda root]# ls /afs/cambridge/afsdoc/
  35. ChangeLog html LICENSE pdf RELNOTES-1.2.2
  36. And then if you look in the mountpoint catalogue, you'll see something like:
  37. [root@andromeda root]# cat /proc/mounts
  38. ...
  39. #root.afs. /afs afs rw 0 0
  40. #root.cell. /afs/cambridge.redhat.com afs rw 0 0
  41. #afsdoc. /afs/cambridge.redhat.com/afsdoc afs rw 0 0
  42. ===========================
  43. AUTOMATIC MOUNTPOINT EXPIRY
  44. ===========================
  45. Automatic expiration of mountpoints is easy, provided you've mounted the
  46. mountpoint to be expired in the automounting procedure outlined above.
  47. To do expiration, you need to follow these steps:
  48. (3) Create at least one list off which the vfsmounts to be expired can be
  49. hung. Access to this list will be governed by the vfsmount_lock.
  50. (4) In step (2c) above, the call to do_add_mount() should be provided with a
  51. pointer to this list. It will hang the vfsmount off of it if it succeeds.
  52. (5) When you want mountpoints to be expired, call mark_mounts_for_expiry()
  53. with a pointer to this list. This will process the list, marking every
  54. vfsmount thereon for potential expiry on the next call.
  55. If a vfsmount was already flagged for expiry, and if its usage count is 1
  56. (it's only referenced by its parent vfsmount), then it will be deleted
  57. from the namespace and thrown away (effectively unmounted).
  58. It may prove simplest to simply call this at regular intervals, using
  59. some sort of timed event to drive it.
  60. The expiration flag is cleared by calls to mntput. This means that expiration
  61. will only happen on the second expiration request after the last time the
  62. mountpoint was accessed.
  63. If a mountpoint is moved, it gets removed from the expiration list. If a bind
  64. mount is made on an expirable mount, the new vfsmount will not be on the
  65. expiration list and will not expire.
  66. If a namespace is copied, all mountpoints contained therein will be copied,
  67. and the copies of those that are on an expiration list will be added to the
  68. same expiration list.
  69. =======================
  70. USERSPACE DRIVEN EXPIRY
  71. =======================
  72. As an alternative, it is possible for userspace to request expiry of any
  73. mountpoint (though some will be rejected - the current process's idea of the
  74. rootfs for example). It does this by passing the MNT_EXPIRE flag to
  75. umount(). This flag is considered incompatible with MNT_FORCE and MNT_DETACH.
  76. If the mountpoint in question is in referenced by something other than
  77. umount() or its parent mountpoint, an EBUSY error will be returned and the
  78. mountpoint will not be marked for expiration or unmounted.
  79. If the mountpoint was not already marked for expiry at that time, an EAGAIN
  80. error will be given and it won't be unmounted.
  81. Otherwise if it was already marked and it wasn't referenced, unmounting will
  82. take place as usual.
  83. Again, the expiration flag is cleared every time anything other than umount()
  84. looks at a mountpoint.