Skip to contentSkip to conversation

cleanups btrfs_extent_readonly() and scrub, part1

PATCH In review Anand Jain 3 participants 13 messages Feb 11, 2021 – Feb 25, 2021 Btrfs file system

lore
Share & tools
lore

Anand Jain

author
#0 lore raw

cover cleanups btrfs_extent_readonly() and scrub, part1

This patchset makes btrfs_extent_readonly() static and changes the return type to bool.
And drops few unwanted function declarations in the scrub.c.

Thanks. Anand

Anand Jain (5):
btrfs: make btrfs_extent_readonly() static
btrfs: btrfs_extent_readonly() change return type to bool
btrfs: scrub drop few function declarations
btrfs: scrub_checksum_tree_block() drop its function declaration
btrfs: scrub_checksum_data() drop its function declaration

 fs/btrfs/ctree.h       |   1 -
 fs/btrfs/extent-tree.c |  13 ---
 fs/btrfs/inode.c       |  13 +++
 fs/btrfs/scrub.c       | 202 ++++++++++++++++++++---------------------
 4 files changed, 109 insertions(+), 120 deletions(-)
Signature · 1 line
2.27.0
author
#1 lore raw

PATCH 1/5 btrfs: make btrfs_extent_readonly() static

btrfs_extent_readonly() is used by can_nocow_extent() in inode.c. So move btrfs_extent_readonly() from extent-tree.c to inode.c and declare it as static.

---
 fs/btrfs/ctree.h       |  1 -
 fs/btrfs/extent-tree.c | 13 -------------
 fs/btrfs/inode.c       | 13 +++++++++++++
 3 files changed, 13 insertions(+), 14 deletions(-)
fs/btrfs/ctree.h +0 -1
index 40ec3393d2a1..df9dfb322ab4 100644
@@ -2691,7 +2691,6 @@ int btrfs_finish_extent_commit(struct btrfs_trans_handle *trans);
 int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
 			 struct btrfs_ref *generic_ref);
 
