From: Dmitry Monakhov <dmonakhov@openvz.org>
To: linux-ext4@vger.kernel.org
Cc: tytso@mit.edu
Subject: Re: [PATCH 1/2] ext4: Prevent panic for destroyed devices
Date: Thu, 18 Feb 2016 12:35:34 +0300 [thread overview]
Message-ID: <87d1ru2wex.fsf@openvz.org> (raw)
In-Reply-To: <1455618965-26699-1-git-send-email-dmonakhov@openvz.org>
[-- Attachment #1: Type: text/plain, Size: 3045 bytes --]
Dmitry Monakhov <dmonakhov@openvz.org> writes:
> Some devices(nbd) can becomes unoperatable via kill_bdev
> so its pagecache will be invalidated and all buffers becomes unmapped.
> In that situation we will trigger BUGON on submit_bh.
>
> #Testcase
> mkdir -p a/mnt
> cd a
> truncate -s 1G img
> mkfs.ext4 -F img
> qemu-nbd -c /dev/nbd0 img
> mount /dev/nbd0 /mnt
> cp -r /bin/ /mnt&
> # Disconnect nbd while cp is active
> qemu-nbd -d /dev/nbd0
> sync
Hm...
Actually there are many places where we submit BHs w/o checks
nojournal code is full of such places.
It looks like we need some sort of AOP_TRUNCATE_PAGE error code
for generic buffer submission path
diff --git a/fs/buffer.c b/fs/buffer.c
index e1632ab..1cf94ec 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -3127,6 +3127,10 @@ int __sync_dirty_buffer(struct buffer_head *bh, int rw)
WARN_ON(atomic_read(&bh->b_count) < 1);
lock_buffer(bh);
+ if(unlikely(!buffer_mapped(bh))) {
+ unlock_buffer(bh);
+ return AOP_TRUNCATE_PAGE; /* or EIO */
+ }
if (test_clear_buffer_dirty(bh)) {
get_bh(bh);
bh->b_end_io = end_buffer_write_sync;
>
> Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
> ---
> fs/ext4/super.c | 24 +++++++++++++++++++++---
> 1 file changed, 21 insertions(+), 3 deletions(-)
>
> diff --git a/fs/ext4/super.c b/fs/ext4/super.c
> index 3ed01ec..617d8b4a 100644
> --- a/fs/ext4/super.c
> +++ b/fs/ext4/super.c
> @@ -4320,7 +4320,7 @@ static int ext4_commit_super(struct super_block *sb, int sync)
> struct buffer_head *sbh = EXT4_SB(sb)->s_sbh;
> int error = 0;
>
> - if (!sbh || block_device_ejected(sb))
> + if (!sbh || !buffer_mapped(sbh) || block_device_ejected(sb))
> return error;
> if (buffer_write_io_error(sbh)) {
> /*
> @@ -4368,8 +4368,26 @@ static int ext4_commit_super(struct super_block *sb, int sync)
> ext4_superblock_csum_set(sb);
> mark_buffer_dirty(sbh);
> if (sync) {
> - error = __sync_dirty_buffer(sbh,
> - test_opt(sb, BARRIER) ? WRITE_FUA : WRITE_SYNC);
> + lock_buffer(sbh);
> + /* superblock bh may be invalidated due to drive failure */
> + if (!buffer_mapped(sbh)) {
> + unlock_buffer(sbh);
> + ext4_msg(sb, KERN_ERR, "Can not write superblock "
> + "because disk cache was invalidated");
> + return -EIO;
> + }
> + if (test_clear_buffer_dirty(sbh)) {
> + get_bh(sbh);
> + sbh->b_end_io = end_buffer_write_sync;
> + error = submit_bh(test_opt(sb, BARRIER) ?
> + WRITE_FUA : WRITE_SYNC, sbh);
> + wait_on_buffer(sbh);
> + if (!error && !buffer_uptodate(sbh))
> + error = -EIO;
> + } else {
> + unlock_buffer(sbh);
> + }
> +
> if (error)
> return error;
>
> --
> 1.8.3.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]
next prev parent reply other threads:[~2016-02-18 9:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-16 10:36 [PATCH 1/2] ext4: Prevent panic for destroyed devices Dmitry Monakhov
2016-02-16 10:36 ` [PATCH 2/2] jbd2: " Dmitry Monakhov
2016-03-13 22:28 ` Theodore Ts'o
2016-02-18 9:35 ` Dmitry Monakhov [this message]
2016-02-19 5:13 ` [PATCH 1/2] ext4: " Theodore Ts'o
2016-03-13 22:26 ` Theodore Ts'o
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=87d1ru2wex.fsf@openvz.org \
--to=dmonakhov@openvz.org \
--cc=linux-ext4@vger.kernel.org \
--cc=tytso@mit.edu \
/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).