diff options
author | David Sterba <dsterba@suse.com> | 2020-05-29 15:54:41 +0200 |
---|---|---|
committer | David Sterba <dsterba@suse.com> | 2020-07-27 12:55:23 +0200 |
commit | 521e1022274000af1981411673e4019d44bdea7f (patch) | |
tree | 2cf1ff525c1586c5bebb7f0a599a62f369e88406 /fs/btrfs | |
parent | d41ebef2005f3b1669da334183088668c168c74a (diff) | |
download | linux-521e1022274000af1981411673e4019d44bdea7f.tar.bz2 |
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>
Diffstat (limited to 'fs/btrfs')
-rw-r--r-- | fs/btrfs/scrub.c | 33 |
1 files changed, 9 insertions, 24 deletions
diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c index 19a64c72f38e..663bb2c22c50 100644 --- a/fs/btrfs/scrub.c +++ b/fs/btrfs/scrub.c @@ -1814,15 +1814,10 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock) SHASH_DESC_ON_STACK(shash, fs_info->csum_shash); u8 calculated_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; 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); page = sblock->pagev[0]->page; @@ -1850,24 +1845,14 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock) BTRFS_UUID_SIZE)) sblock->header_error = 1; - len = sctx->fs_info->nodesize - BTRFS_CSUM_SIZE; - mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE; - p = kaddr + BTRFS_CSUM_SIZE; - index = 0; - for (;;) { - u64 l = min_t(u64, len, mapped_size); + shash->tfm = fs_info->csum_shash; + crypto_shash_init(shash); + crypto_shash_update(shash, kaddr + BTRFS_CSUM_SIZE, + PAGE_SIZE - BTRFS_CSUM_SIZE); - crypto_shash_update(shash, p, l); - len -= l; - if (len == 0) - 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; + for (i = 1; i < num_pages; i++) { + kaddr = page_address(sblock->pagev[i]->page); + crypto_shash_update(shash, kaddr, PAGE_SIZE); } crypto_shash_final(shash, calculated_csum); |