Skip to contentSkip to conversation

Btrfs: fix allocation size calculations in alloc_btrfs_bio

PATCH In review Chris Mason 3 participants 4 messages Feb 20, 2015 – Feb 23, 2015 Btrfs file system

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Btrfs: fix allocation size calculations in alloc_btrfs_bio

Since commit 8e5cfb55d3f (Btrfs: Make raid_map array be inlined in btrfs_bio structure), the raid map array is allocated along with the btrfs bio in alloc_btrfs_bio. The calculation used to decide how much we need to allocate was using the wrong parameter passed into the allocation function.

The passed in real_stripes will be zero if a target replace operation is not currently running. We want to use total_stripes instead.

---
 fs/btrfs/volumes.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c +8 -1
index cd4d131..8222f6f 100644
@@ -4903,10 +4903,17 @@ static void sort_parity_stripes(struct btrfs_bio *bbio, int num_stripes)
 static struct btrfs_bio *alloc_btrfs_bio(int total_stripes, int real_stripes)
 {
 	struct btrfs_bio *bbio = kzalloc(
+		 /* the size of the btrfs_bio */
 		sizeof(struct btrfs_bio) +
+		/* plus the variable array for the stripes */
 		sizeof(struct btrfs_bio_stripe) * (total_stripes) +
+		/* plus the variable array for the tgt dev */
 		sizeof(int) * (real_stripes) +
-		sizeof(u64) * (real_stripes),
+		/*
+		 * plus the raid_map, which includes both the tgt dev
+		 * and the stripes
+		 */
+		sizeof(u64) * (total_stripes),
 		GFP_NOFS);
 	if (!bbio)
 		return NULL;
Signature · 1 line
1.8.1
Tested-by on v1 1/1
#1 lore raw
Quoted 11 lines · Chris Mason

Since commit 8e5cfb55d3f (Btrfs: Make raid_map array be inlined in btrfs_bio structure), the raid map array is allocated along with the btrfs bio in alloc_btrfs_bio. The calculation used to decide how much we need to allocate was using the wrong parameter passed into the allocation function.

The passed in real_stripes will be zero if a target replace operation is not currently running. We want to use total_stripes instead.

Current master + this patch with full slub_debug is now ok with btrfs/023.

#2 lore raw
Quoted 12 lines · David Sterba
Quoted 11 lines · Chris Mason

Since commit 8e5cfb55d3f (Btrfs: Make raid_map array be inlined in btrfs_bio structure), the raid map array is allocated along with the btrfs bio in alloc_btrfs_bio. The calculation used to decide how
much
we need to allocate was using the wrong parameter passed into the allocation function.

The passed in real_stripes will be zero if a target replace
operation
is not currently running. We want to use total_stripes instead.

Quoted 7 lines
Quoted 2 lines

Current master + this patch with full slub_debug is now ok with btrfs/023.

Thanks Dave. It also survived all night with raid6 and stress.sh. I'm sending to Linus today.

-chris

#3 lore raw
In reply to Chris Mason

Hi, Chris Mason

* From: Chris Mason [mailto:[email protected]]

Quoted 4 lines

Sent: Friday, February 20, 2015 10:00 AM
To: linux-btrfs; Zhao Lei; [email protected]
Subject: [PATCH] Btrfs: fix allocation size calculations in alloc_btrfs_bio

Quoted 8 lines

Since commit 8e5cfb55d3f (Btrfs: Make raid_map array be inlined in btrfs_bio structure), the raid map array is allocated along with the btrfs bio in alloc_btrfs_bio. The calculation used to decide how much we need to allocate was using the wrong parameter passed into the allocation function.

The passed in real_stripes will be zero if a target replace operation is not currently running. We want to use total_stripes instead.

Sorry, my bad.

Thanks
Zhaolei

Quoted 32 lines
---
 fs/btrfs/volumes.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
fs/btrfs/volumes.c index cd4d131..8222f6f renamed from fs/btrfs/volumes.c +0 -0

100644

fs/btrfs/volumes.c +8 -2
@@ -4903,10 +4903,17 @@ static void sort_parity_stripes(struct btrfs_bio
 *bbio, int num_stripes)  static struct btrfs_bio *alloc_btrfs_bio(int
 total_stripes, int real_stripes)  {
 	struct btrfs_bio *bbio = kzalloc(
+		 /* the size of the btrfs_bio */
 		sizeof(struct btrfs_bio) +
+		/* plus the variable array for the stripes */
 		sizeof(struct btrfs_bio_stripe) * (total_stripes) +
+		/* plus the variable array for the tgt dev */
 		sizeof(int) * (real_stripes) +
-		sizeof(u64) * (real_stripes),
+		/*
+		 * plus the raid_map, which includes both the tgt dev
+		 * and the stripes
+		 */
+		sizeof(u64) * (total_stripes),
 		GFP_NOFS);
 	if (!bbio)
 		return NULL;
--

1.8.1