All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/5] btrfs-progs: Cleanup open-coded btrfs_chunk_item_size
@ 2017-05-15  8:27 Qu Wenruo
  2017-05-15  8:27 ` [PATCH 2/5] btrfs-progs: Enhance chunk item validation check Qu Wenruo
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Qu Wenruo @ 2017-05-15  8:27 UTC (permalink / raw)
  To: linux-btrfs, dsterba; +Cc: hurikhan77

In btrfs_check_chunk_valid() we calculates chunk item using open code.

use btrfs_chunk_item_size() to replace them.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 volumes.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/volumes.c b/volumes.c
index b350e259..62e23aee 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1685,6 +1685,7 @@ int btrfs_check_chunk_valid(struct btrfs_root *root,
 	u16 num_stripes;
 	u16 sub_stripes;
 	u64 type;
+	u32 chunk_ondisk_size;
 
 	length = btrfs_chunk_length(leaf, chunk);
 	stripe_len = btrfs_chunk_stripe_len(leaf, chunk);
@@ -1724,16 +1725,16 @@ int btrfs_check_chunk_valid(struct btrfs_root *root,
 			BTRFS_BLOCK_GROUP_PROFILE_MASK) & type);
 		return -EIO;
 	}
+
+	chunk_ondisk_size = btrfs_chunk_item_size(num_stripes);
 	/*
 	 * Btrfs_chunk contains at least one stripe, and for sys_chunk
 	 * it can't exceed the system chunk array size
 	 * For normal chunk, it should match its chunk item size.
 	 */
 	if (num_stripes < 1 ||
-	    (slot == -1 && sizeof(struct btrfs_stripe) * num_stripes >
-	     BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) ||
-	    (slot >= 0 && sizeof(struct btrfs_stripe) * (num_stripes - 1) >
-	     btrfs_item_size_nr(leaf, slot))) {
+	    (slot == -1 && chunk_ondisk_size > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) ||
+	    (slot >= 0 && chunk_ondisk_size > btrfs_item_size_nr(leaf, slot))) {
 		error("invalid num_stripes: %u", num_stripes);
 		return -EIO;
 	}
-- 
2.12.2




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

end of thread, other threads:[~2017-05-31  2:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-05-15  8:27 [PATCH 1/5] btrfs-progs: Cleanup open-coded btrfs_chunk_item_size Qu Wenruo
2017-05-15  8:27 ` [PATCH 2/5] btrfs-progs: Enhance chunk item validation check Qu Wenruo
2017-05-29 17:39   ` David Sterba
2017-05-31  2:18     ` Qu Wenruo
2017-05-15  8:27 ` [PATCH 3/5] btrfs-progs: check: Reuse btrfs_check_chunk_valid in lowmem mode Qu Wenruo
2017-05-15  8:27 ` [PATCH 4/5] btrfs-progs: Introduce function to get correct stripe length Qu Wenruo
2017-05-15  8:27 ` [PATCH 5/5] btrfs-progs: lowmem check: Fix false alert on missing chunk or dev extent Qu Wenruo

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.