Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ext4: replace opencoded i_writecount usage with inode_is_open_for_write()

There is a function which clearly conveys the objective of checking
i_writecount. Additionally the usage in ext4_mb_initialize_context was
wrong, since a node would have wrongfully been reported as writable if
i_writecount had a negative value (MMAP_DENY_WRITE).

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Jan Kara <jack@suse.cz>

authored by

Nikolay Borisov and committed by
Theodore Ts'o
82dd124c 53cf9784

+4 -5
+1 -1
fs/ext4/inode.c
··· 391 391 * inode's preallocations. 392 392 */ 393 393 if ((ei->i_reserved_data_blocks == 0) && 394 - (atomic_read(&inode->i_writecount) == 0)) 394 + !inode_is_open_for_write(inode)) 395 395 ext4_discard_preallocations(inode); 396 396 } 397 397
+3 -4
fs/ext4/mballoc.c
··· 4176 4176 isize = (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1) 4177 4177 >> bsbits; 4178 4178 4179 - if ((size == isize) && 4180 - !ext4_fs_is_busy(sbi) && 4181 - (atomic_read(&ac->ac_inode->i_writecount) == 0)) { 4179 + if ((size == isize) && !ext4_fs_is_busy(sbi) && 4180 + !inode_is_open_for_write(ac->ac_inode)) { 4182 4181 ac->ac_flags |= EXT4_MB_HINT_NOPREALLOC; 4183 4182 return; 4184 4183 } ··· 4257 4258 (unsigned) ar->goal, ac->ac_flags, ac->ac_2order, 4258 4259 (unsigned) ar->lleft, (unsigned) ar->pleft, 4259 4260 (unsigned) ar->lright, (unsigned) ar->pright, 4260 - atomic_read(&ar->inode->i_writecount) ? "" : "non-"); 4261 + inode_is_open_for_write(ar->inode) ? "" : "non-"); 4261 4262 return 0; 4262 4263 4263 4264 }