linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nikolay Borisov <nborisov@suse.com>
To: Qu Wenruo <wqu@suse.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH v2] btrfs-progs: Don't BUG_ON() when write_dev_supers() fails
Date: Thu, 11 Apr 2019 13:53:33 +0300	[thread overview]
Message-ID: <a94bde2a-04cb-1d80-03fb-760b01ba3f66@suse.com> (raw)
In-Reply-To: <20190411095742.13482-1-wqu@suse.com>



On 11.04.19 г. 12:57 ч., Qu Wenruo wrote:
> [BUG]
> Since commit "btrfs-progs: disk-io: Flush to ensure super block write is
> FUA" mkfs-tests/017 will fail like:
> 
>   ====== RUN MUSTFAIL /home/adam/btrfs-progs/mkfs.btrfs -K -f /dev/mapper/btrfs-progs-thin-vol
>   ERROR: failed to write super block for devid 1: flush error: Input/output error
>   disk-io.c:1810: write_all_supers: BUG_ON `ret` triggered, value -5
>   /home/adam/btrfs-progs/mkfs.btrfs(+0x1e5c1)[0x557a2c83e5c1]
>   /home/adam/btrfs-progs/mkfs.btrfs(+0x1e65f)[0x557a2c83e65f]
>   /home/adam/btrfs-progs/mkfs.btrfs(write_all_supers+0x1ce)[0x557a2c843a8a]
>   /home/adam/btrfs-progs/mkfs.btrfs(write_ctree_super+0x12d)[0x557a2c843be2]
>   /home/adam/btrfs-progs/mkfs.btrfs(btrfs_commit_transaction+0x250)[0x557a2c887c56]
>   /home/adam/btrfs-progs/mkfs.btrfs(+0xc0b1)[0x557a2c82c0b1]
>   /home/adam/btrfs-progs/mkfs.btrfs(main+0x1049)[0x557a2c82e929]
>   /usr/lib/libc.so.6(__libc_start_main+0xf3)[0x7f6689e99223]
>   /home/adam/btrfs-progs/mkfs.btrfs(_start+0x2e)[0x557a2c82b86e]
>   failed (expected): /home/adam/btrfs-progs/mkfs.btrfs -K -f /dev/mapper/btrfs-progs-thin-vol
> 
> [CAUSE]
> Just one BUG_ON() in write_all_supers().
> 
> [FIX]
> Just remove the BUG_ON(). Callers of write_all_supers() are already
> checking the return value.
> 
> Also since write_all_supers() can return error, make write_ctree_super()
> callers, btrfs_commit_transaction() and close_ctree_fs_info() to
> handle the error correctly.
> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
> Changelog:
> v2:
> - Make write_ctree_super() callers to handle the error properly
> ---
>  disk-io.c     | 16 ++++++++++------
>  transaction.c |  2 +-
>  2 files changed, 11 insertions(+), 7 deletions(-)
> 
> diff --git a/disk-io.c b/disk-io.c
> index 10550151c5bb..a3aa8b29f2a3 100644
> --- a/disk-io.c
> +++ b/disk-io.c
> @@ -1807,7 +1807,8 @@ int write_all_supers(struct btrfs_fs_info *fs_info)
>  		btrfs_set_super_flags(sb, flags | BTRFS_HEADER_FLAG_WRITTEN);
>  
>  		ret = write_dev_supers(fs_info, sb, dev);
> -		BUG_ON(ret);
> +		if (ret < 0)
> +			return ret;
>  	}
>  	return 0;
>  }
> @@ -1863,17 +1864,20 @@ int close_ctree_fs_info(struct btrfs_fs_info *fs_info)
>  		BUG_ON(ret);
>  		ret = __commit_transaction(trans, root);
>  		BUG_ON(ret);
> -		write_ctree_super(trans);
> +		ret = write_ctree_super(trans);
>  		kfree(trans);

if (ret) {
     err = ret;
     goto skip_commit
}

>  	}
>  
>  	if (fs_info->finalize_on_close) {
>  		btrfs_set_super_magic(fs_info->super_copy, BTRFS_MAGIC);
>  		root->fs_info->finalize_on_close = 0;
> -		ret = write_all_supers(fs_info);
> -		if (ret)
> -			fprintf(stderr,
> -				"failed to write new super block err %d\n", ret);
> +		if (!ret) {
> +			ret = write_all_supers(fs_info);
> +			if (ret)
> +				fprintf(stderr,
> +				"failed to write new super block err %d\n",
> +					ret);
> +		}

And you won't have to touch this code at all.

>  	}
>  
>  skip_commit:
> diff --git a/transaction.c b/transaction.c
> index e756db332fec..3a63988b0969 100644
> --- a/transaction.c
> +++ b/transaction.c
> @@ -197,7 +197,7 @@ commit_tree:
>  	__commit_transaction(trans, root);
>  	if (ret < 0)
>  		goto out;
> -	write_ctree_super(trans);
> +	ret = write_ctree_super(trans);
>  	btrfs_finish_extent_commit(trans, fs_info->extent_root,
>  			           &fs_info->pinned_extents);
>  	kfree(trans);
> 

      reply	other threads:[~2019-04-11 10:53 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-11  9:57 [PATCH v2] btrfs-progs: Don't BUG_ON() when write_dev_supers() fails Qu Wenruo
2019-04-11 10:53 ` Nikolay Borisov [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=a94bde2a-04cb-1d80-03fb-760b01ba3f66@suse.com \
    --to=nborisov@suse.com \
    --cc=linux-btrfs@vger.kernel.org \
    --cc=wqu@suse.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).