aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShaohua Li <shli@fb.com>2017-08-14 15:04:55 -0700
committerJens Axboe <axboe@kernel.dk>2017-08-23 08:54:05 -0600
commit94bc02e30fb8d04429ecf91820abbea0eb5c4ee1 (patch)
treebac5eeec638378121c08409c9a74b9f2f83088dc
parentnullb: add interface to power on disk (diff)
downloadlinux-dev-94bc02e30fb8d04429ecf91820abbea0eb5c4ee1.tar.xz
linux-dev-94bc02e30fb8d04429ecf91820abbea0eb5c4ee1.zip
nullb: use ida to manage index
We now dynamically create disks. Managing the disk index with ida to avoid bump up the index too much. Signed-off-by: Shaohua Li <shli@fb.com> Signed-off-by: Jens Axboe <axboe@kernel.dk>
-rw-r--r--drivers/block/null_blk.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
index cf14c46d3462..2f66627d8c4b 100644
--- a/drivers/block/null_blk.c
+++ b/drivers/block/null_blk.c
@@ -87,7 +87,7 @@ struct nullb {
static LIST_HEAD(nullb_list);
static struct mutex lock;
static int null_major;
-static int nullb_indexes;
+static DEFINE_IDA(nullb_indexes);
static struct kmem_cache *ppa_cache;
static struct blk_mq_tag_set tag_set;
@@ -871,6 +871,8 @@ static void null_del_dev(struct nullb *nullb)
{
struct nullb_device *dev = nullb->dev;
+ ida_simple_remove(&nullb_indexes, nullb->index);
+
list_del_init(&nullb->list);
if (dev->use_lightnvm)
@@ -1118,7 +1120,7 @@ static int null_add_dev(struct nullb_device *dev)
queue_flag_clear_unlocked(QUEUE_FLAG_ADD_RANDOM, nullb->q);
mutex_lock(&lock);
- nullb->index = nullb_indexes++;
+ nullb->index = ida_simple_get(&nullb_indexes, 0, 0, GFP_KERNEL);
dev->index = nullb->index;
mutex_unlock(&lock);