1 ext4: prevent data corruption with journaling + DAX
3 From: Ross Zwisler <ross.zwisler@linux.intel.com>
5 The current code has the potential for data corruption when changing an
6 inode's journaling mode, as that can result in a subsequent unsafe change
9 I've captured an instance of this data corruption in the following fstest:
11 https://patchwork.kernel.org/patch/9948377/
13 Prevent this data corruption from happening by disallowing changes to the
14 journaling mode if the '-o dax' mount option was used. This means that for
15 a given filesystem we could have a mix of inodes using either DAX or
16 data journaling, but whatever state the inodes are in will be held for the
17 duration of the mount.
19 Signed-off-by: Ross Zwisler <ross.zwisler@linux.intel.com>
20 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
21 Reviewed-by: Jan Kara <jack@suse.cz>
23 fs/ext4/inode.c | 5 -----
24 fs/ext4/ioctl.c | 16 +++++++++++++---
25 2 files changed, 13 insertions(+), 8 deletions(-)
27 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
28 index e963508..3207333 100644
31 @@ -5971,11 +5971,6 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
32 ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA);
36 - * Update inode->i_flags after EXT4_INODE_JOURNAL_DATA was updated.
37 - * E.g. S_DAX may get cleared / set.
39 - ext4_set_inode_flags(inode);
41 jbd2_journal_unlock_updates(journal);
42 percpu_up_write(&sbi->s_journal_flag_rwsem);
43 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
44 index afb66d4..b0b754b 100644
47 @@ -290,10 +290,20 @@ static int ext4_ioctl_setflags(struct inode *inode,
51 - if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
52 + if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
54 + * Changes to the journaling mode can cause unsafe changes to
55 + * S_DAX if we are using the DAX mount option.
57 + if (test_opt(inode->i_sb, DAX)) {
62 err = ext4_change_inode_journal_flag(inode, jflag);
69 if (flags & EXT4_EXTENTS_FL)
70 err = ext4_ext_migrate(inode);