[PATCH v2 1/3] blk-cgroup: check for pd_(alloc|free)_fn in blkcg_activate_policy()

Yu Kuai posted 3 patches 1 year, 5 months ago
There is a newer version of this series
[PATCH v2 1/3] blk-cgroup: check for pd_(alloc|free)_fn in blkcg_activate_policy()
Posted by Yu Kuai 1 year, 5 months ago
From: Yu Kuai <yukuai3@huawei.com>

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 <yukuai3@huawei.com>
---
 block/blk-cgroup.c | 13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index 37e6cc91d576..dcd5e857650a 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1554,6 +1554,14 @@ int blkcg_activate_policy(struct gendisk *disk, const struct blkcg_policy *pol)
 	if (blkcg_policy_enabled(q, pol))
 		return 0;
 
+	/*
+	 * Policy is allowed to be registered without pd_alloc_fn/pd_free_fn,
+	 * for example, ioprio. Such policy will work on blkcg level, not disk
+	 * level, and don't need to be activated.
+	 */
+	if (WARN_ON_ONCE(!pol->pd_alloc_fn || !pol->pd_free_fn))
+		return -EINVAL;
+
 	if (queue_is_mq(q))
 		blk_mq_freeze_queue(q);
 retry:
@@ -1733,7 +1741,10 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 		goto err_unlock;
 	}
 
-	/* Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs */
+	/*
+	 * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
+	 * without pd_alloc_fn/pd_free_fn can't be activated.
+	 */
 	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
 		(!pol->pd_alloc_fn ^ !pol->pd_free_fn))
 		goto err_unlock;
-- 
2.39.2
Re: [PATCH v2 1/3] blk-cgroup: check for pd_(alloc|free)_fn in blkcg_activate_policy()
Posted by Christoph Hellwig 1 year, 5 months ago
On Fri, Jul 19, 2024 at 10:34:29AM +0800, Yu Kuai wrote:
> +	/*
> +	 * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
> +	 * without pd_alloc_fn/pd_free_fn can't be activated.
> +	 */
>  	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
>  		(!pol->pd_alloc_fn ^ !pol->pd_free_fn))
>  		goto err_unlock;
> -- 

I know this is existing code, but can you fix up the incorrect
indentation while you touch this:

 	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
 	    (!pol->pd_alloc_fn ^ !pol->pd_free_fn))

Otherwise looks good:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Re: [PATCH v2 1/3] blk-cgroup: check for pd_(alloc|free)_fn in blkcg_activate_policy()
Posted by Bart Van Assche 1 year, 5 months ago
On 7/18/24 10:29 PM, Christoph Hellwig wrote:
> On Fri, Jul 19, 2024 at 10:34:29AM +0800, Yu Kuai wrote:
>> +	/*
>> +	 * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
>> +	 * without pd_alloc_fn/pd_free_fn can't be activated.
>> +	 */
>>   	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
>>   		(!pol->pd_alloc_fn ^ !pol->pd_free_fn))
>>   		goto err_unlock;
>> -- 
> 
> I know this is existing code, but can you fix up the incorrect
> indentation while you touch this:
> 
>   	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
>   	    (!pol->pd_alloc_fn ^ !pol->pd_free_fn))

Using xor (^) for booleans seems weird to me. Is there any preference in
Linux kernel code whether to use ^ or != to check whether to booleans
are different?

Thanks,

Bart.
Re: [PATCH v2 1/3] blk-cgroup: check for pd_(alloc|free)_fn in blkcg_activate_policy()
Posted by Yu Kuai 1 year, 4 months ago
Hi,

在 2024/07/20 0:25, Bart Van Assche 写道:
> On 7/18/24 10:29 PM, Christoph Hellwig wrote:
>> On Fri, Jul 19, 2024 at 10:34:29AM +0800, Yu Kuai wrote:
>>> +    /*
>>> +     * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and 
>>> policy
>>> +     * without pd_alloc_fn/pd_free_fn can't be activated.
>>> +     */
>>>       if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
>>>           (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
>>>           goto err_unlock;
>>> -- 
>>
>> I know this is existing code, but can you fix up the incorrect
>> indentation while you touch this:
>>
>>       if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
>>           (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
> 
> Using xor (^) for booleans seems weird to me. Is there any preference in
> Linux kernel code whether to use ^ or != to check whether to booleans
> are different?

I don't know, but I feel more comfortable to use '!=' myself.

Thanks,
Kuai

> 
> Thanks,
> 
> Bart.
> 
> .
> 

Re: [PATCH v2 1/3] blk-cgroup: check for pd_(alloc|free)_fn in blkcg_activate_policy()
Posted by Yu Kuai 1 year, 5 months ago
Hi!

在 2024/07/19 13:29, Christoph Hellwig 写道:
> On Fri, Jul 19, 2024 at 10:34:29AM +0800, Yu Kuai wrote:
>> +	/*
>> +	 * Make sure cpd/pd_alloc_fn and cpd/pd_free_fn in pairs, and policy
>> +	 * without pd_alloc_fn/pd_free_fn can't be activated.
>> +	 */
>>   	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
>>   		(!pol->pd_alloc_fn ^ !pol->pd_free_fn))
>>   		goto err_unlock;
>> -- 
> 
> I know this is existing code, but can you fix up the incorrect
> indentation while you touch this:

Yes, and thanks for the review.

Kuai

> 
>   	if ((!pol->cpd_alloc_fn ^ !pol->cpd_free_fn) ||
>   	    (!pol->pd_alloc_fn ^ !pol->pd_free_fn))
> 
> Otherwise looks good:
> 
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> 
> .
>