Commit cd94c9ed authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

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: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent ab11fe5a
......@@ -1499,70 +1499,54 @@ static const struct blk_mq_ops carm_mq_ops = {
.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;
int rc = 0;
for (i = 0; i < CARM_MAX_PORTS; i++) {
struct carm_port *port = &host->port[port_no];
struct gendisk *disk;
struct request_queue *q;
struct carm_port *port;
port = &host->port[i];
port->host = host;
port->port_no = i;
port->port_no = port_no;
disk = alloc_disk(CARM_MINORS_PER_MAJOR);
if (!disk) {
rc = -ENOMEM;
break;
}
if (!disk)
return -ENOMEM;
port->disk = disk;
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->first_minor = i * CARM_MINORS_PER_MAJOR;
disk->first_minor = port_no * CARM_MINORS_PER_MAJOR;
disk->fops = &carm_bd_ops;
disk->private_data = port;
q = blk_mq_init_sq_queue(&port->tag_set, &carm_mq_ops,
max_queue, BLK_MQ_F_SHOULD_MERGE);
if (IS_ERR(q)) {
rc = PTR_ERR(q);
break;
}
if (IS_ERR(q))
return PTR_ERR(q);
disk->queue = q;
blk_queue_max_segments(q, CARM_MAX_REQ_SG);
blk_queue_segment_boundary(q, CARM_SG_BOUNDARY);
q->queuedata = port;
}
return rc;
return 0;
}
static void carm_free_disks(struct carm_host *host)
static void carm_free_disk(struct carm_host *host, unsigned int port_no)
{
unsigned int i;
for (i = 0; i < CARM_MAX_PORTS; i++) {
struct carm_port *port = &host->port[i];
struct carm_port *port = &host->port[port_no];
struct gendisk *disk = port->disk;
if (disk) {
struct request_queue *q = disk->queue;
if (!disk)
return;
if (disk->flags & GENHD_FL_UP)
del_gendisk(disk);
if (q) {
if (disk->queue) {
blk_mq_free_tag_set(&port->tag_set);
blk_cleanup_queue(q);
blk_cleanup_queue(disk->queue);
}
put_disk(disk);
}
}
}
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)
host->major = rc;
rc = carm_init_disks(host);
for (i = 0; i < CARM_MAX_PORTS; i++) {
rc = carm_init_disk(host, i);
if (rc)
goto err_out_blkdev_disks;
}
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:
free_irq(pdev->irq, host);
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);
err_out_free_majors:
if (host->major == 160)
......@@ -1724,6 +1711,7 @@ static int carm_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
static void carm_remove_one (struct pci_dev *pdev)
{
struct carm_host *host = pci_get_drvdata(pdev);
unsigned int i;
if (!host) {
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);
carm_free_disks(host);
for (i = 0; i < CARM_MAX_PORTS; i++)
carm_free_disk(host, i);
unregister_blkdev(host->major, host->name);
if (host->major == 160)
clear_bit(0, &carm_major_alloc);
......
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