aboutsummaryrefslogtreecommitdiffstats
path: root/net/lapb/lapb_in.c
diff options
context:
space:
mode:
authorJoonsoo Kim <iamjoonsoo.kim@lge.com>2015-02-05 15:25:23 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2015-02-05 16:35:30 -0500
commit7b02190c27091f7b4614d9a655981ae20520d22c (patch)
tree911cb38132e335a72c39c1e3c5ed2918e3c84b92 /net/lapb/lapb_in.c
parent7ef3ff2fea8bf5e4a21cef47ad87710a3d0fdb52 (diff)
mm/debug_pagealloc: fix build failure on ppc and some other archs
Kim Phillips reported following build failure. LD init/built-in.o mm/built-in.o: In function `free_pages_prepare': mm/page_alloc.c:770: undefined reference to `.kernel_map_pages' mm/built-in.o: In function `prep_new_page': mm/page_alloc.c:933: undefined reference to `.kernel_map_pages' mm/built-in.o: In function `map_pages': mm/compaction.c:61: undefined reference to `.kernel_map_pages' make: *** [vmlinux] Error 1 Reason for this problem is that commit 031bc5743f15 ("mm/debug-pagealloc: make debug-pagealloc boottime configurable") forgot to remove the old declaration of kernel_map_pages() for some architectures. This patch removes them to fix build failure. Reported-by: Kim Phillips <kim.phillips@freescale.com> Signed-off-by: Joonsoo Kim <iamjoonsoo.kim@lge.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: David Miller <davem@davemloft.net> Cc: David Howells <dhowells@redhat.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'net/lapb/lapb_in.c')
0 files changed, 0 insertions, 0 deletions
id='n92' href='#n92'>92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
















































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































































                                                                                                                                                   
<head>
<style> p { max-width:50em} ol, ul {max-width: 40em}</style>
</head>

Pathname lookup in Linux.
=========================

This write-up is based on three articles published at lwn.net:

- <https://lwn.net/Articles/649115/> Pathname lookup in Linux
- <https://lwn.net/Articles/649729/> RCU-walk: faster pathname lookup in Linux
- <https://lwn.net/Articles/650786/> A walk among the symlinks

Written by Neil Brown with help from Al Viro and Jon Corbet.

Introduction
------------

The most obvious aspect of pathname lookup, which very little
exploration is needed to discover, is that it is complex.  There are
many rules, special cases, and implementation alternatives that all
combine to confuse the unwary reader.  Computer science has long been
acquainted with such complexity and has tools to help manage it.  One
tool that we will make extensive use of is "divide and conquer".  For
the early parts of the analysis we will divide off symlinks - leaving
them until the final part.  Well before we get to symlinks we have
another major division based on the VFS's approach to locking which
will allow us to review "REF-walk" and "RCU-walk" separately.  But we
are getting ahead of ourselves.  There are some important low level
distinctions we need to clarify first.

There are two sorts of ...
--------------------------

[`openat()`]: http://man7.org/linux/man-pages/man2/openat.2.html

Pathnames (sometimes "file names"), used to identify objects in the
filesystem, will be familiar to most readers.  They contain two sorts
of elements: "slashes" that are sequences of one or more "`/`"
characters, and "components" that are sequences of one or more
non-"`/`" characters.  These form two kinds of paths.  Those that
start with slashes are "absolute" and start from the filesystem root.
The others are "relative" and start from the current directory, or
from some other location specified by a file descriptor given to a
"xxx`at`" system call such as "[`openat()`]".

[`execveat()`]: http://man7.org/linux/man-pages/man2/execveat.2.html

It is tempting to describe the second kind as starting with a
component, but that isn't always accurate: a pathname can lack both
slashes and components, it can be empty, in other words.  This is
generally forbidden in POSIX, but some of those "xxx`at`" system calls
in Linux permit it when the `AT_EMPTY_PATH` flag is given.  For
example, if you have an open file descriptor on an executable file you
can execute it by calling [`execveat()`] passing the file descriptor,
an empty path, and the `AT_EMPTY_PATH` flag.

These paths can be divided into two sections: the final component and
everything else.  The "everything else" is the easy bit.  In all cases
it must identify a directory that already exists, otherwise an error
such as `ENOENT` or `ENOTDIR` will be reported.

