linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Austin S. Hemmelgarn" <ahferroin7@gmail.com>
To: Alex Lyakas <alex@zadarastorage.com>,
	linux-btrfs <linux-btrfs@vger.kernel.org>
Cc: Ron Mandel <ron@zadarastorage.com>,
	Yair Hershko <yair@zadarastorage.com>,
	Shyam Kaushik <shyam@zadarastorage.com>,
	Lev Vainblat <lev@zadarastorage.com>,
	Yaron Presente <yaron@zadarastorage.com>
Subject: Re: [RCF - PATCH] btrfs: do not ignore errors from primary superblock
Date: Tue, 17 May 2016 08:46:09 -0400	[thread overview]
Message-ID: <b361ded3-c5fe-0020-35d3-856c1b9d46de@gmail.com> (raw)
In-Reply-To: <7AF66DC0FE0640D1A4E007C4DAC16AC4@alyakaslap>

On 2016-05-17 07:24, Alex Lyakas wrote:
> RFC: This patch not for merging, but only for review and discussion.
>
> When mounting, we consider only the primary superblock on each device.
> But when writing the superblocks, we might silently ignore errors
> from the primary superblock, if we succeeded to write secondary
> superblocks. In such case, the primary superblock was not updated
> properly, and if we crash at this point, later mount will use
> an out-of-date superblock.
>
> This patch changes the behavior to NOT IGNORING any errors on the
> primary superblock,
> and IGNORING any errors on secondary superblocks. This way, we always
> insist on having
> an up-to-date primary superblock.
I don't entirely agree with this reasoning.  We absolutely should not be 
ignoring errors when writing to the primary superblock, but there is no 
reason we should be ignoring them when writing backup superblocks 
either.  Ideally, all superblocks should be up-to-date and consistent 
with each other, as we can't be certain which (if any) of them will be 
readable without errors the next time we mount the filesystem.  We can't 
really provide this consistency guarantee though, because of how modern 
storage devices work (we can't atomically update all three superblocks 
at the same time), but that doesn't mean we shouldn't retry writing a 
backup superblock if there's an error doing so the first time.
>
> diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
> index 4e47849..0ae9f7c 100644
> --- a/fs/btrfs/disk-io.c
> +++ b/fs/btrfs/disk-io.c
> @@ -3357,11 +3357,13 @@ static int write_dev_supers(struct btrfs_device
> *device,
>             bh = __find_get_block(device->bdev, bytenr / 4096,
>                           BTRFS_SUPER_INFO_SIZE);
>             if (!bh) {
> -                errors++;
> +                /* we only care about primary superblock errors */
> +                if (i == 0)
> +                    errors++;
>                 continue;
>             }
>             wait_on_buffer(bh);
> -            if (!buffer_uptodate(bh))
> +            if (!buffer_uptodate(bh) && i == 0)
>                 errors++;
>
>             /* drop our reference */
> @@ -3388,9 +3390,10 @@ static int write_dev_supers(struct btrfs_device
> *device,
>                       BTRFS_SUPER_INFO_SIZE);
>             if (!bh) {
>                 btrfs_err(device->dev_root->fs_info,
> -                    "couldn't get super buffer head for bytenr %llu",
> -                    bytenr);
> -                errors++;
> +                    "couldn't get super buffer head for bytenr %llu (sb
> copy %d)",
> +                    bytenr, i);
> +                if (i == 0)
> +                    errors++;
>                 continue;
>             }
>
> @@ -3413,10 +3416,10 @@ static int write_dev_supers(struct btrfs_device
> *device,
>             ret = btrfsic_submit_bh(WRITE_FUA, bh);
>         else
>             ret = btrfsic_submit_bh(WRITE_SYNC, bh);
> -        if (ret)
> +        if (ret && i == 0)
>             errors++;
>     }
> -    return errors < i ? 0 : -1;
> +    return errors ? -1 : 0;
> }
>
> /*
>
>
> P.S.: when reviewing the code of write_dev_supers(), I also noticed that
> when wait==0 and we hit an error in one __getblk(), then the caller
> (write_all_supers) will not properly wait for submitted buffer-heads to
> complete, and we won't do the additional "brelse(bh);", which wait==0
> case does. Is this a problem?


      reply	other threads:[~2016-05-17 12:46 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-17 11:24 [RCF - PATCH] btrfs: do not ignore errors from primary superblock Alex Lyakas
2016-05-17 12:46 ` Austin S. Hemmelgarn [this message]

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=b361ded3-c5fe-0020-35d3-856c1b9d46de@gmail.com \
    --to=ahferroin7@gmail.com \
    --cc=alex@zadarastorage.com \
    --cc=lev@zadarastorage.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=ron@zadarastorage.com \
    --cc=shyam@zadarastorage.com \
    --cc=yair@zadarastorage.com \
    --cc=yaron@zadarastorage.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).