Commit 6560ec96 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

aoe: use blk_mq_alloc_disk and blk_cleanup_disk

Use blk_mq_alloc_disk and blk_cleanup_disk to simplify the gendisk and
request_queue allocation.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarChaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Link: https://lore.kernel.org/r/20210602065345.355274-17-hch@lst.deSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 08c1d480
...@@ -338,14 +338,13 @@ static const struct blk_mq_ops aoeblk_mq_ops = { ...@@ -338,14 +338,13 @@ static const struct blk_mq_ops aoeblk_mq_ops = {
.queue_rq = aoeblk_queue_rq, .queue_rq = aoeblk_queue_rq,
}; };
/* alloc_disk and add_disk can sleep */ /* blk_mq_alloc_disk and add_disk can sleep */
void void
aoeblk_gdalloc(void *vp) aoeblk_gdalloc(void *vp)
{ {
struct aoedev *d = vp; struct aoedev *d = vp;
struct gendisk *gd; struct gendisk *gd;
mempool_t *mp; mempool_t *mp;
struct request_queue *q;
struct blk_mq_tag_set *set; struct blk_mq_tag_set *set;
ulong flags; ulong flags;
int late = 0; int late = 0;
...@@ -362,19 +361,12 @@ aoeblk_gdalloc(void *vp) ...@@ -362,19 +361,12 @@ aoeblk_gdalloc(void *vp)
if (late) if (late)
return; return;
gd = alloc_disk(AOE_PARTITIONS);
if (gd == NULL) {
pr_err("aoe: cannot allocate disk structure for %ld.%d\n",
d->aoemajor, d->aoeminor);
goto err;
}
mp = mempool_create(MIN_BUFS, mempool_alloc_slab, mempool_free_slab, mp = mempool_create(MIN_BUFS, mempool_alloc_slab, mempool_free_slab,
buf_pool_cache); buf_pool_cache);
if (mp == NULL) { if (mp == NULL) {
printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%d\n", printk(KERN_ERR "aoe: cannot allocate bufpool for %ld.%d\n",
d->aoemajor, d->aoeminor); d->aoemajor, d->aoeminor);
goto err_disk; goto err;
} }
set = &d->tag_set; set = &d->tag_set;
...@@ -391,12 +383,11 @@ aoeblk_gdalloc(void *vp) ...@@ -391,12 +383,11 @@ aoeblk_gdalloc(void *vp)
goto err_mempool; goto err_mempool;
} }
q = blk_mq_init_queue(set); gd = blk_mq_alloc_disk(set, d);
if (IS_ERR(q)) { if (IS_ERR(gd)) {
pr_err("aoe: cannot allocate block queue for %ld.%d\n", pr_err("aoe: cannot allocate block queue for %ld.%d\n",
d->aoemajor, d->aoeminor); d->aoemajor, d->aoeminor);
blk_mq_free_tag_set(set); goto err_tagset;
goto err_mempool;
} }
spin_lock_irqsave(&d->lock, flags); spin_lock_irqsave(&d->lock, flags);
...@@ -405,16 +396,16 @@ aoeblk_gdalloc(void *vp) ...@@ -405,16 +396,16 @@ aoeblk_gdalloc(void *vp)
WARN_ON(d->flags & DEVFL_TKILL); WARN_ON(d->flags & DEVFL_TKILL);
WARN_ON(d->gd); WARN_ON(d->gd);
WARN_ON(d->flags & DEVFL_UP); WARN_ON(d->flags & DEVFL_UP);
blk_queue_max_hw_sectors(q, BLK_DEF_MAX_SECTORS); blk_queue_max_hw_sectors(gd->queue, BLK_DEF_MAX_SECTORS);
blk_queue_io_opt(q, SZ_2M); blk_queue_io_opt(gd->queue, SZ_2M);
d->bufpool = mp; d->bufpool = mp;
d->blkq = gd->queue = q; d->blkq = gd->queue;
q->queuedata = d;
d->gd = gd; d->gd = gd;
if (aoe_maxsectors) if (aoe_maxsectors)
blk_queue_max_hw_sectors(q, aoe_maxsectors); blk_queue_max_hw_sectors(gd->queue, aoe_maxsectors);
gd->major = AOE_MAJOR; gd->major = AOE_MAJOR;
gd->first_minor = d->sysminor; gd->first_minor = d->sysminor;
gd->minors = AOE_PARTITIONS;
gd->fops = &aoe_bdops; gd->fops = &aoe_bdops;
gd->private_data = d; gd->private_data = d;
set_capacity(gd, d->ssize); set_capacity(gd, d->ssize);
...@@ -435,10 +426,10 @@ aoeblk_gdalloc(void *vp) ...@@ -435,10 +426,10 @@ aoeblk_gdalloc(void *vp)
spin_unlock_irqrestore(&d->lock, flags); spin_unlock_irqrestore(&d->lock, flags);
return; return;
err_tagset:
blk_mq_free_tag_set(set);
err_mempool: err_mempool:
mempool_destroy(mp); mempool_destroy(mp);
err_disk:
put_disk(gd);
err: err:
spin_lock_irqsave(&d->lock, flags); spin_lock_irqsave(&d->lock, flags);
d->flags &= ~DEVFL_GD_NOW; d->flags &= ~DEVFL_GD_NOW;
......
...@@ -277,9 +277,8 @@ freedev(struct aoedev *d) ...@@ -277,9 +277,8 @@ freedev(struct aoedev *d)
if (d->gd) { if (d->gd) {
aoedisk_rm_debugfs(d); aoedisk_rm_debugfs(d);
del_gendisk(d->gd); del_gendisk(d->gd);
put_disk(d->gd); blk_cleanup_disk(d->gd);
blk_mq_free_tag_set(&d->tag_set); blk_mq_free_tag_set(&d->tag_set);
blk_cleanup_queue(d->blkq);
} }
t = d->targets; t = d->targets;
e = t + d->ntargets; e = t + d->ntargets;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment