add patch report-delalloc-reserve-as-non-free-in-statfs-for-project-quota
[ext4-patch-queue.git] / do-not-update-s_last_mounted-of-a-frozen-fs
blobda7c43794ef75453812c36a41f82f36c8f8e6d05
1 ext4: do not update s_last_mounted of a frozen fs
3 From: Amir Goldstein <amir73il@gmail.com>
5 If fs is frozen after mount and before the first file open, the
6 update of s_last_mounted bypasses freeze protection and prints out
7 a WARNING splat:
9 $ mount /vdf
10 $ fsfreeze -f /vdf
11 $ cat /vdf/foo
13 [   31.578555] WARNING: CPU: 1 PID: 1415 at
14 fs/ext4/ext4_jbd2.c:53 ext4_journal_check_start+0x48/0x82
16 [   31.614016] Call Trace:
17 [   31.614997]  __ext4_journal_start_sb+0xe4/0x1a4
18 [   31.616771]  ? ext4_file_open+0xb6/0x189
19 [   31.618094]  ext4_file_open+0xb6/0x189
21 If fs is frozen, skip s_last_mounted update.
23 [backport hint: to apply to stable tree, need to apply also patches
24  vfs: add the sb_start_intwrite_trylock() helper
25  ext4: factor out helper ext4_sample_last_mounted()]
27 Cc: stable@vger.kernel.org
28 Fixes: bc0b0d6d69ee ("ext4: update the s_last_mounted field in the superblock")
29 Signed-off-by: Amir Goldstein <amir73il@gmail.com>
30 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
31 Reviewed-by: Jan Kara <jack@suse.cz>
32 ---
33  fs/ext4/file.c | 14 +++++++++-----
34  1 file changed, 9 insertions(+), 5 deletions(-)
36 diff --git a/fs/ext4/file.c b/fs/ext4/file.c
37 index 065e95bb7186..918a59b6bc1a 100644
38 --- a/fs/ext4/file.c
39 +++ b/fs/ext4/file.c
40 @@ -392,7 +392,7 @@ static int ext4_sample_last_mounted(struct super_block *sb,
41         if (likely(sbi->s_mount_flags & EXT4_MF_MNTDIR_SAMPLED))
42                 return 0;
44 -       if (sb_rdonly(sb))
45 +       if (sb_rdonly(sb) || !sb_start_intwrite_trylock(sb))
46                 return 0;
48         sbi->s_mount_flags |= EXT4_MF_MNTDIR_SAMPLED;
49 @@ -406,21 +406,25 @@ static int ext4_sample_last_mounted(struct super_block *sb,
50         path.mnt = mnt;
51         path.dentry = mnt->mnt_root;
52         cp = d_path(&path, buf, sizeof(buf));
53 +       err = 0;
54         if (IS_ERR(cp))
55 -               return 0;
56 +               goto out;
58         handle = ext4_journal_start_sb(sb, EXT4_HT_MISC, 1);
59 +       err = PTR_ERR(handle);
60         if (IS_ERR(handle))
61 -               return PTR_ERR(handle);
62 +               goto out;
63         BUFFER_TRACE(sbi->s_sbh, "get_write_access");
64         err = ext4_journal_get_write_access(handle, sbi->s_sbh);
65         if (err)
66 -               goto out;
67 +               goto out_journal;
68         strlcpy(sbi->s_es->s_last_mounted, cp,
69                 sizeof(sbi->s_es->s_last_mounted));
70         ext4_handle_dirty_super(handle, sb);
71 -out:
72 +out_journal:
73         ext4_journal_stop(handle);
74 +out:
75 +       sb_end_intwrite(sb);
76         return err;
77  }
79 -- 
80 2.7.4