Skip to contentSkip to conversation

null_blk: Remove null block from list in error path

PATCH In review Minfei Huang 3 participants 5 messages Nov 27, 2015 – Dec 14, 2015 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 null_blk: Remove null block from list in error path

To make consistent of null block list, we should remove enqueued null block from the list before freeing it.

---
 drivers/block/null_blk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/block/null_blk.c +5 -1
index ec99568..729ecd7 100644
@@ -738,7 +738,7 @@ static int null_add_dev(void)
 		rv = nvm_register(nullb->q, nullb->disk_name,
 							&null_lnvm_dev_ops);
 		if (rv)
-			goto out_cleanup_blk_queue;
+			goto out_cleanup_blk_list;
 		goto done;
 	}
 
@@ -765,6 +765,10 @@ done:
 out_cleanup_lightnvm:
 	if (use_lightnvm)
 		nvm_unregister(nullb->disk_name);
+out_cleanup_blk_list:
+	mutex_lock(&lock);
+	list_del_init(&nullb->list);
+	mutex_unlock(&lock);
 out_cleanup_blk_queue:
 	blk_cleanup_queue(nullb->q);
 out_cleanup_tags:
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 2/2 null_blk: Do a cleanup for function null_add_dev

If null block is a lightnvm device, it wouldn't need to allocate the variant disk. So it is fine to separate the code for lightnvm and normal device to use if/else.

Thus we don't never need the flag out_cleanup_lightnvm.

---
 drivers/block/null_blk.c | 42 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)
drivers/block/null_blk.c +19 -23
index 729ecd7..7d5d2e7 100644
@@ -739,32 +739,28 @@ static int null_add_dev(void)
 							&null_lnvm_dev_ops);
 		if (rv)
 			goto out_cleanup_blk_list;
-		goto done;
-	}
-
-	disk = nullb->disk = alloc_disk_node(1, home_node);
-	if (!disk) {
-		rv = -ENOMEM;
-		goto out_cleanup_lightnvm;
+	} else {
+		disk = nullb->disk = alloc_disk_node(1, home_node);
+		if (!disk) {
+			rv = -ENOMEM;
+			goto out_cleanup_blk_list;
+		}
+		size = gb * 1024 * 1024 * 1024ULL;
+		set_capacity(disk, size >> 9);
+
+		disk->flags |=
+			GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
+		disk->major		= null_major;
+		disk->first_minor	= nullb->index;
+		disk->fops		= &null_fops;
+		disk->private_data	= nullb;
+		disk->queue		= nullb->q;
+		strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
+
+		add_disk(disk);
 	}
-	size = gb * 1024 * 1024 * 1024ULL;
-	set_capacity(disk, size >> 9);
-
-	disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
-	disk->major		= null_major;
-	disk->first_minor	= nullb->index;
-	disk->fops		= &null_fops;
-	disk->private_data	= nullb;
-	disk->queue		= nullb->q;
-	strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
-
-	add_disk(disk);
-done:
 	return 0;
 
-out_cleanup_lightnvm:
-	if (use_lightnvm)
-		nvm_unregister(nullb->disk_name);
 out_cleanup_blk_list:
 	mutex_lock(&lock);
 	list_del_init(&nullb->list);
Signature · 1 line
1.8.3.1
#2 lore raw

Re: [PATCH 2/2] null_blk: Do a cleanup for function null_add_dev

Ping, Jens.

Could you have any idea about this cleanup patch?

Thanks
Minfei

Quoted 70 lines · Minfei Huang

If null block is a lightnvm device, it wouldn't need to allocate the variant disk. So it is fine to separate the code for lightnvm and normal device to use if/else.

Thus we don't never need the flag out_cleanup_lightnvm.

---
 drivers/block/null_blk.c | 42 +++++++++++++++++++-----------------------
 1 file changed, 19 insertions(+), 23 deletions(-)
drivers/block/null_blk.c +19 -23
index 729ecd7..7d5d2e7 100644
@@ -739,32 +739,28 @@ static int null_add_dev(void)
 							&null_lnvm_dev_ops);
 		if (rv)
 			goto out_cleanup_blk_list;
-		goto done;
-	}
-
-	disk = nullb->disk = alloc_disk_node(1, home_node);
-	if (!disk) {
-		rv = -ENOMEM;
-		goto out_cleanup_lightnvm;
+	} else {
+		disk = nullb->disk = alloc_disk_node(1, home_node);
+		if (!disk) {
+			rv = -ENOMEM;
+			goto out_cleanup_blk_list;
+		}
+		size = gb * 1024 * 1024 * 1024ULL;
+		set_capacity(disk, size >> 9);
+
+		disk->flags |=
+			GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
+		disk->major		= null_major;
+		disk->first_minor	= nullb->index;
+		disk->fops		= &null_fops;
+		disk->private_data	= nullb;
+		disk->queue		= nullb->q;
+		strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
+
+		add_disk(disk);
 	}
-	size = gb * 1024 * 1024 * 1024ULL;
-	set_capacity(disk, size >> 9);
-
-	disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO;
-	disk->major		= null_major;
-	disk->first_minor	= nullb->index;
-	disk->fops		= &null_fops;
-	disk->private_data	= nullb;
-	disk->queue		= nullb->q;
-	strncpy(disk->disk_name, nullb->disk_name, DISK_NAME_LEN);
-
-	add_disk(disk);
-done:
 	return 0;
 
-out_cleanup_lightnvm:
-	if (use_lightnvm)
-		nvm_unregister(nullb->disk_name);
 out_cleanup_blk_list:
 	mutex_lock(&lock);
 	list_del_init(&nullb->list);
Signature · 1 line
1.8.3.1
#3 lore raw
In reply to Minfei Huang

Ping.

Any comment is appreciate.

Thanks
Minfei

Quoted 40 lines · Minfei Huang

To make consistent of null block list, we should remove enqueued null block from the list before freeing it.

---
 drivers/block/null_blk.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/block/null_blk.c +5 -1
index ec99568..729ecd7 100644
@@ -738,7 +738,7 @@ static int null_add_dev(void)
 		rv = nvm_register(nullb->q, nullb->disk_name,
 							&null_lnvm_dev_ops);
 		if (rv)
-			goto out_cleanup_blk_queue;
+			goto out_cleanup_blk_list;
 		goto done;
 	}
 
@@ -765,6 +765,10 @@ done:
 out_cleanup_lightnvm:
 	if (use_lightnvm)
 		nvm_unregister(nullb->disk_name);
+out_cleanup_blk_list:
+	mutex_lock(&lock);
+	list_del_init(&nullb->list);
+	mutex_unlock(&lock);
 out_cleanup_blk_queue:
 	blk_cleanup_queue(nullb->q);
 out_cleanup_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/
#4 lore raw
Quoted 7 lines · Minfei Huang

Ping.

Any comment is appreciate.

Thanks
Minfei

That'll work. Thanks for fixing up my mistake.