linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/9] Scrub cleanups
@ 2020-06-01 15:23 David Sterba
  2020-06-01 15:23 ` [PATCH 1/9] btrfs: scrub: remove kmap/kunmap of pages David Sterba
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Remove kmaps, simplify the checksum calculations.

David Sterba (9):
  btrfs: scrub: remove kmap/kunmap of pages
  btrfs: scrub: unify naming of page address variables
  btrfs: scrub: simplify superblock checksum calculation
  btrfs: scrub: remove temporary csum array in scrub_checksum_super
  btrfs: scrub: clean up temporary page variables in
    scrub_checksum_super
  btrfs: scrub: simplify data block checksum calculation
  btrfs: scrub: clean up temporary page variables in scrub_checksum_data
  btrfs: scrub: simplify tree block checksum calculation
  btrfs: scrub: clean up temporary page variables in
    scrub_checksum_tree_block

 fs/btrfs/scrub.c | 151 +++++++++++++----------------------------------
 1 file changed, 42 insertions(+), 109 deletions(-)

-- 
2.25.0


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH 1/9] btrfs: scrub: remove kmap/kunmap of pages
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 2/9] btrfs: scrub: unify naming of page address variables David Sterba
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

All pages that scrub uses in the scrub_block::pagev array are allocated
with GFP_KERNEL and never part of any mapping, so kmap is not necessary,
we only need to know the page address.

In scrub_write_page_to_dev_replace we don't even need to call
flush_dcache_page because of the same reason as above.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 23 ++++++++---------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 016a025e36c7..368791b17bac 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1616,13 +1616,9 @@ static int scrub_write_page_to_dev_replace(struct scrub_block *sblock,
 	struct scrub_page *spage = sblock->pagev[page_num];
 
 	BUG_ON(spage->page == NULL);
-	if (spage->io_error) {
-		void *mapped_buffer = kmap_atomic(spage->page);
+	if (spage->io_error)
+		clear_page(page_address(spage->page));
 
-		clear_page(mapped_buffer);
-		flush_dcache_page(spage->page);
-		kunmap_atomic(mapped_buffer);
-	}
 	return scrub_add_page_to_wr_bio(sblock->sctx, spage);
 }
 
@@ -1805,7 +1801,7 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 
 	on_disk_csum = sblock->pagev[0]->csum;
 	page = sblock->pagev[0]->page;
-	buffer = kmap_atomic(page);
+	buffer = page_address(page);
 
 	len = sctx->fs_info->sectorsize;
 	index = 0;
@@ -1813,7 +1809,6 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 		u64 l = min_t(u64, len, PAGE_SIZE);
 
 		crypto_shash_update(shash, buffer, l);
-		kunmap_atomic(buffer);
 		len -= l;
 		if (len == 0)
 			break;
@@ -1821,7 +1816,7 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 		BUG_ON(index >= sblock->page_count);
 		BUG_ON(!sblock->pagev[index]->page);
 		page = sblock->pagev[index]->page;
-		buffer = kmap_atomic(page);
+		buffer = page_address(page);
 	}
 
 	crypto_shash_final(shash, csum);
@@ -1851,7 +1846,7 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 
 	BUG_ON(sblock->page_count < 1);
 	page = sblock->pagev[0]->page;
-	mapped_buffer = kmap_atomic(page);
+	mapped_buffer = page_address(page);
 	h = (struct btrfs_header *)mapped_buffer;
 	memcpy(on_disk_csum, h->csum, sctx->csum_size);
 
@@ -1883,7 +1878,6 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 		u64 l = min_t(u64, len, mapped_size);
 
 		crypto_shash_update(shash, p, l);
-		kunmap_atomic(mapped_buffer);
 		len -= l;
 		if (len == 0)
 			break;
@@ -1891,7 +1885,7 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 		BUG_ON(index >= sblock->page_count);
 		BUG_ON(!sblock->pagev[index]->page);
 		page = sblock->pagev[index]->page;
-		mapped_buffer = kmap_atomic(page);
+		mapped_buffer = page_address(page);
 		mapped_size = PAGE_SIZE;
 		p = mapped_buffer;
 	}
@@ -1925,7 +1919,7 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 
 	BUG_ON(sblock->page_count < 1);
 	page = sblock->pagev[0]->page;
-	mapped_buffer = kmap_atomic(page);
+	mapped_buffer = page_address(page);
 	s = (struct btrfs_super_block *)mapped_buffer;
 	memcpy(on_disk_csum, s->csum, sctx->csum_size);
 
@@ -1946,7 +1940,6 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 		u64 l = min_t(u64, len, mapped_size);
 
 		crypto_shash_update(shash, p, l);
-		kunmap_atomic(mapped_buffer);
 		len -= l;
 		if (len == 0)
 			break;
@@ -1954,7 +1947,7 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 		BUG_ON(index >= sblock->page_count);
 		BUG_ON(!sblock->pagev[index]->page);
 		page = sblock->pagev[index]->page;
-		mapped_buffer = kmap_atomic(page);
+		mapped_buffer = page_address(page);
 		mapped_size = PAGE_SIZE;
 		p = mapped_buffer;
 	}
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 2/9] btrfs: scrub: unify naming of page address variables
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
  2020-06-01 15:23 ` [PATCH 1/9] btrfs: scrub: remove kmap/kunmap of pages David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 3/9] btrfs: scrub: simplify superblock checksum calculation David Sterba
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

