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 <amir73il@gmail.com>
Signed-off-by: Vivek Goyal <vgoyal@redhat.com>
Reviewed-by: Amir Goldstein <amir73il@gmail.com>
Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
This commit is contained in:
Vivek Goyal 2020-06-01 11:56:51 -04:00 committed by Miklos Szeredi
parent 59fb20138a
commit 6815f479ca
1 changed files with 28 additions and 29 deletions

View File

@ -812,7 +812,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
struct dentry *this; struct dentry *this;
unsigned int i; unsigned int i;
int err; int err;
bool metacopy = false; bool uppermetacopy = false;
struct ovl_lookup_data d = { struct ovl_lookup_data d = {
.sb = dentry->d_sb, .sb = dentry->d_sb,
.name = dentry->d_name, .name = dentry->d_name,
@ -858,7 +858,7 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
goto out_put_upper; goto out_put_upper;
if (d.metacopy) if (d.metacopy)
metacopy = true; uppermetacopy = true;
} }
if (d.redirect) { if (d.redirect) {
@ -895,6 +895,21 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
if (!this) if (!this)
continue; continue;
if ((uppermetacopy || d.metacopy) && !ofs->config.metacopy) {
err = -EPERM;
pr_warn_ratelimited("refusing to follow metacopy origin for (%pd2)\n", dentry);
goto out_put;
}
/*
* Do not store intermediate metacopy dentries in chain,
* except top most lower metacopy dentry
*/
if (d.metacopy && ctr) {
dput(this);
continue;
}
/* /*
* If no origin fh is stored in upper of a merge dir, store fh * If no origin fh is stored in upper of a merge dir, store fh
* of lower dir and set upper parent "impure". * of lower dir and set upper parent "impure".
@ -929,17 +944,6 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
origin = this; origin = this;
} }
if (d.metacopy)
metacopy = true;
/*
* Do not store intermediate metacopy dentries in chain,
* except top most lower metacopy dentry
*/
if (d.metacopy && ctr) {
dput(this);
continue;
}
stack[ctr].dentry = this; stack[ctr].dentry = this;
stack[ctr].layer = lower.layer; stack[ctr].layer = lower.layer;
ctr++; ctr++;
@ -971,22 +975,17 @@ struct dentry *ovl_lookup(struct inode *dir, struct dentry *dentry,
} }
} }
if (metacopy) { /*
/* * For regular non-metacopy upper dentries, there is no lower
* Found a metacopy dentry but did not find corresponding * path based lookup, hence ctr will be zero. If a dentry is found
* data dentry * using ORIGIN xattr on upper, install it in stack.
*/ *
if (d.metacopy) { * For metacopy dentry, path based lookup will find lower dentries.
err = -EIO; * Just make sure a corresponding data dentry has been found.
goto out_put; */
} if (d.metacopy || (uppermetacopy && !ctr)) {
err = -EIO;
err = -EPERM; goto out_put;
if (!ofs->config.metacopy) {
pr_warn_ratelimited("refusing to follow metacopy origin for (%pd2)\n",
dentry);
goto out_put;
}
} else if (!d.is_dir && upperdentry && !ctr && origin_path) { } else if (!d.is_dir && upperdentry && !ctr && origin_path) {
if (WARN_ON(stack != NULL)) { if (WARN_ON(stack != NULL)) {
err = -EIO; err = -EIO;