@@ -4305,12 +4305,15 @@ static int ext4_do_update_inode(handle_t *handle,
43054305 struct ext4_inode * raw_inode = ext4_raw_inode (iloc );
43064306 struct ext4_inode_info * ei = EXT4_I (inode );
43074307 struct buffer_head * bh = iloc -> bh ;
4308+ struct super_block * sb = inode -> i_sb ;
43084309 int err = 0 , rc , block ;
4309- int need_datasync = 0 ;
4310+ int need_datasync = 0 , set_large_file = 0 ;
43104311 uid_t i_uid ;
43114312 gid_t i_gid ;
43124313
4313- /* For fields not not tracking in the in-memory inode,
4314+ spin_lock (& ei -> i_raw_lock );
4315+
4316+ /* For fields not tracked in the in-memory inode,
43144317 * initialise them to zero for new inodes. */
43154318 if (ext4_test_inode_state (inode , EXT4_STATE_NEW ))
43164319 memset (raw_inode , 0 , EXT4_SB (inode -> i_sb )-> s_inode_size );
@@ -4348,8 +4351,10 @@ static int ext4_do_update_inode(handle_t *handle,
43484351 EXT4_INODE_SET_XTIME (i_atime , inode , raw_inode );
43494352 EXT4_EINODE_SET_XTIME (i_crtime , ei , raw_inode );
43504353
4351- if (ext4_inode_blocks_set (handle , raw_inode , ei ))
4354+ if (ext4_inode_blocks_set (handle , raw_inode , ei )) {
4355+ spin_unlock (& ei -> i_raw_lock );
43524356 goto out_brelse ;
4357+ }
43534358 raw_inode -> i_dtime = cpu_to_le32 (ei -> i_dtime );
43544359 raw_inode -> i_flags = cpu_to_le32 (ei -> i_flags & 0xFFFFFFFF );
43554360 if (likely (!test_opt2 (inode -> i_sb , HURD_COMPAT )))
@@ -4361,24 +4366,11 @@ static int ext4_do_update_inode(handle_t *handle,
43614366 need_datasync = 1 ;
43624367 }
43634368 if (ei -> i_disksize > 0x7fffffffULL ) {
4364- struct super_block * sb = inode -> i_sb ;
43654369 if (!EXT4_HAS_RO_COMPAT_FEATURE (sb ,
43664370 EXT4_FEATURE_RO_COMPAT_LARGE_FILE ) ||
43674371 EXT4_SB (sb )-> s_es -> s_rev_level ==
4368- cpu_to_le32 (EXT4_GOOD_OLD_REV )) {
4369- /* If this is the first large file
4370- * created, add a flag to the superblock.
4371- */
4372- err = ext4_journal_get_write_access (handle ,
4373- EXT4_SB (sb )-> s_sbh );
4374- if (err )
4375- goto out_brelse ;
4376- ext4_update_dynamic_rev (sb );
4377- EXT4_SET_RO_COMPAT_FEATURE (sb ,
4378- EXT4_FEATURE_RO_COMPAT_LARGE_FILE );
4379- ext4_handle_sync (handle );
4380- err = ext4_handle_dirty_super (handle , sb );
4381- }
4372+ cpu_to_le32 (EXT4_GOOD_OLD_REV ))
4373+ set_large_file = 1 ;
43824374 }
43834375 raw_inode -> i_generation = cpu_to_le32 (inode -> i_generation );
43844376 if (S_ISCHR (inode -> i_mode ) || S_ISBLK (inode -> i_mode )) {
@@ -4410,12 +4402,23 @@ static int ext4_do_update_inode(handle_t *handle,
44104402
44114403 ext4_inode_csum_set (inode , raw_inode , ei );
44124404
4405+ spin_unlock (& ei -> i_raw_lock );
4406+
44134407 BUFFER_TRACE (bh , "call ext4_handle_dirty_metadata" );
44144408 rc = ext4_handle_dirty_metadata (handle , NULL , bh );
44154409 if (!err )
44164410 err = rc ;
44174411 ext4_clear_inode_state (inode , EXT4_STATE_NEW );
4418-
4412+ if (set_large_file ) {
4413+ err = ext4_journal_get_write_access (handle , EXT4_SB (sb )-> s_sbh );
4414+ if (err )
4415+ goto out_brelse ;
4416+ ext4_update_dynamic_rev (sb );
4417+ EXT4_SET_RO_COMPAT_FEATURE (sb ,
4418+ EXT4_FEATURE_RO_COMPAT_LARGE_FILE );
4419+ ext4_handle_sync (handle );
4420+ err = ext4_handle_dirty_super (handle , sb );
4421+ }
44194422 ext4_update_inode_fsync_trans (handle , inode , need_datasync );
44204423out_brelse :
44214424 brelse (bh );
0 commit comments