Skip to content

Commit 6bdfdc6

Browse files
Zheng Qixingkawasaki
authored andcommitted
blk-cgroup: factor policy pd teardown loop into helper
Move the teardown sequence which offlines and frees per-policy blkg_policy_data (pd) into a helper for readability. No functional change intended. Signed-off-by: Zheng Qixing <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Yu Kuai <[email protected]>
1 parent f962a4d commit 6bdfdc6

File tree

1 file changed

+27
-31
lines changed

1 file changed

+27
-31
lines changed

block/blk-cgroup.c

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,31 @@ struct cgroup_subsys io_cgrp_subsys = {
15591559
};
15601560
EXPORT_SYMBOL_GPL(io_cgrp_subsys);
15611561

1562+
/*
1563+
* Tear down per-blkg policy data for @pol on @q.
1564+
*/
1565+
static void blkcg_policy_teardown_pds(struct request_queue *q,
1566+
const struct blkcg_policy *pol)
1567+
{
1568+
struct blkcg_gq *blkg;
1569+
1570+
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1571+
struct blkcg *blkcg = blkg->blkcg;
1572+
struct blkg_policy_data *pd;
1573+
1574+
spin_lock(&blkcg->lock);
1575+
pd = blkg->pd[pol->plid];
1576+
if (pd) {
1577+
if (pd->online && pol->pd_offline_fn)
1578+
pol->pd_offline_fn(pd);
1579+
pd->online = false;
1580+
pol->pd_free_fn(pd);
1581+
blkg->pd[pol->plid] = NULL;
1582+
}
1583+
spin_unlock(&blkcg->lock);
1584+
}
1585+
}
1586+
15621587
/**
15631588
* blkcg_activate_policy - activate a blkcg policy on a gendisk
15641589
* @disk: gendisk of interest
@@ -1669,21 +1694,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
16691694
enomem:
16701695
/* alloc failed, take down everything */
16711696
spin_lock_irq(&q->queue_lock);
1672-
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1673-
struct blkcg *blkcg = blkg->blkcg;
1674-
struct blkg_policy_data *pd;
1675-
1676-
spin_lock(&blkcg->lock);
1677-
pd = blkg->pd[pol->plid];
1678-
if (pd) {
1679-
if (pd->online && pol->pd_offline_fn)
1680-
pol->pd_offline_fn(pd);
1681-
pd->online = false;
1682-
pol->pd_free_fn(pd);
1683-
blkg->pd[pol->plid] = NULL;
1684-
}
1685-
spin_unlock(&blkcg->lock);
1686-
}
1697+
blkcg_policy_teardown_pds(q, pol);
16871698
spin_unlock_irq(&q->queue_lock);
16881699
ret = -ENOMEM;
16891700
goto out;
@@ -1702,7 +1713,6 @@ void blkcg_deactivate_policy(struct gendisk *disk,
17021713
const struct blkcg_policy *pol)
17031714
{
17041715
struct request_queue *q = disk->queue;
1705-
struct blkcg_gq *blkg;
17061716
unsigned int memflags;
17071717

17081718
if (!blkcg_policy_enabled(q, pol))
@@ -1713,22 +1723,8 @@ void blkcg_deactivate_policy(struct gendisk *disk,
17131723

17141724
mutex_lock(&q->blkcg_mutex);
17151725
spin_lock_irq(&q->queue_lock);
1716-
17171726
__clear_bit(pol->plid, q->blkcg_pols);
1718-
1719-
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1720-
struct blkcg *blkcg = blkg->blkcg;
1721-
1722-
spin_lock(&blkcg->lock);
1723-
if (blkg->pd[pol->plid]) {
1724-
if (blkg->pd[pol->plid]->online && pol->pd_offline_fn)
1725-
pol->pd_offline_fn(blkg->pd[pol->plid]);
1726-
pol->pd_free_fn(blkg->pd[pol->plid]);
1727-
blkg->pd[pol->plid] = NULL;
1728-
}
1729-
spin_unlock(&blkcg->lock);
1730-
}
1731-
1727+
blkcg_policy_teardown_pds(q, pol);
17321728
spin_unlock_irq(&q->queue_lock);
17331729
mutex_unlock(&q->blkcg_mutex);
17341730

0 commit comments

Comments
 (0)