As the page mapping has been removed, rename the variables to 'kaddr'
that we use everywhere else. The type is changed to 'char *' so pointer
arithmetic works without casts.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 368791b17bac..7dc4a090db57 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1788,7 +1788,7 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 	u8 csum[BTRFS_CSUM_SIZE];
 	u8 *on_disk_csum;
 	struct page *page;
-	void *buffer;
+	char *kaddr;
 	u64 len;
 	int index;
 
@@ -1801,14 +1801,14 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 
 	on_disk_csum = sblock->pagev[0]->csum;
 	page = sblock->pagev[0]->page;
-	buffer = page_address(page);
+	kaddr = page_address(page);
 
 	len = sctx->fs_info->sectorsize;
 	index = 0;
 	for (;;) {
 		u64 l = min_t(u64, len, PAGE_SIZE);
 
-		crypto_shash_update(shash, buffer, l);
+		crypto_shash_update(shash, kaddr, l);
 		len -= l;
 		if (len == 0)
 			break;
@@ -1816,7 +1816,7 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 		BUG_ON(index >= sblock->page_count);
 		BUG_ON(!sblock->pagev[index]->page);
 		page = sblock->pagev[index]->page;
-		buffer = page_address(page);
+		kaddr = page_address(page);
 	}
 
 	crypto_shash_final(shash, csum);
@@ -1835,7 +1835,7 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 	u8 calculated_csum[BTRFS_CSUM_SIZE];
 	u8 on_disk_csum[BTRFS_CSUM_SIZE];
 	struct page *page;
-	void *mapped_buffer;
+	char *kaddr;
 	u64 mapped_size;
 	void *p;
 	u64 len;
@@ -1846,8 +1846,8 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 
 	BUG_ON(sblock->page_count < 1);
 	page = sblock->pagev[0]->page;
