@@ -340,7 +340,6 @@ static inline void ovl_lockdep_annotate_inode_mutex_key(struct inode *inode)
static void ovl_fill_inode(struct inode *inode, umode_t mode, dev_t rdev)
{
- inode->i_ino = get_next_ino();
inode->i_mode = mode;
inode->i_flags |= S_NOCMTIME;
#ifdef CONFIG_FS_POSIX_ACL
@@ -393,6 +392,16 @@ static void ovl_set_inode_data(struct inode *inode, struct inode *realinode,
WRITE_ONCE(inode->i_private, ovl_inode_data(realinode, is_upper));
}
+static void ovl_inode_init_ino(struct inode *inode, struct inode *realinode)
+{
+ if (ovl_same_sb(inode->i_sb)) {
+ inode->i_ino = realinode->i_ino;
+ inode->i_generation = realinode->i_generation;
+ } else {
+ inode->i_ino = get_next_ino();
+ }
+}
+
static void ovl_insert_inode_hash(struct inode *inode, struct inode *realinode)
{
WARN_ON(!inode_unhashed(inode));
@@ -401,6 +410,7 @@ static void ovl_insert_inode_hash(struct inode *inode, struct inode *realinode)
void ovl_inode_init(struct inode *inode, struct inode *realinode, bool is_upper)
{
+ ovl_inode_init_ino(inode, realinode);
ovl_set_inode_data(inode, realinode, is_upper);
if (is_upper && !S_ISDIR(realinode->i_mode))
ovl_insert_inode_hash(inode, realinode);
@@ -421,6 +431,7 @@ static int ovl_inode_test(struct inode *inode, void *data)
static int ovl_inode_set(struct inode *inode, void *data)
{
+ ovl_inode_init_ino(inode, OVL_INODE_REAL(data));
WRITE_ONCE(inode->i_private, data);
return 0;
}
When all layers are on same fs, initialize overlay inode with ino/generation of a real inode. Move initialization of overlay inode ino from ovl_fill_inode() to when real inode is available, but before a new inode is inserted to hash. This does not affect the result of stat(2) of an overlay file, which always returns the current real inode number. The overlay ino is going to be used for overlay inodes lookup by stable inode. Signed-off-by: Amir Goldstein <amir73il@gmail.com> --- fs/overlayfs/inode.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)