Skip to content

Commit 62c832e

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: simplify i_ino initialization
Move i_ino initialization to ovl_inode_init() to avoid the dance of setting i_ino in ovl_fill_inode() sometimes on the first call and sometimes on the seconds call. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 2effc5c commit 62c832e

File tree

4 files changed

+39
-31
lines changed

4 files changed

+39
-31
lines changed

fs/overlayfs/inode.c

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,7 @@ static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode)
561561
#endif
562562
}
563563

564-
static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev,
565-
unsigned long ino, int fsid)
564+
static void ovl_map_ino(struct inode *inode, unsigned long ino, int fsid)
566565
{
567566
int xinobits = ovl_xino_bits(inode->i_sb);
568567

@@ -572,10 +571,6 @@ static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev,
572571
* so inode number exposed via /proc/locks and a like will be
573572
* consistent with d_ino and st_ino values. An i_ino value inconsistent
574573
* with d_ino also causes nfsd readdirplus to fail.
575-
*
576-
* When called from ovl_create_object() => ovl_new_inode(), with
577-
* ino = 0, i_ino will be updated to consistent value later on in
578-
* ovl_get_inode() => ovl_fill_inode().
579574
*/
580575
if (ovl_same_dev(inode->i_sb)) {
581576
inode->i_ino = ino;
@@ -584,6 +579,28 @@ static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev,
584579
} else {
585580
inode->i_ino = get_next_ino();
586581
}
582+
}
583+
584+
void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
585+
unsigned long ino, int fsid)
586+
{
587+
struct inode *realinode;
588+
589+
if (oip->upperdentry)
590+
OVL_I(inode)->__upperdentry = oip->upperdentry;
591+
if (oip->lowerpath && oip->lowerpath->dentry)
592+
OVL_I(inode)->lower = igrab(d_inode(oip->lowerpath->dentry));
593+
if (oip->lowerdata)
594+
OVL_I(inode)->lowerdata = igrab(d_inode(oip->lowerdata));
595+
596+
realinode = ovl_inode_real(inode);
597+
ovl_copyattr(realinode, inode);
598+
ovl_copyflags(realinode, inode);
599+
ovl_map_ino(inode, ino, fsid);
600+
}
601+
602+
static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev)
603+
{
587604
inode->i_mode = mode;
588605
inode->i_flags |= S_NOCMTIME;
589606
#ifdef CONFIG_FS_POSIX_ACL
@@ -721,7 +738,7 @@ struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev)
721738

722739
inode = new_inode(sb);
723740
if (inode)
724-
ovl_fill_inode(inode, mode, rdev, 0, 0);
741+
ovl_fill_inode(inode, mode, rdev);
725742

726743
return inode;
727744
}
@@ -946,8 +963,8 @@ struct inode *ovl_get_inode(struct super_block *sb,
946963
ino = realinode->i_ino;
947964
fsid = lowerpath->layer->fsid;
948965
}
949-
ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev, ino, fsid);
950-
ovl_inode_init(inode, upperdentry, lowerdentry, oip->lowerdata);
966+
ovl_fill_inode(inode, realinode->i_mode, realinode->i_rdev);
967+
ovl_inode_init(inode, oip, ino, fsid);
951968

952969
if (upperdentry && ovl_is_impuredir(upperdentry))
953970
ovl_set_flag(OVL_IMPURE, inode);

fs/overlayfs/overlayfs.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,8 +264,6 @@ void ovl_set_upperdata(struct inode *inode);
264264
bool ovl_redirect_dir(struct super_block *sb);
265265
const char *ovl_dentry_get_redirect(struct dentry *dentry);
266266
void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect);
267-
void ovl_inode_init(struct inode *inode, struct dentry *upperdentry,
268-
struct dentry *lowerdentry, struct dentry *lowerdata);
269267
void ovl_inode_update(struct inode *inode, struct dentry *upperdentry);
270268
void ovl_dir_modified(struct dentry *dentry, bool impurity);
271269
u64 ovl_dentry_version_get(struct dentry *dentry);
@@ -410,6 +408,8 @@ struct ovl_inode_params {
410408
char *redirect;
411409
struct dentry *lowerdata;
412410
};
411+
void ovl_inode_init(struct inode *inode, struct ovl_inode_params *oip,
412+
unsigned long ino, int fsid);
413413
struct inode *ovl_new_inode(struct super_block *sb, umode_t mode, dev_t rdev);
414414
struct inode *ovl_lookup_inode(struct super_block *sb, struct dentry *real,
415415
bool is_upper);

fs/overlayfs/super.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,13 @@ static struct dentry *ovl_get_root(struct super_block *sb,
15941594
struct ovl_entry *oe)
15951595
{
15961596
struct dentry *root;
1597+
struct ovl_path *lowerpath = &oe->lowerstack[0];
1598+
unsigned long ino = d_inode(lowerpath->dentry)->i_ino;
1599+
int fsid = lowerpath->layer->fsid;
1600+
struct ovl_inode_params oip = {
1601+
.upperdentry = upperdentry,
1602+
.lowerpath = lowerpath,
1603+
};
15971604

15981605
root = d_make_root(ovl_new_inode(sb, S_IFDIR, 0));
15991606
if (!root)
@@ -1602,6 +1609,9 @@ static struct dentry *ovl_get_root(struct super_block *sb,
16021609
root->d_fsdata = oe;
16031610

16041611
if (upperdentry) {
1612+
/* Root inode uses upper st_ino/i_ino */
1613+
ino = d_inode(upperdentry)->i_ino;
1614+
fsid = 0;
16051615
ovl_dentry_set_upper_alias(root);
16061616
if (ovl_is_impuredir(upperdentry))
16071617
ovl_set_flag(OVL_IMPURE, d_inode(root));
@@ -1611,8 +1621,7 @@ static struct dentry *ovl_get_root(struct super_block *sb,
16111621
ovl_set_flag(OVL_WHITEOUTS, d_inode(root));
16121622
ovl_dentry_set_flag(OVL_E_CONNECTED, root);
16131623
ovl_set_upperdata(d_inode(root));
1614-
ovl_inode_init(d_inode(root), upperdentry, ovl_dentry_lower(root),
1615-
NULL);
1624+
ovl_inode_init(d_inode(root), &oip, ino, fsid);
16161625

16171626
return root;
16181627
}

fs/overlayfs/util.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -386,24 +386,6 @@ void ovl_dentry_set_redirect(struct dentry *dentry, const char *redirect)
386386
oi->redirect = redirect;
387387
}
388388

389-
void ovl_inode_init(struct inode *inode, struct dentry *upperdentry,
390-
struct dentry *lowerdentry, struct dentry *lowerdata)
391-
{
392-
struct inode *realinode = d_inode(upperdentry ?: lowerdentry);
393-
394-
if (upperdentry)
395-
OVL_I(inode)->__upperdentry = upperdentry;
396-
if (lowerdentry)
397-
OVL_I(inode)->lower = igrab(d_inode(lowerdentry));
398-
if (lowerdata)
399-
OVL_I(inode)->lowerdata = igrab(d_inode(lowerdata));
400-
401-
ovl_copyattr(realinode, inode);
402-
ovl_copyflags(realinode, inode);
403-
if (!inode->i_ino)
404-
inode->i_ino = realinode->i_ino;
405-
}
406-
407389
void ovl_inode_update(struct inode *inode, struct dentry *upperdentry)
408390
{
409391
struct inode *upperinode = d_inode(upperdentry);

0 commit comments

Comments
 (0)