Skip to content

Commit 1e4928d

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 <zhengqixing@huawei.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Yu Kuai <yukuai@fnnas.com>
1 parent 756051f commit 1e4928d

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
@@ -1673,21 +1698,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
16731698
enomem:
16741699
/* alloc failed, take down everything */
16751700
spin_lock_irq(&q->queue_lock);
1676-
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1677-
struct blkcg *blkcg = blkg->blkcg;
1678-
struct blkg_policy_data *pd;
1679-
1680-
spin_lock(&blkcg->lock);
1681-
pd = blkg->pd[pol->plid];
1682-
if (pd) {
1683-
if (pd->online && pol->pd_offline_fn)
1684-
pol->pd_offline_fn(pd);
1685-
pd->online = false;
1686-
pol->pd_free_fn(pd);
1687-
blkg->pd[pol->plid] = NULL;
1688-
}
1689-
spin_unlock(&blkcg->lock);
1690-
}
1701+
blkcg_policy_teardown_pds(q, pol);
16911702
spin_unlock_irq(&q->queue_lock);
16921703
ret = -ENOMEM;
16931704
goto out;
@@ -1706,7 +1717,6 @@ void blkcg_deactivate_policy(struct gendisk *disk,
17061717
const struct blkcg_policy *pol)
17071718
{
17081719
struct request_queue *q = disk->queue;
1709-
struct blkcg_gq *blkg;
17101720
unsigned int memflags;
17111721

17121722
if (!blkcg_policy_enabled(q, pol))
@@ -1717,22 +1727,8 @@ void blkcg_deactivate_policy(struct gendisk *disk,
17171727

17181728
mutex_lock(&q->blkcg_mutex);
17191729
spin_lock_irq(&q->queue_lock);
1720-
17211730
__clear_bit(pol->plid, q->blkcg_pols);
1722-
1723-
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1724-
struct blkcg *blkcg = blkg->blkcg;
1725-
1726-
spin_lock(&blkcg->lock);
1727-
if (blkg->pd[pol->plid]) {
1728-
if (blkg->pd[pol->plid]->online && pol->pd_offline_fn)
1729-
pol->pd_offline_fn(blkg->pd[pol->plid]);
1730-
pol->pd_free_fn(blkg->pd[pol->plid]);
1731-
blkg->pd[pol->plid] = NULL;
1732-
}
1733-
spin_unlock(&blkcg->lock);
1734-
}
1735-
1731+
blkcg_policy_teardown_pds(q, pol);
17361732
spin_unlock_irq(&q->queue_lock);
17371733
mutex_unlock(&q->blkcg_mutex);
17381734

0 commit comments

Comments
 (0)