add patch add-ext4_should_use_dax
[ext4-patch-queue.git] / prevent-data-corruption-with-journaling-and-dax
blob4fd43e839ba122d88aeb49996e8f16e18eefe285
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
7 in S_DAX.
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>
22 ---
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
29 --- a/fs/ext4/inode.c
30 +++ b/fs/ext4/inode.c
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);
33         }
34         ext4_set_aops(inode);
35 -       /*
36 -        * Update inode->i_flags after EXT4_INODE_JOURNAL_DATA was updated.
37 -        * E.g. S_DAX may get cleared / set.
38 -        */
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
45 --- a/fs/ext4/ioctl.c
46 +++ b/fs/ext4/ioctl.c
47 @@ -290,10 +290,20 @@ static int ext4_ioctl_setflags(struct inode *inode,
48         if (err)
49                 goto flags_out;
51 -       if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
52 +       if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
53 +               /*
54 +                * Changes to the journaling mode can cause unsafe changes to
55 +                * S_DAX if we are using the DAX mount option.
56 +                */
57 +               if (test_opt(inode->i_sb, DAX)) {
58 +                       err = -EBUSY;
59 +                       goto flags_out;
60 +               }
62                 err = ext4_change_inode_journal_flag(inode, jflag);
63 -       if (err)
64 -               goto flags_out;
65 +               if (err)
66 +                       goto flags_out;
67 +       }
68         if (migrate) {
69                 if (flags & EXT4_EXTENTS_FL)
70                         err = ext4_ext_migrate(inode);
71 -- 
72 2.9.5