Skip to content

Commit

Permalink
sunvdc: use blk_mq_alloc_disk
Browse files Browse the repository at this point in the history
Use the blk_mq_alloc_disk API to simplify the gendisk and request_queue
allocation.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Link: https://lore.kernel.org/r/20210602065345.355274-14-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and Jens Axboe committed Jun 11, 2021
1 parent 51fbfed commit afea05a
Showing 1 changed file with 13 additions and 34 deletions.
47 changes: 13 additions & 34 deletions drivers/block/sunvdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -780,27 +780,6 @@ static const struct blk_mq_ops vdc_mq_ops = {
.queue_rq = vdc_queue_rq,
};

static void cleanup_queue(struct request_queue *q)
{
struct vdc_port *port = q->queuedata;

blk_cleanup_queue(q);
blk_mq_free_tag_set(&port->tag_set);
}

static struct request_queue *init_queue(struct vdc_port *port)
{
struct request_queue *q;

q = blk_mq_init_sq_queue(&port->tag_set, &vdc_mq_ops, VDC_TX_RING_SIZE,
BLK_MQ_F_SHOULD_MERGE);
if (IS_ERR(q))
return q;

q->queuedata = port;
return q;
}

static int probe_disk(struct vdc_port *port)
{
struct request_queue *q;
Expand Down Expand Up @@ -838,21 +817,21 @@ static int probe_disk(struct vdc_port *port)
(u64)geom.num_sec);
}

q = init_queue(port);
if (IS_ERR(q)) {
printk(KERN_ERR PFX "%s: Could not allocate queue.\n",
port->vio.name);
return PTR_ERR(q);
}
g = alloc_disk(1 << PARTITION_SHIFT);
if (!g) {
err = blk_mq_alloc_sq_tag_set(&port->tag_set, &vdc_mq_ops,
VDC_TX_RING_SIZE, BLK_MQ_F_SHOULD_MERGE);
if (err)
return err;

g = blk_mq_alloc_disk(&port->tag_set, port);
if (IS_ERR(g)) {
printk(KERN_ERR PFX "%s: Could not allocate gendisk.\n",
port->vio.name);
cleanup_queue(q);
return -ENOMEM;
blk_mq_free_tag_set(&port->tag_set);
return PTR_ERR(g);
}

port->disk = g;
q = g->queue;

/* Each segment in a request is up to an aligned page in size. */
blk_queue_segment_boundary(q, PAGE_SIZE - 1);
Expand All @@ -862,6 +841,7 @@ static int probe_disk(struct vdc_port *port)
blk_queue_max_hw_sectors(q, port->max_xfer_size);
g->major = vdc_major;
g->first_minor = port->vio.vdev->dev_no << PARTITION_SHIFT;
g->minors = 1 << PARTITION_SHIFT;
strcpy(g->disk_name, port->disk_name);

g->fops = &vdc_fops;
Expand Down Expand Up @@ -1083,9 +1063,8 @@ static int vdc_port_remove(struct vio_dev *vdev)
del_timer_sync(&port->vio.timer);

del_gendisk(port->disk);
cleanup_queue(port->disk->queue);
put_disk(port->disk);
port->disk = NULL;
blk_cleanup_disk(port->disk);
blk_mq_free_tag_set(&port->tag_set);

vdc_free_tx_ring(port);
vio_ldc_free(&port->vio);
Expand Down

0 comments on commit afea05a

Please sign in to comment.