The final component is not so simple.  Not only do different system
calls interpret it quite differently (e.g. some create it, some do
not), but it might not even exist: neither the empty pathname nor the
pathname that is just slashes have a final component.  If it does
exist, it could be "`.`" or "`..`" which are handled quite differently
from other components.

[POSIX]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html#tag_04_12

If a pathname ends with a slash, such as "`/tmp/foo/`" it might be
tempting to consider that to have an empty final component.  In many
ways that would lead to correct results, but not always.  In
particular, `mkdir()` and `rmdir()` each create or remove a directory named
by the final component, and they are required to work with pathnames
ending in "`/`".  According to [POSIX]

> A pathname that contains at least one non- &lt;slash> character and
> that ends with one or more trailing &lt;slash> characters shall not
> be resolved successfully unless the last pathname component before
> the trailing <slash> characters names an existing directory or a
> directory entry that is to be created for a directory immediately
> after the pathname is resolved.

The Linux pathname walking code (mostly in `fs/namei.c`) deals with
all of these issues: breaking the path into components, handling the
"everything else" quite separately from the final component, and
checking that the trailing slash is not used where it isn't
permitted.  It also addresses the important issue of concurrent
access.

While one process is looking up a pathname, another might be making
changes that affect that lookup.  One fairly extreme case is that if
"a/b" were renamed to "a/c/b" while another process were looking up
"a/b/..", that process might successfully resolve on "a/c".
Most races are much more subtle, and a big part of the task of
pathname lookup is to prevent them from having damaging effects.  Many
of the possible races are seen most clearly in the context of the
"dcache" and an understanding of that is central to understanding
pathname lookup.

More than just a cache.
-----------------------

The "dcache" caches information about names in each filesystem to
make them quickly available for lookup.  Each entry (known as a
"dentry") contains three significant fields: a component name, a
pointer to a parent dentry, and a pointer to the "inode" which
contains further information about the object in that parent with
the given name.  The inode pointer can be `NULL` indicating that the
name doesn't exist in the parent.  While there can be linkage in the
dentry of a directory to the dentries of the children, that linkage is
not used for pathname lookup, and so will not be considered here.

The dcache has a number of uses apart from accelerating lookup.  One
that will be particularly relevant is that it is closely integrated
with the mount table that records which filesystem is mounted where.
What the mount table actually stores is which dentry is mounted on top
of which other dentry.

When considering the dcache, we have another of our "two types"
distinctions: there are two types of filesystems.

Some filesystems ensure that the information in the dcache is always
completely accurate (though not necessarily complete).  This can allow
the VFS to determine if a particular file does or doesn't exist
without checking with the filesystem, and means that the VFS can
protect the filesystem against certain races and other problems.
These are typically "local" filesystems such as ext3, XFS, and Btrfs.

Other filesystems don't provide that guarantee because they cannot.
These are typically filesystems that are shared across a network,
whether remote filesystems like NFS and 9P, or cluster filesystems
like ocfs2 or cephfs.  These filesystems allow the VFS to revalidate
cached information, and must provide their own protection against
awkward races.  The VFS can detect these filesystems by the
`DCACHE_OP_REVALIDATE` flag being set in the dentry.

REF-walk: simple concurrency management with refcounts and spinlocks
--------------------------------------------------------------------

With all of those divisions carefully classified, we can now start
looking at the actual process of walking along a path.  In particular
we will start with the handling of the "everything else" part of a
pathname, and focus on the "REF-walk" approach to concurrency
management.  This code is found in the `link_path_walk()` function, if
you ignore all the places that only run when "`LOOKUP_RCU`"
(indicating the use of RCU-walk) is set.

[Meet the Lockers]: https://lwn.net/Articles/453685/

REF-walk is fairly heavy-handed with locks and reference counts.  Not
as heavy-handed as in the old "big kernel lock" days, but certainly not
afraid of taking a lock when one is needed.  It uses a variety of
different concurrency controls.  A background understanding of the
various primitives is assumed, or can be gleaned from elsewhere such
as in [Meet the Lockers].

The locking mechanisms used by REF-walk include:

### dentry->d_lockref ###

This uses the lockref primitive to provide both a spinlock and a
reference count.  The special-sauce of this primitive is that the
conceptual sequence "lock; inc_ref; unlock;" can often be performed
with a single atomic memory operation.

Holding a reference on a dentry ensures that the dentry won't suddenly
be freed and used for something else, so the values in various fields
will behave as expected.  It also protects the `->d_inode` reference
to the inode to some extent.

