1 --- a/fs/overlayfs/overlayfs.c
2 +++ b/fs/overlayfs/overlayfs.c
3 @@ -253,8 +253,7 @@ static struct ovl_cache_entry *ovl_cache
6 static struct ovl_cache_entry *ovl_cache_entry_new(const char *name, int len,
7 - u64 ino, unsigned int d_type,
9 + u64 ino, unsigned int d_type)
11 struct ovl_cache_entry *p;
13 @@ -267,7 +266,7 @@ static struct ovl_cache_entry *ovl_cache
17 - p->is_whiteout = is_whiteout;
18 + p->is_whiteout = false;
22 @@ -275,7 +274,7 @@ static struct ovl_cache_entry *ovl_cache
24 static int ovl_cache_entry_add_rb(struct ovl_readdir_data *rdd,
25 const char *name, int len, u64 ino,
26 - unsigned int d_type, bool is_whiteout)
27 + unsigned int d_type)
29 struct rb_node **newp = &rdd->root->rb_node;
30 struct rb_node *parent = NULL;
31 @@ -296,11 +295,18 @@ static int ovl_cache_entry_add_rb(struct
35 - p = ovl_cache_entry_new(name, len, ino, d_type, is_whiteout);
36 + p = ovl_cache_entry_new(name, len, ino, d_type);
40 - list_add_tail(&p->l_node, rdd->list);
42 + * Add links before other types to be able to quicky mark
43 + * any whiteout entries
45 + if (d_type == DT_LNK)
46 + list_add(&p->l_node, rdd->list);
48 + list_add_tail(&p->l_node, rdd->list);
49 rb_link_node(&p->node, parent, newp);
50 rb_insert_color(&p->node, rdd->root);
52 @@ -318,7 +324,7 @@ static int ovl_fill_lower(void *buf, con
54 list_move_tail(&p->l_node, rdd->middle);
56 - p = ovl_cache_entry_new(name, namelen, ino, d_type, false);
57 + p = ovl_cache_entry_new(name, namelen, ino, d_type);
61 @@ -343,26 +349,9 @@ static int ovl_fill_upper(void *buf, con
62 loff_t offset, u64 ino, unsigned int d_type)
64 struct ovl_readdir_data *rdd = buf;
65 - bool is_whiteout = false;
68 - if (d_type == DT_LNK) {
69 - struct dentry *dentry;
71 - dentry = lookup_one_len(name, rdd->dir, namelen);
72 - if (IS_ERR(dentry)) {
73 - rdd->err = PTR_ERR(dentry);
76 - is_whiteout = ovl_is_whiteout(dentry);
80 - rdd->err = ovl_cache_entry_add_rb(rdd, name, namelen, ino, d_type,
85 + return ovl_cache_entry_add_rb(rdd, name, namelen, ino, d_type);
88 static int ovl_dir_read(struct path *realpath, struct ovl_readdir_data *rdd,
89 @@ -428,6 +417,26 @@ static void ovl_dir_reset(struct file *f
93 +static void ovl_dir_mark_whiteouts(struct ovl_readdir_data *rdd)
95 + struct ovl_cache_entry *p;
96 + struct dentry *dentry;
98 + mutex_lock(&rdd->dir->d_inode->i_mutex);
99 + list_for_each_entry(p, rdd->list, l_node) {
100 + if (p->type != DT_LNK)
103 + dentry = lookup_one_len(p->name, rdd->dir, p->len);
104 + if (IS_ERR(dentry))
107 + p->is_whiteout = ovl_is_whiteout(dentry);
110 + mutex_unlock(&rdd->dir->d_inode->i_mutex);
113 static int ovl_dir_read_merged(struct path *upperpath, struct path *lowerpath,
114 struct ovl_readdir_data *rdd)
116 @@ -441,6 +450,8 @@ static int ovl_dir_read_merged(struct pa
117 err = ovl_dir_read(upperpath, rdd, ovl_fill_upper);
121 + ovl_dir_mark_whiteouts(rdd);
124 * Insert lowerpath entries before upperpath ones, this allows