btrfs: scrub: simplify tree block checksum calculation
Use a simpler iteration over tree block pages, same what csum_tree_block does: first page always exists, loop over the rest. Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
d41ebef200
commit
521e102227
@ -1814,15 +1814,10 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
|
|||||||
SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
|
SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
|
||||||
u8 calculated_csum[BTRFS_CSUM_SIZE];
|
u8 calculated_csum[BTRFS_CSUM_SIZE];
|
||||||
u8 on_disk_csum[BTRFS_CSUM_SIZE];
|
u8 on_disk_csum[BTRFS_CSUM_SIZE];
|
||||||
|
const int num_pages = sctx->fs_info->nodesize >> PAGE_SHIFT;
|
||||||
|
int i;
|
||||||
struct page *page;
|
struct page *page;
|
||||||
char *kaddr;
|
char *kaddr;
|
||||||
u64 mapped_size;
|
|
||||||
void *p;
|
|
||||||
u64 len;
|
|
||||||
int index;
|
|
||||||
|
|
||||||
shash->tfm = fs_info->csum_shash;
|
|
||||||
crypto_shash_init(shash);
|
|
||||||
|
|
||||||
BUG_ON(sblock->page_count < 1);
|
BUG_ON(sblock->page_count < 1);
|
||||||
page = sblock->pagev[0]->page;
|
page = sblock->pagev[0]->page;
|
||||||
@ -1850,24 +1845,14 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
|
|||||||
BTRFS_UUID_SIZE))
|
BTRFS_UUID_SIZE))
|
||||||
sblock->header_error = 1;
|
sblock->header_error = 1;
|
||||||
|
|
||||||
len = sctx->fs_info->nodesize - BTRFS_CSUM_SIZE;
|
shash->tfm = fs_info->csum_shash;
|
||||||
mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE;
|
crypto_shash_init(shash);
|
||||||
p = kaddr + BTRFS_CSUM_SIZE;
|
crypto_shash_update(shash, kaddr + BTRFS_CSUM_SIZE,
|
||||||
index = 0;
|
PAGE_SIZE - BTRFS_CSUM_SIZE);
|
||||||
for (;;) {
|
|
||||||
u64 l = min_t(u64, len, mapped_size);
|
|
||||||
|
|
||||||
crypto_shash_update(shash, p, l);
|
for (i = 1; i < num_pages; i++) {
|
||||||
len -= l;
|
kaddr = page_address(sblock->pagev[i]->page);
|
||||||
if (len == 0)
|
crypto_shash_update(shash, kaddr, PAGE_SIZE);
|
||||||
break;
|
|
||||||
index++;
|
|
||||||
BUG_ON(index >= sblock->page_count);
|
|
||||||
BUG_ON(!sblock->pagev[index]->page);
|
|
||||||
page = sblock->pagev[index]->page;
|
|
||||||
kaddr = page_address(page);
|
|
||||||
mapped_size = PAGE_SIZE;
|
|
||||||
p = kaddr;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
crypto_shash_final(shash, calculated_csum);
|
crypto_shash_final(shash, calculated_csum);
|
||||||
|
Loading…
Reference in New Issue
Block a user