Skip to content

Commit aff1204

Browse files
hbirthMiklos Szeredi
authored andcommitted
fuse: fix inode initialization race
Fix a race between fuse_iget() and fuse_reverse_inval_inode() where invalidation can arrive while an inode is being initialized, causing the invalidation to be lost. By keeping the inode state I_NEW as long as the attributes are not valid the invalidation can wait until the inode is fully initialized. Suggested-by: Joanne Koong <joannelkoong@gmail.com> Signed-off-by: Horst Birthelmer <hbirthelmer@ddn.com> Signed-off-by: Miklos Szeredi <mszeredi@redhat.com>
1 parent 204aa22 commit aff1204

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

fs/fuse/inode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,7 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
470470
struct inode *inode;
471471
struct fuse_inode *fi;
472472
struct fuse_conn *fc = get_fuse_conn_super(sb);
473+
bool is_new_inode = false;
473474

474475
/*
475476
* Auto mount points get their node id from the submount root, which is
@@ -505,13 +506,13 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
505506
if (!inode)
506507
return NULL;
507508

508-
if ((inode_state_read_once(inode) & I_NEW)) {
509+
is_new_inode = inode_state_read_once(inode) & I_NEW;
510+
if (is_new_inode) {
509511
inode->i_flags |= S_NOATIME;
510512
if (!fc->writeback_cache || !S_ISREG(attr->mode))
511513
inode->i_flags |= S_NOCMTIME;
512514
inode->i_generation = generation;
513515
fuse_init_inode(inode, attr, fc);
514-
unlock_new_inode(inode);
515516
} else if (fuse_stale_inode(inode, generation, attr)) {
516517
/* nodeid was reused, any I/O on the old inode should fail */
517518
fuse_make_bad(inode);
@@ -528,6 +529,8 @@ struct inode *fuse_iget(struct super_block *sb, u64 nodeid,
528529
done:
529530
fuse_change_attributes_i(inode, attr, NULL, attr_valid, attr_version,
530531
evict_ctr);
532+
if (is_new_inode)
533+
unlock_new_inode(inode);
531534
return inode;
532535
}
533536

0 commit comments

Comments
 (0)