Skip to content

Commit a9520cd

Browse files
htejunaxboe
authored andcommitted
blkcg: make blkcg_policy methods take a pointer to blkcg_policy_data
The newly added ->pd_alloc_fn() and ->pd_free_fn() deal with pd (blkg_policy_data) while the older ones use blkg (blkcg_gq). As using blkg doesn't make sense for ->pd_alloc_fn() and after allocation pd can always be mapped to blkg and given that these are policy-specific methods, it makes sense to converge on pd. This patch makes all methods deal with pd instead of blkg. Most conversions are trivial. In blk-cgroup.c, a couple method invocation sites now test whether pd exists instead of policy state for consistency. This shouldn't cause any behavioral differences. Signed-off-by: Tejun Heo <[email protected]> Cc: Vivek Goyal <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent b2ce264 commit a9520cd

File tree

4 files changed

+26
-27
lines changed

4 files changed

+26
-27
lines changed

block/blk-cgroup.c

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
242242
struct blkcg_policy *pol = blkcg_policy[i];
243243

244244
if (blkg->pd[i] && pol->pd_init_fn)
245-
pol->pd_init_fn(blkg);
245+
pol->pd_init_fn(blkg->pd[i]);
246246
}
247247

248248
/* insert */
@@ -256,7 +256,7 @@ static struct blkcg_gq *blkg_create(struct blkcg *blkcg,
256256
struct blkcg_policy *pol = blkcg_policy[i];
257257

258258
if (blkg->pd[i] && pol->pd_online_fn)
259-
pol->pd_online_fn(blkg);
259+
pol->pd_online_fn(blkg->pd[i]);
260260
}
261261
}
262262
blkg->online = true;
@@ -347,7 +347,7 @@ static void blkg_destroy(struct blkcg_gq *blkg)
347347
struct blkcg_policy *pol = blkcg_policy[i];
348348

349349
if (blkg->pd[i] && pol->pd_offline_fn)
350-
pol->pd_offline_fn(blkg);
350+
pol->pd_offline_fn(blkg->pd[i]);
351351
}
352352
blkg->online = false;
353353

@@ -468,9 +468,8 @@ static int blkcg_reset_stats(struct cgroup_subsys_state *css,
468468
for (i = 0; i < BLKCG_MAX_POLS; i++) {
469469
struct blkcg_policy *pol = blkcg_policy[i];
470470

471-
if (blkcg_policy_enabled(blkg->q, pol) &&
472-
pol->pd_reset_stats_fn)
473-
pol->pd_reset_stats_fn(blkg);
471+
if (blkg->pd[i] && pol->pd_reset_stats_fn)
472+
pol->pd_reset_stats_fn(blkg->pd[i]);
474473
}
475474
}
476475

@@ -1076,7 +1075,7 @@ int blkcg_activate_policy(struct request_queue *q,
10761075
pd->blkg = blkg;
10771076
pd->plid = pol->plid;
10781077
if (pol->pd_init_fn)
1079-
pol->pd_init_fn(blkg);
1078+
pol->pd_init_fn(pd);
10801079
}
10811080

10821081
__set_bit(pol->plid, q->blkcg_pols);
@@ -1116,10 +1115,9 @@ void blkcg_deactivate_policy(struct request_queue *q,
11161115
/* grab blkcg lock too while removing @pd from @blkg */
11171116
spin_lock(&blkg->blkcg->lock);
11181117

1119-
if (pol->pd_offline_fn)
1120-
pol->pd_offline_fn(blkg);
1121-
11221118
if (blkg->pd[pol->plid]) {
1119+
if (pol->pd_offline_fn)
1120+
pol->pd_offline_fn(blkg->pd[pol->plid]);
11231121
pol->pd_free_fn(blkg->pd[pol->plid]);
11241122
blkg->pd[pol->plid] = NULL;
11251123
}

block/blk-throttle.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -377,9 +377,10 @@ static struct blkg_policy_data *throtl_pd_alloc(gfp_t gfp, int node)
377377
return &tg->pd;
378378
}
379379

380-
static void throtl_pd_init(struct blkcg_gq *blkg)
380+
static void throtl_pd_init(struct blkg_policy_data *pd)
381381
{
382-
struct throtl_grp *tg = blkg_to_tg(blkg);
382+
struct throtl_grp *tg = pd_to_tg(pd);
383+
struct blkcg_gq *blkg = tg_to_blkg(tg);
383384
struct throtl_data *td = blkg->q->td;
384385
struct throtl_service_queue *sq = &tg->service_queue;
385386

@@ -417,13 +418,13 @@ static void tg_update_has_rules(struct throtl_grp *tg)
417418
(tg->bps[rw] != -1 || tg->iops[rw] != -1);
418419
}
419420