The association between a dentry and its inode is fairly permanent.
For example, when a file is renamed, the dentry and inode move
together to the new location.  When a file is created the dentry will
initially be negative (i.e. `d_inode` is `NULL`), and will be assigned
to the new inode as part of the act of creation.

When a file is deleted, this can be reflected in the cache either by
setting `d_inode` to `NULL`, or by removing it from the hash table
(described shortly) used to look up the name in the parent directory.
If the dentry is still in use the second option is used as it is
perfectly legal to keep using an open file after it has been deleted
and having the dentry around helps.  If the dentry is not otherwise in
use (i.e. if the refcount in `d_lockref` is one), only then will
`d_inode` be set to `NULL`.  Doing it this way is more efficient for a
very common case.

So as long as a counted reference is held to a dentry, a non-`NULL` `->d_inode`
value will never be changed.

### dentry->d_lock ###

`d_lock` is a synonym for the spinlock that is part of `d_lockref` above.
For our purposes, holding this lock protects against the dentry being
renamed or unlinked.  In particular, its parent (`d_parent`), and its
name (`d_name`) cannot be changed, and it cannot be removed from the
dentry hash table.

When looking for a name in a directory, REF-walk takes `d_lock` on
each candidate dentry that it finds in the hash table and then checks
that the parent and name are correct.  So it doesn't lock the parent
while searching in the cache; it only locks children.

When looking for the parent for a given name (to handle "`..`"),
REF-walk can take `d_lock` to get a stable reference to `d_parent`,
but it first tries a more lightweight approach.  As seen in
`dget_parent()`, if a reference can be claimed on the parent, and if
subsequently `d_parent` can be seen to have not changed, then there is
no need to actually take the lock on the child.

### rename_lock ###

Looking up a given name in a given directory involves computing a hash
from the two values (the name and the dentry of the directory),
accessing that slot in a hash table, and searching the linked list
that is found there.

When a dentry is renamed, the name and the parent dentry can both
change so the hash will almost certainly change too.  This would move the
dentry to a different chain in the hash table.  If a filename search
happened to be looking at a dentry that was moved in this way,
it might end up continuing the search down the wrong chain,
and so miss out on part of the correct chain.

The name-lookup process (`d_lookup()`) does _not_ try to prevent this
from happening, but only to detect when it happens.
`rename_lock` is a seqlock that is updated whenever any dentry is
renamed.  If `d_lookup` finds that a rename happened while it
unsuccessfully scanned a chain in the hash table, it simply tries
again.

### inode->i_mutex ###

`i_mutex` is a mutex that serializes all changes to a particular
directory.  This ensures that, for example, an `unlink()` and a `rename()`
cannot both happen at the same time.  It also keeps the directory
stable while the filesystem is asked to look up a name that is not
currently in the dcache.

This has a complementary role to that of `d_lock`: `i_mutex` on a
directory protects all of the names in that directory, while `d_lock`
on a name protects just one name in a directory.  Most changes to the
dcache hold `i_mutex` on the relevant directory inode and briefly take
`d_lock` on one or more the dentries while the change happens.  One
exception is when idle dentries are removed from the dcache due to
memory pressure.  This uses `d_lock`, but `i_mutex` plays no role.

The mutex affects pathname lookup in two distinct ways.  Firstly it
serializes lookup of a name in a directory.  `walk_component()` uses
`lookup_fast()` first which, in turn, checks to see if the name is in the cache,
using only `d_lock` locking.  If the name isn't found, then `walk_component()`
falls back to `lookup_slow()` which takes `i_mutex`, checks again that
the name isn't in the cache, and then calls in to the filesystem to get a
definitive answer.  A new dentry will be added to the cache regardless of
the result.

Secondly, when pathname lookup reaches the final component, it will
sometimes need to take `i_mutex` before performing the last lookup so
that the required exclusion can be achieved.  How path lookup chooses
to take, or not take, `i_mutex` is one of the
issues addressed in a subsequent section.

### mnt->mnt_count ###

`mnt_count` is a per-CPU reference counter on "`mount`" structures.
Per-CPU here means that incrementing the count is cheap as it only
uses CPU-local memory, but checking if the count is zero is expensive as
it needs to check with every CPU.  Taking a `mnt_count` reference
prevents the mount structure from disappearing as the result of regular
unmount operations, but does not prevent a "lazy" unmount.  So holding
`mnt_count` doesn't ensure that the mount remains in the namespace and,
in particular, doesn't stabilize the link to the mounted-on dentry.  It
does, however, ensure that the `mount` data structure remains coherent,
and it provides a reference to the root dentry of the mounted
filesystem.  So a reference through `->mnt_count` provides a stable
reference to the mounted dentry, but not the mounted-on dentry.

