]> git.dujemihanovic.xyz Git - linux.git/commitdiff
bcachefs: Fix I_NEW warning in race path in bch2_inode_insert()
authorKent Overstreet <kent.overstreet@linux.dev>
Thu, 20 Jun 2024 17:20:49 +0000 (13:20 -0400)
committerKent Overstreet <kent.overstreet@linux.dev>
Fri, 21 Jun 2024 14:17:07 +0000 (10:17 -0400)
discard_new_inode() is the correct interface for tearing down an indoe
that was fully created but not made visible to other threads, but it
expects I_NEW to be set, which we don't use.

Reported-by: https://github.com/koverstreet/bcachefs/issues/690
Fixes: bcachefs: Fix race path in bch2_inode_insert()
Signed-off-by: Kent Overstreet <kent.overstreet@linux.dev>
fs/bcachefs/fs.c

index 8314d3e1582d31462a4de3a0c8d0d39caefb1b6f..615ef8305c6eb41d96c43999f9e830fdf479cd8a 100644 (file)
@@ -188,6 +188,12 @@ static struct bch_inode_info *bch2_inode_insert(struct bch_fs *c, struct bch_ino
        BUG_ON(!old);
 
        if (unlikely(old != inode)) {
+               /*
+                * bcachefs doesn't use I_NEW; we have no use for it since we
+                * only insert fully created inodes in the inode hash table. But
+                * discard_new_inode() expects it to be set...
+                */
+               inode->v.i_flags |= I_NEW;
                discard_new_inode(&inode->v);
                inode = old;
        } else {
@@ -195,8 +201,10 @@ static struct bch_inode_info *bch2_inode_insert(struct bch_fs *c, struct bch_ino
                list_add(&inode->ei_vfs_inode_list, &c->vfs_inodes_list);
                mutex_unlock(&c->vfs_inodes_lock);
                /*
-                * we really don't want insert_inode_locked2() to be setting
-                * I_NEW...
+                * Again, I_NEW makes no sense for bcachefs. This is only needed
+                * for clearing I_NEW, but since the inode was already fully
+                * created and initialized we didn't actually want
+                * inode_insert5() to set it for us.
                 */
                unlock_new_inode(&inode->v);
        }