提交 95e598e7 编写于 作者: Z zhangyi (F) 提交者: Miklos Szeredi

ovl: simplify ovl_check_empty_and_clear()

Filter out non-whiteout non-upper entries from list of merge dir entries
while checking if merge dir is empty in ovl_check_empty_dir().
The remaining work for ovl_clear_empty() is to clear all entries on the
list.

[amir: split patch from rmdir bug fix]
Signed-off-by: Nzhangyi (F) <yi.zhang@huawei.com>
Signed-off-by: NAmir Goldstein <amir73il@gmail.com>
Signed-off-by: NMiklos Szeredi <mszeredi@redhat.com>
上级 b79e05aa
...@@ -300,7 +300,6 @@ static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry) ...@@ -300,7 +300,6 @@ 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);
...@@ -313,13 +312,13 @@ static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry) ...@@ -313,13 +312,13 @@ static struct dentry *ovl_check_empty_and_clear(struct dentry *dentry)
* When removing an empty opaque directory, then it makes no sense to * When removing an empty opaque directory, then it makes no sense to
* replace it with an exact replica of itself. * replace it with an exact replica of itself.
* *
* If no upperdentry then skip clearing whiteouts. * If upperdentry has whiteouts, clear them.
* *
* Can race with copy-up, since we don't hold the upperdir mutex. * Can race with copy-up, since we don't hold the upperdir mutex.
* Doesn't matter, since copy-up can't create a non-empty directory * Doesn't matter, since copy-up can't create a non-empty directory
* from an empty one. * from an empty one.
*/ */
if (OVL_TYPE_UPPER(type) && OVL_TYPE_MERGE(type)) if (!list_empty(&list))
ret = ovl_clear_empty(dentry, &list); ret = ovl_clear_empty(dentry, &list);
out_free: out_free:
......
...@@ -26,6 +26,7 @@ struct ovl_cache_entry { ...@@ -26,6 +26,7 @@ struct ovl_cache_entry {
struct list_head l_node; struct list_head l_node;
struct rb_node node; struct rb_node node;
struct ovl_cache_entry *next_maybe_whiteout; struct ovl_cache_entry *next_maybe_whiteout;
bool is_upper;
bool is_whiteout; bool is_whiteout;
char name[]; char name[];
}; };
...@@ -158,6 +159,7 @@ static struct ovl_cache_entry *ovl_cache_entry_new(struct ovl_readdir_data *rdd, ...@@ -158,6 +159,7 @@ static struct ovl_cache_entry *ovl_cache_entry_new(struct ovl_readdir_data *rdd,
/* Defer setting d_ino for upper entry to ovl_iterate() */ /* Defer setting d_ino for upper entry to ovl_iterate() */
if (ovl_calc_d_ino(rdd, p)) if (ovl_calc_d_ino(rdd, p))
p->ino = 0; p->ino = 0;
p->is_upper = rdd->is_upper;
p->is_whiteout = false; p->is_whiteout = false;
if (d_type == DT_CHR) { if (d_type == DT_CHR) {
...@@ -851,7 +853,7 @@ const struct file_operations ovl_dir_operations = { ...@@ -851,7 +853,7 @@ const struct file_operations ovl_dir_operations = {
int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list) int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
{ {
int err; int err;
struct ovl_cache_entry *p; struct ovl_cache_entry *p, *n;
struct rb_root root = RB_ROOT; struct rb_root root = RB_ROOT;
err = ovl_dir_read_merged(dentry, list, &root); err = ovl_dir_read_merged(dentry, list, &root);
...@@ -860,18 +862,29 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list) ...@@ -860,18 +862,29 @@ int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
err = 0; err = 0;
list_for_each_entry(p, list, l_node) { list_for_each_entry_safe(p, n, list, l_node) {
if (p->is_whiteout) /*
* Select whiteouts in upperdir, they should
* be cleared when deleting this directory.
*/
if (p->is_whiteout) {
if (p->is_upper)
continue; continue;
goto del_entry;
}
if (p->name[0] == '.') { if (p->name[0] == '.') {
if (p->len == 1) if (p->len == 1)
continue; goto del_entry;
if (p->len == 2 && p->name[1] == '.') if (p->len == 2 && p->name[1] == '.')
continue; goto del_entry;
} }
err = -ENOTEMPTY; err = -ENOTEMPTY;
break; break;
del_entry:
list_del(&p->l_node);
kfree(p);
} }
return err; return err;
...@@ -885,7 +898,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list) ...@@ -885,7 +898,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list)
list_for_each_entry(p, list, l_node) { list_for_each_entry(p, list, l_node) {
struct dentry *dentry; struct dentry *dentry;
if (!p->is_whiteout) if (WARN_ON(!p->is_whiteout || !p->is_upper))
continue; continue;
dentry = lookup_one_len(p->name, upper, p->len); dentry = lookup_one_len(p->name, upper, p->len);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册