linux/fs/overlayfs
Vivek Goyal 452061fd45 ovl: Set d->last properly during lookup
d->last signifies that this is the last layer we are looking into and there
is no more. And that means this allows for some optimzation opportunities
during lookup. For example, in ovl_lookup_single() we don't have to check
for opaque xattr of a directory is this is the last layer we are looking
into (d->last = true).

But knowing for sure whether we are looking into last layer can be very
tricky. If redirects are not enabled, then we can look at poe->numlower and
figure out if the lookup we are about to is last layer or not. But if
redircts are enabled then it is possible poe->numlower suggests that we are
looking in last layer, but there is an absolute redirect present in found
element and that redirects us to a layer in root and that means lookup will
continue in lower layers further.

For example, consider following.

/upperdir/pure (opaque=y)
/upperdir/pure/foo (opaque=y,redirect=/bar)
/lowerdir/bar

In this case pure is "pure upper". When we look for "foo", that time
poe->numlower=0. But that alone does not mean that we will not search for a
merge candidate in /lowerdir. Absolute redirect changes that.

IOW, d->last should not be set just based on poe->numlower if redirects are
enabled. That can lead to setting d->last while it should not have and that
means we will not check for opaque xattr while we should have.

So do this.

 - If redirects are not enabled, then continue to rely on poe->numlower
   information to determine if it is last layer or not.

 - If redirects are enabled, then set d->last = true only if this is the
   last layer in root ovl_entry (roe).

Suggested-by: Amir Goldstein <amir73il@gmail.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
Fixes: 02b69b284c ("ovl: lookup redirects")
Cc: <stable@vger.kernel.org> #v4.10
2018-04-12 12:04:48 +02:00
..
copy_up.c ovl: copy up of disconnected dentries 2018-01-24 11:25:58 +01:00
dir.c ovl: whiteout index when union nlink drops to zero 2018-01-24 11:25:56 +01:00
export.c ovl: fix ptr_ret.cocci warnings 2018-02-26 12:45:20 +01:00
inode.c ovl: set i_ino to the value of st_ino for NFS export 2018-04-12 12:04:48 +02:00
Kconfig ovl: update Kconfig texts 2018-03-07 11:47:15 +01:00
Makefile ovl: encode pure upper file handles 2018-01-24 11:25:59 +01:00
namei.c ovl: Set d->last properly during lookup 2018-04-12 12:04:48 +02:00
overlayfs.h ovl: check lower ancestry on encode of lower dir file handle 2018-02-16 15:53:20 +01:00
ovl_entry.h ovl: store 'has_upper' and 'opaque' as bit flags 2018-01-24 11:25:58 +01:00
readdir.c ovl: whiteout orphan index entries on mount 2018-01-24 11:25:56 +01:00
super.c ovl: check lower ancestry on encode of lower dir file handle 2018-02-16 15:53:20 +01:00
util.c ovl: set i_ino to the value of st_ino for NFS export 2018-04-12 12:04:48 +02:00