-	mapped_buffer = page_address(page);
-	h = (struct btrfs_header *)mapped_buffer;
+	kaddr = page_address(page);
+	h = (struct btrfs_header *)kaddr;
 	memcpy(on_disk_csum, h->csum, sctx->csum_size);
 
 	/*
@@ -1872,7 +1872,7 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 
 	len = sctx->fs_info->nodesize - BTRFS_CSUM_SIZE;
 	mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE;
-	p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE;
+	p = kaddr + BTRFS_CSUM_SIZE;
 	index = 0;
 	for (;;) {
 		u64 l = min_t(u64, len, mapped_size);
@@ -1885,9 +1885,9 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 		BUG_ON(index >= sblock->page_count);
 		BUG_ON(!sblock->pagev[index]->page);
 		page = sblock->pagev[index]->page;
-		mapped_buffer = page_address(page);
+		kaddr = page_address(page);
 		mapped_size = PAGE_SIZE;
-		p = mapped_buffer;
+		p = kaddr;
 	}
 
 	crypto_shash_final(shash, calculated_csum);
@@ -1906,7 +1906,7 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 	u8 calculated_csum[BTRFS_CSUM_SIZE];
 	u8 on_disk_csum[BTRFS_CSUM_SIZE];
 	struct page *page;
-	void *mapped_buffer;
+	char *kaddr;
 	u64 mapped_size;
 	void *p;
 	int fail_gen = 0;
@@ -1919,8 +1919,8 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 
 	BUG_ON(sblock->page_count < 1);
 	page = sblock->pagev[0]->page;
-	mapped_buffer = page_address(page);
-	s = (struct btrfs_super_block *)mapped_buffer;
+	kaddr = page_address(page);
+	s = (struct btrfs_super_block *)kaddr;
 	memcpy(on_disk_csum, s->csum, sctx->csum_size);
 
 	if (sblock->pagev[0]->logical != btrfs_super_bytenr(s))
@@ -1934,7 +1934,7 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 
 	len = BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE;
 	mapped_size = PAGE_SIZE - BTRFS_CSUM_SIZE;
-	p = ((u8 *)mapped_buffer) + BTRFS_CSUM_SIZE;
+	p = kaddr + BTRFS_CSUM_SIZE;
 	index = 0;
 	for (;;) {
 		u64 l = min_t(u64, len, mapped_size);
@@ -1947,9 +1947,9 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 		BUG_ON(index >= sblock->page_count);
 		BUG_ON(!sblock->pagev[index]->page);
 		page = sblock->pagev[index]->page;
-		mapped_buffer = page_address(page);
+		kaddr = page_address(page);
 		mapped_size = PAGE_SIZE;
-		p = mapped_buffer;
+		p = kaddr;
 	}
 
 	crypto_shash_final(shash, calculated_csum);
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 3/9] btrfs: scrub: simplify superblock checksum calculation
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
  2020-06-01 15:23 ` [PATCH 1/9] btrfs: scrub: remove kmap/kunmap of pages David Sterba
  2020-06-01 15:23 ` [PATCH 2/9] btrfs: scrub: unify naming of page address variables David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 4/9] btrfs: scrub: remove temporary csum array in scrub_checksum_super David Sterba
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

BTRFS_SUPER_INFO_SIZE is 4096, and fits to a page on all supported
architectures, so we can calculate the checksum in one go.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 31 ++++---------------------------
 1 file changed, 4 insertions(+), 27 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 7dc4a090db57..13ee43f29751 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1907,15 +1907,8 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 	u8 on_disk_csum[BTRFS_CSUM_SIZE];
 	struct page *page;
 	char *kaddr;
-	u64 mapped_size;
-	void *p;
 	int fail_gen = 0;
 	int fail_cor = 0;
-	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;
@@ -1932,27 +1925,11 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 	if (!scrub_check_fsid(s->fsid, sblock->pagev[0]))
 		++fail_cor;
 
-	len = BTRFS_SUPER_INFO_SIZE - 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);
-
-		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;
-	}
+	shash->tfm = fs_info->csum_shash;
+	crypto_shash_init(shash);
+	crypto_shash_digest(shash, kaddr + BTRFS_CSUM_SIZE,
+			BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE, calculated_csum);
 
-	crypto_shash_final(shash, calculated_csum);
 	if (memcmp(calculated_csum, on_disk_csum, sctx->csum_size))
 		++fail_cor;
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 4/9] btrfs: scrub: remove temporary csum array in scrub_checksum_super
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
                   ` (2 preceding siblings ...)
  2020-06-01 15:23 ` [PATCH 3/9] btrfs: scrub: simplify superblock checksum calculation David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 5/9] btrfs: scrub: clean up temporary page variables " David Sterba
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

The page contents with the checksum is available during the entire
function so we don't need to make a copy.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 13ee43f29751..abb39c5255d2 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1904,7 +1904,6 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
 	u8 calculated_csum[BTRFS_CSUM_SIZE];
-	u8 on_disk_csum[BTRFS_CSUM_SIZE];
 	struct page *page;
 	char *kaddr;
 	int fail_gen = 0;
@@ -1914,7 +1913,6 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 	page = sblock->pagev[0]->page;
 	kaddr = page_address(page);
 	s = (struct btrfs_super_block *)kaddr;
-	memcpy(on_disk_csum, s->csum, sctx->csum_size);
 
 	if (sblock->pagev[0]->logical != btrfs_super_bytenr(s))
 		++fail_cor;
@@ -1930,7 +1928,7 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 	crypto_shash_digest(shash, kaddr + BTRFS_CSUM_SIZE,
 			BTRFS_SUPER_INFO_SIZE - BTRFS_CSUM_SIZE, calculated_csum);
 
-	if (memcmp(calculated_csum, on_disk_csum, sctx->csum_size))
+	if (memcmp(calculated_csum, s->csum, sctx->csum_size))
 		++fail_cor;
 
 	if (fail_cor + fail_gen) {
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 5/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_super
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
                   ` (3 preceding siblings ...)
  2020-06-01 15:23 ` [PATCH 4/9] btrfs: scrub: remove temporary csum array in scrub_checksum_super David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 6/9] btrfs: scrub: simplify data block checksum calculation David Sterba
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Add proper variable for the scrub page and use it instead of repeatedly
dereferencing the other structures.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index abb39c5255d2..aecaf5c7f655 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1904,23 +1904,23 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
 	u8 calculated_csum[BTRFS_CSUM_SIZE];
-	struct page *page;
+	struct scrub_page *spage;
 	char *kaddr;
 	int fail_gen = 0;
 	int fail_cor = 0;
 
 	BUG_ON(sblock->page_count < 1);
-	page = sblock->pagev[0]->page;
-	kaddr = page_address(page);
+	spage = sblock->pagev[0];
+	kaddr = page_address(spage->page);
 	s = (struct btrfs_super_block *)kaddr;
 
-	if (sblock->pagev[0]->logical != btrfs_super_bytenr(s))
+	if (spage->logical != btrfs_super_bytenr(s))
 		++fail_cor;
 
-	if (sblock->pagev[0]->generation != btrfs_super_generation(s))
+	if (spage->generation != btrfs_super_generation(s))
 		++fail_gen;
 
-	if (!scrub_check_fsid(s->fsid, sblock->pagev[0]))
+	if (!scrub_check_fsid(s->fsid, spage))
 		++fail_cor;
 
 	shash->tfm = fs_info->csum_shash;
@@ -1941,10 +1941,10 @@ static int scrub_checksum_super(struct scrub_block *sblock)
 		++sctx->stat.super_errors;
 		spin_unlock(&sctx->stat_lock);
 		if (fail_cor)
-			btrfs_dev_stat_inc_and_print(sblock->pagev[0]->dev,
+			btrfs_dev_stat_inc_and_print(spage->dev,
 				BTRFS_DEV_STAT_CORRUPTION_ERRS);
 		else
-			btrfs_dev_stat_inc_and_print(sblock->pagev[0]->dev,
+			btrfs_dev_stat_inc_and_print(spage->dev,
 				BTRFS_DEV_STAT_GENERATION_ERRS);
 	}
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 6/9] btrfs: scrub: simplify data block checksum calculation
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
                   ` (4 preceding siblings ...)
  2020-06-01 15:23 ` [PATCH 5/9] btrfs: scrub: clean up temporary page variables " David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 7/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_data David Sterba
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

We have sectorsize same as PAGE_SIZE, the checksum can be calculated in
one go.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 24 +++---------------------
 1 file changed, 3 insertions(+), 21 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index aecaf5c7f655..16c83130d884 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1789,37 +1789,19 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 	u8 *on_disk_csum;
 	struct page *page;
 	char *kaddr;
-	u64 len;
-	int index;
 
 	BUG_ON(sblock->page_count < 1);
 	if (!sblock->pagev[0]->have_csum)
 		return 0;
 
-	shash->tfm = fs_info->csum_shash;
-	crypto_shash_init(shash);
-
 	on_disk_csum = sblock->pagev[0]->csum;
 	page = sblock->pagev[0]->page;
 	kaddr = page_address(page);
 
-	len = sctx->fs_info->sectorsize;
-	index = 0;
-	for (;;) {
-		u64 l = min_t(u64, len, PAGE_SIZE);
-
-		crypto_shash_update(shash, kaddr, 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);
-	}
+	shash->tfm = fs_info->csum_shash;
+	crypto_shash_init(shash);
+	crypto_shash_digest(shash, kaddr, PAGE_SIZE, csum);
 
-	crypto_shash_final(shash, csum);
 	if (memcmp(csum, on_disk_csum, sctx->csum_size))
 		sblock->checksum_error = 1;
 
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 7/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_data
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
                   ` (5 preceding siblings ...)
  2020-06-01 15:23 ` [PATCH 6/9] btrfs: scrub: simplify data block checksum calculation David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 8/9] btrfs: scrub: simplify tree block checksum calculation David Sterba
  2020-06-01 15:23 ` [PATCH 9/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_tree_block David Sterba
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Add proper variable for the scrub page and use it instead of repeatedly
dereferencing the other structures.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 12 +++++-------
 1 file changed, 5 insertions(+), 7 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 16c83130d884..19a64c72f38e 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1786,23 +1786,21 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 	struct btrfs_fs_info *fs_info = sctx->fs_info;
 	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
 	u8 csum[BTRFS_CSUM_SIZE];
-	u8 *on_disk_csum;
-	struct page *page;
+	struct scrub_page *spage;
 	char *kaddr;
 
 	BUG_ON(sblock->page_count < 1);
-	if (!sblock->pagev[0]->have_csum)
+	spage = sblock->pagev[0];
+	if (!spage->have_csum)
 		return 0;
 
-	on_disk_csum = sblock->pagev[0]->csum;
-	page = sblock->pagev[0]->page;
-	kaddr = page_address(page);
+	kaddr = page_address(spage->page);
 
 	shash->tfm = fs_info->csum_shash;
 	crypto_shash_init(shash);
 	crypto_shash_digest(shash, kaddr, PAGE_SIZE, csum);
 
-	if (memcmp(csum, on_disk_csum, sctx->csum_size))
+	if (memcmp(csum, spage->csum, sctx->csum_size))
 		sblock->checksum_error = 1;
 
 	return sblock->checksum_error;
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 8/9] btrfs: scrub: simplify tree block checksum calculation
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
                   ` (6 preceding siblings ...)
  2020-06-01 15:23 ` [PATCH 7/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_data David Sterba
@ 2020-06-01 15:23 ` David Sterba
  2020-06-01 15:23 ` [PATCH 9/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_tree_block David Sterba
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

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>
---
 fs/btrfs/scrub.c | 33 +++++++++------------------------
 1 file 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);
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH 9/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_tree_block
  2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
                   ` (7 preceding siblings ...)
  2020-06-01 15:23 ` [PATCH 8/9] btrfs: scrub: simplify tree block checksum calculation David Sterba
@ 2020-06-01 15:23 ` David Sterba
  8 siblings, 0 replies; 10+ messages in thread
From: David Sterba @ 2020-06-01 15:23 UTC (permalink / raw)
  To: linux-btrfs; +Cc: David Sterba

Add proper variable for the scrub page and use it instead of repeatedly
dereferencing the other structures.

Signed-off-by: David Sterba <dsterba@suse.com>
---
 fs/btrfs/scrub.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/fs/btrfs/scrub.c b/fs/btrfs/scrub.c
index 663bb2c22c50..d935ac06323f 100644
--- a/fs/btrfs/scrub.c
+++ b/fs/btrfs/scrub.c
@@ -1816,12 +1816,12 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 	u8 on_disk_csum[BTRFS_CSUM_SIZE];
 	const int num_pages = sctx->fs_info->nodesize >> PAGE_SHIFT;
 	int i;
-	struct page *page;
+	struct scrub_page *spage;
 	char *kaddr;
 
 	BUG_ON(sblock->page_count < 1);
-	page = sblock->pagev[0]->page;
-	kaddr = page_address(page);
+	spage = sblock->pagev[0];
+	kaddr = page_address(spage->page);
 	h = (struct btrfs_header *)kaddr;
 	memcpy(on_disk_csum, h->csum, sctx->csum_size);
 
@@ -1830,15 +1830,15 @@ static int scrub_checksum_tree_block(struct scrub_block *sblock)
 	 * a) don't have an extent buffer and
 	 * b) the page is already kmapped
 	 */
