[2/5] btrfs-progs: Enhance chunk item validation check
diff mbox

Message ID 20170515082742.21363-2-quwenruo@cn.fujitsu.com
State New
Headers show

Commit Message

Qu Wenruo May 15, 2017, 8:27 a.m. UTC
btrfs_check_chunk_valid() doesn't check if
1) chunk flag has conflicting flags
   For example chunk type DATA|METADATA|RAID1|RAID10 is completely
   invalid, while current check_chunk_valid() can't detect it.
2) num_stripes is invalid for RAID10
   Num_stripes 5 is not valid for RAID10.

This patch will enhance btrfs_check_chunk_valid() to handle above cases.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
---
 volumes.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

Comments

David Sterba May 29, 2017, 5:39 p.m. UTC | #1
On Mon, May 15, 2017 at 04:27:39PM +0800, Qu Wenruo wrote:
> btrfs_check_chunk_valid() doesn't check if
> 1) chunk flag has conflicting flags
>    For example chunk type DATA|METADATA|RAID1|RAID10 is completely
>    invalid, while current check_chunk_valid() can't detect it.
> 2) num_stripes is invalid for RAID10
>    Num_stripes 5 is not valid for RAID10.
> 
> This patch will enhance btrfs_check_chunk_valid() to handle above cases.
> 
> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>

Most tests fail with this patch, mkfs or from restored images created.
Simple test-check or test-misc fails in the first test. Have I missed
some other patch or test update?
--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Qu Wenruo May 31, 2017, 2:18 a.m. UTC | #2
At 05/30/2017 01:39 AM, David Sterba wrote:
> On Mon, May 15, 2017 at 04:27:39PM +0800, Qu Wenruo wrote:
>> btrfs_check_chunk_valid() doesn't check if
>> 1) chunk flag has conflicting flags
>>     For example chunk type DATA|METADATA|RAID1|RAID10 is completely
>>     invalid, while current check_chunk_valid() can't detect it.
>> 2) num_stripes is invalid for RAID10
>>     Num_stripes 5 is not valid for RAID10.
>>
>> This patch will enhance btrfs_check_chunk_valid() to handle above cases.
>>
>> Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
> 
> Most tests fail with this patch, mkfs or from restored images created.
> Simple test-check or test-misc fails in the first test. Have I missed
> some other patch or test update?
> 
> 
Sorry, I formatted patch based on an old branch, which doesn't have the 
extra fix for single profile.

I'll update the branch and add the needed test case in next branch, 
along with infrastructure update to make loop device setup more easy to use.

Thanks,
Qu


--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch
diff mbox

diff --git a/volumes.c b/volumes.c
index 62e23aee..1e352869 100644
--- a/volumes.c
+++ b/volumes.c
@@ -1725,6 +1725,19 @@  int btrfs_check_chunk_valid(struct btrfs_root *root,
 			BTRFS_BLOCK_GROUP_PROFILE_MASK) & type);
 		return -EIO;
 	}
+	if (!(type & BTRFS_BLOCK_GROUP_TYPE_MASK)) {
+		error("missing chunk type flag: %llu", type);
+		return -EIO;
+	}
+	if (!is_power_of_2(type & BTRFS_BLOCK_GROUP_PROFILE_MASK)) {
+		error("conflicting chunk type detected: %llu", type);
+		return -EIO;
+	}
+	if ((type & BTRFS_BLOCK_GROUP_PROFILE_MASK) &&
+	    !is_power_of_2(type & BTRFS_BLOCK_GROUP_PROFILE_MASK)) {
+		error("conflicting chunk profile detected: %llu", type);
+		return -EIO;
+	}
 
 	chunk_ondisk_size = btrfs_chunk_item_size(num_stripes);
 	/*
@@ -1741,7 +1754,8 @@  int btrfs_check_chunk_valid(struct btrfs_root *root,
 	/*
 	 * Device number check against profile
 	 */
-	if ((type & BTRFS_BLOCK_GROUP_RAID10 && sub_stripes == 0) ||
+	if ((type & BTRFS_BLOCK_GROUP_RAID10 && (sub_stripes != 2 ||
+		  !IS_ALIGNED(num_stripes, sub_stripes))) ||
 	    (type & BTRFS_BLOCK_GROUP_RAID1 && num_stripes < 1) ||
 	    (type & BTRFS_BLOCK_GROUP_RAID5 && num_stripes < 2) ||
 	    (type & BTRFS_BLOCK_GROUP_RAID6 && num_stripes < 3) ||