summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJens Axboe <axboe@kernel.dk>2012-09-07 13:02:02 -0600
committerJens Axboe <axboe@kernel.dk>2012-10-04 11:04:38 +0200
commit682d2507d559486bc8a19c654a9c5d947e76a9ab (patch)
tree8792bf0c51f071944803491d58e282c56f82198c
parent3299911025b285c5b739d9fe3bceda2c0a0aa193 (diff)
null: add support for multiple devices (nr_devices option)
Use 2 by default. Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--drivers/block/null.c19
1 files changed, 14 insertions, 5 deletions
diff --git a/drivers/block/null.c b/drivers/block/null.c
index 0f4063677dae..a284d5e24556 100644
--- a/drivers/block/null.c
+++ b/drivers/block/null.c
@@ -10,6 +10,7 @@
struct nullb {
struct list_head list;
+ unsigned int index;
struct request_queue *q;
struct gendisk *disk;
struct hrtimer timer;
@@ -19,6 +20,7 @@ struct nullb {
static LIST_HEAD(nullb_list);
static struct mutex lock;
static int null_major;
+static int nullb_indexes;
struct completion_queue {
struct llist_head list;
@@ -65,6 +67,10 @@ static int bs = 512;
module_param(bs, int, S_IRUGO);
MODULE_PARM_DESC(bs, "Block size (in bytes)");
+static int nr_devices = 2;
+module_param(nr_devices, int, S_IRUGO);
+MODULE_PARM_DESC(nr_devices, "Number of devices to register");
+
static int irqmode = NULL_IRQ_SOFTIRQ;
module_param(irqmode, int, S_IRUGO);
MODULE_PARM_DESC(irqmode, "IRQ completion handler. 0-none, 1-softirq, 2-timer");
@@ -355,6 +361,7 @@ static int null_add_dev(void)
mutex_lock(&lock);
list_add_tail(&nullb->list, &nullb_list);
+ nullb->index = nullb_indexes++;
mutex_unlock(&lock);
blk_queue_logical_block_size(nullb->q, bs);
@@ -367,11 +374,11 @@ static int null_add_dev(void)
disk->flags |= GENHD_FL_EXT_DEVT;
spin_lock_init(&nullb->lock);
disk->major = null_major;
- disk->first_minor = 0;
+ disk->first_minor = nullb->index;
disk->fops = &null_fops;
disk->private_data = nullb;
disk->queue = nullb->q;
- sprintf(disk->disk_name, "nullb%d", 0);
+ sprintf(disk->disk_name, "nullb%d", nullb->index);
add_disk(disk);
return 0;
}
@@ -408,9 +415,11 @@ static int __init null_init(void)
if (null_major < 0)
return null_major;
- if (null_add_dev()) {
- unregister_blkdev(null_major, "nullb");
- return -EINVAL;
+ for (i = 0; i < nr_devices; i++) {
+ if (null_add_dev()) {
+ unregister_blkdev(null_major, "nullb");
+ return -EINVAL;
+ }
}
pr_info("null: module loaded\n");