Skip to content

Commit 53f3251

Browse files
adam900710kdave
authored andcommitted
btrfs: scrub: support subpage tree block scrub
To support subpage tree block scrub, scrub_checksum_tree_block() only needs to learn 2 new tricks: - Follow sector size Now scrub_page only represents one sector, we need to follow it properly. - Run checksum on all sectors Since scrub_page only represents one sector, we need to run checksum on all sectors, not only (nodesize >> PAGE_SIZE). Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent d0a7a9c commit 53f3251

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

fs/btrfs/scrub.c

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,12 +1811,22 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
18111811
SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
18121812
u8 calculated_csum[BTRFS_CSUM_SIZE];
18131813
u8 on_disk_csum[BTRFS_CSUM_SIZE];
1814-
const int num_pages = sctx->fs_info->nodesize >> PAGE_SHIFT;
1814+
/*
1815+
* This is done in sectorsize steps even for metadata as there's a
1816+
* constraint for nodesize to be aligned to sectorsize. This will need
1817+
* to change so we don't misuse data and metadata units like that.
1818+
*/
1819+
const u32 sectorsize = sctx->fs_info->sectorsize;
1820+
const int num_sectors = fs_info->nodesize >> fs_info->sectorsize_bits;
18151821
int i;
18161822
struct scrub_page *spage;
18171823
char *kaddr;
18181824

18191825
BUG_ON(sblock->page_count < 1);
1826+
1827+
/* Each member in pagev is just one block, not a full page */
1828+
ASSERT(sblock->page_count == num_sectors);
1829+
18201830
spage = sblock->pagev[0];
18211831
kaddr = page_address(spage->page);
18221832
h = (struct btrfs_header *)kaddr;
@@ -1845,11 +1855,11 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
18451855
shash->tfm = fs_info->csum_shash;
18461856
crypto_shash_init(shash);
18471857
crypto_shash_update(shash, kaddr + BTRFS_CSUM_SIZE,
1848-
PAGE_SIZE - BTRFS_CSUM_SIZE);
1858+
sectorsize - BTRFS_CSUM_SIZE);
18491859

1850-
for (i = 1; i < num_pages; i++) {
1860+
for (i = 1; i < num_sectors; i++) {
18511861
kaddr = page_address(sblock->pagev[i]->page);
1852-
crypto_shash_update(shash, kaddr, PAGE_SIZE);
1862+
crypto_shash_update(shash, kaddr, sectorsize);
18531863
}
18541864

18551865
crypto_shash_final(shash, calculated_csum);

0 commit comments

Comments
 (0)