Commit 30c17ebf authored by Miklos Szeredi's avatar Miklos Szeredi

ovl: simplify empty checking

The empty checking logic is duplicated in ovl_check_empty_and_clear() and
ovl_remove_and_whiteout(), except the condition for clearing whiteouts is
different:

ovl_check_empty_and_clear() checked for being upper

ovl_remove_and_whiteout() checked for merge OR lower

Move the intersection of those checks (upper AND merge) into
ovl_check_empty_and_clear() and simplify ovl_remove_and_whiteout().
Signed-off-by: default avatarMiklos Szeredi <mszeredi@redhat.com>
parent 29c42e80
...@@ -307,23 +307,29 @@ static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry) ...@@ -307,23 +307,29 @@ static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry)
{ {
int err; int err;
struct dentry *ret = NULL; struct dentry *ret = NULL;
enum ovl_path_type type = ovl_path_type(dentry);
LIST_HEAD(list); LIST_HEAD(list);
err = ovl_check_empty_dir(dentry, &list); err = ovl_check_empty_dir(dentry, &list);
if (err) if (err) {
ret = ERR_PTR(err); ret = ERR_PTR(err);
else { goto out_free;
}
/* /*
* When removing an empty opaque directory, then it makes no sense to
* replace it with an exact replica of itself.
*
* If no upperdentry then skip clearing whiteouts. * If no upperdentry then skip clearing whiteouts.
* *
* Can race with copy-up, since we don't hold the upperdir * Can race with copy-up, since we don't hold the upperdir mutex.
* mutex. Doesn't matter, since copy-up can't create a * Doesn't matter, since copy-up can't create a non-empty directory
* non-empty directory from an empty one. * from an empty one.
*/ */
if (ovl_dentry_upper(dentry)) if (OVL_TYPE_UPPER(type) && OVL_TYPE_MERGE(type))
ret = ovl_clear_empty(dentry, &list); ret = ovl_clear_empty(dentry, &list);
}
out_free:
ovl_cache_free(&list); ovl_cache_free(&list);
return ret; return ret;
...@@ -551,24 +557,10 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir) ...@@ -551,24 +557,10 @@ static int ovl_remove_and_whiteout(struct dentry *dentry, bool is_dir)
return -EROFS; return -EROFS;
if (is_dir) { if (is_dir) {
if (OVL_TYPE_MERGE_OR_LOWER(ovl_path_type(dentry))) {
opaquedir = ovl_check_empty_and_clear(dentry); opaquedir = ovl_check_empty_and_clear(dentry);
err = PTR_ERR(opaquedir); err = PTR_ERR(opaquedir);
if (IS_ERR(opaquedir)) if (IS_ERR(opaquedir))
goto out; goto out;
} else {
LIST_HEAD(list);
/*
* When removing an empty opaque directory, then it
* makes no sense to replace it with an exact replica of
* itself. But emptiness still needs to be checked.
*/
err = ovl_check_empty_dir(dentry, &list);
ovl_cache_free(&list);
if (err)
goto out;
}
} }
err = ovl_lock_rename_workdir(workdir, upperdir); err = ovl_lock_rename_workdir(workdir, upperdir);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment