Skip to content

Commit a8ab6d3

Browse files
weiny2tytso
authored andcommitted
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: Jan Kara <jack@suse.cz> Signed-off-by: Ira Weiny <ira.weiny@intel.com> Link: https://lore.kernel.org/r/20200528150003.828793-5-ira.weiny@intel.com Signed-off-by: Theodore Ts'o <tytso@mit.edu>
1 parent fc626fe commit a8ab6d3

3 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎fs/ext4/ext4.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1979,6 +1979,7 @@ static inline bool ext4_has_incompat_features(struct super_block *sb)
19791979
*/
19801980
#define EXT4_FLAGS_RESIZING 0
19811981
#define EXT4_FLAGS_SHUTDOWN 1
1982+
#define EXT4_FLAGS_BDEV_IS_DAX 2
19821983

19831984
static inline int ext4_forced_shutdown(struct ext4_sb_info *sbi)
19841985
{

‎fs/ext4/inode.c‎

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4398,10 +4398,10 @@ int ext4_get_inode_loc(struct inode *inode, struct ext4_iloc *iloc)
43984398
!ext4_test_inode_state(inode, EXT4_STATE_XATTR));
43994399
}
44004400

4401-
static bool ext4_should_use_dax(struct inode *inode)
4401+
static bool ext4_should_enable_dax(struct inode *inode)
44024402
{
4403-
if (!test_opt(inode->i_sb, DAX_ALWAYS))
4404-
return false;
4403+
struct ext4_sb_info *sbi = EXT4_SB(inode->i_sb);
4404+
44054405
if (!S_ISREG(inode->i_mode))
44064406
return false;
44074407
if (ext4_should_journal_data(inode))
@@ -4412,7 +4412,12 @@ static bool ext4_should_use_dax(struct inode *inode)
44124412
return false;
44134413
if (ext4_test_inode_flag(inode, EXT4_INODE_VERITY))
44144414
return false;
4415-
return true;
4415+
if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags))
4416+
return false;
4417+
if (test_opt(inode->i_sb, DAX_ALWAYS))
4418+
return true;
4419+
4420+
return false;
44164421
}
44174422

44184423
void ext4_set_inode_flags(struct inode *inode)
@@ -4430,7 +4435,7 @@ void ext4_set_inode_flags(struct inode *inode)
44304435
new_fl |= S_NOATIME;
44314436
if (flags & EXT4_DIRSYNC_FL)
44324437
new_fl |= S_DIRSYNC;
4433-
if (ext4_should_use_dax(inode))
4438+
if (ext4_should_enable_dax(inode))
44344439
new_fl |= S_DAX;
44354440
if (flags & EXT4_ENCRYPT_FL)
44364441
new_fl |= S_ENCRYPTED;

‎fs/ext4/super.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4092,13 +4092,16 @@ static int ext4_fill_super(struct super_block *sb, void *data, int silent)
40924092
goto failed_mount;
40934093
}
40944094

4095+
if (bdev_dax_supported(sb->s_bdev, blocksize))
4096+
set_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags);
4097+
40954098
if (sbi->s_mount_opt & EXT4_MOUNT_DAX_ALWAYS) {
40964099
if (ext4_has_feature_inline_data(sb)) {
40974100
ext4_msg(sb, KERN_ERR, "Cannot use DAX on a filesystem"
40984101
" that may contain inline data");
40994102
goto failed_mount;
41004103
}
4101-
if (!bdev_dax_supported(sb->s_bdev, blocksize)) {
4104+
if (!test_bit(EXT4_FLAGS_BDEV_IS_DAX, &sbi->s_ext4_flags)) {
41024105
ext4_msg(sb, KERN_ERR,
41034106
"DAX unsupported by block device.");
41044107
goto failed_mount;

0 commit comments

Comments
 (0)