Skip to contentSkip to conversation

docs: block: null_blk: enhance document style

PATCH In review André Almeida 5 participants 17 messages Sep 11, 2019 – Sep 13, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 docs: block: null_blk: enhance document style

Use proper ReST syntax for chapters. Add more information to enhance standardization in the file and to make the rendering more homogeneous. Add a SPDX identifier. Mark single-queue mode as deprecated.

---
I've asked the file creator (Matias Bjørling <[email protected]>), and he confirmed that I could use GPL-2.0 for this file.

 Documentation/block/null_blk.rst | 33 +++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)
Documentation/block/null_blk.rst +18 -15
index 31451d80783c..edbbab2f12f8 100644
@@ -1,19 +1,16 @@
+.. SPDX-License-Identifier: GPL-2.0
+
 ========================
 Null block device driver
 ========================
 
-1. Overview
-===========
+Overview
+========
 
-The null block device (/dev/nullb*) is used for benchmarking the various
+The null block device (``/dev/nullb*``) is used for benchmarking the various
 block-layer implementations. It emulates a block device of X gigabytes in size.
-The following instances are possible:
-
-  Single-queue block-layer
-
-    - Request-based.
-    - Single submission queue per device.
-    - Implements IO scheduling algorithms (CFQ, Deadline, noop).
+It does not execute any read/write operation, just mark them as complete in
+the request queue. The following instances are possible:
 
   Multi-queue block-layer
 
@@ -27,15 +24,15 @@ The following instances are possible:
 
 All of them have a completion queue for each core in the system.
 
-2. Module parameters applicable for all instances
-=================================================
+Module parameters
+=================
 
 queue_mode=[0-2]: Default: 2-Multi-queue
   Selects which block-layer the module should instantiate with.
 
   =  ============
   0  Bio-based
-  1  Single-queue
+  1  Single-queue (deprecated)
   2  Multi-queue
   =  ============
 
@@ -67,7 +64,7 @@ irqmode=[0-2]: Default: 1-Soft-irq
 completion_nsec=[ns]: Default: 10,000ns
   Combined with irqmode=2 (timer). The time each completion event must wait.
 
-submit_queues=[1..nr_cpus]:
+submit_queues=[1..nr_cpus]: Default: 1
   The number of submission queues attached to the device driver. If unset, it
   defaults to 1. For multi-queue, it is ignored when use_per_node_hctx module
   parameter is 1.
@@ -75,9 +72,11 @@ submit_queues=[1..nr_cpus]:
 hw_queue_depth=[0..qdepth]: Default: 64
   The hardware queue depth of the device.
 
-III: Multi-queue specific parameters
+Multi-queue specific parameters
+-------------------------------
 
 use_per_node_hctx=[0/1]: Default: 0
+  Number of hardware context queues.
 
   =  =====================================================================
   0  The number of submit queues are set to the value of the submit_queues
@@ -87,6 +86,7 @@ use_per_node_hctx=[0/1]: Default: 0
   =  =====================================================================
 
 no_sched=[0/1]: Default: 0
+  Enable/disable the io scheduler.
 
   =  ======================================
   0  nullb* use default blk-mq io scheduler
@@ -94,6 +94,7 @@ no_sched=[0/1]: Default: 0
   =  ======================================
 
 blocking=[0/1]: Default: 0
+  Blocking behavior of the request queue.
 
   =  ===============================================================
   0  Register as a non-blocking blk-mq driver device.
@@ -103,6 +104,7 @@ blocking=[0/1]: Default: 0
   =  ===============================================================
 
 shared_tags=[0/1]: Default: 0
+  Sharing tags between devices.
 
   =  ================================================================
   0  Tag set is not shared.
@@ -111,6 +113,7 @@ shared_tags=[0/1]: Default: 0
   =  ================================================================
 
 zoned=[0/1]: Default: 0
+  Device is a random-access or a zoned block device.
 
   =  ======================================================================
   0  Block device is exposed as a random-access block device.
