Skip to content

Commit 3582dd2

Browse files
committed
aoe: convert aoeblk to blk-mq
Straight forward conversion - instead of rewriting the internal buffer retrieval logic, just replace the previous elevator peeking with an internal list of requests. Reviewed-by: "Ed L. Cashin" <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent e01ad46 commit 3582dd2

File tree

4 files changed

+61
-25
lines changed

4 files changed

+61
-25
lines changed

drivers/block/aoe/aoe.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
/* Copyright (c) 2013 Coraid, Inc. See COPYING for GPL terms. */
2+
#include <linux/blk-mq.h>
3+
24
#define VERSION "85"
35
#define AOE_MAJOR 152
46
#define DEVICE_NAME "aoe"
@@ -164,6 +166,8 @@ struct aoedev {
164166
struct gendisk *gd;
165167
struct dentry *debugfs;
166168
struct request_queue *blkq;
169+
struct list_head rq_list;
170+
struct blk_mq_tag_set tag_set;
167171
struct hd_geometry geo;
168172
sector_t ssize;
169173
struct timer_list timer;

drivers/block/aoe/aoeblk.c

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#include <linux/kernel.h>
88
#include <linux/hdreg.h>
9-
#include <linux/blkdev.h>
9+
#include <linux/blk-mq.h>
1010
#include <linux/backing-dev.h>
1111
#include <linux/fs.h>
1212
#include <linux/ioctl.h>
@@ -268,23 +268,25 @@ aoeblk_release(struct gendisk *disk, fmode_t mode)
268268
spin_unlock_irqrestore(&d->lock, flags);
269269
}
270270

271-
static void
272-
aoeblk_request(struct request_queue *q)
271+
static blk_status_t aoeblk_queue_rq(struct blk_mq_hw_ctx *hctx,
272+
const struct blk_mq_queue_data *bd)
273273
{
274-
struct aoedev *d;
275-
struct request *rq;
274+
struct aoedev *d = hctx->queue->queuedata;
275+
276+
spin_lock_irq(&d->lock);
276277

277-
d = q->queuedata;
278278
if ((d->flags & DEVFL_UP) == 0) {
279279
pr_info_ratelimited("aoe: device %ld.%d is not up\n",
280280
d->aoemajor, d->aoeminor);
281-
while ((rq = blk_peek_request(q))) {
282-
blk_start_request(rq);
283-
aoe_end_request(d, rq, 1);
284-
}
285-
return;
281+
spin_unlock_irq(&d->lock);
282+
blk_mq_start_request(bd->rq);
283+
return BLK_STS_IOERR;
286284
}
285+
286+
list_add_tail(&bd->rq->queuelist, &d->rq_list);
287287
aoecmd_work(d);
288+
spin_unlock_irq(&d->lock);
289+
return BLK_STS_OK;
288290
}
289291

290292
static int
@@ -339,6 +341,10 @@ static const struct block_device_operations aoe_bdops = {
339341
.owner = THIS_MODULE,
340342
};
341343

344+
static const struct blk_mq_ops aoeblk_mq_ops = {
345+
.queue_rq = aoeblk_queue_rq,
346+
};
347+
342348
/* alloc_disk and add_disk can sleep */
343349
void
344350
aoeblk_gdalloc(void *vp)
@@ -347,9 +353,11 @@ aoeblk_gdalloc(void *vp)
347353
struct gendisk *gd;
348354
mempool_t *mp;
349355
struct request_queue *q;
356+
struct blk_mq_tag_set *set;
350357
enum { KB = 1024, MB = KB * KB, READ_AHEAD = 2 * MB, };
351358
ulong flags;
352359
int late = 0;
360+
int err;
353361

