Skip to content

Commit 4d314f7

Browse files
amir73ilMiklos Szeredi
authored andcommitted
ovl: use a private non-persistent ino pool
There is no reason to deplete the system's global get_next_ino() pool for overlay non-persistent inode numbers and there is no reason at all to allocate non-persistent inode numbers for non-directories. For non-directories, it is much better to leave i_ino the same as real i_ino, to be consistent with st_ino/d_ino. Signed-off-by: Amir Goldstein <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 83552ea commit 4d314f7

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

fs/overlayfs/inode.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -561,6 +561,15 @@ static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode)
561561
#endif
562562
}
563563

564+
static void ovl_next_ino(struct inode *inode)
565+
{
566+
struct ovl_fs *ofs = inode->i_sb->s_fs_info;
567+
568+
inode->i_ino = atomic_long_inc_return(&ofs->last_ino);
569+
if (unlikely(!inode->i_ino))
570+
inode->i_ino = atomic_long_inc_return(&ofs->last_ino);
571+
}
572+
564573
static void ovl_map_ino(struct inode *inode, unsigned long ino, int fsid)
565574
{
566575
int xinobits = ovl_xino_bits(inode->i_sb);
@@ -572,12 +581,12 @@ static void ovl_map_ino(struct inode *inode, unsigned long ino, int fsid)
572581
* consistent with d_ino and st_ino values. An i_ino value inconsistent
573582
* with d_ino also causes nfsd readdirplus to fail.
574583
*/
584+
inode->i_ino = ino;
575585
if (ovl_same_dev(inode->i_sb)) {
576-
inode->i_ino = ino;
577586
if (xinobits && fsid && !(ino >> (64 - xinobits)))
578587
inode->i_ino |= (unsigned long)fsid << (64 - xinobits);
579-
} else {
580-
inode->i_ino = get_next_ino();
588+
} else if (S_ISDIR(inode->i_mode)) {
589+
ovl_next_ino(inode);
581590
}
582591
}
583592

fs/overlayfs/ovl_entry.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ struct ovl_fs {
7575
struct inode *indexdir_trap;
7676
/* -1: disabled, 0: same fs, 1..32: number of unused ino bits */
7777
int xino_mode;
78+
/* For allocation of non-persistent inode numbers */
79+
atomic_long_t last_ino;
7880
};
7981

8082
static inline struct ovl_fs *OVL_FS(struct super_block *sb)

fs/overlayfs/super.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,7 @@ static int ovl_fill_super(struct super_block *sb, void *data, int silent)
17361736

17371737
sb->s_stack_depth = 0;
17381738
sb->s_maxbytes = MAX_LFS_FILESIZE;
1739+
atomic_long_set(&ofs->last_ino, 1);
17391740
/* Assume underlaying fs uses 32bit inodes unless proven otherwise */
17401741
if (ofs->config.xino != OVL_XINO_OFF) {
17411742
ofs->xino_mode = BITS_PER_LONG - 32;

0 commit comments

Comments
 (0)