Signature · 1 line
2.23.0
#1 lore raw

PATCH 2/3 null_blk: fix module name at log message

The name of the module is "null_blk", not "null". Make pr_info() follow the pattern of pr_err() log messages.

---
 drivers/block/null_blk_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/block/null_blk_main.c +2 -2
index 99328ded60d1..7bc553ff7407 100644
@@ -1311,7 +1311,7 @@ static bool should_requeue_request(struct request *rq)
 
 static enum blk_eh_timer_return null_timeout_rq(struct request *rq, bool res)
 {
-	pr_info("null: rq %p timed out\n", rq);
+	pr_info("null_blk: rq %p timed out\n", rq);
 	blk_mq_complete_request(rq);
 	return BLK_EH_DONE;
 }
@@ -1803,7 +1803,7 @@ static int __init null_init(void)
 		}
 	}
 
-	pr_info("null: module loaded\n");
+	pr_info("null_blk: module loaded\n");
 	return 0;
 
 err_dev:
Signature · 1 line
2.23.0
#2 lore raw

Re: [PATCH 2/3] null_blk: fix module name at log message

Hi André, Jens,

Quoted 3 lines · André Almeida

The name of the module is "null_blk", not "null". Make pr_info() follow the pattern of pr_err() log messages.

Instead of doing these fixes manually, it's more consistent and smarter to use pr_fmt. There are many examples of drivers doing that.

I don't know if this patch can be dropped, and replaced with one used pr_fmt or if doesn't worth the trouble.

It would be even better to also patch Documentation/process/coding-style.rst, in particular the printing section, making a mention to pr_fmt.

Thanks,
Ezequiel

maintainer
#3 lore raw

Re: [PATCH 2/3] null_blk: fix module name at log message

Quoted 7 lines · Ezequiel Garcia

Hi André, Jens,

Quoted 3 lines · André Almeida

The name of the module is "null_blk", not "null". Make pr_info() follow the pattern of pr_err() log messages.

Quoted 8 lines

Instead of doing these fixes manually, it's more consistent and smarter to use pr_fmt. There are many examples of drivers doing that.

I don't know if this patch can be dropped, and replaced with one used pr_fmt or if doesn't worth the trouble.

It would be even better to also patch Documentation/process/coding-style.rst, in particular the printing section, making a mention to pr_fmt.

André, please address the comments in this email and from Willy. Note that the previous patch is queued up, so you'll need to make it relative to that.

Signature · 1 line
Jens Axboe
#4 lore raw

Re: [PATCH 2/3] null_blk: fix module name at log message

Quoted 14 lines · Jens Axboe
Quoted 13 lines · Ezequiel Garcia

Hi André, Jens,

Quoted 3 lines · André Almeida

The name of the module is "null_blk", not "null". Make pr_info() follow the pattern of pr_err() log messages.

Instead of doing these fixes manually, it's more consistent and smarter to use pr_fmt. There are many examples of drivers doing that.

I don't know if this patch can be dropped, and replaced with one used pr_fmt or if doesn't worth the trouble.

Quoted 7 lines
Quoted 2 lines

It would be even better to also patch Documentation/process/coding-style.rst, in particular the printing section, making a mention to pr_fmt.

André, please address the comments in this email and from Willy. Note that the previous patch is queued up, so you'll need to make it relative to that.

Ok Jens, I'll do it.

#5 lore raw

PATCH 3/3 null_blk: validated the number of devices

In reply to André Almeida

There is no sense defining a negative number of devices, so change the type to unsigned. If the number of devices is 0, it is impossible to the userspace interact with the module, so there is no reasoning in loading it.

---
 drivers/block/null_blk_main.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/block/null_blk_main.c +5 -1
