Skip to content

Commit a38eb3d

Browse files
Johannes Thumshirnkdave
authored andcommitted
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>
1 parent b8f3290 commit a38eb3d

File tree

7 files changed

+37
-22
lines changed

7 files changed

+37
-22
lines changed

btrfs-corrupt-block.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ static void corrupt_keys(struct btrfs_trans_handle *trans,
158158
if (!trans) {
159159
u16 csum_size =
160160
btrfs_super_csum_size(fs_info->super_copy);
161-
csum_tree_block_size(eb, csum_size, 0);
161+
u16 csum_type = btrfs_super_csum_type(fs_info->super_copy);
162+
csum_tree_block_size(eb, csum_size, 0, csum_type);
162163
write_extent_to_disk(eb);
163164
}
164165
}

cmds/rescue-chunk-recover.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,8 @@ static int scan_one_device(void *dev_scan_struct)
768768
continue;
769769
}
770770

771-
if (verify_tree_block_csum_silent(buf, rc->csum_size)) {
771+
if (verify_tree_block_csum_silent(buf, rc->csum_size,
772+
rc->csum_type)) {
772773
bytenr += rc->sectorsize;
773774
continue;
774775
}

convert/common.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,8 @@ static inline int write_temp_extent_buffer(int fd, struct extent_buffer *buf,
223223
{
224224
int ret;
225225

226-
csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
226+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
227+
cfg->csum_type);
227228

228229
/* Temporary extent buffer is always mapped 1:1 on disk */
229230
ret = pwrite(fd, buf->data, buf->len, bytenr);

convert/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,8 @@ static int migrate_super_block(int fd, u64 old_bytenr)
10581058
BUG_ON(btrfs_super_bytenr(super) != old_bytenr);
10591059
btrfs_set_super_bytenr(super, BTRFS_SUPER_INFO_OFFSET);
10601060

1061-
csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0);
1061+
csum_tree_block_size(buf, btrfs_csum_sizes[BTRFS_CSUM_TYPE_CRC32], 0,
1062+
btrfs_super_csum_type(super));
10621063
ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
10631064
BTRFS_SUPER_INFO_OFFSET);
10641065
if (ret != BTRFS_SUPER_INFO_SIZE)

disk-io.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void btrfs_csum_final(u32 crc, u8 *result)
149149
}
150150

151151
static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
152-
int verify, int silent)
152+
int verify, int silent, u16 csum_type)
153153
{
154154
u8 result[BTRFS_CSUM_SIZE];
155155
u32 len;
@@ -174,24 +174,27 @@ static int __csum_tree_block_size(struct extent_buffer *buf, u16 csum_size,
174174
return 0;
175175
}
176176

177-
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_size, int verify)
177+
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_size, int verify,
178+
u16 csum_type)
178179
{
179-
return __csum_tree_block_size(buf, csum_size, verify, 0);
180+
return __csum_tree_block_size(buf, csum_size, verify, 0, csum_type);
180181
}
181182

182-
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size)
183+
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size,
184+
u16 csum_type)
183185
{
184-
return __csum_tree_block_size(buf, csum_size, 1, 1);
186+
return __csum_tree_block_size(buf, csum_size, 1, 1, csum_type);
185187
}
186188

187189
int csum_tree_block(struct btrfs_fs_info *fs_info,
188190
struct extent_buffer *buf, int verify)
189191
{
190-
u16 csum_size =
191-
btrfs_super_csum_size(fs_info->super_copy);
192+
u16 csum_size = btrfs_super_csum_size(fs_info->super_copy);
193+
u16 csum_type = btrfs_super_csum_type(fs_info->super_copy);
194+
192195
if (verify && fs_info->suppress_check_block_errors)
193-
return verify_tree_block_csum_silent(buf, csum_size);
194-
return csum_tree_block_size(buf, csum_size, verify);
196+
return verify_tree_block_csum_silent(buf, csum_size, csum_type);
197+
return csum_tree_block_size(buf, csum_size, verify, csum_type);
195198
}
196199

