add patch fix-compile-warning-when-using-JBUFFER_TRACE
[ext4-patch-queue.git] / replace-open-i_writecount-usage
blobffd907f3978bb0fd771694707b2dadd52e0facff
1 ext4: replace opencoded i_writecount usage with inode_is_open_for_write()
3 From: Nikolay Borisov <nborisov@suse.com>
5 There is a function which clearly conveys the objective of checking
6 i_writecount. Additionally the usage in ext4_mb_initialize_context was
7 wrong, since a node would have wrongfully been reported as writable if
8 i_writecount had a negative value (MMAP_DENY_WRITE).
10 Signed-off-by: Nikolay Borisov <nborisov@suse.com>
11 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
12 Reviewed-by: Jan Kara <jack@suse.cz>
13 ---
14  fs/ext4/inode.c   | 2 +-
15  fs/ext4/mballoc.c | 7 +++----
16  2 files changed, 4 insertions(+), 5 deletions(-)
18 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
19 index 22a9d8159720..04e5bc0b5c8d 100644
20 --- a/fs/ext4/inode.c
21 +++ b/fs/ext4/inode.c
22 @@ -391,7 +391,7 @@ void ext4_da_update_reserve_space(struct inode *inode,
23          * inode's preallocations.
24          */
25         if ((ei->i_reserved_data_blocks == 0) &&
26 -           (atomic_read(&inode->i_writecount) == 0))
27 +           !inode_is_open_for_write(inode))
28                 ext4_discard_preallocations(inode);
29  }
31 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
32 index e2248083cdca..6fb76d408093 100644
33 --- a/fs/ext4/mballoc.c
34 +++ b/fs/ext4/mballoc.c
35 @@ -4176,9 +4176,8 @@ static void ext4_mb_group_or_file(struct ext4_allocation_context *ac)
36         isize = (i_size_read(ac->ac_inode) + ac->ac_sb->s_blocksize - 1)
37                 >> bsbits;
39 -       if ((size == isize) &&
40 -           !ext4_fs_is_busy(sbi) &&
41 -           (atomic_read(&ac->ac_inode->i_writecount) == 0)) {
42 +       if ((size == isize) && !ext4_fs_is_busy(sbi) &&
43 +           !inode_is_open_for_write(ac->ac_inode)) {
44                 ac->ac_flags |= EXT4_MB_HINT_NOPREALLOC;
45                 return;
46         }
47 @@ -4258,7 +4257,7 @@ ext4_mb_initialize_context(struct ext4_allocation_context *ac,
48                         (unsigned) ar->goal, ac->ac_flags, ac->ac_2order,
49                         (unsigned) ar->lleft, (unsigned) ar->pleft,
50                         (unsigned) ar->lright, (unsigned) ar->pright,
51 -                       atomic_read(&ar->inode->i_writecount) ? "" : "non-");
52 +                       inode_is_open_for_write(ar->inode) ? "" : "non-");
53         return 0;
55  }
56 -- 
57 2.17.1