Skip to content

Commit 59fb201

Browse files
rhvgoyalMiklos Szeredi
authored andcommitted
ovl: simplify setting of origin for index lookup
overlayfs can keep index of copied up files and directories and it seems to serve two primary puroposes. For regular files, it avoids breaking lower hardlinks over copy up. For directories it seems to be used for various error checks. During ovl_lookup(), we lookup for index using lower dentry in many a cases. That lower dentry is called "origin" and following is a summary of current logic. If there is no upperdentry, always lookup for index using lower dentry. For regular files it helps avoiding breaking hard links over copyup and for directories it seems to be just error checks. If there is an upperdentry, then there are 3 possible cases. - For directories, lower dentry is found using two ways. One is regular path based lookup in lower layers and second is using ORIGIN xattr on upper dentry. First verify that path based lookup lower dentry matches the one pointed by upper ORIGIN xattr. If yes, use this verified origin for index lookup. - For regular files (non-metacopy), there is no path based lookup in lower layers as lookup stops once we find upper dentry. So there is no origin verification. If there is ORIGIN xattr present on upper, use that to lookup index otherwise don't. - For regular metacopy files, again lower dentry is found using path based lookup as well as ORIGIN xattr on upper. Path based lookup is continued in this case to find lower data dentry for metacopy upper. So like directories we only use verified origin. If ORIGIN xattr is not present (Either because lower did not support file handles or because this is hardlink copied up with index=off), then don't use path lookup based lower dentry as origin. This is same as regular non-metacopy file case. Suggested-by: Amir Goldstein <[email protected]> Signed-off-by: Vivek Goyal <[email protected]> Reviewed-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 522f6e6 commit 59fb201

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

fs/overlayfs/namei.c

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -994,25 +994,30 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
994994
}
995995
stack = origin_path;
996996
ctr = 1;
997+
origin = origin_path->dentry;
997998
origin_path = NULL;
998999
}
9991000

10001001
/*
1001-
* Lookup index by lower inode and verify it matches upper inode.
1002-
* We only trust dir index if we verified that lower dir matches
1003-
* origin, otherwise dir index entries may be inconsistent and we
1004-
* ignore them.
1002+
* Always lookup index if there is no-upperdentry.
10051003
*
1006-
* For non-dir upper metacopy dentry, we already set "origin" if we
1007-
* verified that lower matched upper origin. If upper origin was
1008-
* not present (because lower layer did not support fh encode/decode),
1009-
* or indexing is not enabled, do not set "origin" and skip looking up
1010-
* index. This case should be handled in same way as a non-dir upper
1011-
* without ORIGIN is handled.
1004+
* For the case of upperdentry, we have set origin by now if it
1005+
* needed to be set. There are basically three cases.
1006+
*
1007+
* For directories, lookup index by lower inode and verify it matches
1008+
* upper inode. We only trust dir index if we verified that lower dir
1009+
* matches origin, otherwise dir index entries may be inconsistent
1010+
* and we ignore them.
1011+
*
1012+
* For regular upper, we already set origin if upper had ORIGIN
1013+
* xattr. There is no verification though as there is no path
1014+
* based dentry lookup in lower in this case.
1015+
*
1016+
* For metacopy upper, we set a verified origin already if index
1017+
* is enabled and if upper had an ORIGIN xattr.
10121018
*
1013-
* Always lookup index of non-dir non-metacopy and non-upper.
10141019
*/
1015-
if (ctr && (!upperdentry || (!d.is_dir && !metacopy)))
1020+
if (!upperdentry && ctr)
10161021
origin = stack[0].dentry;
10171022

10181023
if (origin && ovl_indexdir(dentry->d_sb) &&

0 commit comments

Comments
 (0)