1 --- a/fs/overlayfs/overlayfs.c
2 +++ b/fs/overlayfs/overlayfs.c
3 @@ -1700,37 +1700,56 @@ static int ovl_check_empty_dir(struct de
7 -static int ovl_unlink_whiteout(void *buf, const char *name, int namelen,
8 - loff_t offset, u64 ino, unsigned int d_type)
9 +static int ovl_fill_links(void *buf, const char *name, int namelen,
10 + loff_t offset, u64 ino, unsigned int d_type)
12 struct ovl_readdir_data *rdd = buf;
13 + struct ovl_cache_entry *p;
16 - /* check d_type to filter out "." and ".." */
17 - if (d_type == DT_LNK) {
18 - struct dentry *dentry;
19 + if (d_type != DT_LNK)
22 - dentry = lookup_one_len(name, rdd->dir, namelen);
23 - if (IS_ERR(dentry)) {
24 - rdd->err = PTR_ERR(dentry);
26 - rdd->err = vfs_unlink(rdd->dir->d_inode, dentry);
30 + p = ovl_cache_entry_new(name, namelen, ino, d_type);
35 + list_add(&p->l_node, rdd->list);
39 static int ovl_remove_whiteouts(struct dentry *dentry)
41 struct path upperpath;
42 - struct ovl_readdir_data rdd = { .list = NULL };
44 + struct ovl_readdir_data rdd = { .list = &list };
45 + struct ovl_cache_entry *p, *t;
48 ovl_path_upper(dentry, &upperpath);
49 rdd.dir = upperpath.dentry;
51 - return ovl_dir_read(&upperpath, &rdd, ovl_unlink_whiteout);
52 + ret = ovl_dir_read(&upperpath, &rdd, ovl_fill_links);
54 + mutex_lock(&rdd.dir->d_inode->i_mutex);
55 + list_for_each_entry_safe(p, t, &list, l_node) {
56 + struct dentry *dentry;
59 + dentry = lookup_one_len(p->name, rdd.dir, p->len);
60 + if (IS_ERR(dentry)) {
61 + ret = PTR_ERR(dentry);
63 + ret = vfs_unlink(rdd.dir->d_inode, dentry);
68 + list_del(&p->l_node);
71 + mutex_unlock(&rdd.dir->d_inode->i_mutex);
76 static int ovl_rmdir(struct inode *dir, struct dentry *dentry)