index 7bc553ff7407..ab4b87677139 100644
@@ -141,7 +141,7 @@ static int g_bs = 512;
 module_param_named(bs, g_bs, int, 0444);
 MODULE_PARM_DESC(bs, "Block size (in bytes)");
 
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
 module_param(nr_devices, int, 0444);
 MODULE_PARM_DESC(nr_devices, "Number of devices to register");
 
@@ -1758,6 +1758,10 @@ static int __init null_init(void)
 		pr_err("null_blk: legacy IO path no longer available\n");
 		return -EINVAL;
 	}
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}
 	if (g_queue_mode == NULL_Q_MQ && g_use_per_node_hctx) {
 		if (g_submit_queues != nr_online_nodes) {
 			pr_warn("null_blk: submit_queues param is set to %u.\n",
Signature · 1 line
2.23.0
#6 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

drivers/block/null_blk_main.c static int g_bs = 512; · line 145

Quoted 4 lines · André Almeida
drivers/block/null_blk_main.c +1 -1
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
 module_param(nr_devices, int, 0444);

^^^ you forgot to change the module_param to match

drivers/block/null_blk_main.c static int __init null_init(void) · line 1764

Quoted 4 lines
drivers/block/null_blk_main.c +4 -0
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}

I don't think this is necessary.

#7 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

Hello Matthew,

Quoted 8 lines · Matthew Wilcox

drivers/block/null_blk_main.c static int g_bs = 512; · line 145

Quoted 4 lines · André Almeida
drivers/block/null_blk_main.c +1 -1
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
 module_param(nr_devices, int, 0444);

^^^ you forgot to change the module_param to match

Quoted 7 lines

drivers/block/null_blk_main.c static int __init null_init(void) · line 1764

Quoted 4 lines
drivers/block/null_blk_main.c +4 -0
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}

I don't think this is necessary.

Could you explain why you don't think is necessary? As I see, the module can't be used without any /dev/nullb* device, so why we should load it?

Thanks,
André

#8 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

Quoted 19 lines · André Almeida

Hello Matthew,

Quoted 8 lines · Matthew Wilcox

drivers/block/null_blk_main.c static int g_bs = 512; · line 145

Quoted 4 lines · André Almeida
drivers/block/null_blk_main.c +1 -1
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
  module_param(nr_devices, int, 0444);

^^^ you forgot to change the module_param to match

Quoted 7 lines

drivers/block/null_blk_main.c static int __init null_init(void) · line 1764

Quoted 4 lines
drivers/block/null_blk_main.c +4 -0
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}

I don't think this is necessary.

Quoted 6 lines

Could you explain why you don't think is necessary? As I see, the module can't be used without any /dev/nullb* device, so why we should load it?

Thanks,
André

I think Matthew is right here. I think module can be loaded with nr_devices=0.

Did you get a chance to test nr_device=0 condition ?

Also, did you get a chance to test this patch with all the possible conditions ?

#9 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

Quoted 23 lines · Chaitanya Kulkarni
Quoted 22 lines · André Almeida

Hello Matthew,

Quoted 8 lines · Matthew Wilcox

drivers/block/null_blk_main.c static int g_bs = 512; · line 145

Quoted 4 lines · André Almeida
drivers/block/null_blk_main.c +1 -1
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
  module_param(nr_devices, int, 0444);

^^^ you forgot to change the module_param to match

Quoted 7 lines

drivers/block/null_blk_main.c static int __init null_init(void) · line 1764

Quoted 4 lines
drivers/block/null_blk_main.c +4 -0
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}

I don't think this is necessary.

Could you explain why you don't think is necessary? As I see, the module can't be used without any /dev/nullb* device, so why we should load it?

Quoted 9 lines
Quoted 3 lines

Thanks,
André

I think Matthew is right here. I think module can be loaded with nr_devices=0.

Did you get a chance to test nr_device=0 condition ?

Yes. It says "module loaded" and lsmod shows that it is loaded indeed. But you don't have any /dev/nullb*, so you can't do much with the module.

With this patch, it refuses to load the module.

