Commit a8ab6d38 authored by Ira Weiny's avatar Ira Weiny Committed by Theodore Ts'o

fs/ext4: Update ext4_should_use_dax()

S_DAX should only be enabled when the underlying block device supports
dax.

Cache the underlying support for DAX in the super block and modify
ext4_should_use_dax() to check for device support prior to the over
riding mount option.

While we are at it change the function to ext4_should_enable_dax() as
this better reflects the ask as well as matches xfs.
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarIra Weiny <ira.weiny@intel.com>

Link: https://lore.kernel.org/r/20200528150003.828793-5-ira.weiny@intel.comSigned-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
parent fc626fe3
...@@ -1979,6 +1979,7 @@ static inline bool ext4_has_incompat_features(struct super_block *sb) ...@@ -1979,6 +1979,7 @@ static inline bool ext4_has_incompat_features(struct super_block *sb)
*/ */
#define EXT4_FLAGS_RESIZING 0 #define EXT4_FLAGS_RESIZING 0
#define EXT4_FLAGS_SHUTDOWN 1 #define EXT4_FLAGS_SHUTDOWN 1
#define EXT4_FLAGS_BDEV_IS_DAX 2
static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi) static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi)
{ {
......
...@@ -4398,10 +4398,10 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc) ...@@ -4398,10 +4398,10 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
!ext4_test_inode_state(inode, EXT4_STATE_XATTR)); !ext4_test_inode_state(inode, EXT4_STATE_XATTR));
} }
static bool ext4_should_use_dax(struct inode *inode) static bool ext4_should_enable_dax(struct inode *inode)
{ {
if (!test_opt(inode->i_sb, DAX_ALWAYS)) struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
return false;
if (!S_ISREG(inode->i_mode)) if (!S_ISREG(inode->i_mode))
return false; return false;
if (ext4_should_journal_data(inode)) if (ext4_should_journal_data(inode))
...@@ -4412,7 +4412,12 @@ static bool ext4_should_use_dax(struct inode *inode) ...@@ -4412,7 +4412,12 @@ static bool ext4_should_use_dax(struct inode *inode)
return false; return false;
if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY)) if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY))
return false; return false;
return true; if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags))
return false;
if (test_opt(inode->i_sb, DAX_ALWAYS))
return true;
return false;
} }
void ext4_set_inode_flags(struct inode *inode) void ext4_set_inode_flags(struct inode *inode)
...@@ -4430,7 +4435,7 @@ void ext4_set_inode_flags(struct inode *inode) ...@@ -4430,7 +4435,7 @@ void ext4_set_inode_flags(struct inode *inode)
new_fl |= S_NOATIME; new_fl |= S_NOATIME;
if (flags & EXT4_DIRSYNC_FL) if (flags & EXT4_DIRSYNC_FL)
new_fl |= S_DIRSYNC; new_fl |= S_DIRSYNC;
if (ext4_should_use_dax(inode)) if (ext4_should_enable_dax(inode))
new_fl |= S_DAX; new_fl |= S_DAX;
if (flags & EXT4_ENCRYPT_FL) if (flags & EXT4_ENCRYPT_FL)
new_fl |= S_ENCRYPTED; new_fl |= S_ENCRYPTED;
......
...@@ -4092,13 +4092,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent) ...@@ -4092,13 +4092,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
goto failed_mount; goto failed_mount;
} }
if (bdev_dax_supported(sb->s_bdev, blocksize))
set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags);
if (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) { if (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) {
if (ext4_has_feature_inline_data(sb)) { if (ext4_has_feature_inline_data(sb)) {
ext4_msg(sb, KERN_ERR, "Cannot use DAX on a filesystem" ext4_msg(sb, KERN_ERR, "Cannot use DAX on a filesystem"
" that may contain inline data"); " that may contain inline data");
goto failed_mount; goto failed_mount;
} }
if (!bdev_dax_supported(sb->s_bdev, blocksize)) { if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags)) {
ext4_msg(sb, KERN_ERR, ext4_msg(sb, KERN_ERR,
"DAX unsupported by block device."); "DAX unsupported by block device.");
goto failed_mount; goto failed_mount;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment