sx8: cleanup queue and disk allocation / freeing

Make the disk/queue alloc and free helpers per-port by moving the
trivial loops into the callers.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
This commit is contained in:
Christoph Hellwig 2018-11-09 14:51:09 +01:00 committed by Jens Axboe
parent ab11fe5af1
commit cd94c9ed59
1 changed files with 46 additions and 57 deletions

View File

@ -1499,71 +1499,55 @@ static const struct blk_mq_ops carm_mq_ops = {
.queue_rq = carm_queue_rq, .queue_rq = carm_queue_rq,
}; };
static int carm_init_disks(struct carm_host *host) static int carm_init_disk(struct carm_host *host, unsigned int port_no)
{ {
unsigned int i; struct carm_port *port = &host->port[port_no];
int rc = 0;
for (i = 0; i < CARM_MAX_PORTS; i++) {
struct gendisk *disk; struct gendisk *disk;
struct request_queue *q; struct request_queue *q;
struct carm_port *port;
port = &host->port[i];
port->host = host; port->host = host;
port->port_no = i; port->port_no = port_no;
disk = alloc_disk(CARM_MINORS_PER_MAJOR); disk = alloc_disk(CARM_MINORS_PER_MAJOR);
if (!disk) { if (!disk)
rc = -ENOMEM; return -ENOMEM;
break;
}
port->disk = disk; port->disk = disk;
sprintf(disk->disk_name, DRV_NAME "/%u", sprintf(disk->disk_name, DRV_NAME "/%u",
(unsigned int) (host->id * CARM_MAX_PORTS) + i); (unsigned int)host->id * CARM_MAX_PORTS + port_no);
disk->major = host->major; disk->major = host->major;
disk->first_minor = i * CARM_MINORS_PER_MAJOR; disk->first_minor = port_no * CARM_MINORS_PER_MAJOR;
disk->fops = &carm_bd_ops; disk->fops = &carm_bd_ops;
disk->private_data = port; disk->private_data = port;
q = blk_mq_init_sq_queue(&port->tag_set, &carm_mq_ops, q = blk_mq_init_sq_queue(&port->tag_set, &carm_mq_ops,
max_queue, BLK_MQ_F_SHOULD_MERGE); max_queue, BLK_MQ_F_SHOULD_MERGE);
if (IS_ERR(q)) { if (IS_ERR(q))
rc = PTR_ERR(q); return PTR_ERR(q);
break;
}
disk->queue = q; disk->queue = q;
blk_queue_max_segments(q, CARM_MAX_REQ_SG); blk_queue_max_segments(q, CARM_MAX_REQ_SG);
blk_queue_segment_boundary(q, CARM_SG_BOUNDARY); blk_queue_segment_boundary(q, CARM_SG_BOUNDARY);
q->queuedata = port; q->queuedata = port;
return 0;
} }
return rc; static void carm_free_disk(struct carm_host *host, unsigned int port_no)
}
static void carm_free_disks(struct carm_host *host)
{ {
unsigned int i; struct carm_port *port = &host->port[port_no];
for (i = 0; i < CARM_MAX_PORTS; i++) {
struct carm_port *port = &host->port[i];
struct gendisk *disk = port->disk; struct gendisk *disk = port->disk;
if (disk) { if (!disk)
struct request_queue *q = disk->queue; return;
if (disk->flags & GENHD_FL_UP) if (disk->flags & GENHD_FL_UP)
del_gendisk(disk); del_gendisk(disk);
if (q) { if (disk->queue) {
blk_mq_free_tag_set(&port->tag_set); blk_mq_free_tag_set(&port->tag_set);
blk_cleanup_queue(q); blk_cleanup_queue(disk->queue);
} }
put_disk(disk); put_disk(disk);
} }
}
}
static int carm_init_shm(struct carm_host *host) static int carm_init_shm(struct carm_host *host)
{ {
@ -1667,9 +1651,11 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
if (host->flags & FL_DYN_MAJOR) if (host->flags & FL_DYN_MAJOR)
host->major = rc; host->major = rc;
rc = carm_init_disks(host); for (i = 0; i < CARM_MAX_PORTS; i++) {
rc = carm_init_disk(host, i);
if (rc) if (rc)
goto err_out_blkdev_disks; goto err_out_blkdev_disks;
}
pci_set_master(pdev); pci_set_master(pdev);
@ -1699,7 +1685,8 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
err_out_free_irq: err_out_free_irq:
free_irq(pdev->irq, host); free_irq(pdev->irq, host);
err_out_blkdev_disks: err_out_blkdev_disks:
carm_free_disks(host); for (i = 0; i < CARM_MAX_PORTS; i++)
carm_free_disk(host, i);
unregister_blkdev(host->major, host->name); unregister_blkdev(host->major, host->name);
err_out_free_majors: err_out_free_majors:
if (host->major == 160) if (host->major == 160)
@ -1724,6 +1711,7 @@ err_out:
static void carm_remove_one (struct pci_dev *pdev) static void carm_remove_one (struct pci_dev *pdev)
{ {
struct carm_host *host = pci_get_drvdata(pdev); struct carm_host *host = pci_get_drvdata(pdev);
unsigned int i;
if (!host) { if (!host) {
printk(KERN_ERR PFX "BUG: no host data for PCI(%s)\n", printk(KERN_ERR PFX "BUG: no host data for PCI(%s)\n",
@ -1732,7 +1720,8 @@ static void carm_remove_one (struct pci_dev *pdev)
} }
free_irq(pdev->irq, host); free_irq(pdev->irq, host);
carm_free_disks(host); for (i = 0; i < CARM_MAX_PORTS; i++)
carm_free_disk(host, i);
unregister_blkdev(host->major, host->name); unregister_blkdev(host->major, host->name);
if (host->major == 160) if (host->major == 160)
clear_bit(0, &carm_major_alloc); clear_bit(0, &carm_major_alloc);