Skip to content

Commit 6815f47

Browse files
rhvgoyalMiklos Szeredi
authored andcommitted
ovl: use only uppermetacopy state in ovl_lookup()
Currently we use a variable "metacopy" which signifies that dentry could be either uppermetacopy or lowermetacopy. Amir suggested that we can move code around and use d.metacopy in such a way that we don't need lowermetacopy and just can do away with uppermetacopy. So this patch replaces "metacopy" with "uppermetacopy". It also moves some code little higher to keep reading little simpler. 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 59fb201 commit 6815f47

File tree

1 file changed

+28
-29
lines changed

1 file changed

+28
-29
lines changed

fs/overlayfs/namei.c

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
812812
struct dentry *this;
813813
unsigned int i;
814814
int err;
815-
bool metacopy = false;
815+
bool uppermetacopy = false;
816816
struct ovl_lookup_data d = {
817817
.sb = dentry->d_sb,
818818
.name = dentry->d_name,
@@ -858,7 +858,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
858858
goto out_put_upper;
859859

860860
if (d.metacopy)
861-
metacopy = true;
861+
uppermetacopy = true;
862862
}
863863

864864
if (d.redirect) {
@@ -895,6 +895,21 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
895895
if (!this)
896896
continue;
897897

898+
if ((uppermetacopy || d.metacopy) && !ofs->config.metacopy) {
899+
err = -EPERM;
900+
pr_warn_ratelimited("refusing to follow metacopy origin for (%pd2)\n", dentry);
901+
goto out_put;
902+
}
903+
904+
/*
905+
* Do not store intermediate metacopy dentries in chain,
906+
* except top most lower metacopy dentry
907+
*/
908+
if (d.metacopy && ctr) {
909+
dput(this);
910+
continue;
911+
}
912+
898913
/*
899914
* If no origin fh is stored in upper of a merge dir, store fh
900915
* of lower dir and set upper parent "impure".
@@ -929,17 +944,6 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
929944
origin = this;
930945
}
931946

932-
if (d.metacopy)
933-
metacopy = true;
934-
/*
935-
* Do not store intermediate metacopy dentries in chain,
936-
* except top most lower metacopy dentry
937-
*/
938-
if (d.metacopy && ctr) {
939-
dput(this);
940-
continue;
941-
}
942-
943947
stack[ctr].dentry = this;
944948
stack[ctr].layer = lower.layer;
945949
ctr++;
@@ -971,22 +975,17 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
971975
}
972976
}
973977

974-
if (metacopy) {
975-
/*
976-
* Found a metacopy dentry but did not find corresponding
977-
* data dentry
978-
*/
979-
if (d.metacopy) {
980-
err = -EIO;
981-
goto out_put;
982-
}
983-
984-
err = -EPERM;
985-
if (!ofs->config.metacopy) {
986-
pr_warn_ratelimited("refusing to follow metacopy origin for (%pd2)\n",
987-
dentry);
988-
goto out_put;
989-
}
978+
/*
979+
* For regular non-metacopy upper dentries, there is no lower
980+
* path based lookup, hence ctr will be zero. If a dentry is found
981+
* using ORIGIN xattr on upper, install it in stack.
982+
*
983+
* For metacopy dentry, path based lookup will find lower dentries.
984+
* Just make sure a corresponding data dentry has been found.
985+
*/
986+
if (d.metacopy || (uppermetacopy && !ctr)) {
987+
err = -EIO;
988+
goto out_put;
990989
} else if (!d.is_dir && upperdentry && !ctr && origin_path) {
991990
if (WARN_ON(stack != NULL)) {
992991
err = -EIO;

0 commit comments

Comments
 (0)