Skip to content

Commit db61367

Browse files
committed
blkcg: invoke blkcg_policy->pd_init() after parent is linked
Currently, when creating a new blkcg_gq, each policy's pd_init_fn() is invoked in blkg_alloc() before the parent is linked. This makes it difficult for policies to perform initializations which are dependent on the parent. This patch moves pd_init_fn() invocations to blkg_create() after the parent blkg is linked where the new blkg is fully initialized. As this means that blkg_free() can't assume that pd's are initialized, pd_exit_fn() invocations are moved to __blkg_release(). This guarantees that pd_exit_fn() is also invoked with fully initialized blkgs with valid parent pointers. This will help implementing hierarchy support in blk-throttle. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Vivek Goyal <vgoyal@redhat.com>
1 parent aa539cb commit db61367

1 file changed

Lines changed: 22 additions & 17 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,8 @@ static void blkg_free(struct blkcg_gq *blkg)
5151
if (!blkg)
5252
return;
5353

54-
for (i = 0; i < BLKCG_MAX_POLS; i++) {
55-
struct blkcg_policy *pol = blkcg_policy[i];
56-
struct blkg_policy_data *pd = blkg->pd[i];
57-
58-
if (!pd)
59-
continue;
60-
61-
if (pol && pol->pd_exit_fn)
62-
pol->pd_exit_fn(blkg);
63-
64-
kfree(pd);
65-
}
54+
for (i = 0; i < BLKCG_MAX_POLS; i++)
55+
kfree(blkg->pd[i]);
6656

6757
blk_exit_rl(&blkg->rl);
6858
kfree(blkg);
@@ -114,10 +104,6 @@ static struct blkcg_gq *blkg_alloc(struct blkcg *blkcg, struct request_queue *q,
114104
blkg->pd[i] = pd;
115105
pd->blkg = blkg;
116106
pd->plid = i;
117-
118-
/* invoke per-policy init */
119-
if (pol->pd_init_fn)
120-
pol->pd_init_fn(blkg);
121107
}
122108

123109
return blkg;
@@ -214,7 +200,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
214200
}
215201
blkg = new_blkg;
216202

217-
/* link parent and insert */
203+
/* link parent */
218204
if (blkcg_parent(blkcg)) {
219205
blkg->parent = __blkg_lookup(blkcg_parent(blkcg), q, false);
220206
if (WARN_ON_ONCE(!blkg->parent)) {
@@ -224,6 +210,15 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
224210
blkg_get(blkg->parent);
225211
}
226212

213+
/* invoke per-policy init */
214+
for (i = 0; i < BLKCG_MAX_POLS; i++) {
215+
struct blkcg_policy *pol = blkcg_policy[i];
216+
217+
if (blkg->pd[i] && pol->pd_init_fn)
218+
pol->pd_init_fn(blkg);
219+
}
220+
221+
/* insert */
227222
spin_lock(&blkcg->lock);
228223
ret = radix_tree_insert(&blkcg->blkg_tree, q->id, blkg);
229224
if (likely(!ret)) {
@@ -381,6 +376,16 @@ static void blkg_rcu_free(struct rcu_head *rcu_head)
381376

382377
void __blkg_release(struct blkcg_gq *blkg)
383378
{
379+
int i;
380+
381+
/* tell policies that this one is being freed */
382+
for (i = 0; i < BLKCG_MAX_POLS; i++) {
383+
struct blkcg_policy *pol = blkcg_policy[i];
384+
385+
if (blkg->pd[i] && pol->pd_exit_fn)
386+
pol->pd_exit_fn(blkg);
387+
}
388+
384389
/* release the blkcg and parent blkg refs this blkg has been holding */
385390
css_put(&blkg->blkcg->css);
386391
if (blkg->parent)

0 commit comments

Comments
 (0)