-	if (sblock->pagev[0]->logical != btrfs_stack_header_bytenr(h))
+	if (spage->logical != btrfs_stack_header_bytenr(h))
 		sblock->header_error = 1;
 
-	if (sblock->pagev[0]->generation != btrfs_stack_header_generation(h)) {
+	if (spage->generation != btrfs_stack_header_generation(h)) {
 		sblock->header_error = 1;
 		sblock->generation_error = 1;
 	}
 
-	if (!scrub_check_fsid(h->fsid, sblock->pagev[0]))
+	if (!scrub_check_fsid(h->fsid, spage))
 		sblock->header_error = 1;
 
 	if (memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid,
-- 
2.25.0


^ permalink raw reply related	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2020-06-01 15:23 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-01 15:23 [PATCH 0/9] Scrub cleanups David Sterba
2020-06-01 15:23 ` [PATCH 1/9] btrfs: scrub: remove kmap/kunmap of pages David Sterba
2020-06-01 15:23 ` [PATCH 2/9] btrfs: scrub: unify naming of page address variables David Sterba
2020-06-01 15:23 ` [PATCH 3/9] btrfs: scrub: simplify superblock checksum calculation David Sterba
2020-06-01 15:23 ` [PATCH 4/9] btrfs: scrub: remove temporary csum array in scrub_checksum_super David Sterba
2020-06-01 15:23 ` [PATCH 5/9] btrfs: scrub: clean up temporary page variables " David Sterba
2020-06-01 15:23 ` [PATCH 6/9] btrfs: scrub: simplify data block checksum calculation David Sterba
2020-06-01 15:23 ` [PATCH 7/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_data David Sterba
2020-06-01 15:23 ` [PATCH 8/9] btrfs: scrub: simplify tree block checksum calculation David Sterba
2020-06-01 15:23 ` [PATCH 9/9] btrfs: scrub: clean up temporary page variables in scrub_checksum_tree_block David Sterba

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).