btrfs-progs: Don't BUG_ON() when write_dev_supers() fails
diff mbox series

Message ID 20190411053015.5857-1-wqu@suse.com
State New
Headers show
Series
  • btrfs-progs: Don't BUG_ON() when write_dev_supers() fails
Related show

Commit Message

Qu Wenruo April 11, 2019, 5:30 a.m. UTC
[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.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 disk-io.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Nikolay Borisov April 11, 2019, 6:17 a.m. UTC | #1
On 11.04.19 г. 8:30 ч., 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.

Not entirely true. btrfs_commit_transaction calls write_ctree_super and
ignores the retval (which is the retval of write_all_supers). I wonder
if there is anything more that could be done in this context though?

I'm in favor of removing the BUG_ON though. If there isn't anything else
to do in btrfs_commit_transaction:

Reviewed-by: Nikolay Borisov <nborisov@suse.com>

> 
> Signed-off-by: Qu Wenruo <wqu@suse.com>
> ---
>  disk-io.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/disk-io.c b/disk-io.c
> index 10550151c5bb..3517de3d8672 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;
>  }
>

Patch
diff mbox series

diff --git a/disk-io.c b/disk-io.c
index 10550151c5bb..3517de3d8672 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;
 }