197200
struct extent_buffer *btrfs_find_tree_block(struct btrfs_fs_info *fs_info,

disk-io.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,9 @@ void btrfs_csum_final(u32 crc, u8 *result);
191191

192192
int btrfs_open_device(struct btrfs_device *dev);
193193
int csum_tree_block_size(struct extent_buffer *buf, u16 csum_sectorsize,
194-
int verify);
195-
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size);
194+
int verify, u16 csum_type);
195+
int verify_tree_block_csum_silent(struct extent_buffer *buf, u16 csum_size,
196+
u16 csum_type);
196197
int btrfs_read_buffer(struct extent_buffer *buf, u64 parent_transid);
197198
int write_tree_block(struct btrfs_trans_handle *trans,
198199
struct btrfs_fs_info *fs_info,

mkfs/common.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ static int btrfs_create_tree_root(int fd, struct btrfs_mkfs_config *cfg,
101101
}
102102

103103
/* generate checksum */
104-
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
104+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
105+
cfg->csum_type);
105106

106107
/* write back root tree */
107108
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)
292293
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_EXTENT_TREE]);
293294
btrfs_set_header_owner(buf, BTRFS_EXTENT_TREE_OBJECTID);
294295
btrfs_set_header_nritems(buf, nritems);
295-
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
296+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
297+
cfg->csum_type);
296298
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_EXTENT_TREE]);
297299
if (ret != cfg->nodesize) {
298300
ret = (ret < 0 ? -errno : -EIO);
@@ -380,7 +382,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
380382
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_CHUNK_TREE]);
381383
btrfs_set_header_owner(buf, BTRFS_CHUNK_TREE_OBJECTID);
382384
btrfs_set_header_nritems(buf, nritems);
383-
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
385+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
386+
cfg->csum_type);
384387
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CHUNK_TREE]);
385388
if (ret != cfg->nodesize) {
386389
ret = (ret < 0 ? -errno : -EIO);
@@ -420,7 +423,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
420423
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_DEV_TREE]);
421424
btrfs_set_header_owner(buf, BTRFS_DEV_TREE_OBJECTID);
422425
btrfs_set_header_nritems(buf, nritems);
423-
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
426+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
427+
cfg->csum_type);
424428
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_DEV_TREE]);
425429
if (ret != cfg->nodesize) {
426430
ret = (ret < 0 ? -errno : -EIO);
@@ -433,7 +437,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
433437
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_FS_TREE]);
434438
btrfs_set_header_owner(buf, BTRFS_FS_TREE_OBJECTID);
435439
btrfs_set_header_nritems(buf, 0);
436-
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
440+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
441+
cfg->csum_type);
437442
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_FS_TREE]);
438443
if (ret != cfg->nodesize) {
439444
ret = (ret < 0 ? -errno : -EIO);
@@ -445,7 +450,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
445450
btrfs_set_header_bytenr(buf, cfg->blocks[MKFS_CSUM_TREE]);
446451
btrfs_set_header_owner(buf, BTRFS_CSUM_TREE_OBJECTID);
447452
btrfs_set_header_nritems(buf, 0);
448-
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
453+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
454+
cfg->csum_type);
449455
ret = pwrite(fd, buf->data, cfg->nodesize, cfg->blocks[MKFS_CSUM_TREE]);
450456
if (ret != cfg->nodesize) {
451457
ret = (ret < 0 ? -errno : -EIO);
@@ -456,7 +462,8 @@ int make_btrfs(int fd, struct btrfs_mkfs_config *cfg)
456462
memset(buf->data, 0, BTRFS_SUPER_INFO_SIZE);
457463
memcpy(buf->data, &super, sizeof(super));
458464
buf->len = BTRFS_SUPER_INFO_SIZE;
459-
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0);
465+
csum_tree_block_size(buf, btrfs_csum_sizes[cfg->csum_type], 0,
466+
cfg->csum_type);
460467
ret = pwrite(fd, buf->data, BTRFS_SUPER_INFO_SIZE,
461468
cfg->blocks[MKFS_SUPER_BLOCK]);
462469
if (ret != BTRFS_SUPER_INFO_SIZE) {

0 commit comments

Comments
 (0)