Skip to content

Commit 8143764

Browse files
htejunaxboe
authored andcommitted
blkcg: minor updates around blkcg_policy_data
* Rename blkcg->pd[] to blkcg->cpd[] so that cpd is consistently used for blkcg_policy_data. * Make blkcg_policy->cpd_init_fn() take blkcg_policy_data instead of blkcg. This makes it consistent with blkg_policy_data methods and to-be-added cpd alloc/free methods. * blkcg_policy_data->blkcg and cpd_to_blkcg() added so that cpd_init_fn() can determine the associated blkcg from blkcg_policy_data. v2: blkcg_policy_data->blkcg initializations were missing. Added. Signed-off-by: Tejun Heo <[email protected]> Cc: Vivek Goyal <[email protected]> Cc: Arianna Avanzini <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent a9520cd commit 8143764

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

block/blk-cgroup.c

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
821821
mutex_unlock(&blkcg_pol_mutex);
822822

823823
for (i = 0; i < BLKCG_MAX_POLS; i++)
824-
kfree(blkcg->pd[i]);
824+
kfree(blkcg->cpd[i]);
825825
kfree(blkcg);
826826
}
827827

@@ -857,15 +857,16 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
857857
if (!pol || !pol->cpd_size)
858858
continue;
859859

860-
BUG_ON(blkcg->pd[i]);
860+
BUG_ON(blkcg->cpd[i]);
861861
cpd = kzalloc(pol->cpd_size, GFP_KERNEL);
862862
if (!cpd) {
863863
ret = ERR_PTR(-ENOMEM);
864864
goto free_pd_blkcg;
865865
}
866-
blkcg->pd[i] = cpd;
866+
blkcg->cpd[i] = cpd;
867+
cpd->blkcg = blkcg;
867868
cpd->plid = i;
868-
pol->cpd_init_fn(blkcg);
869+
pol->cpd_init_fn(cpd);
869870
}
870871

871872
spin_lock_init(&blkcg->lock);
@@ -881,7 +882,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
881882

882883
free_pd_blkcg:
883884
for (i--; i >= 0; i--)
884-
kfree(blkcg->pd[i]);
885+
kfree(blkcg->cpd[i]);
885886
free_blkcg:
886887
kfree(blkcg);
887888
mutex_unlock(&blkcg_pol_mutex);
@@ -1168,9 +1169,10 @@ int blkcg_policy_register(struct blkcg_policy *pol)
11681169
goto err_free_cpds;
11691170
}
11701171

1171-
blkcg->pd[pol->plid] = cpd;
1172+
blkcg->cpd[pol->plid] = cpd;
1173+
cpd->blkcg = blkcg;
11721174
cpd->plid = pol->plid;
1173-
pol->cpd_init_fn(blkcg);
1175+
pol->cpd_init_fn(cpd);
11741176
}
11751177
}
11761178

@@ -1186,8 +1188,8 @@ int blkcg_policy_register(struct blkcg_policy *pol)
11861188
err_free_cpds:
11871189
if (pol->cpd_size) {
11881190
list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
1189-
kfree(blkcg->pd[pol->plid]);
1190-
blkcg->pd[pol->plid] = NULL;
1191+
kfree(blkcg->cpd[pol->plid]);
1192+
blkcg->cpd[pol->plid] = NULL;
11911193
}
11921194
}
11931195
blkcg_policy[pol->plid] = NULL;
@@ -1222,8 +1224,8 @@ void blkcg_policy_unregister(struct blkcg_policy *pol)
12221224

12231225
if (pol->cpd_size) {
12241226
list_for_each_entry(blkcg, &all_blkcgs, all_blkcgs_node) {
1225-
kfree(blkcg->pd[pol->plid]);
1226-
blkcg->pd[pol->plid] = NULL;
1227+
kfree(blkcg->cpd[pol->plid]);
1228+
blkcg->cpd[pol->plid] = NULL;
12271229
}
12281230
}
12291231
blkcg_policy[pol->plid] = NULL;