### mount_lock ###

`mount_lock` is a global seqlock, a bit like `rename_lock`.  It can be used to
check if any change has been made to any mount points.

While walking down the tree (away from the root) this lock is used when
crossing a mount point to check that the crossing was safe.  That is,
the value in the seqlock is read, then the code finds the mount that
is mounted on the current directory, if there is one, and increments
the `mnt_count`.  Finally the value in `mount_lock` is checked against
the old value.  If there is no change, then the crossing was safe.  If there
was a change, the `mnt_count` is decremented and the whole process is
retried.

When walking up the tree (towards the root) by following a ".." link,
a little more care is needed.  In this case the seqlock (which
contains both a counter and a spinlock) is fully locked to prevent
any changes to any mount points while stepping up.  This locking is
needed to stabilize the link to the mounted-on dentry, which the
refcount on the mount itself doesn't ensure.

### RCU ###

Finally the global (but extremely lightweight) RCU read lock is held
from time to time to ensure certain data structures don't get freed
unexpectedly.

In particular it is held while scanning chains in the dcache hash
table, and the mount point hash table.

Bringing it together with `struct nameidata`
--------------------------------------------

[First edition Unix]: http://minnie.tuhs.org/cgi-bin/utree.pl?file=V1/u2.s

Throughout the process of walking a path, the current status is stored
in a `struct nameidata`, "namei" being the traditional name - dating
all the way back to [First Edition Unix] - of the function that
converts a "name" to an "inode".  `struct nameidata` contains (among
other fields):

### `struct path path` ###

A `path` contains a `struct vfsmount` (which is
embedded in a `struct mount`) and a `struct dentry`.  Together these
record the current status of the walk.  They start out referring to the
starting point (the current working directory, the root directory, or some other
directory identified by a file descriptor), and are updated on each
step.  A reference through `d_lockref` and `mnt_count` is always
held.

### `struct qstr last` ###

This is a string together with a length (i.e. _not_ `nul` terminated)
that is the "next" component in the pathname.

### `int last_type` ###

This is one of `LAST_NORM`, `LAST_ROOT`, `LAST_DOT`, `LAST_DOTDOT`, or
`LAST_BIND`.  The `last` field is only valid if the type is
`LAST_NORM`.  `LAST_BIND` is used when following a symlink and no
components of the symlink have been processed yet.  Others should be
fairly self-explanatory.

### `struct path root` ###

This is used to hold a reference to the effective root of the
filesystem.  Often that reference won't be needed, so this field is
only assigned the first time it is used, or when a non-standard root
is requested.  Keeping a reference in the `nameidata` ensures that
only one root is in effect for the entire path walk, even if it races
with a `chroot()` system call.

The root is needed when either of two conditions holds: (1) either the
pathname or a symbolic link starts with a "'/'", or (2) a "`..`"
component is being handled, since "`..`" from the root must always stay
at the root.  The value used is usually the current root directory of
the calling process.  An alternate root can be provided as when
`sysctl()` calls `file_open_root()`, and when NFSv4 or Btrfs call
`mount_subtree()`.  In each case a pathname is being looked up in a very
specific part of the filesystem, and the lookup must not be allowed to
escape that subtree.  It works a bit like a local `chroot()`.

Ignoring the handling of symbolic links, we can now describe the
"`link_path_walk()`" function, which handles the lookup of everything
except the final component as:

>  Given a path (`name`) and a nameidata structure (`nd`), check that the
>  current directory has execute permission and then advance `name`
>  over one component while updating `last_type` and `last`.  If that
>  was the final component, then return, otherwise call
>  `walk_component()` and repeat from the top.

`walk_component()` is even easier.  If the component is `LAST_DOTS`,
it calls `handle_dots()` which does the necessary locking as already
described.  If it finds a `LAST_NORM` component it first calls
"`lookup_fast()`" which only looks in the dcache, but will ask the
filesystem to revalidate the result if it is that sort of filesystem.
If that doesn't get a good result, it calls "`lookup_slow()`" which
takes the `i_mutex`, rechecks the cache, and then asks the filesystem
to find a definitive answer.  Each of these will call
`follow_managed()` (as described below) to handle any mount points.

