Skip to content

Commit 2effc5c

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: factor out helper ovl_get_root()
Allocates and initializes the root dentry and inode. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 735c907 commit 2effc5c

File tree

1 file changed

+29
-15
lines changed

1 file changed

+29
-15
lines changed

fs/overlayfs/super.c

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,34 @@ static int ovl_check_overlapping_layers(struct super_block *sb,
15891589
return 0;
15901590
}
15911591

1592+
static struct dentry *ovl_get_root(struct super_block *sb,
1593+
struct dentry *upperdentry,
1594+
struct ovl_entry *oe)
1595+
{
1596+
struct dentry *root;
1597+
1598+
root = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
1599+
if (!root)
1600+
return NULL;
1601+
1602+
root->d_fsdata = oe;
1603+
1604+
if (upperdentry) {
1605+
ovl_dentry_set_upper_alias(root);
1606+
if (ovl_is_impuredir(upperdentry))
1607+
ovl_set_flag(OVL_IMPURE, d_inode(root));
1608+
}
1609+
1610+
/* Root is always merge -> can have whiteouts */
1611+
ovl_set_flag(OVL_WHITEOUTS, d_inode(root));
1612+
ovl_dentry_set_flag(OVL_E_CONNECTED, root);
1613+
ovl_set_upperdata(d_inode(root));
1614+
ovl_inode_init(d_inode(root), upperdentry, ovl_dentry_lower(root),
1615+
NULL);
1616+
1617+
return root;
1618+
}
1619+
15921620
static int ovl_fill_super(struct super_block *sb, void *data, int silent)
15931621
{
15941622
struct path upperpath = { };
@@ -1710,25 +1738,11 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
17101738
sb->s_flags |= SB_POSIXACL;
17111739

17121740
err = -ENOMEM;
1713-
root_dentry = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
1741+
root_dentry = ovl_get_root(sb, upperpath.dentry, oe);
17141742
if (!root_dentry)
17151743
goto out_free_oe;
17161744

1717-
root_dentry->d_fsdata = oe;
1718-
17191745
mntput(upperpath.mnt);
1720-
if (upperpath.dentry) {
1721-
ovl_dentry_set_upper_alias(root_dentry);
1722-
if (ovl_is_impuredir(upperpath.dentry))
1723-
ovl_set_flag(OVL_IMPURE, d_inode(root_dentry));
1724-
}
1725-
1726-
/* Root is always merge -> can have whiteouts */
1727-
ovl_set_flag(OVL_WHITEOUTS, d_inode(root_dentry));
1728-
ovl_dentry_set_flag(OVL_E_CONNECTED, root_dentry);
1729-
ovl_set_upperdata(d_inode(root_dentry));
1730-
ovl_inode_init(d_inode(root_dentry), upperpath.dentry,
1731-
ovl_dentry_lower(root_dentry), NULL);
17321746

17331747
sb->s_root = root_dentry;
17341748

0 commit comments

Comments
 (0)