aboutsummaryrefslogtreecommitdiffstats
path: root/block
diff options
context:
space:
mode:
authorMing Lei <tom.leiming@gmail.com>2014-05-27 11:35:13 -0400
committerJens Axboe <axboe@fb.com>2014-05-27 11:37:06 -0400
commit624dbe47541643b72868a59b2c0059bb53dc923f (patch)
treea76bcab29780e3cf73b80e81de2e912904436ab9 /block
parent1f9f07e917f43af420f8cb3afc2b3fa703cea6e9 (diff)
blk-mq: avoid code duplication
blk_mq_exit_hw_queues() and blk_mq_free_hw_queues() are introduced to avoid code duplication. Signed-off-by: Ming Lei <tom.leiming@gmail.com> Signed-off-by: Jens Axboe <axboe@fb.com>
Diffstat (limited to 'block')
-rw-r--r--block/blk-mq.c61
1 files changed, 37 insertions, 24 deletions
diff --git a/block/blk-mq.c b/block/blk-mq.c
index dad22a9abe49..07851753a049 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -1523,11 +1523,43 @@ static int blk_mq_hctx_notify(void *data, unsigned long action,
1523 return NOTIFY_OK; 1523 return NOTIFY_OK;
1524} 1524}
1525 1525
1526static void blk_mq_exit_hw_queues(struct request_queue *q,
1527 struct blk_mq_tag_set *set, int nr_queue)
1528{
1529 struct blk_mq_hw_ctx *hctx;
1530 unsigned int i;
1531
1532 queue_for_each_hw_ctx(q, hctx, i) {
1533 if (i == nr_queue)
1534 break;
1535
1536 if (set->ops->exit_hctx)
1537 set->ops->exit_hctx(hctx, i);
1538
1539 blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);
1540 kfree(hctx->ctxs);
1541 blk_mq_free_bitmap(&hctx->ctx_map);
1542 }
1543
1544}
1545
1546static void blk_mq_free_hw_queues(struct request_queue *q,
1547 struct blk_mq_tag_set *set)
1548{
1549 struct blk_mq_hw_ctx *hctx;
1550 unsigned int i;
1551
1552 queue_for_each_hw_ctx(q, hctx, i) {
1553 free_cpumask_var(hctx->cpumask);
1554 set->ops->free_hctx(hctx, i);
1555 }
1556}
1557
1526static int blk_mq_init_hw_queues(struct request_queue *q, 1558static int blk_mq_init_hw_queues(struct request_queue *q,
1527 struct blk_mq_tag_set *set) 1559 struct blk_mq_tag_set *set)
1528{ 1560{
1529 struct blk_mq_hw_ctx *hctx; 1561 struct blk_mq_hw_ctx *hctx;
1530 unsigned int i, j; 1562 unsigned int i;
1531 1563
1532 /* 1564 /*
1533 * Initialize hardware queues 1565 * Initialize hardware queues
@@ -1579,17 +1611,7 @@ static int blk_mq_init_hw_queues(struct request_queue *q,
1579 /* 1611 /*
1580 * Init failed 1612 * Init failed
1581 */ 1613 */
1582 queue_for_each_hw_ctx(q, hctx, j) { 1614 blk_mq_exit_hw_queues(q, set, i);
1583 if (i == j)
1584 break;
1585
1586 if (set->ops->exit_hctx)
1587 set->ops->exit_hctx(hctx, j);
1588
1589 blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);
1590 kfree(hctx->ctxs);
1591 blk_mq_free_bitmap(&hctx->ctx_map);
1592 }
1593 1615
1594 return 1; 1616 return 1;
1595} 1617}
@@ -1838,21 +1860,12 @@ EXPORT_SYMBOL(blk_mq_init_queue);
1838 1860
1839void blk_mq_free_queue(struct request_queue *q) 1861void blk_mq_free_queue(struct request_queue *q)
1840{ 1862{
1841 struct blk_mq_hw_ctx *hctx; 1863 struct blk_mq_tag_set *set = q->tag_set;
1842 int i;
1843 1864
1844 blk_mq_del_queue_tag_set(q); 1865 blk_mq_del_queue_tag_set(q);
1845 1866
1846 queue_for_each_hw_ctx(q, hctx, i) { 1867 blk_mq_exit_hw_queues(q, set, set->nr_hw_queues);
1847 blk_mq_tag_idle(hctx); 1868 blk_mq_free_hw_queues(q, set);
1848 kfree(hctx->ctxs);
1849 blk_mq_free_bitmap(&hctx->ctx_map);
1850 blk_mq_unregister_cpu_notifier(&hctx->cpu_notifier);
1851 if (q->mq_ops->exit_hctx)
1852 q->mq_ops->exit_hctx(hctx, i);
1853 free_cpumask_var(hctx->cpumask);
1854 q->mq_ops->free_hctx(hctx, i);
1855 }
1856 1869
1857 free_percpu(q->queue_ctx); 1870 free_percpu(q->queue_ctx);
1858 kfree(q->queue_hw_ctx); 1871 kfree(q->queue_hw_ctx);