Quoted 3 lines

Also, did you get a chance to test this patch with all the possible conditions ?

I did not tested with all possible conditions, but I tested with the following ones:

* Using a negative number of devices:
- Previously, it would alloc and add a huge number of devices until the
system gets out of memory
- With module_param as uint, it will throw a "invalid for parameter
`nr_devices'" and refuse to load

* Using a range of values (1, 10, 100, 1000):
- It will works as expect, creating some /dev/nullbX accordingly with
your parameter. Works fine with and without this patch.

#10 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

Quoted 31 lines · André Almeida
Quoted 30 lines · Chaitanya Kulkarni
Quoted 19 lines · André Almeida

Hello Matthew,

Quoted 8 lines · Matthew Wilcox

drivers/block/null_blk_main.c static int g_bs = 512; · line 145

Quoted 4 lines · André Almeida
drivers/block/null_blk_main.c +1 -1
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
  module_param(nr_devices, int, 0444);

^^^ you forgot to change the module_param to match

Quoted 7 lines

drivers/block/null_blk_main.c static int __init null_init(void) · line 1764

Quoted 4 lines
drivers/block/null_blk_main.c +4 -0
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}

I don't think this is necessary.

Quoted 6 lines

Could you explain why you don't think is necessary? As I see, the module can't be used without any /dev/nullb* device, so why we should load it?

Thanks,
André

I think Matthew is right here. I think module can be loaded with nr_devices=0.

Quoted 7 lines
Quoted 2 lines

Did you get a chance to test nr_device=0 condition ?

Yes. It says "module loaded" and lsmod shows that it is loaded indeed. But you don't have any /dev/nullb*, so you can't do much with the module.

With this patch, it refuses to load the module.

Why is that an improvement? I agree it's an uninteresting thing to ask for, but I don't see a compelling need to fail the module load because of it.

Quoted 9 lines

I did not tested with all possible conditions, but I tested with the following ones:

* Using a negative number of devices:
- Previously, it would alloc and add a huge number of devices until the
system gets out of memory
- With module_param as uint, it will throw a "invalid for parameter
`nr_devices'" and refuse to load

Quoted 3 lines

* Using a range of values (1, 10, 100, 1000):
- It will works as expect, creating some /dev/nullbX accordingly with
your parameter. Works fine with and without this patch.

If you ask it to create 4 billion devices, what happens? Obviously we'll run out of dev_t at some point ...

#11 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

Quoted 35 lines · Matthew Wilcox
Quoted 34 lines · André Almeida
Quoted 32 lines · Chaitanya Kulkarni
Quoted 19 lines · André Almeida

Hello Matthew,

Quoted 8 lines · Matthew Wilcox

drivers/block/null_blk_main.c static int g_bs = 512; · line 145

Quoted 4 lines · André Almeida
drivers/block/null_blk_main.c +1 -1
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
  module_param(nr_devices, int, 0444);

^^^ you forgot to change the module_param to match

Quoted 7 lines

drivers/block/null_blk_main.c static int __init null_init(void) · line 1764

Quoted 4 lines
drivers/block/null_blk_main.c +4 -0
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}

I don't think this is necessary.

Quoted 6 lines

Could you explain why you don't think is necessary? As I see, the module can't be used without any /dev/nullb* device, so why we should load it?

Thanks,
André

I think Matthew is right here. I think module can be loaded with nr_devices=0.

Did you get a chance to test nr_device=0 condition ?

Quoted 9 lines
Quoted 4 lines

Yes. It says "module loaded" and lsmod shows that it is loaded indeed. But you don't have any /dev/nullb*, so you can't do much with the module.

With this patch, it refuses to load the module.

Why is that an improvement? I agree it's an uninteresting thing to ask for, but I don't see a compelling need to fail the module load because of it.

Indeed, failing is used when there is something wrong with the module, and this is not the case when (nr_devices == 0). I will remove this, thanks!

