It is not possible to write a super block copy in sequential write required zones as this prevents in-place updates required for super blocks. This patch limits super block possible locations to zones accepting random writes. In particular, the zone containing the first block of the device or partition being formatted must accept random writes. Signed-off-by: Naohiro Aota <naohiro.aota@xxxxxxx> --- disk-io.c | 10 ++++++++++ volumes.h | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/disk-io.c b/disk-io.c index be44eead5cef..5dd55723b9b7 100644 --- a/disk-io.c +++ b/disk-io.c @@ -1632,6 +1632,14 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info, BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE); btrfs_csum_final(crc, &sb->csum[0]); + if (btrfs_dev_is_sequential(device, fs_info->super_bytenr)) { + errno = EIO; + error( +"failed to write super block for devid %llu: require random write zone: %m", + device->devid); + return -EIO; + } + /* * super_copy is BTRFS_SUPER_INFO_SIZE bytes and is * zero filled, we can use it directly @@ -1660,6 +1668,8 @@ static int write_dev_supers(struct btrfs_fs_info *fs_info, bytenr = btrfs_sb_offset(i); if (bytenr + BTRFS_SUPER_INFO_SIZE > device->total_bytes) break; + if (btrfs_dev_is_sequential(device, bytenr)) + continue; btrfs_set_super_bytenr(sb, bytenr); diff --git a/volumes.h b/volumes.h index edbb0f36aa75..b5e7a07df5a8 100644 --- a/volumes.h +++ b/volumes.h @@ -319,4 +319,8 @@ int btrfs_fix_device_size(struct btrfs_fs_info *fs_info, struct btrfs_device *device); int btrfs_fix_super_size(struct btrfs_fs_info *fs_info); int btrfs_fix_device_and_super_size(struct btrfs_fs_info *fs_info); +static inline bool btrfs_dev_is_sequential(struct btrfs_device *device, u64 pos) +{ + return zone_is_sequential(&device->zone_info, pos); +} #endif -- 2.23.0