add patch jbd2-convert-timers-to-use-timer_setup
[ext4-patch-queue.git] / add-ext4_should_use_dax
blobc5c07c54c5de646d6651ec5d0495b1965a61bc33
1 ext4: add ext4_should_use_dax()
3 From: Ross Zwisler <ross.zwisler@linux.intel.com>
5 This helper, in the spirit of ext4_should_dioread_nolock() et al., replaces
6 the complex conditional in ext4_set_inode_flags().
8 Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
9 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
10 Reviewed-by: Jan Kara <jack@suse.cz>
11 ---
12  fs/ext4/inode.c | 19 ++++++++++++++++---
13  1 file changed, 16 insertions(+), 3 deletions(-)
15 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
16 index 3207333..525dd63 100644
17 --- a/fs/ext4/inode.c
18 +++ b/fs/ext4/inode.c
19 @@ -4577,6 +4577,21 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
20                 !ext4_test_inode_state(inode, EXT4_STATE_XATTR));
21  }
23 +static bool ext4_should_use_dax(struct inode *inode)
25 +       if (!test_opt(inode->i_sb, DAX))
26 +               return false;
27 +       if (!S_ISREG(inode->i_mode))
28 +               return false;
29 +       if (ext4_should_journal_data(inode))
30 +               return false;
31 +       if (ext4_has_inline_data(inode))
32 +               return false;
33 +       if (ext4_encrypted_inode(inode))
34 +               return false;
35 +       return true;
38  void ext4_set_inode_flags(struct inode *inode)
39  {
40         unsigned int flags = EXT4_I(inode)->i_flags;
41 @@ -4592,9 +4607,7 @@ void ext4_set_inode_flags(struct inode *inode)
42                 new_fl |= S_NOATIME;
43         if (flags & EXT4_DIRSYNC_FL)
44                 new_fl |= S_DIRSYNC;
45 -       if (test_opt(inode->i_sb, DAX) && S_ISREG(inode->i_mode) &&
46 -           !ext4_should_journal_data(inode) && !ext4_has_inline_data(inode) &&
47 -           !ext4_encrypted_inode(inode))
48 +       if (ext4_should_use_dax(inode))
49                 new_fl |= S_DAX;
50         inode_set_flags(inode, new_fl,
51                         S_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX);
52 -- 
53 2.9.5