Skip to content

Commit c83dbe4

Browse files
zhengqixing56kernel-patches-daemon
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: Tang Yizhou <yizhou.tang@shopee.com> Signed-off-by: Yu Kuai <yukuai@fygo.io>
1 parent 80f427e commit c83dbe4

1 file changed

Lines changed: 27 additions & 30 deletions

File tree

block/blk-cgroup.c

Lines changed: 27 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,31 @@ struct cgroup_subsys io_cgrp_subsys = {
15291529
};
15301530
EXPORT_SYMBOL_GPL(io_cgrp_subsys);
15311531

1532+
/*
1533+
* Tear down per-blkg policy data for @pol on @q.
1534+
*/
1535+
static void blkcg_policy_teardown_pds(struct request_queue *q,
1536+
const struct blkcg_policy *pol)
1537+
{
1538+
struct blkcg_gq *blkg;
1539+
1540+
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1541+
struct blkcg *blkcg = blkg->blkcg;
1542+
struct blkg_policy_data *pd;
1543+
1544+
spin_lock(&blkcg->lock);
1545+
pd = blkg->pd[pol->plid];
1546+
if (pd) {
1547+
if (pd->online && pol->pd_offline_fn)
1548+
pol->pd_offline_fn(pd);
1549+
pd->online = false;
1550+
pol->pd_free_fn(pd);
1551+
WRITE_ONCE(blkg->pd[pol->plid], NULL);
1552+
}
1553+
spin_unlock(&blkcg->lock);
1554+
}
1555+
}
1556+
15321557
/**
15331558
* blkcg_activate_policy - activate a blkcg policy on a gendisk
15341559
* @disk: gendisk of interest
@@ -1644,21 +1669,7 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
16441669
enomem:
16451670
/* alloc failed, take down everything */
16461671
spin_lock_irq(&q->queue_lock);
1647-
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1648-
struct blkcg *blkcg = blkg->blkcg;
1649-
struct blkg_policy_data *pd;
1650-
1651-
spin_lock(&blkcg->lock);
1652-
pd = blkg->pd[pol->plid];
1653-
if (pd) {
1654-
if (pd->online && pol->pd_offline_fn)
1655-
pol->pd_offline_fn(pd);
1656-
pd->online = false;
1657-
pol->pd_free_fn(pd);
1658-
WRITE_ONCE(blkg->pd[pol->plid], NULL);
1659-
}
1660-
spin_unlock(&blkcg->lock);
1661-
}
1672+
blkcg_policy_teardown_pds(q, pol);
16621673
spin_unlock_irq(&q->queue_lock);
16631674
ret = -ENOMEM;
16641675
goto out;
@@ -1677,7 +1688,6 @@ void blkcg_deactivate_policy(struct gendisk *disk,
16771688
const struct blkcg_policy *pol)
16781689
{
16791690
struct request_queue *q = disk->queue;
1680-
struct blkcg_gq *blkg;
16811691
unsigned int memflags;
16821692

16831693
if (!blkcg_policy_enabled(q, pol))
@@ -1690,20 +1700,7 @@ void blkcg_deactivate_policy(struct gendisk *disk,
16901700
spin_lock_irq(&q->queue_lock);
16911701

16921702
__clear_bit(pol->plid, q->blkcg_pols);
1693-
1694-
list_for_each_entry(blkg, &q->blkg_list, q_node) {
1695-
struct blkcg *blkcg = blkg->blkcg;
1696-
1697-
spin_lock(&blkcg->lock);
1698-
if (blkg->pd[pol->plid]) {
1699-
if (blkg->pd[pol->plid]->online && pol->pd_offline_fn)
1700-
pol->pd_offline_fn(blkg->pd[pol->plid]);
1701-
pol->pd_free_fn(blkg->pd[pol->plid]);
1702-
blkg->pd[pol->plid] = NULL;
1703-
}
1704-
spin_unlock(&blkcg->lock);
1705-
}
1706-
1703+
blkcg_policy_teardown_pds(q, pol);
17071704
spin_unlock_irq(&q->queue_lock);
17081705
mutex_unlock(&q->blkcg_mutex);
17091706

0 commit comments

Comments
 (0)