Skip to contentSkip to conversation

blk-mg-tag: Make tag's codeflow more reasonably during initializing

PATCH In review Minfei Huang 1 participant 2 messages Nov 27, 2015 – Dec 8, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 blk-mg-tag: Make tag's codeflow more reasonably during initializing

From: Minfei Huang <[email protected]>

It might be more reasonable to cleanup all of the allocations in same function, if there is a fatal. Thus we can make function more independency to export it.

For this patch, variant tag will be allocated in blk_mq_init_tags, and it will be freed in same function, if there is an error during initializing the tag.

What the blk_mq_init_bitmap_tags does is to allocate bitmap.

---
 block/blk-mq-tag.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
block/blk-mq-tag.c +18 -12
index a07ca34..7a1d9a8 100644
@@ -596,23 +596,24 @@ static void bt_free(struct blk_mq_bitmap_tags *bt)
 	kfree(bt->bs);
 }
 
-static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
-						   int node, int alloc_policy)
+static int blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
+		int node, int alloc_policy)
 {
+	int ret = 0;
 	unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
 
 	tags->alloc_policy = alloc_policy;
 
-	if (bt_alloc(&tags->bitmap_tags, depth, node, false))
-		goto enomem;
-	if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, node, true))
-		goto enomem;
+	ret = bt_alloc(&tags->bitmap_tags, depth, node, false);
+	if (ret)
+		goto out;
 
-	return tags;
-enomem:
-	bt_free(&tags->bitmap_tags);
-	kfree(tags);
-	return NULL;
+	ret = bt_alloc(&tags->breserved_tags,
+			tags->nr_reserved_tags, node, true);
+	if (ret)
+		bt_free(&tags->bitmap_tags);
+out:
+	return ret;
 }
 
 struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
@@ -638,7 +639,12 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
 	tags->nr_tags = total_tags;
 	tags->nr_reserved_tags = reserved_tags;
 
-	return blk_mq_init_bitmap_tags(tags, node, alloc_policy);
+	if (blk_mq_init_bitmap_tags(tags, node, alloc_policy)) {
+		kfree(tags);
+		return NULL;
+	}
+
+	return tags;
 }
 
 void blk_mq_free_tags(struct blk_mq_tags *tags)
Signature · 1 line
1.8.3.1
#1 lore raw

Ping.

Any comment is appreciate.

Thanks
Minfei

Quoted 79 lines · Minfei Huang

From: Minfei Huang <[email protected]>

It might be more reasonable to cleanup all of the allocations in same function, if there is a fatal. Thus we can make function more independency to export it.

For this patch, variant tag will be allocated in blk_mq_init_tags, and it will be freed in same function, if there is an error during initializing the tag.

What the blk_mq_init_bitmap_tags does is to allocate bitmap.

---
 block/blk-mq-tag.c | 30 ++++++++++++++++++------------
 1 file changed, 18 insertions(+), 12 deletions(-)
block/blk-mq-tag.c +18 -12
index a07ca34..7a1d9a8 100644
@@ -596,23 +596,24 @@ static void bt_free(struct blk_mq_bitmap_tags *bt)
 	kfree(bt->bs);
 }
 
-static struct blk_mq_tags *blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
-						   int node, int alloc_policy)
+static int blk_mq_init_bitmap_tags(struct blk_mq_tags *tags,
+		int node, int alloc_policy)
 {
+	int ret = 0;
 	unsigned int depth = tags->nr_tags - tags->nr_reserved_tags;
 
 	tags->alloc_policy = alloc_policy;
 
-	if (bt_alloc(&tags->bitmap_tags, depth, node, false))
-		goto enomem;
-	if (bt_alloc(&tags->breserved_tags, tags->nr_reserved_tags, node, true))
-		goto enomem;
+	ret = bt_alloc(&tags->bitmap_tags, depth, node, false);
+	if (ret)
+		goto out;
 
-	return tags;
-enomem:
-	bt_free(&tags->bitmap_tags);
-	kfree(tags);
-	return NULL;
+	ret = bt_alloc(&tags->breserved_tags,
+			tags->nr_reserved_tags, node, true);
+	if (ret)
+		bt_free(&tags->bitmap_tags);
+out:
+	return ret;
 }
 
 struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
@@ -638,7 +639,12 @@ struct blk_mq_tags *blk_mq_init_tags(unsigned int total_tags,
 	tags->nr_tags = total_tags;
 	tags->nr_reserved_tags = reserved_tags;
 
-	return blk_mq_init_bitmap_tags(tags, node, alloc_policy);
+	if (blk_mq_init_bitmap_tags(tags, node, alloc_policy)) {
+		kfree(tags);
+		return NULL;
+	}
+
+	return tags;
 }
 
 void blk_mq_free_tags(struct blk_mq_tags *tags)
Signature · 7 lines
1.8.3.1

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/