Skip to content

Commit 504f384

Browse files
Al ViroMiklos Szeredi
authored andcommitted
ovl: ovl_obtain_alias(): don't call d_instantiate_anon() for old
The situation is the same as for __d_obtain_alias() (which is what that thing is parallel to) - if we find a preexisting alias, we want to grab it, drop the inode and return the alias we'd found. The only thing d_instantiate_anon() does compared to that is spurious security_d_instiate() that has already been done to that dentry with exact same arguments. Signed-off-by: Al Viro <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent d80172c commit 504f384

File tree

1 file changed

+21
-17
lines changed

1 file changed

+21
-17
lines changed

fs/overlayfs/export.c

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -308,31 +308,35 @@ static struct dentry *ovl_obtain_alias(struct super_block *sb,
308308
ovl_set_flag(OVL_UPPERDATA, inode);
309309

310310
dentry = d_find_any_alias(inode);
311-
if (!dentry) {
312-
dentry = d_alloc_anon(inode->i_sb);
313-
if (!dentry)
314-
goto nomem;
315-
oe = ovl_alloc_entry(lower ? 1 : 0);
316-
if (!oe)
317-
goto nomem;
318-
319-
if (lower) {
320-
oe->lowerstack->dentry = dget(lower);
321-
oe->lowerstack->layer = lowerpath->layer;
322-
}
323-
dentry->d_fsdata = oe;
324-
if (upper_alias)
325-
ovl_dentry_set_upper_alias(dentry);
311+
if (dentry)
312+
goto out_iput;
313+
314+
dentry = d_alloc_anon(inode->i_sb);
315+
if (unlikely(!dentry))
316+
goto nomem;
317+
oe = ovl_alloc_entry(lower ? 1 : 0);
318+
if (!oe)
319+
goto nomem;
320+
321+
if (lower) {
322+
oe->lowerstack->dentry = dget(lower);
323+
oe->lowerstack->layer = lowerpath->layer;
326324
}
325+
dentry->d_fsdata = oe;
326+
if (upper_alias)
327+
ovl_dentry_set_upper_alias(dentry);
328+
327329
ovl_dentry_update_reval(dentry, upper,
328330
DCACHE_OP_REVALIDATE | DCACHE_OP_WEAK_REVALIDATE);
329331

330332
return d_instantiate_anon(dentry, inode);
331333

332334
nomem:
333-
iput(inode);
334335
dput(dentry);
335-
return ERR_PTR(-ENOMEM);
336+
dentry = ERR_PTR(-ENOMEM);
337+
out_iput:
338+
iput(inode);
339+
return dentry;
336340
}
337341

338342
/* Get the upper or lower dentry in stach whose on layer @idx */

0 commit comments

Comments
 (0)