btrfs-progs: mkfs: use sbwrite to update superblock in regular and zoned mode
Use sbwrite instead of pwrite to support superblock logging in zoned mode. In addition, call fsync() to persist the superblock to ensure the write order. It also helps us to detect an unaligned write (write to a position other than the write pointer) error. Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
de677ad21d
commit
9d42778b48
|
@ -472,13 +472,16 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||
buf->len = BTRFS_SUPER_INFO_SIZE;
|
||||
csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0,
|
||||
cfg->csum_type);
|
||||
ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
|
||||
cfg->blocks[MKFS_SUPER_BLOCK]);
|
||||
ret = sbwrite(fd, buf->data, cfg->blocks[MKFS_SUPER_BLOCK]);
|
||||
if (ret != BTRFS_SUPER_INFO_SIZE) {
|
||||
ret = (ret < 0 ? -errno : -EIO);
|
||||
goto out;
|
||||
}
|
||||
|
||||
ret = fsync(fd);
|
||||
if (ret)
|
||||
goto out;
|
||||
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
|
|
Loading…
Reference in a new issue