From: Mauricio Faria de Oliveira <mfo@canonical.com>
To: Jan Kara <jack@suse.cz>
Cc: linux-ext4@vger.kernel.org,
dann frazier <dann.frazier@canonical.com>,
Mauricio Faria de Oliveira <mauricio.foliveira@gmail.com>,
Jan Kara <jack@suse.com>
Subject: Re: [RFC PATCH v2 1/5] jbd2: test case for ext4 data=journal/mmap() journal corruption
Date: Tue, 18 Aug 2020 22:15:37 -0300 [thread overview]
Message-ID: <CAO9xwp1hjSFYjSYdvjAJ8bs24=Vyc3Uk3RtmGz0_HiHDW_SVCw@mail.gmail.com> (raw)
In-Reply-To: <20200818143844.GB1902@quack2.suse.cz>
On Tue, Aug 18, 2020 at 11:38 AM Jan Kara <jack@suse.cz> wrote:
>
> On Sun 09-08-20 22:02:04, Mauricio Faria de Oliveira wrote:
> > This checks during journal commit, right after calculating the
> > checksum of a buffer head, whether its contents match the 'BUG'
> > string (the cookie string in the test case userspace part.)
> >
> > If so, it sleeps 5 seconds for such contents to change (i.e.,
> > so that the actual checksum changes from what was calculated.)
> >
> > And if it changed, set a flag to panic after committing to disk.
> >
> > Then, on filesystem remount/journal recovery there is an invalid
> > checksum error, and recovery fails:
> >
> > $ sudo mount -o data=journal,journal_checksum $DEV $MNT
> > [ 100.832223] EXT4-fs: Warning: mounting with data=journal disables
> > delayed allocation, dioread_nolock, and O_DIRECT support!
> > [ 100.837488] JBD2: Invalid checksum recovering data block 8706 in log
> > [ 100.842010] JBD2: recovery failed
> > [ 100.843045] EXT4-fs (loop0): error loading journal
> > mount: /ext4: can't read superblock on /dev/loop0.
>
> Nice to have this for testing but when you'll do some "official"
> submission, just send this patch separately so that it's clear shouldn't be
> included in the kernel...
>
Yup, absolutely. :) I forgot to make its subject line different as in
other test-case parts.
> Honza
>
> > ---
> > fs/jbd2/commit.c | 29 +++++++++++++++++++++++++++++
> > 1 file changed, 29 insertions(+)
> >
> > diff --git a/fs/jbd2/commit.c b/fs/jbd2/commit.c
> > index 6d2da8ad0e6f..51f713089e35 100644
> > --- a/fs/jbd2/commit.c
> > +++ b/fs/jbd2/commit.c
> > @@ -26,6 +26,11 @@
> > #include <linux/bitops.h>
> > #include <trace/events/jbd2.h>
> >
> > +#include <linux/printk.h>
> > +#include <linux/delay.h>
> > +
> > +static journal_t *force_panic;
> > +
> > /*
> > * IO end handler for temporary buffer_heads handling writes to the journal.
> > */
> > @@ -331,14 +336,35 @@ static void jbd2_block_tag_csum_set(journal_t *j, journal_block_tag_t *tag,
> > __u32 csum32;
> > __be32 seq;
> >
> > + // For the testcase
> > + __u32 csum32_later;
> > + __u8 *bh_data;
> > +
> > if (!jbd2_journal_has_csum_v2or3(j))
> > return;
> >
> > seq = cpu_to_be32(sequence);
> > addr = kmap_atomic(page);
> > csum32 = jbd2_chksum(j, j->j_csum_seed, (__u8 *)&seq, sizeof(seq));
> > + csum32_later = csum32; // Copy csum32 to check again later
> > csum32 = jbd2_chksum(j, csum32, addr + offset_in_page(bh->b_data),
> > bh->b_size);
> > +
> > + // Check for testcase cookie 'BUG' in the buffer_head data.
> > + bh_data = addr + offset_in_page(bh->b_data);
> > + if (bh_data[0] == 'B' &&
> > + bh_data[1] == 'U' &&
> > + bh_data[2] == 'G') {
> > + pr_info("TESTCASE: Cookie found. Waiting 5 seconds for changes.\n");
> > + msleep(5000);
> > + pr_info("TESTCASE: Cookie eaten. Resumed.\n");
> > + }
> > +
> > + // Check the checksum again for changes/panic after commit.
> > + csum32_later = jbd2_chksum(j, csum32_later, addr + offset_in_page(bh->b_data), bh->b_size);
> > + if (csum32 != csum32_later)
> > + force_panic = j;
> > +
> > kunmap_atomic(addr);
> >
> > if (jbd2_has_feature_csum3(j))
> > @@ -885,6 +911,9 @@ void jbd2_journal_commit_transaction(journal_t *journal)
> > blkdev_issue_flush(journal->j_dev, GFP_NOFS);
> > }
> >
> > + if (force_panic == journal)
> > + panic("TESTCASE: checksum changed; commit record done; panic!\n");
> > +
> > if (err)
> > jbd2_journal_abort(journal, err);
> >
> > --
> > 2.17.1
> >
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
--
Mauricio Faria de Oliveira
next prev parent reply other threads:[~2020-08-19 1:15 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-10 1:02 [RFC PATCH v2 0/5] ext4/jbd2: data=journal: write-protect pages on transaction commit Mauricio Faria de Oliveira
2020-08-10 1:02 ` [RFC PATCH v2 1/5] jbd2: test case for ext4 data=journal/mmap() journal corruption Mauricio Faria de Oliveira
2020-08-18 14:38 ` Jan Kara
2020-08-19 1:15 ` Mauricio Faria de Oliveira [this message]
2020-08-10 1:02 ` [RFC PATCH v2 2/5] jbd2: introduce journal callbacks j_submit|finish_inode_data_buffers Mauricio Faria de Oliveira
2020-08-18 14:52 ` Jan Kara
2020-08-19 1:20 ` Mauricio Faria de Oliveira
2020-08-19 9:16 ` Jan Kara
2020-08-10 1:02 ` [RFC PATCH v2 3/5] ext4: data=journal: write-protect pages on submit inode data buffers callback Mauricio Faria de Oliveira
2020-08-19 8:44 ` Jan Kara
2020-08-19 10:41 ` Jan Kara
2020-08-20 22:55 ` Mauricio Faria de Oliveira
2020-08-21 10:26 ` Jan Kara
2020-08-10 1:02 ` [RFC PATCH v2 4/5] ext4: data=journal: add inode to transaction inode list in ext4_page_mkwrite() Mauricio Faria de Oliveira
2020-08-10 1:02 ` [RFC PATCH v2 5/5] ext4/jbd2: debugging messages Mauricio Faria de Oliveira
2020-08-19 8:46 ` Jan Kara
2020-08-10 1:02 ` [RFC PATCH v2/SETUP SCRIPT] Mauricio Faria de Oliveira
2020-08-10 1:02 ` [RFC PATCH v2/TEST CASE] Mauricio Faria de Oliveira
2020-08-19 9:27 ` [RFC PATCH v2 0/5] ext4/jbd2: data=journal: write-protect pages on transaction commit Jan Kara
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CAO9xwp1hjSFYjSYdvjAJ8bs24=Vyc3Uk3RtmGz0_HiHDW_SVCw@mail.gmail.com' \
--to=mfo@canonical.com \
--cc=dann.frazier@canonical.com \
--cc=jack@suse.com \
--cc=jack@suse.cz \
--cc=linux-ext4@vger.kernel.org \
--cc=mauricio.foliveira@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).