354362
spin_lock_irqsave(&d->lock, flags);
355363
if (d->flags & DEVFL_GDALLOC
@@ -376,10 +384,25 @@ aoeblk_gdalloc(void *vp)
376384
d->aoemajor, d->aoeminor);
377385
goto err_disk;
378386
}
379-
q = blk_init_queue(aoeblk_request, &d->lock);
380-
if (q == NULL) {
387+
388+
set = &d->tag_set;
389+
set->ops = &aoeblk_mq_ops;
390+
set->nr_hw_queues = 1;
391+
set->queue_depth = 128;
392+
set->numa_node = NUMA_NO_NODE;
393+
set->flags = BLK_MQ_F_SHOULD_MERGE;
394+
err = blk_mq_alloc_tag_set(set);
395+
if (err) {
396+
pr_err("aoe: cannot allocate tag set for %ld.%d\n",
397+
d->aoemajor, d->aoeminor);
398+
goto err_mempool;
399+
}
400+
401+
q = blk_mq_init_queue(set);
402+
if (IS_ERR(q)) {
381403
pr_err("aoe: cannot allocate block queue for %ld.%d\n",
382404
d->aoemajor, d->aoeminor);
405+
blk_mq_free_tag_set(set);
383406
goto err_mempool;
384407
}
385408

drivers/block/aoe/aoecmd.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include <linux/ata.h>
88
#include <linux/slab.h>
99
#include <linux/hdreg.h>
10-
#include <linux/blkdev.h>
10+
#include <linux/blk-mq.h>
1111
#include <linux/skbuff.h>
1212
#include <linux/netdevice.h>
1313
#include <linux/genhd.h>
@@ -813,7 +813,7 @@ rexmit_timer(struct timer_list *timer)
813813
out:
814814
if ((d->flags & DEVFL_KICKME) && d->blkq) {
815815
d->flags &= ~DEVFL_KICKME;
816-
d->blkq->request_fn(d->blkq);
816+
blk_mq_run_hw_queues(d->blkq, true);
817817
}
818818

819819
d->timer.expires = jiffies + TIMERTICK;
@@ -857,10 +857,12 @@ nextbuf(struct aoedev *d)
857857
return d->ip.buf;
858858
rq = d->ip.rq;
859859
if (rq == NULL) {
860-
rq = blk_peek_request(q);
860+
rq = list_first_entry_or_null(&d->rq_list, struct request,
861+
queuelist);
861862
if (rq == NULL)
862863
return NULL;
863-
blk_start_request(rq);
864+
list_del_init(&rq->queuelist);
865+
blk_mq_start_request(rq);
864866
d->ip.rq = rq;
865867
d->ip.nxbio = rq->bio;
866868
rq->special = (void *) rqbiocnt(rq);
@@ -1045,18 +1047,23 @@ aoe_end_request(struct aoedev *d, struct request *rq, int fastfail)
10451047
struct bio *bio;
10461048
int bok;
10471049
struct request_queue *q;
1050+
blk_status_t err = BLK_STS_OK;
10481051

10491052
q = d->blkq;
10501053
if (rq == d->ip.rq)
10511054
d->ip.rq = NULL;
10521055
do {
10531056
bio = rq->bio;
10541057
bok = !fastfail && !bio->bi_status;
1055-
} while (__blk_end_request(rq, bok ? BLK_STS_OK : BLK_STS_IOERR, bio->bi_iter.bi_size));
1058+
if (!bok)
1059+
err = BLK_STS_IOERR;
1060+
} while (blk_update_request(rq, bok ? BLK_STS_OK : BLK_STS_IOERR, bio->bi_iter.bi_size));
1061+
1062+
__blk_mq_end_request(rq, err);
10561063

10571064
/* cf. http://lkml.org/lkml/2006/10/31/28 */
10581065
if (!fastfail)
1059-
__blk_run_queue(q);
1066+
blk_mq_run_hw_queues(q, true);
10601067
}
10611068

10621069
static void

drivers/block/aoe/aoedev.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
#include <linux/hdreg.h>
8-
#include <linux/blkdev.h>
8+
#include <linux/blk-mq.h>
99
#include <linux/netdevice.h>
1010
#include <linux/delay.h>
1111
#include <linux/slab.h>
@@ -197,7 +197,6 @@ aoedev_downdev(struct aoedev *d)
197197
{
198198
struct aoetgt *t, **tt, **te;
199199
struct list_head *head, *pos, *nx;
200-
struct request *rq;
201200
int i;
202201

203202
d->flags &= ~DEVFL_UP;
@@ -225,10 +224,11 @@ aoedev_downdev(struct aoedev *d)
225224

226225
/* fast fail all pending I/O */
227226
if (d->blkq) {
228-
while ((rq = blk_peek_request(d->blkq))) {
229-
blk_start_request(rq);
230-
aoe_end_request(d, rq, 1);
231-
}
227+
/* UP is cleared, freeze+quiesce to insure all are errored */
228+
blk_mq_freeze_queue(d->blkq);
229+
blk_mq_quiesce_queue(d->blkq);
230+
blk_mq_unquiesce_queue(d->blkq);
231+
blk_mq_unfreeze_queue(d->blkq);
232232
}
233233

234234
if (d->gd)
@@ -277,6 +277,7 @@ freedev(struct aoedev *d)
277277
aoedisk_rm_debugfs(d);
278278
del_gendisk(d->gd);
279279
put_disk(d->gd);
280+
blk_mq_free_tag_set(&d->tag_set);
280281
blk_cleanup_queue(d->blkq);
281282
}
282283
t = d->targets;
@@ -463,6 +464,7 @@ aoedev_by_aoeaddr(ulong maj, int min, int do_alloc)
463464
d->ntargets = NTARGETS;
464465
INIT_WORK(&d->work, aoecmd_sleepwork);
465466
spin_lock_init(&d->lock);
467+
INIT_LIST_HEAD(&d->rq_list);
466468
skb_queue_head_init(&d->skbpool);
467469
timer_setup(&d->timer, dummy_timer, 0);
468470
d->timer.expires = jiffies + HZ;

0 commit comments

Comments
 (0)