In the absence of symbolic links, `walk_component()` creates a new
`struct path` containing a counted reference to the new dentry and a
reference to the new `vfsmount` which is only counted if it is
different from the previous `vfsmount`.  It then calls
`path_to_nameidata()` to install the new `struct path` in the
`struct nameidata` and drop the unneeded references.

This "hand-over-hand" sequencing of getting a reference to the new
dentry before dropping the reference to the previous dentry may
seem obvious, but is worth pointing out so that we will recognize its
analogue in the "RCU-walk" version.

Handling the final component.
-----------------------------

`link_path_walk()` only walks as far as setting `nd->last` and
`nd->last_type` to refer to the final component of the path.  It does
not call `walk_component()` that last time.  Handling that final
component remains for the caller to sort out. Those callers are
`path_lookupat()`, `path_parentat()`, `path_mountpoint()` and
`path_openat()` each of which handles the differing requirements of
different system calls.

`path_parentat()` is clearly the simplest - it just wraps a little bit
of housekeeping around `link_path_walk()` and returns the parent
directory and final component to the caller.  The caller will be either
aiming to create a name (via `filename_create()`) or remove or rename
a name (in which case `user_path_parent()` is used).  They will use
`i_mutex` to exclude other changes while they validate and then
perform their operation.

`path_lookupat()` is nearly as simple - it is used when an existing
object is wanted such as by `stat()` or `chmod()`.  It essentially just
calls `walk_component()` on the final component through a call to
`lookup_last()`.  `path_lookupat()` returns just the final dentry.

`path_mountpoint()` handles the special case of unmounting which must
not try to revalidate the mounted filesystem.  It effectively
contains, through a call to `mountpoint_last()`, an alternate
implementation of `lookup_slow()` which skips that step.  This is
important when unmounting a filesystem that is inaccessible, such as
one provided by a dead NFS server.

Finally `path_openat()` is used for the `open()` system call; it
contains, in support functions starting with "`do_last()`", all the
complexity needed to handle the different subtleties of O_CREAT (with
or without O_EXCL), final "`/`" characters, and trailing symbolic
links.  We will revisit this in the final part of this series, which
focuses on those symbolic links.  "`do_last()`" will sometimes, but
not always, take `i_mutex`, depending on what it finds.

Each of these, or the functions which call them, need to be alert to
the possibility that the final component is not `LAST_NORM`.  If the
goal of the lookup is to create something, then any value for
`last_type` other than `LAST_NORM` will result in an error.  For
example if `path_parentat()` reports `LAST_DOTDOT`, then the caller
won't try to create that name.  They also check for trailing slashes
by testing `last.name[last.len]`.  If there is any character beyond
the final component, it must be a trailing slash.

Revalidation and automounts
---------------------------

Apart from symbolic links, there are only two parts of the "REF-walk"
process not yet covered.  One is the handling of stale cache entries
and the other is automounts.

On filesystems that require it, the lookup routines will call the
`->d_revalidate()` dentry method to ensure that the cached information
is current.  This will often confirm validity or update a few details
from a server.  In some cases it may find that there has been change
further up the path and that something that was thought to be valid
previously isn't really.  When this happens the lookup of the whole
path is aborted and retried with the "`LOOKUP_REVAL`" flag set.  This
forces revalidation to be more thorough.  We will see more details of
this retry process in the next article.

Automount points are locations in the filesystem where an attempt to
lookup a name can trigger changes to how that lookup should be
handled, in particular by mounting a filesystem there.  These are
covered in greater detail in autofs4.txt in the Linux documentation
tree, but a few notes specifically related to path lookup are in order
here.

The Linux VFS has a concept of "managed" dentries which is reflected
in function names such as "`follow_managed()`".  There are three
potentially interesting things about these dentries corresponding
to three different flags that might be set in `dentry->d_flags`:

### `DCACHE_MANAGE_TRANSIT` ###

If this flag has been set, then the filesystem has requested that the
`d_manage()` dentry operation be called before handling any possible
mount point.  This can perform two particular services:

It can block to avoid races.  If an automount point is being
unmounted, the `d_manage()` function will usually wait for that
process to complete before letting the new lookup proceed and possibly
trigger a new automount.

It can selectively allow only some processes to transit through a
mount point.  When a server process is managing automounts, it may