-int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr);
 void btrfs_clear_space_info_full(struct btrfs_fs_info *info);
 
 /*
fs/btrfs/extent-tree.c +0 -13
index 78ad31a59e59..5e228d6ad63f 100644
@@ -2490,19 +2490,6 @@ int btrfs_dec_ref(struct btrfs_trans_handle *trans, struct btrfs_root *root,
 	return __btrfs_mod_ref(trans, root, buf, full_backref, 0);
 }
 
-int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
-{
-	struct btrfs_block_group *block_group;
-	int readonly = 0;
-
-	block_group = btrfs_lookup_block_group(fs_info, bytenr);
-	if (!block_group || block_group->ro)
-		readonly = 1;
-	if (block_group)
-		btrfs_put_block_group(block_group);
-	return readonly;
-}
-
 static u64 get_alloc_profile_by_root(struct btrfs_root *root, int data)
 {
 	struct btrfs_fs_info *fs_info = root->fs_info;
fs/btrfs/inode.c +13 -0
index 6303034a7e7b..2ed7d736e39a 100644
@@ -7256,6 +7256,19 @@ static struct extent_map *btrfs_new_extent_direct(struct btrfs_inode *inode,
 	return em;
 }
 
+static int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
+{
+	struct btrfs_block_group *block_group;
+	int readonly = 0;
+
+	block_group = btrfs_lookup_block_group(fs_info, bytenr);
+	if (!block_group || block_group->ro)
+		readonly = 1;
+	if (block_group)
+		btrfs_put_block_group(block_group);
+	return readonly;
+}
+
 /*
  * Check if we can do nocow write into the range [@offset, @offset + @len)
  *
Signature · 1 line
2.27.0
author
#2 lore raw

PATCH 2/5 btrfs: btrfs_extent_readonly() change return type to bool

In reply to Anand Jain

btrfs_extent_readonly() checks if the bg is readonly, the bool return type will suffice its need.

---
 fs/btrfs/inode.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
fs/btrfs/inode.c +3 -3
index 2ed7d736e39a..ebb2b8e3a71c 100644
@@ -7256,14 +7256,14 @@ static struct extent_map *btrfs_new_extent_direct(struct btrfs_inode *inode,
 	return em;
 }
 
-static int btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
+static bool btrfs_extent_readonly(struct btrfs_fs_info *fs_info, u64 bytenr)
 {
 	struct btrfs_block_group *block_group;
-	int readonly = 0;
+	bool readonly = false;
 
 	block_group = btrfs_lookup_block_group(fs_info, bytenr);
 	if (!block_group || block_group->ro)
-		readonly = 1;
+		readonly = true;
 	if (block_group)
 		btrfs_put_block_group(block_group);
 	return readonly;
Signature · 1 line
2.27.0
author
#4 lore raw

PATCH 3/5 btrfs: scrub drop few function declarations

In reply to Anand Jain

Drop function declarations at the beginning of the file scrub.c. These functions are defined before they are used in the same file.

No functional changes.

---
 fs/btrfs/scrub.c | 8 --------
 1 file changed, 8 deletions(-)
fs/btrfs/scrub.c +0 -8
index 70a90ca2c8da..029477dd77de 100644
@@ -206,9 +206,6 @@ struct full_stripe_lock {
 	struct mutex mutex;
 };
 
-static void scrub_pending_bio_inc(struct scrub_ctx *sctx);
-static void scrub_pending_bio_dec(struct scrub_ctx *sctx);
-static int scrub_handle_errored_block(struct scrub_block *sblock_to_check);
 static int scrub_setup_recheck_block(struct scrub_block *original_sblock,
 				     struct scrub_block *sblocks_for_recheck);
 static void scrub_recheck_block(struct btrfs_fs_info *fs_info,
@@ -226,14 +223,11 @@ static int scrub_write_page_to_dev_replace(struct scrub_block *sblock,
 static int scrub_checksum_data(struct scrub_block *sblock);
 static int scrub_checksum_tree_block(struct scrub_block *sblock);
 static int scrub_checksum_super(struct scrub_block *sblock);
-static void scrub_block_get(struct scrub_block *sblock);
 static void scrub_block_put(struct scrub_block *sblock);
 static void scrub_page_get(struct scrub_page *spage);
 static void scrub_page_put(struct scrub_page *spage);
 static void scrub_parity_get(struct scrub_parity *sparity);
 static void scrub_parity_put(struct scrub_parity *sparity);
-static int scrub_add_page_to_rd_bio(struct scrub_ctx *sctx,
-				    struct scrub_page *spage);
 static int scrub_pages(struct scrub_ctx *sctx, u64 logical, u32 len,
 		       u64 physical, struct btrfs_device *dev, u64 flags,
 		       u64 gen, int mirror_num, u8 *csum,
@@ -251,8 +245,6 @@ static int scrub_add_page_to_wr_bio(struct scrub_ctx *sctx,
 static void scrub_wr_submit(struct scrub_ctx *sctx);
 static void scrub_wr_bio_end_io(struct bio *bio);
 static void scrub_wr_bio_end_io_worker(struct btrfs_work *work);
-static void __scrub_blocked_if_needed(struct btrfs_fs_info *fs_info);
-static void scrub_blocked_if_needed(struct btrfs_fs_info *fs_info);
 static void scrub_put_ctx(struct scrub_ctx *sctx);
 
 static inline int scrub_is_page_on_raid56(struct scrub_page *spage)
Signature · 1 line
2.27.0
author
#6 lore raw

PATCH 4/5 btrfs: scrub_checksum_tree_block() drop its function declaration

In reply to Anand Jain

Move the static function scrub_checksum_tree_block() before its use in the scrub.c, and drop its declaration.

No functional changes.

---
 fs/btrfs/scrub.c | 133 +++++++++++++++++++++++------------------------
 1 file changed, 66 insertions(+), 67 deletions(-)
fs/btrfs/scrub.c +66 -67
index 029477dd77de..bc335dd6a54f 100644
@@ -221,7 +221,6 @@ static void scrub_write_block_to_dev_replace(struct scrub_block *sblock);
 static int scrub_write_page_to_dev_replace(struct scrub_block *sblock,
 					   int page_num);
 static int scrub_checksum_data(struct scrub_block *sblock);
-static int scrub_checksum_tree_block(struct scrub_block *sblock);
 static int scrub_checksum_super(struct scrub_block *sblock);
 static void scrub_block_put(struct scrub_block *sblock);
 static void scrub_page_get(struct scrub_page *spage);
@@ -1506,6 +1505,72 @@ static inline int scrub_check_fsid(u8 fsid[],
 	return !ret;
 }
 
+static int scrub_checksum_tree_block(struct scrub_block *sblock)
+{
+	struct scrub_ctx *sctx = sblock->sctx;
+	struct btrfs_header *h;
+	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];
+	/*
+	 * This is done in sectorsize steps even for metadata as there's a
+	 * constraint for nodesize to be aligned to sectorsize. This will need
+	 * to change so we don't misuse data and metadata units like that.
+	 */
+	const u32 sectorsize = sctx->fs_info->sectorsize;
+	const int num_sectors = fs_info->nodesize >> fs_info->sectorsize_bits;
+	int i;
+	struct scrub_page *spage;
+	char *kaddr;
+
+	BUG_ON(sblock->page_count < 1);
+
+	/* Each member in pagev is just one block, not a full page */
+	ASSERT(sblock->page_count == num_sectors);
+
+	spage = sblock->pagev[0];
+	kaddr = page_address(spage->page);
+	h = (struct btrfs_header *)kaddr;
+	memcpy(on_disk_csum, h->csum, sctx->fs_info->csum_size);
+
+	/*
+	 * we don't use the getter functions here, as we
+	 * a) don't have an extent buffer and
+	 * b) the page is already kmapped
+	 */
+	if (spage->logical != btrfs_stack_header_bytenr(h))
+		sblock->header_error = 1;
+
+	if (spage->generation != btrfs_stack_header_generation(h)) {
+		sblock->header_error = 1;
+		sblock->generation_error = 1;
+	}
+
+	if (!scrub_check_fsid(h->fsid, spage))
+		sblock->header_error = 1;
+
+	if (memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid,
+		   BTRFS_UUID_SIZE))
+		sblock->header_error = 1;
+
+	shash->tfm = fs_info->csum_shash;
+	crypto_shash_init(shash);
+	crypto_shash_update(shash, kaddr + BTRFS_CSUM_SIZE,
+			    sectorsize - BTRFS_CSUM_SIZE);
+
+	for (i = 1; i < num_sectors; i++) {
+		kaddr = page_address(sblock->pagev[i]->page);
+		crypto_shash_update(shash, kaddr, sectorsize);
+	}
+
+	crypto_shash_final(shash, calculated_csum);
+	if (memcmp(calculated_csum, on_disk_csum, sctx->fs_info->csum_size))
+		sblock->checksum_error = 1;
+
+	return sblock->header_error || sblock->checksum_error;
+}
+
 static void scrub_recheck_block_checksum(struct scrub_block *sblock)
 {
 	sblock->header_error = 0;
@@ -1835,72 +1900,6 @@ static int scrub_checksum_data(struct scrub_block *sblock)
 	return sblock->checksum_error;
 }
 
