path-lookup.rst 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414
  1. ===============
  2. Pathname lookup
  3. ===============
  4. This write-up is based on three articles published at lwn.net:
  5. - <https://lwn.net/Articles/649115/> Pathname lookup in Linux
  6. - <https://lwn.net/Articles/649729/> RCU-walk: faster pathname lookup in Linux
  7. - <https://lwn.net/Articles/650786/> A walk among the symlinks
  8. Written by Neil Brown with help from Al Viro and Jon Corbet.
  9. It has subsequently been updated to reflect changes in the kernel
  10. including:
  11. - per-directory parallel name lookup.
  12. - ``openat2()`` resolution restriction flags.
  13. Introduction to pathname lookup
  14. ===============================
  15. The most obvious aspect of pathname lookup, which very little
  16. exploration is needed to discover, is that it is complex. There are
  17. many rules, special cases, and implementation alternatives that all
  18. combine to confuse the unwary reader. Computer science has long been
  19. acquainted with such complexity and has tools to help manage it. One
  20. tool that we will make extensive use of is "divide and conquer". For
  21. the early parts of the analysis we will divide off symlinks - leaving
  22. them until the final part. Well before we get to symlinks we have
  23. another major division based on the VFS's approach to locking which
  24. will allow us to review "REF-walk" and "RCU-walk" separately. But we
  25. are getting ahead of ourselves. There are some important low level
  26. distinctions we need to clarify first.
  27. There are two sorts of ...
  28. --------------------------
  29. .. _openat: http://man7.org/linux/man-pages/man2/openat.2.html
  30. Pathnames (sometimes "file names"), used to identify objects in the
  31. filesystem, will be familiar to most readers. They contain two sorts
  32. of elements: "slashes" that are sequences of one or more "``/``"
  33. characters, and "components" that are sequences of one or more
  34. non-"``/``" characters. These form two kinds of paths. Those that
  35. start with slashes are "absolute" and start from the filesystem root.
  36. The others are "relative" and start from the current directory, or
  37. from some other location specified by a file descriptor given to
  38. "``*at()``" system calls such as `openat() <openat_>`_.
  39. .. _execveat: http://man7.org/linux/man-pages/man2/execveat.2.html
  40. It is tempting to describe the second kind as starting with a
  41. component, but that isn't always accurate: a pathname can lack both
  42. slashes and components, it can be empty, in other words. This is
  43. generally forbidden in POSIX, but some of those "``*at()``" system calls
  44. in Linux permit it when the ``AT_EMPTY_PATH`` flag is given. For
  45. example, if you have an open file descriptor on an executable file you
  46. can execute it by calling `execveat() <execveat_>`_ passing
  47. the file descriptor, an empty path, and the ``AT_EMPTY_PATH`` flag.
  48. These paths can be divided into two sections: the final component and
  49. everything else. The "everything else" is the easy bit. In all cases
  50. it must identify a directory that already exists, otherwise an error
  51. such as ``ENOENT`` or ``ENOTDIR`` will be reported.
  52. The final component is not so simple. Not only do different system
  53. calls interpret it quite differently (e.g. some create it, some do
  54. not), but it might not even exist: neither the empty pathname nor the
  55. pathname that is just slashes have a final component. If it does
  56. exist, it could be "``.``" or "``..``" which are handled quite differently
  57. from other components.
  58. .. _POSIX: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_12
  59. If a pathname ends with a slash, such as "``/tmp/foo/``" it might be
  60. tempting to consider that to have an empty final component. In many
  61. ways that would lead to correct results, but not always. In
  62. particular, ``mkdir()`` and ``rmdir()`` each create or remove a directory named
  63. by the final component, and they are required to work with pathnames
  64. ending in "``/``". According to POSIX_:
  65. A pathname that contains at least one non-<slash> character and
  66. that ends with one or more trailing <slash> characters shall not
  67. be resolved successfully unless the last pathname component before
  68. the trailing <slash> characters names an existing directory or a
  69. directory entry that is to be created for a directory immediately
  70. after the pathname is resolved.
  71. The Linux pathname walking code (mostly in ``fs/namei.c``) deals with
  72. all of these issues: breaking the path into components, handling the
  73. "everything else" quite separately from the final component, and
  74. checking that the trailing slash is not used where it isn't
  75. permitted. It also addresses the important issue of concurrent
  76. access.
  77. While one process is looking up a pathname, another might be making
  78. changes that affect that lookup. One fairly extreme case is that if
  79. "a/b" were renamed to "a/c/b" while another process were looking up
  80. "a/b/..", that process might successfully resolve on "a/c".
  81. Most races are much more subtle, and a big part of the task of
  82. pathname lookup is to prevent them from having damaging effects. Many
  83. of the possible races are seen most clearly in the context of the
  84. "dcache" and an understanding of that is central to understanding
  85. pathname lookup.
  86. More than just a cache
  87. ----------------------
  88. The "dcache" caches information about names in each filesystem to
  89. make them quickly available for lookup. Each entry (known as a
  90. "dentry") contains three significant fields: a component name, a
  91. pointer to a parent dentry, and a pointer to the "inode" which
  92. contains further information about the object in that parent with
  93. the given name. The inode pointer can be ``NULL`` indicating that the
  94. name doesn't exist in the parent. While there can be linkage in the
  95. dentry of a directory to the dentries of the children, that linkage is
  96. not used for pathname lookup, and so will not be considered here.
  97. The dcache has a number of uses apart from accelerating lookup. One
  98. that will be particularly relevant is that it is closely integrated
  99. with the mount table that records which filesystem is mounted where.
  100. What the mount table actually stores is which dentry is mounted on top
  101. of which other dentry.
  102. When considering the dcache, we have another of our "two types"
  103. distinctions: there are two types of filesystems.
  104. Some filesystems ensure that the information in the dcache is always
  105. completely accurate (though not necessarily complete). This can allow
  106. the VFS to determine if a particular file does or doesn't exist
  107. without checking with the filesystem, and means that the VFS can
  108. protect the filesystem against certain races and other problems.
  109. These are typically "local" filesystems such as ext3, XFS, and Btrfs.
  110. Other filesystems don't provide that guarantee because they cannot.
  111. These are typically filesystems that are shared across a network,
  112. whether remote filesystems like NFS and 9P, or cluster filesystems
  113. like ocfs2 or cephfs. These filesystems allow the VFS to revalidate
  114. cached information, and must provide their own protection against
  115. awkward races. The VFS can detect these filesystems by the
  116. ``DCACHE_OP_REVALIDATE`` flag being set in the dentry.
  117. REF-walk: simple concurrency management with refcounts and spinlocks
  118. --------------------------------------------------------------------
  119. With all of those divisions carefully classified, we can now start
  120. looking at the actual process of walking along a path. In particular
  121. we will start with the handling of the "everything else" part of a
  122. pathname, and focus on the "REF-walk" approach to concurrency
  123. management. This code is found in the ``link_path_walk()`` function, if
  124. you ignore all the places that only run when "``LOOKUP_RCU``"
  125. (indicating the use of RCU-walk) is set.
  126. .. _Meet the Lockers: https://lwn.net/Articles/453685/
  127. REF-walk is fairly heavy-handed with locks and reference counts. Not
  128. as heavy-handed as in the old "big kernel lock" days, but certainly not
  129. afraid of taking a lock when one is needed. It uses a variety of
  130. different concurrency controls. A background understanding of the
  131. various primitives is assumed, or can be gleaned from elsewhere such
  132. as in `Meet the Lockers`_.
  133. The locking mechanisms used by REF-walk include:
  134. dentry->d_lockref
  135. ~~~~~~~~~~~~~~~~~
  136. This uses the lockref primitive to provide both a spinlock and a
  137. reference count. The special-sauce of this primitive is that the
  138. conceptual sequence "lock; inc_ref; unlock;" can often be performed
  139. with a single atomic memory operation.
  140. Holding a reference on a dentry ensures that the dentry won't suddenly
  141. be freed and used for something else, so the values in various fields
  142. will behave as expected. It also protects the ``->d_inode`` reference
  143. to the inode to some extent.
  144. The association between a dentry and its inode is fairly permanent.
  145. For example, when a file is renamed, the dentry and inode move
  146. together to the new location. When a file is created the dentry will
  147. initially be negative (i.e. ``d_inode`` is ``NULL``), and will be assigned
  148. to the new inode as part of the act of creation.
  149. When a file is deleted, this can be reflected in the cache either by
  150. setting ``d_inode`` to ``NULL``, or by removing it from the hash table
  151. (described shortly) used to look up the name in the parent directory.
  152. If the dentry is still in use the second option is used as it is
  153. perfectly legal to keep using an open file after it has been deleted
  154. and having the dentry around helps. If the dentry is not otherwise in
  155. use (i.e. if the refcount in ``d_lockref`` is one), only then will
  156. ``d_inode`` be set to ``NULL``. Doing it this way is more efficient for a
  157. very common case.
  158. So as long as a counted reference is held to a dentry, a non-``NULL`` ``->d_inode``
  159. value will never be changed.
  160. dentry->d_lock
  161. ~~~~~~~~~~~~~~
  162. ``d_lock`` is a synonym for the spinlock that is part of ``d_lockref`` above.
  163. For our purposes, holding this lock protects against the dentry being
  164. renamed or unlinked. In particular, its parent (``d_parent``), and its
  165. name (``d_name``) cannot be changed, and it cannot be removed from the
  166. dentry hash table.
  167. When looking for a name in a directory, REF-walk takes ``d_lock`` on
  168. each candidate dentry that it finds in the hash table and then checks
  169. that the parent and name are correct. So it doesn't lock the parent
  170. while searching in the cache; it only locks children.
  171. When looking for the parent for a given name (to handle "``..``"),
  172. REF-walk can take ``d_lock`` to get a stable reference to ``d_parent``,
  173. but it first tries a more lightweight approach. As seen in
  174. ``dget_parent()``, if a reference can be claimed on the parent, and if
  175. subsequently ``d_parent`` can be seen to have not changed, then there is
  176. no need to actually take the lock on the child.
  177. rename_lock
  178. ~~~~~~~~~~~
  179. Looking up a given name in a given directory involves computing a hash
  180. from the two values (the name and the dentry of the directory),
  181. accessing that slot in a hash table, and searching the linked list
  182. that is found there.
  183. When a dentry is renamed, the name and the parent dentry can both
  184. change so the hash will almost certainly change too. This would move the
  185. dentry to a different chain in the hash table. If a filename search
  186. happened to be looking at a dentry that was moved in this way,
  187. it might end up continuing the search down the wrong chain,
  188. and so miss out on part of the correct chain.
  189. The name-lookup process (``d_lookup()``) does *not* try to prevent this
  190. from happening, but only to detect when it happens.
  191. ``rename_lock`` is a seqlock that is updated whenever any dentry is
  192. renamed. If ``d_lookup`` finds that a rename happened while it
  193. unsuccessfully scanned a chain in the hash table, it simply tries
  194. again.
  195. ``rename_lock`` is also used to detect and defend against potential attacks
  196. against ``LOOKUP_BENEATH`` and ``LOOKUP_IN_ROOT`` when resolving ".." (where
  197. the parent directory is moved outside the root, bypassing the ``path_equal()``
  198. check). If ``rename_lock`` is updated during the lookup and the path encounters
  199. a "..", a potential attack occurred and ``handle_dots()`` will bail out with
  200. ``-EAGAIN``.
  201. inode->i_rwsem
  202. ~~~~~~~~~~~~~~
  203. ``i_rwsem`` is a read/write semaphore that serializes all changes to a particular
  204. directory. This ensures that, for example, an ``unlink()`` and a ``rename()``
  205. cannot both happen at the same time. It also keeps the directory
  206. stable while the filesystem is asked to look up a name that is not
  207. currently in the dcache or, optionally, when the list of entries in a
  208. directory is being retrieved with ``readdir()``.
  209. This has a complementary role to that of ``d_lock``: ``i_rwsem`` on a
  210. directory protects all of the names in that directory, while ``d_lock``
  211. on a name protects just one name in a directory. Most changes to the
  212. dcache hold ``i_rwsem`` on the relevant directory inode and briefly take
  213. ``d_lock`` on one or more the dentries while the change happens. One
  214. exception is when idle dentries are removed from the dcache due to
  215. memory pressure. This uses ``d_lock``, but ``i_rwsem`` plays no role.
  216. The semaphore affects pathname lookup in two distinct ways. Firstly it
  217. prevents changes during lookup of a name in a directory. ``walk_component()`` uses
  218. ``lookup_fast()`` first which, in turn, checks to see if the name is in the cache,
  219. using only ``d_lock`` locking. If the name isn't found, then ``walk_component()``
  220. falls back to ``lookup_slow()`` which takes a shared lock on ``i_rwsem``, checks again that
  221. the name isn't in the cache, and then calls in to the filesystem to get a
  222. definitive answer. A new dentry will be added to the cache regardless of
  223. the result.
  224. Secondly, when pathname lookup reaches the final component, it will
  225. sometimes need to take an exclusive lock on ``i_rwsem`` before performing the last lookup so
  226. that the required exclusion can be achieved. How path lookup chooses
  227. to take, or not take, ``i_rwsem`` is one of the
  228. issues addressed in a subsequent section.
  229. If two threads attempt to look up the same name at the same time - a
  230. name that is not yet in the dcache - the shared lock on ``i_rwsem`` will
  231. not prevent them both adding new dentries with the same name. As this
  232. would result in confusion an extra level of interlocking is used,
  233. based around a secondary hash table (``in_lookup_hashtable``) and a
  234. per-dentry flag bit (``DCACHE_PAR_LOOKUP``).
  235. To add a new dentry to the cache while only holding a shared lock on
  236. ``i_rwsem``, a thread must call ``d_alloc_parallel()``. This allocates a
  237. dentry, stores the required name and parent in it, checks if there
  238. is already a matching dentry in the primary or secondary hash
  239. tables, and if not, stores the newly allocated dentry in the secondary
  240. hash table, with ``DCACHE_PAR_LOOKUP`` set.
  241. If a matching dentry was found in the primary hash table then that is
  242. returned and the caller can know that it lost a race with some other
  243. thread adding the entry. If no matching dentry is found in either
  244. cache, the newly allocated dentry is returned and the caller can
  245. detect this from the presence of ``DCACHE_PAR_LOOKUP``. In this case it
  246. knows that it has won any race and now is responsible for asking the
  247. filesystem to perform the lookup and find the matching inode. When
  248. the lookup is complete, it must call ``d_lookup_done()`` which clears
  249. the flag and does some other house keeping, including removing the
  250. dentry from the secondary hash table - it will normally have been
  251. added to the primary hash table already. Note that a ``struct
  252. waitqueue_head`` is passed to ``d_alloc_parallel()``, and
  253. ``d_lookup_done()`` must be called while this ``waitqueue_head`` is still
  254. in scope.
  255. If a matching dentry is found in the secondary hash table,
  256. ``d_alloc_parallel()`` has a little more work to do. It first waits for
  257. ``DCACHE_PAR_LOOKUP`` to be cleared, using a wait_queue that was passed
  258. to the instance of ``d_alloc_parallel()`` that won the race and that
  259. will be woken by the call to ``d_lookup_done()``. It then checks to see
  260. if the dentry has now been added to the primary hash table. If it
  261. has, the dentry is returned and the caller just sees that it lost any
  262. race. If it hasn't been added to the primary hash table, the most
  263. likely explanation is that some other dentry was added instead using
  264. ``d_splice_alias()``. In any case, ``d_alloc_parallel()`` repeats all the
  265. look ups from the start and will normally return something from the
  266. primary hash table.
  267. mnt->mnt_count
  268. ~~~~~~~~~~~~~~
  269. ``mnt_count`` is a per-CPU reference counter on "``mount``" structures.
  270. Per-CPU here means that incrementing the count is cheap as it only
  271. uses CPU-local memory, but checking if the count is zero is expensive as
  272. it needs to check with every CPU. Taking a ``mnt_count`` reference
  273. prevents the mount structure from disappearing as the result of regular
  274. unmount operations, but does not prevent a "lazy" unmount. So holding
  275. ``mnt_count`` doesn't ensure that the mount remains in the namespace and,
  276. in particular, doesn't stabilize the link to the mounted-on dentry. It
  277. does, however, ensure that the ``mount`` data structure remains coherent,
  278. and it provides a reference to the root dentry of the mounted
  279. filesystem. So a reference through ``->mnt_count`` provides a stable
  280. reference to the mounted dentry, but not the mounted-on dentry.
  281. mount_lock
  282. ~~~~~~~~~~
  283. ``mount_lock`` is a global seqlock, a bit like ``rename_lock``. It can be used to
  284. check if any change has been made to any mount points.
  285. While walking down the tree (away from the root) this lock is used when
  286. crossing a mount point to check that the crossing was safe. That is,
  287. the value in the seqlock is read, then the code finds the mount that
  288. is mounted on the current directory, if there is one, and increments
  289. the ``mnt_count``. Finally the value in ``mount_lock`` is checked against
  290. the old value. If there is no change, then the crossing was safe. If there
  291. was a change, the ``mnt_count`` is decremented and the whole process is
  292. retried.
  293. When walking up the tree (towards the root) by following a ".." link,
  294. a little more care is needed. In this case the seqlock (which
  295. contains both a counter and a spinlock) is fully locked to prevent
  296. any changes to any mount points while stepping up. This locking is
  297. needed to stabilize the link to the mounted-on dentry, which the
  298. refcount on the mount itself doesn't ensure.
  299. ``mount_lock`` is also used to detect and defend against potential attacks
  300. against ``LOOKUP_BENEATH`` and ``LOOKUP_IN_ROOT`` when resolving ".." (where
  301. the parent directory is moved outside the root, bypassing the ``path_equal()``
  302. check). If ``mount_lock`` is updated during the lookup and the path encounters
  303. a "..", a potential attack occurred and ``handle_dots()`` will bail out with
  304. ``-EAGAIN``.
  305. RCU
  306. ~~~
  307. Finally the global (but extremely lightweight) RCU read lock is held
  308. from time to time to ensure certain data structures don't get freed
  309. unexpectedly.
  310. In particular it is held while scanning chains in the dcache hash
  311. table, and the mount point hash table.
  312. Bringing it together with ``struct nameidata``
  313. ----------------------------------------------
  314. .. _First edition Unix: https://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/u2.s
  315. Throughout the process of walking a path, the current status is stored
  316. in a ``struct nameidata``, "namei" being the traditional name - dating
  317. all the way back to `First Edition Unix`_ - of the function that
  318. converts a "name" to an "inode". ``struct nameidata`` contains (among
  319. other fields):
  320. ``struct path path``
  321. ~~~~~~~~~~~~~~~~~~~~
  322. A ``path`` contains a ``struct vfsmount`` (which is
  323. embedded in a ``struct mount``) and a ``struct dentry``. Together these
  324. record the current status of the walk. They start out referring to the
  325. starting point (the current working directory, the root directory, or some other
  326. directory identified by a file descriptor), and are updated on each
  327. step. A reference through ``d_lockref`` and ``mnt_count`` is always
  328. held.
  329. ``struct qstr last``
  330. ~~~~~~~~~~~~~~~~~~~~
  331. This is a string together with a length (i.e. *not* ``nul`` terminated)
  332. that is the "next" component in the pathname.
  333. ``int last_type``
  334. ~~~~~~~~~~~~~~~~~
  335. This is one of ``LAST_NORM``, ``LAST_ROOT``, ``LAST_DOT`` or ``LAST_DOTDOT``.
  336. The ``last`` field is only valid if the type is ``LAST_NORM``.
  337. ``struct path root``
  338. ~~~~~~~~~~~~~~~~~~~~
  339. This is used to hold a reference to the effective root of the
  340. filesystem. Often that reference won't be needed, so this field is
  341. only assigned the first time it is used, or when a non-standard root
  342. is requested. Keeping a reference in the ``nameidata`` ensures that
  343. only one root is in effect for the entire path walk, even if it races
  344. with a ``chroot()`` system call.
  345. It should be noted that in the case of ``LOOKUP_IN_ROOT`` or
  346. ``LOOKUP_BENEATH``, the effective root becomes the directory file descriptor
  347. passed to ``openat2()`` (which exposes these ``LOOKUP_`` flags).
  348. The root is needed when either of two conditions holds: (1) either the
  349. pathname or a symbolic link starts with a "'/'", or (2) a "``..``"
  350. component is being handled, since "``..``" from the root must always stay
  351. at the root. The value used is usually the current root directory of
  352. the calling process. An alternate root can be provided as when
  353. ``sysctl()`` calls ``file_open_root()``, and when NFSv4 or Btrfs call
  354. ``mount_subtree()``. In each case a pathname is being looked up in a very
  355. specific part of the filesystem, and the lookup must not be allowed to
  356. escape that subtree. It works a bit like a local ``chroot()``.
  357. Ignoring the handling of symbolic links, we can now describe the
  358. "``link_path_walk()``" function, which handles the lookup of everything
  359. except the final component as:
  360. Given a path (``name``) and a nameidata structure (``nd``), check that the
  361. current directory has execute permission and then advance ``name``
  362. over one component while updating ``last_type`` and ``last``. If that
  363. was the final component, then return, otherwise call
  364. ``walk_component()`` and repeat from the top.
  365. ``walk_component()`` is even easier. If the component is ``LAST_DOTS``,
  366. it calls ``handle_dots()`` which does the necessary locking as already
  367. described. If it finds a ``LAST_NORM`` component it first calls
  368. "``lookup_fast()``" which only looks in the dcache, but will ask the
  369. filesystem to revalidate the result if it is that sort of filesystem.
  370. If that doesn't get a good result, it calls "``lookup_slow()``" which
  371. takes ``i_rwsem``, rechecks the cache, and then asks the filesystem
  372. to find a definitive answer. Each of these will call
  373. ``follow_managed()`` (as described below) to handle any mount points.
  374. In the absence of symbolic links, ``walk_component()`` creates a new
  375. ``struct path`` containing a counted reference to the new dentry and a
  376. reference to the new ``vfsmount`` which is only counted if it is
  377. different from the previous ``vfsmount``. It then calls
  378. ``path_to_nameidata()`` to install the new ``struct path`` in the
  379. ``struct nameidata`` and drop the unneeded references.
  380. This "hand-over-hand" sequencing of getting a reference to the new
  381. dentry before dropping the reference to the previous dentry may
  382. seem obvious, but is worth pointing out so that we will recognize its
  383. analogue in the "RCU-walk" version.
  384. Handling the final component
  385. ----------------------------
  386. ``link_path_walk()`` only walks as far as setting ``nd->last`` and
  387. ``nd->last_type`` to refer to the final component of the path. It does
  388. not call ``walk_component()`` that last time. Handling that final
  389. component remains for the caller to sort out. Those callers are
  390. ``path_lookupat()``, ``path_parentat()``, ``path_mountpoint()`` and
  391. ``path_openat()`` each of which handles the differing requirements of
  392. different system calls.
  393. ``path_parentat()`` is clearly the simplest - it just wraps a little bit
  394. of housekeeping around ``link_path_walk()`` and returns the parent
  395. directory and final component to the caller. The caller will be either
  396. aiming to create a name (via ``filename_create()``) or remove or rename
  397. a name (in which case ``user_path_parent()`` is used). They will use
  398. ``i_rwsem`` to exclude other changes while they validate and then
  399. perform their operation.
  400. ``path_lookupat()`` is nearly as simple - it is used when an existing
  401. object is wanted such as by ``stat()`` or ``chmod()``. It essentially just
  402. calls ``walk_component()`` on the final component through a call to
  403. ``lookup_last()``. ``path_lookupat()`` returns just the final dentry.
  404. ``path_mountpoint()`` handles the special case of unmounting which must
  405. not try to revalidate the mounted filesystem. It effectively
  406. contains, through a call to ``mountpoint_last()``, an alternate
  407. implementation of ``lookup_slow()`` which skips that step. This is
  408. important when unmounting a filesystem that is inaccessible, such as
  409. one provided by a dead NFS server.
  410. Finally ``path_openat()`` is used for the ``open()`` system call; it
  411. contains, in support functions starting with "``do_last()``", all the
  412. complexity needed to handle the different subtleties of O_CREAT (with
  413. or without O_EXCL), final "``/``" characters, and trailing symbolic
  414. links. We will revisit this in the final part of this series, which
  415. focuses on those symbolic links. "``do_last()``" will sometimes, but
  416. not always, take ``i_rwsem``, depending on what it finds.
  417. Each of these, or the functions which call them, need to be alert to
  418. the possibility that the final component is not ``LAST_NORM``. If the
  419. goal of the lookup is to create something, then any value for
  420. ``last_type`` other than ``LAST_NORM`` will result in an error. For
  421. example if ``path_parentat()`` reports ``LAST_DOTDOT``, then the caller
  422. won't try to create that name. They also check for trailing slashes
  423. by testing ``last.name[last.len]``. If there is any character beyond
  424. the final component, it must be a trailing slash.
  425. Revalidation and automounts
  426. ---------------------------
  427. Apart from symbolic links, there are only two parts of the "REF-walk"
  428. process not yet covered. One is the handling of stale cache entries
  429. and the other is automounts.
  430. On filesystems that require it, the lookup routines will call the
  431. ``->d_revalidate()`` dentry method to ensure that the cached information
  432. is current. This will often confirm validity or update a few details
  433. from a server. In some cases it may find that there has been change
  434. further up the path and that something that was thought to be valid
  435. previously isn't really. When this happens the lookup of the whole
  436. path is aborted and retried with the "``LOOKUP_REVAL``" flag set. This
  437. forces revalidation to be more thorough. We will see more details of
  438. this retry process in the next article.
  439. Automount points are locations in the filesystem where an attempt to
  440. lookup a name can trigger changes to how that lookup should be
  441. handled, in particular by mounting a filesystem there. These are
  442. covered in greater detail in autofs.txt in the Linux documentation
  443. tree, but a few notes specifically related to path lookup are in order
  444. here.
  445. The Linux VFS has a concept of "managed" dentries which is reflected
  446. in function names such as "``follow_managed()``". There are three
  447. potentially interesting things about these dentries corresponding
  448. to three different flags that might be set in ``dentry->d_flags``:
  449. ``DCACHE_MANAGE_TRANSIT``
  450. ~~~~~~~~~~~~~~~~~~~~~~~~~
  451. If this flag has been set, then the filesystem has requested that the
  452. ``d_manage()`` dentry operation be called before handling any possible
  453. mount point. This can perform two particular services:
  454. It can block to avoid races. If an automount point is being
  455. unmounted, the ``d_manage()`` function will usually wait for that
  456. process to complete before letting the new lookup proceed and possibly
  457. trigger a new automount.
  458. It can selectively allow only some processes to transit through a
  459. mount point. When a server process is managing automounts, it may
  460. need to access a directory without triggering normal automount
  461. processing. That server process can identify itself to the ``autofs``
  462. filesystem, which will then give it a special pass through
  463. ``d_manage()`` by returning ``-EISDIR``.
  464. ``DCACHE_MOUNTED``
  465. ~~~~~~~~~~~~~~~~~~
  466. This flag is set on every dentry that is mounted on. As Linux
  467. supports multiple filesystem namespaces, it is possible that the
  468. dentry may not be mounted on in *this* namespace, just in some
  469. other. So this flag is seen as a hint, not a promise.
  470. If this flag is set, and ``d_manage()`` didn't return ``-EISDIR``,
  471. ``lookup_mnt()`` is called to examine the mount hash table (honoring the
  472. ``mount_lock`` described earlier) and possibly return a new ``vfsmount``
  473. and a new ``dentry`` (both with counted references).
  474. ``DCACHE_NEED_AUTOMOUNT``
  475. ~~~~~~~~~~~~~~~~~~~~~~~~~
  476. If ``d_manage()`` allowed us to get this far, and ``lookup_mnt()`` didn't
  477. find a mount point, then this flag causes the ``d_automount()`` dentry
  478. operation to be called.
  479. The ``d_automount()`` operation can be arbitrarily complex and may
  480. communicate with server processes etc. but it should ultimately either
  481. report that there was an error, that there was nothing to mount, or
  482. should provide an updated ``struct path`` with new ``dentry`` and ``vfsmount``.
  483. In the latter case, ``finish_automount()`` will be called to safely
  484. install the new mount point into the mount table.
  485. There is no new locking of import here and it is important that no
  486. locks (only counted references) are held over this processing due to
  487. the very real possibility of extended delays.
  488. This will become more important next time when we examine RCU-walk
  489. which is particularly sensitive to delays.
  490. RCU-walk - faster pathname lookup in Linux
  491. ==========================================
  492. RCU-walk is another algorithm for performing pathname lookup in Linux.
  493. It is in many ways similar to REF-walk and the two share quite a bit
  494. of code. The significant difference in RCU-walk is how it allows for
  495. the possibility of concurrent access.
  496. We noted that REF-walk is complex because there are numerous details
  497. and special cases. RCU-walk reduces this complexity by simply
  498. refusing to handle a number of cases -- it instead falls back to
  499. REF-walk. The difficulty with RCU-walk comes from a different
  500. direction: unfamiliarity. The locking rules when depending on RCU are
  501. quite different from traditional locking, so we will spend a little extra
  502. time when we come to those.
  503. Clear demarcation of roles
  504. --------------------------
  505. The easiest way to manage concurrency is to forcibly stop any other
  506. thread from changing the data structures that a given thread is
  507. looking at. In cases where no other thread would even think of
  508. changing the data and lots of different threads want to read at the
  509. same time, this can be very costly. Even when using locks that permit
  510. multiple concurrent readers, the simple act of updating the count of
  511. the number of current readers can impose an unwanted cost. So the
  512. goal when reading a shared data structure that no other process is
  513. changing is to avoid writing anything to memory at all. Take no
  514. locks, increment no counts, leave no footprints.
  515. The REF-walk mechanism already described certainly doesn't follow this
  516. principle, but then it is really designed to work when there may well
  517. be other threads modifying the data. RCU-walk, in contrast, is
  518. designed for the common situation where there are lots of frequent
  519. readers and only occasional writers. This may not be common in all
  520. parts of the filesystem tree, but in many parts it will be. For the
  521. other parts it is important that RCU-walk can quickly fall back to
  522. using REF-walk.
  523. Pathname lookup always starts in RCU-walk mode but only remains there
  524. as long as what it is looking for is in the cache and is stable. It
  525. dances lightly down the cached filesystem image, leaving no footprints
  526. and carefully watching where it is, to be sure it doesn't trip. If it
  527. notices that something has changed or is changing, or if something
  528. isn't in the cache, then it tries to stop gracefully and switch to
  529. REF-walk.
  530. This stopping requires getting a counted reference on the current
  531. ``vfsmount`` and ``dentry``, and ensuring that these are still valid -
  532. that a path walk with REF-walk would have found the same entries.
  533. This is an invariant that RCU-walk must guarantee. It can only make
  534. decisions, such as selecting the next step, that are decisions which
  535. REF-walk could also have made if it were walking down the tree at the
  536. same time. If the graceful stop succeeds, the rest of the path is
  537. processed with the reliable, if slightly sluggish, REF-walk. If
  538. RCU-walk finds it cannot stop gracefully, it simply gives up and
  539. restarts from the top with REF-walk.
  540. This pattern of "try RCU-walk, if that fails try REF-walk" can be
  541. clearly seen in functions like ``filename_lookup()``,
  542. ``filename_parentat()``, ``filename_mountpoint()``,
  543. ``do_filp_open()``, and ``do_file_open_root()``. These five
  544. correspond roughly to the four ``path_*()`` functions we met earlier,
  545. each of which calls ``link_path_walk()``. The ``path_*()`` functions are
  546. called using different mode flags until a mode is found which works.
  547. They are first called with ``LOOKUP_RCU`` set to request "RCU-walk". If
  548. that fails with the error ``ECHILD`` they are called again with no
  549. special flag to request "REF-walk". If either of those report the
  550. error ``ESTALE`` a final attempt is made with ``LOOKUP_REVAL`` set (and no
  551. ``LOOKUP_RCU``) to ensure that entries found in the cache are forcibly
  552. revalidated - normally entries are only revalidated if the filesystem
  553. determines that they are too old to trust.
  554. The ``LOOKUP_RCU`` attempt may drop that flag internally and switch to
  555. REF-walk, but will never then try to switch back to RCU-walk. Places
  556. that trip up RCU-walk are much more likely to be near the leaves and
  557. so it is very unlikely that there will be much, if any, benefit from
  558. switching back.
  559. RCU and seqlocks: fast and light
  560. --------------------------------
  561. RCU is, unsurprisingly, critical to RCU-walk mode. The
  562. ``rcu_read_lock()`` is held for the entire time that RCU-walk is walking
  563. down a path. The particular guarantee it provides is that the key
  564. data structures - dentries, inodes, super_blocks, and mounts - will
  565. not be freed while the lock is held. They might be unlinked or
  566. invalidated in one way or another, but the memory will not be
  567. repurposed so values in various fields will still be meaningful. This
  568. is the only guarantee that RCU provides; everything else is done using
  569. seqlocks.
  570. As we saw above, REF-walk holds a counted reference to the current
  571. dentry and the current vfsmount, and does not release those references
  572. before taking references to the "next" dentry or vfsmount. It also
  573. sometimes takes the ``d_lock`` spinlock. These references and locks are
  574. taken to prevent certain changes from happening. RCU-walk must not
  575. take those references or locks and so cannot prevent such changes.
  576. Instead, it checks to see if a change has been made, and aborts or
  577. retries if it has.
  578. To preserve the invariant mentioned above (that RCU-walk may only make
  579. decisions that REF-walk could have made), it must make the checks at
  580. or near the same places that REF-walk holds the references. So, when
  581. REF-walk increments a reference count or takes a spinlock, RCU-walk
  582. samples the status of a seqlock using ``read_seqcount_begin()`` or a
  583. similar function. When REF-walk decrements the count or drops the
  584. lock, RCU-walk checks if the sampled status is still valid using
  585. ``read_seqcount_retry()`` or similar.
  586. However, there is a little bit more to seqlocks than that. If
  587. RCU-walk accesses two different fields in a seqlock-protected
  588. structure, or accesses the same field twice, there is no a priori
  589. guarantee of any consistency between those accesses. When consistency
  590. is needed - which it usually is - RCU-walk must take a copy and then
  591. use ``read_seqcount_retry()`` to validate that copy.
  592. ``read_seqcount_retry()`` not only checks the sequence number, but also
  593. imposes a memory barrier so that no memory-read instruction from
  594. *before* the call can be delayed until *after* the call, either by the
  595. CPU or by the compiler. A simple example of this can be seen in
  596. ``slow_dentry_cmp()`` which, for filesystems which do not use simple
  597. byte-wise name equality, calls into the filesystem to compare a name
  598. against a dentry. The length and name pointer are copied into local
  599. variables, then ``read_seqcount_retry()`` is called to confirm the two
  600. are consistent, and only then is ``->d_compare()`` called. When
  601. standard filename comparison is used, ``dentry_cmp()`` is called
  602. instead. Notably it does *not* use ``read_seqcount_retry()``, but
  603. instead has a large comment explaining why the consistency guarantee
  604. isn't necessary. A subsequent ``read_seqcount_retry()`` will be
  605. sufficient to catch any problem that could occur at this point.
  606. With that little refresher on seqlocks out of the way we can look at
  607. the bigger picture of how RCU-walk uses seqlocks.
  608. ``mount_lock`` and ``nd->m_seq``
  609. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  610. We already met the ``mount_lock`` seqlock when REF-walk used it to
  611. ensure that crossing a mount point is performed safely. RCU-walk uses
  612. it for that too, but for quite a bit more.
  613. Instead of taking a counted reference to each ``vfsmount`` as it
  614. descends the tree, RCU-walk samples the state of ``mount_lock`` at the
  615. start of the walk and stores this initial sequence number in the
  616. ``struct nameidata`` in the ``m_seq`` field. This one lock and one
  617. sequence number are used to validate all accesses to all ``vfsmounts``,
  618. and all mount point crossings. As changes to the mount table are
  619. relatively rare, it is reasonable to fall back on REF-walk any time
  620. that any "mount" or "unmount" happens.
  621. ``m_seq`` is checked (using ``read_seqretry()``) at the end of an RCU-walk
  622. sequence, whether switching to REF-walk for the rest of the path or
  623. when the end of the path is reached. It is also checked when stepping
  624. down over a mount point (in ``__follow_mount_rcu()``) or up (in
  625. ``follow_dotdot_rcu()``). If it is ever found to have changed, the
  626. whole RCU-walk sequence is aborted and the path is processed again by
  627. REF-walk.
  628. If RCU-walk finds that ``mount_lock`` hasn't changed then it can be sure
  629. that, had REF-walk taken counted references on each vfsmount, the
  630. results would have been the same. This ensures the invariant holds,
  631. at least for vfsmount structures.
  632. ``dentry->d_seq`` and ``nd->seq``
  633. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  634. In place of taking a count or lock on ``d_reflock``, RCU-walk samples
  635. the per-dentry ``d_seq`` seqlock, and stores the sequence number in the
  636. ``seq`` field of the nameidata structure, so ``nd->seq`` should always be
  637. the current sequence number of ``nd->dentry``. This number needs to be
  638. revalidated after copying, and before using, the name, parent, or
  639. inode of the dentry.
  640. The handling of the name we have already looked at, and the parent is
  641. only accessed in ``follow_dotdot_rcu()`` which fairly trivially follows
  642. the required pattern, though it does so for three different cases.
  643. When not at a mount point, ``d_parent`` is followed and its ``d_seq`` is
  644. collected. When we are at a mount point, we instead follow the
  645. ``mnt->mnt_mountpoint`` link to get a new dentry and collect its
  646. ``d_seq``. Then, after finally finding a ``d_parent`` to follow, we must
  647. check if we have landed on a mount point and, if so, must find that
  648. mount point and follow the ``mnt->mnt_root`` link. This would imply a
  649. somewhat unusual, but certainly possible, circumstance where the
  650. starting point of the path lookup was in part of the filesystem that
  651. was mounted on, and so not visible from the root.
  652. The inode pointer, stored in ``->d_inode``, is a little more
  653. interesting. The inode will always need to be accessed at least
  654. twice, once to determine if it is NULL and once to verify access
  655. permissions. Symlink handling requires a validated inode pointer too.
  656. Rather than revalidating on each access, a copy is made on the first
  657. access and it is stored in the ``inode`` field of ``nameidata`` from where
  658. it can be safely accessed without further validation.
  659. ``lookup_fast()`` is the only lookup routine that is used in RCU-mode,
  660. ``lookup_slow()`` being too slow and requiring locks. It is in
  661. ``lookup_fast()`` that we find the important "hand over hand" tracking
  662. of the current dentry.
  663. The current ``dentry`` and current ``seq`` number are passed to
  664. ``__d_lookup_rcu()`` which, on success, returns a new ``dentry`` and a
  665. new ``seq`` number. ``lookup_fast()`` then copies the inode pointer and
  666. revalidates the new ``seq`` number. It then validates the old ``dentry``
  667. with the old ``seq`` number one last time and only then continues. This
  668. process of getting the ``seq`` number of the new dentry and then
  669. checking the ``seq`` number of the old exactly mirrors the process of
  670. getting a counted reference to the new dentry before dropping that for
  671. the old dentry which we saw in REF-walk.
  672. No ``inode->i_rwsem`` or even ``rename_lock``
  673. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  674. A semaphore is a fairly heavyweight lock that can only be taken when it is
  675. permissible to sleep. As ``rcu_read_lock()`` forbids sleeping,
  676. ``inode->i_rwsem`` plays no role in RCU-walk. If some other thread does
  677. take ``i_rwsem`` and modifies the directory in a way that RCU-walk needs
  678. to notice, the result will be either that RCU-walk fails to find the
  679. dentry that it is looking for, or it will find a dentry which
  680. ``read_seqretry()`` won't validate. In either case it will drop down to
  681. REF-walk mode which can take whatever locks are needed.
  682. Though ``rename_lock`` could be used by RCU-walk as it doesn't require
  683. any sleeping, RCU-walk doesn't bother. REF-walk uses ``rename_lock`` to
  684. protect against the possibility of hash chains in the dcache changing
  685. while they are being searched. This can result in failing to find
  686. something that actually is there. When RCU-walk fails to find
  687. something in the dentry cache, whether it is really there or not, it
  688. already drops down to REF-walk and tries again with appropriate
  689. locking. This neatly handles all cases, so adding extra checks on
  690. rename_lock would bring no significant value.
  691. ``unlazy walk()`` and ``complete_walk()``
  692. -----------------------------------------
  693. That "dropping down to REF-walk" typically involves a call to
  694. ``unlazy_walk()``, so named because "RCU-walk" is also sometimes
  695. referred to as "lazy walk". ``unlazy_walk()`` is called when
  696. following the path down to the current vfsmount/dentry pair seems to
  697. have proceeded successfully, but the next step is problematic. This
  698. can happen if the next name cannot be found in the dcache, if
  699. permission checking or name revalidation couldn't be achieved while
  700. the ``rcu_read_lock()`` is held (which forbids sleeping), if an
  701. automount point is found, or in a couple of cases involving symlinks.
  702. It is also called from ``complete_walk()`` when the lookup has reached
  703. the final component, or the very end of the path, depending on which
  704. particular flavor of lookup is used.
  705. Other reasons for dropping out of RCU-walk that do not trigger a call
  706. to ``unlazy_walk()`` are when some inconsistency is found that cannot be
  707. handled immediately, such as ``mount_lock`` or one of the ``d_seq``
  708. seqlocks reporting a change. In these cases the relevant function
  709. will return ``-ECHILD`` which will percolate up until it triggers a new
  710. attempt from the top using REF-walk.
  711. For those cases where ``unlazy_walk()`` is an option, it essentially
  712. takes a reference on each of the pointers that it holds (vfsmount,
  713. dentry, and possibly some symbolic links) and then verifies that the
  714. relevant seqlocks have not been changed. If there have been changes,
  715. it, too, aborts with ``-ECHILD``, otherwise the transition to REF-walk
  716. has been a success and the lookup process continues.
  717. Taking a reference on those pointers is not quite as simple as just
  718. incrementing a counter. That works to take a second reference if you
  719. already have one (often indirectly through another object), but it
  720. isn't sufficient if you don't actually have a counted reference at
  721. all. For ``dentry->d_lockref``, it is safe to increment the reference
  722. counter to get a reference unless it has been explicitly marked as
  723. "dead" which involves setting the counter to ``-128``.
  724. ``lockref_get_not_dead()`` achieves this.
  725. For ``mnt->mnt_count`` it is safe to take a reference as long as
  726. ``mount_lock`` is then used to validate the reference. If that
  727. validation fails, it may *not* be safe to just drop that reference in
  728. the standard way of calling ``mnt_put()`` - an unmount may have
  729. progressed too far. So the code in ``legitimize_mnt()``, when it
  730. finds that the reference it got might not be safe, checks the
  731. ``MNT_SYNC_UMOUNT`` flag to determine if a simple ``mnt_put()`` is
  732. correct, or if it should just decrement the count and pretend none of
  733. this ever happened.
  734. Taking care in filesystems
  735. --------------------------
  736. RCU-walk depends almost entirely on cached information and often will
  737. not call into the filesystem at all. However there are two places,
  738. besides the already-mentioned component-name comparison, where the
  739. file system might be included in RCU-walk, and it must know to be
  740. careful.
  741. If the filesystem has non-standard permission-checking requirements -
  742. such as a networked filesystem which may need to check with the server
  743. - the ``i_op->permission`` interface might be called during RCU-walk.
  744. In this case an extra "``MAY_NOT_BLOCK``" flag is passed so that it
  745. knows not to sleep, but to return ``-ECHILD`` if it cannot complete
  746. promptly. ``i_op->permission`` is given the inode pointer, not the
  747. dentry, so it doesn't need to worry about further consistency checks.
  748. However if it accesses any other filesystem data structures, it must
  749. ensure they are safe to be accessed with only the ``rcu_read_lock()``
  750. held. This typically means they must be freed using ``kfree_rcu()`` or
  751. similar.
  752. .. _READ_ONCE: https://lwn.net/Articles/624126/
  753. If the filesystem may need to revalidate dcache entries, then
  754. ``d_op->d_revalidate`` may be called in RCU-walk too. This interface
  755. *is* passed the dentry but does not have access to the ``inode`` or the
  756. ``seq`` number from the ``nameidata``, so it needs to be extra careful
  757. when accessing fields in the dentry. This "extra care" typically
  758. involves using `READ_ONCE() <READ_ONCE_>`_ to access fields, and verifying the
  759. result is not NULL before using it. This pattern can be seen in
  760. ``nfs_lookup_revalidate()``.
  761. A pair of patterns
  762. ------------------
  763. In various places in the details of REF-walk and RCU-walk, and also in
  764. the big picture, there are a couple of related patterns that are worth
  765. being aware of.
  766. The first is "try quickly and check, if that fails try slowly". We
  767. can see that in the high-level approach of first trying RCU-walk and
  768. then trying REF-walk, and in places where ``unlazy_walk()`` is used to
  769. switch to REF-walk for the rest of the path. We also saw it earlier
  770. in ``dget_parent()`` when following a "``..``" link. It tries a quick way
  771. to get a reference, then falls back to taking locks if needed.
  772. The second pattern is "try quickly and check, if that fails try
  773. again - repeatedly". This is seen with the use of ``rename_lock`` and
  774. ``mount_lock`` in REF-walk. RCU-walk doesn't make use of this pattern -
  775. if anything goes wrong it is much safer to just abort and try a more
  776. sedate approach.
  777. The emphasis here is "try quickly and check". It should probably be
  778. "try quickly *and carefully*, then check". The fact that checking is
  779. needed is a reminder that the system is dynamic and only a limited
  780. number of things are safe at all. The most likely cause of errors in
  781. this whole process is assuming something is safe when in reality it
  782. isn't. Careful consideration of what exactly guarantees the safety of
  783. each access is sometimes necessary.
  784. A walk among the symlinks
  785. =========================
  786. There are several basic issues that we will examine to understand the
  787. handling of symbolic links: the symlink stack, together with cache
  788. lifetimes, will help us understand the overall recursive handling of
  789. symlinks and lead to the special care needed for the final component.
  790. Then a consideration of access-time updates and summary of the various
  791. flags controlling lookup will finish the story.
  792. The symlink stack
  793. -----------------
  794. There are only two sorts of filesystem objects that can usefully
  795. appear in a path prior to the final component: directories and symlinks.
  796. Handling directories is quite straightforward: the new directory
  797. simply becomes the starting point at which to interpret the next
  798. component on the path. Handling symbolic links requires a bit more
  799. work.
  800. Conceptually, symbolic links could be handled by editing the path. If
  801. a component name refers to a symbolic link, then that component is
  802. replaced by the body of the link and, if that body starts with a '/',
  803. then all preceding parts of the path are discarded. This is what the
  804. "``readlink -f``" command does, though it also edits out "``.``" and
  805. "``..``" components.
  806. Directly editing the path string is not really necessary when looking
  807. up a path, and discarding early components is pointless as they aren't
  808. looked at anyway. Keeping track of all remaining components is
  809. important, but they can of course be kept separately; there is no need
  810. to concatenate them. As one symlink may easily refer to another,
  811. which in turn can refer to a third, we may need to keep the remaining
  812. components of several paths, each to be processed when the preceding
  813. ones are completed. These path remnants are kept on a stack of
  814. limited size.
  815. There are two reasons for placing limits on how many symlinks can
  816. occur in a single path lookup. The most obvious is to avoid loops.
  817. If a symlink referred to itself either directly or through
  818. intermediaries, then following the symlink can never complete
  819. successfully - the error ``ELOOP`` must be returned. Loops can be
  820. detected without imposing limits, but limits are the simplest solution
  821. and, given the second reason for restriction, quite sufficient.
  822. .. _outlined recently: http://thread.gmane.org/gmane.linux.kernel/1934390/focus=1934550
  823. The second reason was `outlined recently`_ by Linus:
  824. Because it's a latency and DoS issue too. We need to react well to
  825. true loops, but also to "very deep" non-loops. It's not about memory
  826. use, it's about users triggering unreasonable CPU resources.
  827. Linux imposes a limit on the length of any pathname: ``PATH_MAX``, which
  828. is 4096. There are a number of reasons for this limit; not letting the
  829. kernel spend too much time on just one path is one of them. With
  830. symbolic links you can effectively generate much longer paths so some
  831. sort of limit is needed for the same reason. Linux imposes a limit of
  832. at most 40 symlinks in any one path lookup. It previously imposed a
  833. further limit of eight on the maximum depth of recursion, but that was
  834. raised to 40 when a separate stack was implemented, so there is now
  835. just the one limit.
  836. The ``nameidata`` structure that we met in an earlier article contains a
  837. small stack that can be used to store the remaining part of up to two
  838. symlinks. In many cases this will be sufficient. If it isn't, a
  839. separate stack is allocated with room for 40 symlinks. Pathname
  840. lookup will never exceed that stack as, once the 40th symlink is
  841. detected, an error is returned.
  842. It might seem that the name remnants are all that needs to be stored on
  843. this stack, but we need a bit more. To see that, we need to move on to
  844. cache lifetimes.
  845. Storage and lifetime of cached symlinks
  846. ---------------------------------------
  847. Like other filesystem resources, such as inodes and directory
  848. entries, symlinks are cached by Linux to avoid repeated costly access
  849. to external storage. It is particularly important for RCU-walk to be
  850. able to find and temporarily hold onto these cached entries, so that
  851. it doesn't need to drop down into REF-walk.
  852. .. _object-oriented design pattern: https://lwn.net/Articles/446317/
  853. While each filesystem is free to make its own choice, symlinks are
  854. typically stored in one of two places. Short symlinks are often
  855. stored directly in the inode. When a filesystem allocates a ``struct
  856. inode`` it typically allocates extra space to store private data (a
  857. common `object-oriented design pattern`_ in the kernel). This will
  858. sometimes include space for a symlink. The other common location is
  859. in the page cache, which normally stores the content of files. The
  860. pathname in a symlink can be seen as the content of that symlink and
  861. can easily be stored in the page cache just like file content.
  862. When neither of these is suitable, the next most likely scenario is
  863. that the filesystem will allocate some temporary memory and copy or
  864. construct the symlink content into that memory whenever it is needed.
  865. When the symlink is stored in the inode, it has the same lifetime as
  866. the inode which, itself, is protected by RCU or by a counted reference
  867. on the dentry. This means that the mechanisms that pathname lookup
  868. uses to access the dcache and icache (inode cache) safely are quite
  869. sufficient for accessing some cached symlinks safely. In these cases,
  870. the ``i_link`` pointer in the inode is set to point to wherever the
  871. symlink is stored and it can be accessed directly whenever needed.
  872. When the symlink is stored in the page cache or elsewhere, the
  873. situation is not so straightforward. A reference on a dentry or even
  874. on an inode does not imply any reference on cached pages of that
  875. inode, and even an ``rcu_read_lock()`` is not sufficient to ensure that
  876. a page will not disappear. So for these symlinks the pathname lookup
  877. code needs to ask the filesystem to provide a stable reference and,
  878. significantly, needs to release that reference when it is finished
  879. with it.
  880. Taking a reference to a cache page is often possible even in RCU-walk
  881. mode. It does require making changes to memory, which is best avoided,
  882. but that isn't necessarily a big cost and it is better than dropping
  883. out of RCU-walk mode completely. Even filesystems that allocate
  884. space to copy the symlink into can use ``GFP_ATOMIC`` to often successfully
  885. allocate memory without the need to drop out of RCU-walk. If a
  886. filesystem cannot successfully get a reference in RCU-walk mode, it
  887. must return ``-ECHILD`` and ``unlazy_walk()`` will be called to return to
  888. REF-walk mode in which the filesystem is allowed to sleep.
  889. The place for all this to happen is the ``i_op->follow_link()`` inode
  890. method. In the present mainline code this is never actually called in
  891. RCU-walk mode as the rewrite is not quite complete. It is likely that
  892. in a future release this method will be passed an ``inode`` pointer when
  893. called in RCU-walk mode so it both (1) knows to be careful, and (2) has the
  894. validated pointer. Much like the ``i_op->permission()`` method we
  895. looked at previously, ``->follow_link()`` would need to be careful that
  896. all the data structures it references are safe to be accessed while
  897. holding no counted reference, only the RCU lock. Though getting a
  898. reference with ``->follow_link()`` is not yet done in RCU-walk mode, the
  899. code is ready to release the reference when that does happen.
  900. This need to drop the reference to a symlink adds significant
  901. complexity. It requires a reference to the inode so that the
  902. ``i_op->put_link()`` inode operation can be called. In REF-walk, that
  903. reference is kept implicitly through a reference to the dentry, so
  904. keeping the ``struct path`` of the symlink is easiest. For RCU-walk,
  905. the pointer to the inode is kept separately. To allow switching from
  906. RCU-walk back to REF-walk in the middle of processing nested symlinks
  907. we also need the seq number for the dentry so we can confirm that
  908. switching back was safe.
  909. Finally, when providing a reference to a symlink, the filesystem also
  910. provides an opaque "cookie" that must be passed to ``->put_link()`` so that it
  911. knows what to free. This might be the allocated memory area, or a
  912. pointer to the ``struct page`` in the page cache, or something else
  913. completely. Only the filesystem knows what it is.
  914. In order for the reference to each symlink to be dropped when the walk completes,
  915. whether in RCU-walk or REF-walk, the symlink stack needs to contain,
  916. along with the path remnants:
  917. - the ``struct path`` to provide a reference to the inode in REF-walk
  918. - the ``struct inode *`` to provide a reference to the inode in RCU-walk
  919. - the ``seq`` to allow the path to be safely switched from RCU-walk to REF-walk
  920. - the ``cookie`` that tells ``->put_path()`` what to put.
  921. This means that each entry in the symlink stack needs to hold five
  922. pointers and an integer instead of just one pointer (the path
  923. remnant). On a 64-bit system, this is about 40 bytes per entry;
  924. with 40 entries it adds up to 1600 bytes total, which is less than
  925. half a page. So it might seem like a lot, but is by no means
  926. excessive.
  927. Note that, in a given stack frame, the path remnant (``name``) is not
  928. part of the symlink that the other fields refer to. It is the remnant
  929. to be followed once that symlink has been fully parsed.
  930. Following the symlink
  931. ---------------------
  932. The main loop in ``link_path_walk()`` iterates seamlessly over all
  933. components in the path and all of the non-final symlinks. As symlinks
  934. are processed, the ``name`` pointer is adjusted to point to a new
  935. symlink, or is restored from the stack, so that much of the loop
  936. doesn't need to notice. Getting this ``name`` variable on and off the
  937. stack is very straightforward; pushing and popping the references is
  938. a little more complex.
  939. When a symlink is found, ``walk_component()`` returns the value ``1``
  940. (``0`` is returned for any other sort of success, and a negative number
  941. is, as usual, an error indicator). This causes ``get_link()`` to be
  942. called; it then gets the link from the filesystem. Providing that
  943. operation is successful, the old path ``name`` is placed on the stack,
  944. and the new value is used as the ``name`` for a while. When the end of
  945. the path is found (i.e. ``*name`` is ``'\0'``) the old ``name`` is restored
  946. off the stack and path walking continues.
  947. Pushing and popping the reference pointers (inode, cookie, etc.) is more
  948. complex in part because of the desire to handle tail recursion. When
  949. the last component of a symlink itself points to a symlink, we
  950. want to pop the symlink-just-completed off the stack before pushing
  951. the symlink-just-found to avoid leaving empty path remnants that would
  952. just get in the way.
  953. It is most convenient to push the new symlink references onto the
  954. stack in ``walk_component()`` immediately when the symlink is found;
  955. ``walk_component()`` is also the last piece of code that needs to look at the
  956. old symlink as it walks that last component. So it is quite
  957. convenient for ``walk_component()`` to release the old symlink and pop
  958. the references just before pushing the reference information for the
  959. new symlink. It is guided in this by two flags; ``WALK_GET``, which
  960. gives it permission to follow a symlink if it finds one, and
  961. ``WALK_PUT``, which tells it to release the current symlink after it has been
  962. followed. ``WALK_PUT`` is tested first, leading to a call to
  963. ``put_link()``. ``WALK_GET`` is tested subsequently (by
  964. ``should_follow_link()``) leading to a call to ``pick_link()`` which sets
  965. up the stack frame.
  966. Symlinks with no final component
  967. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  968. A pair of special-case symlinks deserve a little further explanation.
  969. Both result in a new ``struct path`` (with mount and dentry) being set
  970. up in the ``nameidata``, and result in ``get_link()`` returning ``NULL``.
  971. The more obvious case is a symlink to "``/``". All symlinks starting
  972. with "``/``" are detected in ``get_link()`` which resets the ``nameidata``
  973. to point to the effective filesystem root. If the symlink only
  974. contains "``/``" then there is nothing more to do, no components at all,
  975. so ``NULL`` is returned to indicate that the symlink can be released and
  976. the stack frame discarded.
  977. The other case involves things in ``/proc`` that look like symlinks but
  978. aren't really (and are therefore commonly referred to as "magic-links")::
  979. $ ls -l /proc/self/fd/1
  980. lrwx------ 1 neilb neilb 64 Jun 13 10:19 /proc/self/fd/1 -> /dev/pts/4
  981. Every open file descriptor in any process is represented in ``/proc`` by
  982. something that looks like a symlink. It is really a reference to the
  983. target file, not just the name of it. When you ``readlink`` these
  984. objects you get a name that might refer to the same file - unless it
  985. has been unlinked or mounted over. When ``walk_component()`` follows
  986. one of these, the ``->follow_link()`` method in "procfs" doesn't return
  987. a string name, but instead calls ``nd_jump_link()`` which updates the
  988. ``nameidata`` in place to point to that target. ``->follow_link()`` then
  989. returns ``NULL``. Again there is no final component and ``get_link()``
  990. reports this by leaving the ``last_type`` field of ``nameidata`` as
  991. ``LAST_BIND``.
  992. Following the symlink in the final component
  993. --------------------------------------------
  994. All this leads to ``link_path_walk()`` walking down every component, and
  995. following all symbolic links it finds, until it reaches the final
  996. component. This is just returned in the ``last`` field of ``nameidata``.
  997. For some callers, this is all they need; they want to create that
  998. ``last`` name if it doesn't exist or give an error if it does. Other
  999. callers will want to follow a symlink if one is found, and possibly
  1000. apply special handling to the last component of that symlink, rather
  1001. than just the last component of the original file name. These callers
  1002. potentially need to call ``link_path_walk()`` again and again on
  1003. successive symlinks until one is found that doesn't point to another
  1004. symlink.
  1005. This case is handled by the relevant caller of ``link_path_walk()``, such as
  1006. ``path_lookupat()`` using a loop that calls ``link_path_walk()``, and then
  1007. handles the final component. If the final component is a symlink
  1008. that needs to be followed, then ``trailing_symlink()`` is called to set
  1009. things up properly and the loop repeats, calling ``link_path_walk()``
  1010. again. This could loop as many as 40 times if the last component of
  1011. each symlink is another symlink.
  1012. The various functions that examine the final component and possibly
  1013. report that it is a symlink are ``lookup_last()``, ``mountpoint_last()``
  1014. and ``do_last()``, each of which use the same convention as
  1015. ``walk_component()`` of returning ``1`` if a symlink was found that needs
  1016. to be followed.
  1017. Of these, ``do_last()`` is the most interesting as it is used for
  1018. opening a file. Part of ``do_last()`` runs with ``i_rwsem`` held and this
  1019. part is in a separate function: ``lookup_open()``.
  1020. Explaining ``do_last()`` completely is beyond the scope of this article,
  1021. but a few highlights should help those interested in exploring the
  1022. code.
  1023. 1. Rather than just finding the target file, ``do_last()`` needs to open
  1024. it. If the file was found in the dcache, then ``vfs_open()`` is used for
  1025. this. If not, then ``lookup_open()`` will either call ``atomic_open()`` (if
  1026. the filesystem provides it) to combine the final lookup with the open, or
  1027. will perform the separate ``lookup_real()`` and ``vfs_create()`` steps
  1028. directly. In the later case the actual "open" of this newly found or
  1029. created file will be performed by ``vfs_open()``, just as if the name
  1030. were found in the dcache.
  1031. 2. ``vfs_open()`` can fail with ``-EOPENSTALE`` if the cached information
  1032. wasn't quite current enough. Rather than restarting the lookup from
  1033. the top with ``LOOKUP_REVAL`` set, ``lookup_open()`` is called instead,
  1034. giving the filesystem a chance to resolve small inconsistencies.
  1035. If that doesn't work, only then is the lookup restarted from the top.
  1036. 3. An open with O_CREAT **does** follow a symlink in the final component,
  1037. unlike other creation system calls (like ``mkdir``). So the sequence::
  1038. ln -s bar /tmp/foo
  1039. echo hello > /tmp/foo
  1040. will create a file called ``/tmp/bar``. This is not permitted if
  1041. ``O_EXCL`` is set but otherwise is handled for an O_CREAT open much
  1042. like for a non-creating open: ``should_follow_link()`` returns ``1``, and
  1043. so does ``do_last()`` so that ``trailing_symlink()`` gets called and the
  1044. open process continues on the symlink that was found.
  1045. Updating the access time
  1046. ------------------------
  1047. We previously said of RCU-walk that it would "take no locks, increment
  1048. no counts, leave no footprints." We have since seen that some
  1049. "footprints" can be needed when handling symlinks as a counted
  1050. reference (or even a memory allocation) may be needed. But these
  1051. footprints are best kept to a minimum.
  1052. One other place where walking down a symlink can involve leaving
  1053. footprints in a way that doesn't affect directories is in updating access times.
  1054. In Unix (and Linux) every filesystem object has a "last accessed
  1055. time", or "``atime``". Passing through a directory to access a file
  1056. within is not considered to be an access for the purposes of
  1057. ``atime``; only listing the contents of a directory can update its ``atime``.
  1058. Symlinks are different it seems. Both reading a symlink (with ``readlink()``)
  1059. and looking up a symlink on the way to some other destination can
  1060. update the atime on that symlink.
  1061. .. _clearest statement: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_08
  1062. It is not clear why this is the case; POSIX has little to say on the
  1063. subject. The `clearest statement`_ is that, if a particular implementation
  1064. updates a timestamp in a place not specified by POSIX, this must be
  1065. documented "except that any changes caused by pathname resolution need
  1066. not be documented". This seems to imply that POSIX doesn't really
  1067. care about access-time updates during pathname lookup.
  1068. .. _Linux 1.3.87: https://git.kernel.org/cgit/linux/kernel/git/history/history.git/diff/fs/ext2/symlink.c?id=f806c6db77b8eaa6e00dcfb6b567706feae8dbb8
  1069. An examination of history shows that prior to `Linux 1.3.87`_, the ext2
  1070. filesystem, at least, didn't update atime when following a link.
  1071. Unfortunately we have no record of why that behavior was changed.
  1072. In any case, access time must now be updated and that operation can be
  1073. quite complex. Trying to stay in RCU-walk while doing it is best
  1074. avoided. Fortunately it is often permitted to skip the ``atime``
  1075. update. Because ``atime`` updates cause performance problems in various
  1076. areas, Linux supports the ``relatime`` mount option, which generally
  1077. limits the updates of ``atime`` to once per day on files that aren't
  1078. being changed (and symlinks never change once created). Even without
  1079. ``relatime``, many filesystems record ``atime`` with a one-second
  1080. granularity, so only one update per second is required.
  1081. It is easy to test if an ``atime`` update is needed while in RCU-walk
  1082. mode and, if it isn't, the update can be skipped and RCU-walk mode
  1083. continues. Only when an ``atime`` update is actually required does the
  1084. path walk drop down to REF-walk. All of this is handled in the
  1085. ``get_link()`` function.
  1086. A few flags
  1087. -----------
  1088. A suitable way to wrap up this tour of pathname walking is to list
  1089. the various flags that can be stored in the ``nameidata`` to guide the
  1090. lookup process. Many of these are only meaningful on the final
  1091. component, others reflect the current state of the pathname lookup, and some
  1092. apply restrictions to all path components encountered in the path lookup.
  1093. And then there is ``LOOKUP_EMPTY``, which doesn't fit conceptually with
  1094. the others. If this is not set, an empty pathname causes an error
  1095. very early on. If it is set, empty pathnames are not considered to be
  1096. an error.
  1097. Global state flags
  1098. ~~~~~~~~~~~~~~~~~~
  1099. We have already met two global state flags: ``LOOKUP_RCU`` and
  1100. ``LOOKUP_REVAL``. These select between one of three overall approaches
  1101. to lookup: RCU-walk, REF-walk, and REF-walk with forced revalidation.
  1102. ``LOOKUP_PARENT`` indicates that the final component hasn't been reached
  1103. yet. This is primarily used to tell the audit subsystem the full
  1104. context of a particular access being audited.
  1105. ``LOOKUP_ROOT`` indicates that the ``root`` field in the ``nameidata`` was
  1106. provided by the caller, so it shouldn't be released when it is no
  1107. longer needed.
  1108. ``LOOKUP_JUMPED`` means that the current dentry was chosen not because
  1109. it had the right name but for some other reason. This happens when
  1110. following "``..``", following a symlink to ``/``, crossing a mount point
  1111. or accessing a "``/proc/$PID/fd/$FD``" symlink (also known as a "magic
  1112. link"). In this case the filesystem has not been asked to revalidate the
  1113. name (with ``d_revalidate()``). In such cases the inode may still need
  1114. to be revalidated, so ``d_op->d_weak_revalidate()`` is called if
  1115. ``LOOKUP_JUMPED`` is set when the look completes - which may be at the
  1116. final component or, when creating, unlinking, or renaming, at the penultimate component.
  1117. Resolution-restriction flags
  1118. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1119. In order to allow userspace to protect itself against certain race conditions
  1120. and attack scenarios involving changing path components, a series of flags are
  1121. available which apply restrictions to all path components encountered during
  1122. path lookup. These flags are exposed through ``openat2()``'s ``resolve`` field.
  1123. ``LOOKUP_NO_SYMLINKS`` blocks all symlink traversals (including magic-links).
  1124. This is distinctly different from ``LOOKUP_FOLLOW``, because the latter only
  1125. relates to restricting the following of trailing symlinks.
  1126. ``LOOKUP_NO_MAGICLINKS`` blocks all magic-link traversals. Filesystems must
  1127. ensure that they return errors from ``nd_jump_link()``, because that is how
  1128. ``LOOKUP_NO_MAGICLINKS`` and other magic-link restrictions are implemented.
  1129. ``LOOKUP_NO_XDEV`` blocks all ``vfsmount`` traversals (this includes both
  1130. bind-mounts and ordinary mounts). Note that the ``vfsmount`` which contains the
  1131. lookup is determined by the first mountpoint the path lookup reaches --
  1132. absolute paths start with the ``vfsmount`` of ``/``, and relative paths start
  1133. with the ``dfd``'s ``vfsmount``. Magic-links are only permitted if the
  1134. ``vfsmount`` of the path is unchanged.
  1135. ``LOOKUP_BENEATH`` blocks any path components which resolve outside the
  1136. starting point of the resolution. This is done by blocking ``nd_jump_root()``
  1137. as well as blocking ".." if it would jump outside the starting point.
  1138. ``rename_lock`` and ``mount_lock`` are used to detect attacks against the
  1139. resolution of "..". Magic-links are also blocked.
  1140. ``LOOKUP_IN_ROOT`` resolves all path components as though the starting point
  1141. were the filesystem root. ``nd_jump_root()`` brings the resolution back to
  1142. the starting point, and ".." at the starting point will act as a no-op. As with
  1143. ``LOOKUP_BENEATH``, ``rename_lock`` and ``mount_lock`` are used to detect
  1144. attacks against ".." resolution. Magic-links are also blocked.
  1145. Final-component flags
  1146. ~~~~~~~~~~~~~~~~~~~~~
  1147. Some of these flags are only set when the final component is being
  1148. considered. Others are only checked for when considering that final
  1149. component.
  1150. ``LOOKUP_AUTOMOUNT`` ensures that, if the final component is an automount
  1151. point, then the mount is triggered. Some operations would trigger it
  1152. anyway, but operations like ``stat()`` deliberately don't. ``statfs()``
  1153. needs to trigger the mount but otherwise behaves a lot like ``stat()``, so
  1154. it sets ``LOOKUP_AUTOMOUNT``, as does "``quotactl()``" and the handling of
  1155. "``mount --bind``".
  1156. ``LOOKUP_FOLLOW`` has a similar function to ``LOOKUP_AUTOMOUNT`` but for
  1157. symlinks. Some system calls set or clear it implicitly, while
  1158. others have API flags such as ``AT_SYMLINK_FOLLOW`` and
  1159. ``UMOUNT_NOFOLLOW`` to control it. Its effect is similar to
  1160. ``WALK_GET`` that we already met, but it is used in a different way.
  1161. ``LOOKUP_DIRECTORY`` insists that the final component is a directory.
  1162. Various callers set this and it is also set when the final component
  1163. is found to be followed by a slash.
  1164. Finally ``LOOKUP_OPEN``, ``LOOKUP_CREATE``, ``LOOKUP_EXCL``, and
  1165. ``LOOKUP_RENAME_TARGET`` are not used directly by the VFS but are made
  1166. available to the filesystem and particularly the ``->d_revalidate()``
  1167. method. A filesystem can choose not to bother revalidating too hard
  1168. if it knows that it will be asked to open or create the file soon.
  1169. These flags were previously useful for ``->lookup()`` too but with the
  1170. introduction of ``->atomic_open()`` they are less relevant there.
  1171. End of the road
  1172. ---------------
  1173. Despite its complexity, all this pathname lookup code appears to be
  1174. in good shape - various parts are certainly easier to understand now
  1175. than even a couple of releases ago. But that doesn't mean it is
  1176. "finished". As already mentioned, RCU-walk currently only follows
  1177. symlinks that are stored in the inode so, while it handles many ext4
  1178. symlinks, it doesn't help with NFS, XFS, or Btrfs. That support
  1179. is not likely to be long delayed.