Skip to content

Commit 7ce22a2

Browse files
adam900710kdave
authored andcommitted
btrfs-progs: mkfs: do not use extent buffer to write super block
There is a long history that we used extent_buffer helpers to modify a superblock, but we're moving out of that behavior, and migrate to use the on stack helpers to modify super blocks. In the function make_btrfs() we use a dummy extent buffer just to calculate the checksum for the super block. We do not need such workaround, and can manually call btrfs_csum_data() on @super, and pass @super directly to sbwrite(), completely avoiding the need of a dummy extent buffer. Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 46330e3 commit 7ce22a2

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

mkfs/common.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -754,12 +754,9 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
754754
}
755755

756756
/* and write out the super block */
757-
memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
758-
memcpy(buf->data, &super, sizeof(super));
759-
buf->len = BTRFS_SUPER_INFO_SIZE;
760-
csum_tree_block_size(buf, btrfs_csum_type_size(cfg->csum_type), 0,
761-
cfg->csum_type);
762-
ret = sbwrite(fd, buf->data, BTRFS_SUPER_INFO_OFFSET);
757+
btrfs_csum_data(cfg->csum_type, (u8 *)&super + BTRFS_CSUM_SIZE,
758+
super.csum, sizeof(super) - BTRFS_CSUM_SIZE);
759+
ret = sbwrite(fd, &super, BTRFS_SUPER_INFO_OFFSET);
763760
if (ret != BTRFS_SUPER_INFO_SIZE) {
764761
ret = (ret < 0 ? -errno : -EIO);
765762
goto out;

0 commit comments

Comments
 (0)