420-
static void throtl_pd_online(struct blkcg_gq *blkg)
421+
static void throtl_pd_online(struct blkg_policy_data *pd)
421422
{
422423
/*
423424
* We don't want new groups to escape the limits of its ancestors.
424425
* Update has_rules[] after a new group is brought online.
425426
*/
426-
tg_update_has_rules(blkg_to_tg(blkg));
427+
tg_update_has_rules(pd_to_tg(pd));
427428
}
428429

429430
static void throtl_pd_free(struct blkg_policy_data *pd)
@@ -435,9 +436,9 @@ static void throtl_pd_free(struct blkg_policy_data *pd)
435436
kfree(tg);
436437
}
437438

438-
static void throtl_pd_reset_stats(struct blkcg_gq *blkg)
439+
static void throtl_pd_reset_stats(struct blkg_policy_data *pd)
439440
{
440-
struct throtl_grp *tg = blkg_to_tg(blkg);
441+
struct throtl_grp *tg = pd_to_tg(pd);
441442
int cpu;
442443

443444
for_each_possible_cpu(cpu) {

block/cfq-iosched.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,18 +1597,18 @@ static struct blkg_policy_data *cfq_pd_alloc(gfp_t gfp, int node)
15971597
return &cfqg->pd;
15981598
}
15991599

1600-
static void cfq_pd_init(struct blkcg_gq *blkg)
1600+
static void cfq_pd_init(struct blkg_policy_data *pd)
16011601
{
1602-
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
1603-
struct cfq_group_data *cgd = blkcg_to_cfqgd(blkg->blkcg);
1602+
struct cfq_group *cfqg = pd_to_cfqg(pd);
1603+
struct cfq_group_data *cgd = blkcg_to_cfqgd(pd->blkg->blkcg);
16041604

16051605
cfqg->weight = cgd->weight;
16061606
cfqg->leaf_weight = cgd->leaf_weight;
16071607
}
16081608

1609-
static void cfq_pd_offline(struct blkcg_gq *blkg)
1609+
static void cfq_pd_offline(struct blkg_policy_data *pd)
16101610
{
1611-
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
1611+
struct cfq_group *cfqg = pd_to_cfqg(pd);
16121612
int i;
16131613

16141614
for (i = 0; i < IOPRIO_BE_NR; i++) {
@@ -1661,9 +1661,9 @@ static struct blkg_rwstat cfqg_rwstat_pd_recursive_sum(struct blkg_policy_data *
16611661
return a;
16621662
}
16631663

1664-
static void cfq_pd_reset_stats(struct blkcg_gq *blkg)
1664+
static void cfq_pd_reset_stats(struct blkg_policy_data *pd)
16651665
{
1666-
struct cfq_group *cfqg = blkg_to_cfqg(blkg);
1666+
struct cfq_group *cfqg = pd_to_cfqg(pd);
16671667

16681668
cfqg_stats_reset(&cfqg->stats);
16691669
cfqg_stats_reset(&cfqg->dead_stats);

include/linux/blk-cgroup.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,11 @@ struct blkcg_gq {
125125

126126
typedef void (blkcg_pol_init_cpd_fn)(const struct blkcg *blkcg);
127127
typedef struct blkg_policy_data *(blkcg_pol_alloc_pd_fn)(gfp_t gfp, int node);
128-
typedef void (blkcg_pol_init_pd_fn)(struct blkcg_gq *blkg);
129-
typedef void (blkcg_pol_online_pd_fn)(struct blkcg_gq *blkg);
130-
typedef void (blkcg_pol_offline_pd_fn)(struct blkcg_gq *blkg);
128+
typedef void (blkcg_pol_init_pd_fn)(struct blkg_policy_data *pd);
129+
typedef void (blkcg_pol_online_pd_fn)(struct blkg_policy_data *pd);
130+
typedef void (blkcg_pol_offline_pd_fn)(struct blkg_policy_data *pd);
131131
typedef void (blkcg_pol_free_pd_fn)(struct blkg_policy_data *pd);
132-
typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkcg_gq *blkg);
132+
typedef void (blkcg_pol_reset_pd_stats_fn)(struct blkg_policy_data *pd);
133133

134134
struct blkcg_policy {
135135
int plid;

0 commit comments

Comments
 (0)