Skip to content

Commit ae8650b

Browse files
YuKuai-huaweiaxboe
authored andcommitted
blk-cgroup: check for pd_(alloc|free)_fn in blkcg_activate_policy()
Currently all policies implement pd_(alloc|free)_fn, however, this is not necessary for ioprio that only works for blkcg, not blkg. There are no functional changes, prepare to cleanup activating ioprio policy. Signed-off-by: Yu Kuai <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Acked-by: Tejun Heo <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent 8400291 commit ae8650b

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

block/blk-cgroup.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,6 +1554,14 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
15541554
if (blkcg_policy_enabled(q, pol))
15551555
return 0;
15561556

1557+
/*
1558+
* Policy is allowed to be registered without pd_alloc_fn/pd_free_fn,
1559+
* for example, ioprio. Such policy will work on blkcg level, not disk
1560+
* level, and don't need to be activated.
1561+
*/
1562+
if (WARN_ON_ONCE(!pol->pd_alloc_fn || !pol->pd_free_fn))
1563+
return -EINVAL;
1564+
15571565
if (queue_is_mq(q))
15581566
blk_mq_freeze_queue(q);
15591567
retry:
@@ -1733,9 +1741,12 @@ int blkcg_policy_register(struct blkcg_policy *pol)
17331741
goto err_unlock;
17341742
}
17351743

1736-
/* Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs */
1744+
/*
1745+
* Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
1746+
* without pd_alloc_fn/pd_free_fn can't be activated.
1747+
*/
17371748
if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
1738-
(!pol->pd_alloc_fn ^ !pol->pd_free_fn))
1749+
(!pol->pd_alloc_fn ^ !pol->pd_free_fn))
17391750
goto err_unlock;
17401751

17411752
/* register @pol */

0 commit comments

Comments
 (0)