-static int scrub_checksum_tree_block(struct scrub_block *sblock)
-{
-	struct scrub_ctx *sctx = sblock->sctx;
-	struct btrfs_header *h;
-	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];
-	/*
-	 * This is done in sectorsize steps even for metadata as there's a
-	 * constraint for nodesize to be aligned to sectorsize. This will need
-	 * to change so we don't misuse data and metadata units like that.
-	 */
-	const u32 sectorsize = sctx->fs_info->sectorsize;
-	const int num_sectors = fs_info->nodesize >> fs_info->sectorsize_bits;
-	int i;
-	struct scrub_page *spage;
-	char *kaddr;
-
-	BUG_ON(sblock->page_count < 1);
-
-	/* Each member in pagev is just one block, not a full page */
-	ASSERT(sblock->page_count == num_sectors);
-
-	spage = sblock->pagev[0];
-	kaddr = page_address(spage->page);
-	h = (struct btrfs_header *)kaddr;
-	memcpy(on_disk_csum, h->csum, sctx->fs_info->csum_size);
-
-	/*
-	 * we don't use the getter functions here, as we
-	 * a) don't have an extent buffer and
-	 * b) the page is already kmapped
-	 */
-	if (spage->logical != btrfs_stack_header_bytenr(h))
-		sblock->header_error = 1;
-
-	if (spage->generation != btrfs_stack_header_generation(h)) {
-		sblock->header_error = 1;
-		sblock->generation_error = 1;
-	}
-
-	if (!scrub_check_fsid(h->fsid, spage))
-		sblock->header_error = 1;
-
-	if (memcmp(h->chunk_tree_uuid, fs_info->chunk_tree_uuid,
-		   BTRFS_UUID_SIZE))
-		sblock->header_error = 1;
-
-	shash->tfm = fs_info->csum_shash;
-	crypto_shash_init(shash);
-	crypto_shash_update(shash, kaddr + BTRFS_CSUM_SIZE,
-			    sectorsize - BTRFS_CSUM_SIZE);
-
-	for (i = 1; i < num_sectors; i++) {
-		kaddr = page_address(sblock->pagev[i]->page);
-		crypto_shash_update(shash, kaddr, sectorsize);
-	}
-
-	crypto_shash_final(shash, calculated_csum);
-	if (memcmp(calculated_csum, on_disk_csum, sctx->fs_info->csum_size))
-		sblock->checksum_error = 1;
-
-	return sblock->header_error || sblock->checksum_error;
-}
-
 static int scrub_checksum_super(struct scrub_block *sblock)
 {
 	struct btrfs_super_block *s;
Signature · 1 line
2.27.0
#8 lore raw

Re: [PATCH 4/5] btrfs: scrub_checksum_tree_block() drop its function declaration

In reply to Anand Jain
Quoted 4 lines · Anand Jain

Move the static function scrub_checksum_tree_block() before its use in the scrub.c, and drop its declaration.

No functional changes.

We've rejected patches that move static function within one file unless there's another reason for it other than removing the prototype.

author
#9 lore raw

Re: [PATCH 4/5] btrfs: scrub_checksum_tree_block() drop its function declaration

Quoted 9 lines · David Sterba
Quoted 4 lines · Anand Jain

Move the static function scrub_checksum_tree_block() before its use in the scrub.c, and drop its declaration.

No functional changes.

We've rejected patches that move static function within one file unless there's another reason for it other than removing the prototype.

Ok.
Patches 1-3 aren't of this type. I suppose they will be integrated?

Thanks, Anand

#10 lore raw

Re: [PATCH 4/5] btrfs: scrub_checksum_tree_block() drop its function declaration

Quoted 5 lines · Anand Jain
Quoted 4 lines · David Sterba
Quoted 3 lines · Anand Jain

Move the static function scrub_checksum_tree_block() before its use in the scrub.c, and drop its declaration.

Quoted 8 lines
Quoted 5 lines
Quoted 1 line

No functional changes.

We've rejected patches that move static function within one file unless there's another reason for it other than removing the prototype.

Ok.
Patches 1-3 aren't of this type. I suppose they will be integrated?

Yes, they're good cleanups and now in misc-next, thanks.

author
#11 lore raw

PATCH 5/5 btrfs: scrub_checksum_data() drop its function declaration

In reply to Anand Jain

Move scrub_checksum_data() before its use, and drop its declaration.

No functional changes.

---
 fs/btrfs/scrub.c | 61 ++++++++++++++++++++++++------------------------
 1 file changed, 30 insertions(+), 31 deletions(-)
fs/btrfs/scrub.c +30 -31
index bc335dd6a54f..62ea81eded03 100644
@@ -220,7 +220,6 @@ static int scrub_repair_page_from_good_copy(struct scrub_block *sblock_bad,
 static void scrub_write_block_to_dev_replace(struct scrub_block *sblock);
 static int scrub_write_page_to_dev_replace(struct scrub_block *sblock,
 					   int page_num);
-static int scrub_checksum_data(struct scrub_block *sblock);
 static int scrub_checksum_super(struct scrub_block *sblock);
 static void scrub_block_put(struct scrub_block *sblock);
 static void scrub_page_get(struct scrub_page *spage);
@@ -1505,6 +1504,36 @@ static inline int scrub_check_fsid(u8 fsid[],
 	return !ret;
 }
 
+static int scrub_checksum_data(struct scrub_block *sblock)
+{
+	struct scrub_ctx *sctx = sblock->sctx;
+	struct btrfs_fs_info *fs_info = sctx->fs_info;
+	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
+	u8 csum[BTRFS_CSUM_SIZE];
+	struct scrub_page *spage;
+	char *kaddr;
+
+	BUG_ON(sblock->page_count < 1);
+	spage = sblock->pagev[0];
+	if (!spage->have_csum)
+		return 0;
+
+	kaddr = page_address(spage->page);
+
+	shash->tfm = fs_info->csum_shash;
+	crypto_shash_init(shash);
+
+	/*
+	 * In scrub_pages() and scrub_pages_for_parity() we ensure each spage
+	 * only contains one sector of data.
+	 */
+	crypto_shash_digest(shash, kaddr, fs_info->sectorsize, csum);
+
+	if (memcmp(csum, spage->csum, fs_info->csum_size))
+		sblock->checksum_error = 1;
+	return sblock->checksum_error;
+}
+
 static int scrub_checksum_tree_block(struct scrub_block *sblock)
 {
 	struct scrub_ctx *sctx = sblock->sctx;
@@ -1870,36 +1899,6 @@ static int scrub_checksum(struct scrub_block *sblock)
 	return ret;
 }
 
-static int scrub_checksum_data(struct scrub_block *sblock)
-{
-	struct scrub_ctx *sctx = sblock->sctx;
-	struct btrfs_fs_info *fs_info = sctx->fs_info;
-	SHASH_DESC_ON_STACK(shash, fs_info->csum_shash);
-	u8 csum[BTRFS_CSUM_SIZE];
-	struct scrub_page *spage;
-	char *kaddr;
-
-	BUG_ON(sblock->page_count < 1);
-	spage = sblock->pagev[0];
-	if (!spage->have_csum)
-		return 0;
-
-	kaddr = page_address(spage->page);
-
-	shash->tfm = fs_info->csum_shash;
-	crypto_shash_init(shash);
-
-	/*
-	 * In scrub_pages() and scrub_pages_for_parity() we ensure each spage
-	 * only contains one sector of data.
-	 */
-	crypto_shash_digest(shash, kaddr, fs_info->sectorsize, csum);
-
-	if (memcmp(csum, spage->csum, fs_info->csum_size))
-		sblock->checksum_error = 1;
-	return sblock->checksum_error;
-}
-
 static int scrub_checksum_super(struct scrub_block *sblock)
 {
 	struct btrfs_super_block *s;
Signature · 1 line
2.27.0