Quoted 16 lines
Quoted 9 lines

I did not tested with all possible conditions, but I tested with the following ones:

* Using a negative number of devices:
- Previously, it would alloc and add a huge number of devices until the
system gets out of memory
- With module_param as uint, it will throw a "invalid for parameter
`nr_devices'" and refuse to load

Quoted 3 lines

* Using a range of values (1, 10, 100, 1000):
- It will works as expect, creating some /dev/nullbX accordingly with
your parameter. Works fine with and without this patch.

If you ask it to create 4 billion devices, what happens? Obviously we'll run out of dev_t at some point ...

maintainer
#12 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

In reply to Matthew Wilcox
Quoted 35 lines · Matthew Wilcox
Quoted 34 lines · André Almeida
Quoted 32 lines · Chaitanya Kulkarni
Quoted 19 lines · André Almeida

Hello Matthew,

Quoted 8 lines · Matthew Wilcox

drivers/block/null_blk_main.c static int g_bs = 512; · line 145

Quoted 4 lines · André Almeida
drivers/block/null_blk_main.c +1 -1
-static int nr_devices = 1;
+static unsigned int nr_devices = 1;
   module_param(nr_devices, int, 0444);

^^^ you forgot to change the module_param to match

Quoted 7 lines

drivers/block/null_blk_main.c static int __init null_init(void) · line 1764

Quoted 4 lines
drivers/block/null_blk_main.c +4 -0
+	if (!nr_devices) {
+		pr_err("null_blk: invalid number of devices\n");
+		return -EINVAL;
+	}

I don't think this is necessary.

Quoted 6 lines

Could you explain why you don't think is necessary? As I see, the module can't be used without any /dev/nullb* device, so why we should load it?

Thanks,
André

I think Matthew is right here. I think module can be loaded with nr_devices=0.

Did you get a chance to test nr_device=0 condition ?

Quoted 8 lines
Quoted 4 lines

Yes. It says "module loaded" and lsmod shows that it is loaded indeed. But you don't have any /dev/nullb*, so you can't do much with the module.

With this patch, it refuses to load the module.

Why is that an improvement? I agree it's an uninteresting thing to ask for, but I don't see a compelling need to fail the module load because of it.

It also breaks the case of loading it, then setting up a new device through configfs.

Signature · 1 line
Jens Axboe
#13 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

Quoted 2 lines · Jens Axboe

It also breaks the case of loading it, then setting up a new device through configfs.

Yep, this is exactly I was asking nr_device=0 as modparam is allowed and membacked null_blk creation will fail with this check.

maintainer
#14 lore raw

Re: [PATCH 3/3] null_blk: validated the number of devices

Quoted 7 lines · Chaitanya Kulkarni
Quoted 2 lines · Jens Axboe

It also breaks the case of loading it, then setting up a new device through configfs.

Yep, this is exactly I was asking nr_device=0 as modparam is allowed and membacked null_blk creation will fail with this check.

Yeah, it's totally broken...

Signature · 1 line
Jens Axboe
maintainer
#15 lore raw
In reply to André Almeida
Quoted 3 lines · André Almeida

Use proper ReST syntax for chapters. Add more information to enhance standardization in the file and to make the rendering more homogeneous. Add a SPDX identifier. Mark single-queue mode as deprecated.

Please use a cover letter for sending block patches if there's more than one in the series.

I applied these, though rewrote the commit message for patch #3.

Signature · 1 line
Jens Axboe
#16 lore raw
Quoted 8 lines · Jens Axboe
Quoted 3 lines · André Almeida

Use proper ReST syntax for chapters. Add more information to enhance standardization in the file and to make the rendering more homogeneous. Add a SPDX identifier. Mark single-queue mode as deprecated.

Please use a cover letter for sending block patches if there's more than one in the series.

Thanks for the feedback, I'll do it for next series.

Quoted 2 lines

I applied these, though rewrote the commit message for patch #3.