diff options
author | Jan Kara <jack@suse.cz> | 2023-03-08 15:25:28 +0100 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2023-03-23 22:53:00 -0400 |
commit | e6c28a26b799c7640b77daff3e4a67808c74381c (patch) | |
tree | a1b6a6d1875437cc7eecae49456d881654ebacee /fs/ext4 | |
parent | 3f079114bf522f27f3680238b6429f3dd45535b6 (diff) |
ext4: Fix warnings when freezing filesystem with journaled data
Test generic/390 in data=journal mode often triggers a warning that
ext4_do_writepages() tries to start a transaction on frozen filesystem.
This happens because although all dirty data is properly written, jbd2
checkpointing code writes data through submit_bh() and as a result only
buffer dirty bits are cleared but page dirty bits stay set. Later when
the filesystem is frozen, writeback code comes, tries to write
supposedly dirty pages and the warning triggers. Fix the problem by
calling sync_filesystem() once more after flushing the whole journal to
clear stray page dirty bits.
[ Applied fixup patches to address crashes when running data=journal
tests; see links for more details -- TYT ]
Signed-off-by: Jan Kara <jack@suse.cz>
Link: https://lore.kernel.org/r/20230308142528.12384-1-jack@suse.cz
Reported-by: Eric Biggers <ebiggers@kernel.org>
Link: https://lore.kernel.org/all/20230319183617.GA896@sol.localdomain
Link: https://lore.kernel.org/r/20230323145404.21381-1-jack@suse.cz
Link: https://lore.kernel.org/r/20230323145404.21381-2-jack@suse.cz
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Diffstat (limited to 'fs/ext4')
-rw-r--r-- | fs/ext4/inode.c | 19 | ||||
-rw-r--r-- | fs/ext4/super.c | 11 |
2 files changed, 27 insertions, 3 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 652efb2221bf..6445b8017a8e 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -2410,6 +2410,7 @@ static int mpage_journal_page_buffers(handle_t *handle, static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) { struct address_space *mapping = mpd->inode->i_mapping; + struct super_block *sb = mpd->inode->i_sb; struct folio_batch fbatch; unsigned int nr_folios; pgoff_t index = mpd->first_page; @@ -2427,15 +2428,23 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) else tag = PAGECACHE_TAG_DIRTY; - if (ext4_should_journal_data(mpd->inode)) { + mpd->map.m_len = 0; + mpd->next_page = index; + /* + * Start a transaction for writeback of journalled data. We don't start + * start the transaction if the filesystem is frozen. In that case we + * should not have any dirty data to write anymore but possibly there + * are stray page dirty bits left by the checkpointing code so this + * loop clears them. + */ + if (ext4_should_journal_data(mpd->inode) && + sb->s_writers.frozen < SB_FREEZE_FS) { handle = ext4_journal_start(mpd->inode, EXT4_HT_WRITE_PAGE, bpp); if (IS_ERR(handle)) return PTR_ERR(handle); } folio_batch_init(&fbatch); - mpd->map.m_len = 0; - mpd->next_page = index; while (index <= end) { nr_folios = filemap_get_folios_tag(mapping, &index, end, tag, &fbatch); @@ -2520,12 +2529,16 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd) */ if (!mpd->can_map) { if (ext4_page_nomap_can_writeout(&folio->page)) { + WARN_ON_ONCE(sb->s_writers.frozen == + SB_FREEZE_COMPLETE); err = mpage_submit_page(mpd, &folio->page); if (err < 0) goto out; } /* Pending dirtying of journalled data? */ if (PageChecked(&folio->page)) { + WARN_ON_ONCE(sb->s_writers.frozen >= + SB_FREEZE_FS); err = mpage_journal_page_buffers(handle, mpd, &folio->page); if (err < 0) diff --git a/fs/ext4/super.c b/fs/ext4/super.c index f43e526112ae..f226f8ab469b 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -6293,6 +6293,17 @@ static int ext4_freeze(struct super_block *sb) if (error < 0) goto out; + /* + * Do another sync. We really should not have any dirty data + * anymore but our checkpointing code does not clear page dirty + * bits due to locking constraints so writeback still can get + * started for inodes with journalled data which triggers + * annoying warnings. + */ + error = sync_filesystem(sb); + if (error < 0) + goto out; + /* Journal blocked and flushed, clear needs_recovery flag. */ ext4_clear_feature_journal_needs_recovery(sb); if (ext4_orphan_file_empty(sb)) |