block/cfq-iosched.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ struct cfqg_stats {
220220
/* Per-cgroup data */
221221
struct cfq_group_data {
222222
/* must be the first member */
223-
struct blkcg_policy_data pd;
223+
struct blkcg_policy_data cpd;
224224

225225
unsigned int weight;
226226
unsigned int leaf_weight;
@@ -612,7 +612,7 @@ static inline struct cfq_group *pd_to_cfqg(struct blkg_policy_data *pd)
612612
static struct cfq_group_data
613613
*cpd_to_cfqgd(struct blkcg_policy_data *cpd)
614614
{
615-
return cpd ? container_of(cpd, struct cfq_group_data, pd) : NULL;
615+
return cpd ? container_of(cpd, struct cfq_group_data, cpd) : NULL;
616616
}
617617

618618
static inline struct blkcg_gq *cfqg_to_blkg(struct cfq_group *cfqg)
@@ -1568,12 +1568,11 @@ static void cfqg_stats_init(struct cfqg_stats *stats)
15681568
#endif
15691569
}
15701570

1571-
static void cfq_cpd_init(const struct blkcg *blkcg)
1571+
static void cfq_cpd_init(struct blkcg_policy_data *cpd)
15721572
{
1573-
struct cfq_group_data *cgd =
1574-
cpd_to_cfqgd(blkcg->pd[blkcg_policy_cfq.plid]);
1573+
struct cfq_group_data *cgd = cpd_to_cfqgd(cpd);
15751574

1576-
if (blkcg == &blkcg_root) {
1575+
if (cpd_to_blkcg(cpd) == &blkcg_root) {
15771576
cgd->weight = 2 * CFQ_WEIGHT_DEFAULT;
15781577
cgd->leaf_weight = 2 * CFQ_WEIGHT_DEFAULT;
15791578
} else {

include/linux/blk-cgroup.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ struct blkcg {
4545
struct blkcg_gq *blkg_hint;
4646
struct hlist_head blkg_list;
4747

48-
struct blkcg_policy_data *pd[BLKCG_MAX_POLS];
48+
struct blkcg_policy_data *cpd[BLKCG_MAX_POLS];
4949

5050
struct list_head all_blkcgs_node;
5151
#ifdef CONFIG_CGROUP_WRITEBACK
@@ -88,7 +88,8 @@ struct blkg_policy_data {
8888
* each policy handle per-blkcg data.
8989
*/
9090
struct blkcg_policy_data {
91-
/* the policy id this per-policy data belongs to */
91+
/* the blkcg and policy id this per-policy data belongs to */
92+
struct blkcg *blkcg;
9293
int plid;
9394
};
9495

@@ -123,7 +124,7 @@ struct blkcg_gq {
123124
struct rcu_head rcu_head;
124125
};
125126

126-
typedef void (blkcg_pol_init_cpd_fn)(const struct blkcg *blkcg);
127+
typedef void (blkcg_pol_init_cpd_fn)(struct blkcg_policy_data *cpd);
127128
typedef struct blkg_policy_data *(blkcg_pol_alloc_pd_fn)(gfp_t gfp, int node);
128129
typedef void (blkcg_pol_init_pd_fn)(struct blkg_policy_data *pd);
129130
typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd);
@@ -243,7 +244,7 @@ static inline struct blkg_policy_data *blkg_to_pd(struct blkcg_gq *blkg,
243244
static inline struct blkcg_policy_data *blkcg_to_cpd(struct blkcg *blkcg,
244245
struct blkcg_policy *pol)
245246
{
246-
return blkcg ? blkcg->pd[pol->plid] : NULL;
247+
return blkcg ? blkcg->cpd[pol->plid] : NULL;
247248
}
248249

249250
/**
@@ -257,6 +258,11 @@ static inline struct blkcg_gq *pd_to_blkg(struct blkg_policy_data *pd)
257258
return pd ? pd->blkg : NULL;
258259
}
259260

261+
static inline struct blkcg *cpd_to_blkcg(struct blkcg_policy_data *cpd)
262+
{
263+
return cpd ? cpd->blkcg : NULL;
264+
}
265+
260266
/**
261267
* blkg_path - format cgroup path of blkg
262268
* @blkg: blkg of interest

0 commit comments

Comments
 (0)