mirror of
https://github.com/kdave/btrfs-progs
synced 2025-05-10 20:07:55 +00:00
btrfs-progs: add checksum type to checksumming functions
Add the checksum type to csum_tree_block_size(), __csum_tree_block_size() and verify_tree_block_csum_silent(). Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
b8f3290fe6
commit
a38eb3d426
@ -158,7 +158,8 @@ static void corrupt_keys(struct btrfs_trans_handle *trans,
|
|||||||
if (!trans) {
|
if (!trans) {
|
||||||
u16 csum_size =
|
u16 csum_size =
|
||||||
btrfs_super_csum_size(fs_info->super_copy);
|
btrfs_super_csum_size(fs_info->super_copy);
|
||||||
csum_tree_block_size(eb, csum_size, 0);
|
u16 csum_type = btrfs_super_csum_type(fs_info->super_copy);
|
||||||
|
csum_tree_block_size(eb, csum_size, 0, csum_type);
|
||||||
write_extent_to_disk(eb);
|
write_extent_to_disk(eb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -768,7 +768,8 @@ static int scan_one_device(void *dev_scan_struct)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verify_tree_block_csum_silent(buf, rc->csum_size)) {
|
if (verify_tree_block_csum_silent(buf, rc->csum_size,
|
||||||
|
rc->csum_type)) {
|
||||||
bytenr += rc->sectorsize;
|
bytenr += rc->sectorsize;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -223,7 +223,8 @@ static inline int write_temp_extent_buffer(int fd, struct extent_buffer *buf,
|
|||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
|
|
||||||
/* Temporary extent buffer is always mapped 1:1 on disk */
|
/* Temporary extent buffer is always mapped 1:1 on disk */
|
||||||
ret = pwrite(fd, buf->data, buf->len, bytenr);
|
ret = pwrite(fd, buf->data, buf->len, bytenr);
|
||||||
|
@ -1058,7 +1058,8 @@ static int migrate_super_block(int fd, u64 old_bytenr)
|
|||||||
BUG_ON(btrfs_super_bytenr(super) != old_bytenr);
|
BUG_ON(btrfs_super_bytenr(super) != old_bytenr);
|
||||||
btrfs_set_super_bytenr(super, BTRFS_SUPER_INFO_OFFSET);
|
btrfs_set_super_bytenr(super, BTRFS_SUPER_INFO_OFFSET);
|
||||||
|
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0,
|
||||||
|
btrfs_super_csum_type(super));
|
||||||
ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
|
ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
|
||||||
BTRFS_SUPER_INFO_OFFSET);
|
BTRFS_SUPER_INFO_OFFSET);
|
||||||
if (ret != BTRFS_SUPER_INFO_SIZE)
|
if (ret != BTRFS_SUPER_INFO_SIZE)
|
||||||
|
21
disk-io.c
21
disk-io.c
@ -149,7 +149,7 @@ void btrfs_csum_final(u32 crc, u8 *result)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
|
static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
|
||||||
int verify, int silent)
|
int verify, int silent, u16 csum_type)
|
||||||
{
|
{
|
||||||
u8 result[BTRFS_CSUM_SIZE];
|
u8 result[BTRFS_CSUM_SIZE];
|
||||||
u32 len;
|
u32 len;
|
||||||
@ -174,24 +174,27 @@ static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_size, int verify)
|
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_size, int verify,
|
||||||
|
u16 csum_type)
|
||||||
{
|
{
|
||||||
return __csum_tree_block_size(buf, csum_size, verify, 0);
|
return __csum_tree_block_size(buf, csum_size, verify, 0, csum_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size)
|
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size,
|
||||||
|
u16 csum_type)
|
||||||
{
|
{
|
||||||
return __csum_tree_block_size(buf, csum_size, 1, 1);
|
return __csum_tree_block_size(buf, csum_size, 1, 1, csum_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
int csum_tree_block(struct btrfs_fs_info *fs_info,
|
int csum_tree_block(struct btrfs_fs_info *fs_info,
|
||||||
struct extent_buffer *buf, int verify)
|
struct extent_buffer *buf, int verify)
|
||||||
{
|
{
|
||||||
u16 csum_size =
|
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
|
||||||
btrfs_super_csum_size(fs_info->super_copy);
|
u16 csum_type = btrfs_super_csum_type(fs_info->super_copy);
|
||||||
|
|
||||||
if (verify && fs_info->suppress_check_block_errors)
|
if (verify && fs_info->suppress_check_block_errors)
|
||||||
return verify_tree_block_csum_silent(buf, csum_size);
|
return verify_tree_block_csum_silent(buf, csum_size, csum_type);
|
||||||
return csum_tree_block_size(buf, csum_size, verify);
|
return csum_tree_block_size(buf, csum_size, verify, csum_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
|
struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,
|
||||||
|
@ -191,8 +191,9 @@ void btrfs_csum_final(u32 crc, u8 *result);
|
|||||||
|
|
||||||
int btrfs_open_device(struct btrfs_device *dev);
|
int btrfs_open_device(struct btrfs_device *dev);
|
||||||
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_sectorsize,
|
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_sectorsize,
|
||||||
int verify);
|
int verify, u16 csum_type);
|
||||||
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size);
|
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size,
|
||||||
|
u16 csum_type);
|
||||||
int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid);
|
int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid);
|
||||||
int write_tree_block(struct btrfs_trans_handle *trans,
|
int write_tree_block(struct btrfs_trans_handle *trans,
|
||||||
struct btrfs_fs_info *fs_info,
|
struct btrfs_fs_info *fs_info,
|
||||||
|
@ -101,7 +101,8 @@ static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* generate checksum */
|
/* generate checksum */
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
|
|
||||||
/* write back root tree */
|
/* write back root tree */
|
||||||
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_ROOT_TREE]);
|
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_ROOT_TREE]);
|
||||||
@ -292,7 +293,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||||||
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_EXTENT_TREE]);
|
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_EXTENT_TREE]);
|
||||||
btrfs_set_header_owner(buf, BTRFS_EXTENT_TREE_OBJECTID);
|
btrfs_set_header_owner(buf, BTRFS_EXTENT_TREE_OBJECTID);
|
||||||
btrfs_set_header_nritems(buf, nritems);
|
btrfs_set_header_nritems(buf, nritems);
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_EXTENT_TREE]);
|
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_EXTENT_TREE]);
|
||||||
if (ret != cfg->nodesize) {
|
if (ret != cfg->nodesize) {
|
||||||
ret = (ret < 0 ? -errno : -EIO);
|
ret = (ret < 0 ? -errno : -EIO);
|
||||||
@ -380,7 +382,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||||||
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_CHUNK_TREE]);
|
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_CHUNK_TREE]);
|
||||||
btrfs_set_header_owner(buf, BTRFS_CHUNK_TREE_OBJECTID);
|
btrfs_set_header_owner(buf, BTRFS_CHUNK_TREE_OBJECTID);
|
||||||
btrfs_set_header_nritems(buf, nritems);
|
btrfs_set_header_nritems(buf, nritems);
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CHUNK_TREE]);
|
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CHUNK_TREE]);
|
||||||
if (ret != cfg->nodesize) {
|
if (ret != cfg->nodesize) {
|
||||||
ret = (ret < 0 ? -errno : -EIO);
|
ret = (ret < 0 ? -errno : -EIO);
|
||||||
@ -420,7 +423,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||||||
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_DEV_TREE]);
|
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_DEV_TREE]);
|
||||||
btrfs_set_header_owner(buf, BTRFS_DEV_TREE_OBJECTID);
|
btrfs_set_header_owner(buf, BTRFS_DEV_TREE_OBJECTID);
|
||||||
btrfs_set_header_nritems(buf, nritems);
|
btrfs_set_header_nritems(buf, nritems);
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_DEV_TREE]);
|
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_DEV_TREE]);
|
||||||
if (ret != cfg->nodesize) {
|
if (ret != cfg->nodesize) {
|
||||||
ret = (ret < 0 ? -errno : -EIO);
|
ret = (ret < 0 ? -errno : -EIO);
|
||||||
@ -433,7 +437,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||||||
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_FS_TREE]);
|
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_FS_TREE]);
|
||||||
btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
|
btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
|
||||||
btrfs_set_header_nritems(buf, 0);
|
btrfs_set_header_nritems(buf, 0);
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_FS_TREE]);
|
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_FS_TREE]);
|
||||||
if (ret != cfg->nodesize) {
|
if (ret != cfg->nodesize) {
|
||||||
ret = (ret < 0 ? -errno : -EIO);
|
ret = (ret < 0 ? -errno : -EIO);
|
||||||
@ -445,7 +450,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||||||
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_CSUM_TREE]);
|
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_CSUM_TREE]);
|
||||||
btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
|
btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
|
||||||
btrfs_set_header_nritems(buf, 0);
|
btrfs_set_header_nritems(buf, 0);
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CSUM_TREE]);
|
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CSUM_TREE]);
|
||||||
if (ret != cfg->nodesize) {
|
if (ret != cfg->nodesize) {
|
||||||
ret = (ret < 0 ? -errno : -EIO);
|
ret = (ret < 0 ? -errno : -EIO);
|
||||||
@ -456,7 +462,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
|
|||||||
memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
|
memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
|
||||||
memcpy(buf->data, &super, sizeof(super));
|
memcpy(buf->data, &super, sizeof(super));
|
||||||
buf->len = BTRFS_SUPER_INFO_SIZE;
|
buf->len = BTRFS_SUPER_INFO_SIZE;
|
||||||
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
|
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
|
||||||
|
cfg->csum_type);
|
||||||
ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
|
ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
|
||||||
cfg->blocks[MKFS_SUPER_BLOCK]);
|
cfg->blocks[MKFS_SUPER_BLOCK]);
|
||||||
if (ret != BTRFS_SUPER_INFO_SIZE) {
|
if (ret != BTRFS_SUPER_INFO_SIZE) {
|
||||||
|
Loading…
Reference in New Issue
Block a user