Fix up descriptions.
[ext4-patch-queue.git] / prevent-data-corruption-with-journaling-and-dax
blobcf38085fc3f3b254287ebbd6ff14c1c5b73d45b0
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 Cc: stable@vger.kernel.org
23 ---
24  fs/ext4/inode.c |  5 -----
25  fs/ext4/ioctl.c | 16 +++++++++++++---
26  2 files changed, 13 insertions(+), 8 deletions(-)
28 diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
29 index e963508..3207333 100644
30 --- a/fs/ext4/inode.c
31 +++ b/fs/ext4/inode.c
32 @@ -5971,11 +5971,6 @@ int ext4_change_inode_journal_flag(struct inode *inode, int val)
33                 ext4_clear_inode_flag(inode, EXT4_INODE_JOURNAL_DATA);
34         }
35         ext4_set_aops(inode);
36 -       /*
37 -        * Update inode->i_flags after EXT4_INODE_JOURNAL_DATA was updated.
38 -        * E.g. S_DAX may get cleared / set.
39 -        */
40 -       ext4_set_inode_flags(inode);
42         jbd2_journal_unlock_updates(journal);
43         percpu_up_write(&sbi->s_journal_flag_rwsem);
44 diff --git a/fs/ext4/ioctl.c b/fs/ext4/ioctl.c
45 index afb66d4..b0b754b 100644
46 --- a/fs/ext4/ioctl.c
47 +++ b/fs/ext4/ioctl.c
48 @@ -290,10 +290,20 @@ static int ext4_ioctl_setflags(struct inode *inode,
49         if (err)
50                 goto flags_out;
52 -       if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL))
53 +       if ((jflag ^ oldflags) & (EXT4_JOURNAL_DATA_FL)) {
54 +               /*
55 +                * Changes to the journaling mode can cause unsafe changes to
56 +                * S_DAX if we are using the DAX mount option.
57 +                */
58 +               if (test_opt(inode->i_sb, DAX)) {
59 +                       err = -EBUSY;
60 +                       goto flags_out;
61 +               }
63                 err = ext4_change_inode_journal_flag(inode, jflag);
64 -       if (err)
65 -               goto flags_out;
66 +               if (err)
67 +                       goto flags_out;
68 +       }
69         if (migrate) {
70                 if (flags & EXT4_EXTENTS_FL)
71                         err = ext4_ext_migrate(inode);
72 -- 
73 2.9.5