Skip to content

Commit 82dd124

Browse files
lorddoskiastytso
authored andcommitted
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>
1 parent 53cf978 commit 82dd124

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

fs/ext4/inode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ void ext4_da_update_reserve_space(struct inode *inode,
391391
* inode's preallocations.
392392
*/
393393
if ((ei->i_reserved_data_blocks == 0) &&
394-
(atomic_read(&inode->i_writecount) == 0))
394+
!inode_is_open_for_write(inode))
395395
ext4_discard_preallocations(inode);
396396
}
397397

fs/ext4/mballoc.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4176,9 +4176,8 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac)
41764176
isize = (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1)
41774177
>> bsbits;
41784178

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)) {
41824181
ac->ac_flags |= EXT4_MB_HINT_NOPREALLOC;
41834182
return;
41844183
}
@@ -4258,7 +4257,7 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac,
42584257
(unsigned) ar->goal, ac->ac_flags, ac->ac_2order,
42594258
(unsigned) ar->lleft, (unsigned) ar->pleft,
42604259
(unsigned) ar->lright, (unsigned) ar->pright,
4261-
atomic_read(&ar->inode->i_writecount) ? "" : "non-");
4260+
inode_is_open_for_write(ar->inode) ? "" : "non-");
42624261
return 0;
42634262

42644263
}

0 commit comments

Comments
 (0)