All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] blkcg: add sanity check for blkcg policy operations
@ 2017-10-11  9:46 weiping zhang
  2017-10-11 16:51 ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: weiping zhang @ 2017-10-11  9:46 UTC (permalink / raw)
  To: axboe, jthumshirn; +Cc: linux-block

blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs,
otherwise policy would register fail.

Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
---
 block/blk-cgroup.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
index e7ec676..67b01c5 100644
--- a/block/blk-cgroup.c
+++ b/block/blk-cgroup.c
@@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)
 	if (i >= BLKCG_MAX_POLS)
 		goto err_unlock;
 
+	/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */
+	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
+		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
+		goto err_unlock;
+
+	/* Make sure pd_alloc_fn and pd_free_fn in pairs */
+	if ((pol->pd_alloc_fn && !pol->pd_free_fn) ||
+		(!pol->pd_alloc_fn && pol->pd_free_fn))
+		goto err_unlock;
+
 	/* register @pol */
 	pol->plid = i;
 	blkcg_policy[pol->plid] = pol;
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] blkcg: add sanity check for blkcg policy operations
  2017-10-11  9:46 [PATCH v2] blkcg: add sanity check for blkcg policy operations weiping zhang
@ 2017-10-11 16:51 ` Jens Axboe
  2017-10-12  6:26   ` weiping zhang
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2017-10-11 16:51 UTC (permalink / raw)
  To: jthumshirn, linux-block

On 10/11/2017 03:46 AM, weiping zhang wrote:
> blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs,
> otherwise policy would register fail.
> 
> Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> ---
>  block/blk-cgroup.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> index e7ec676..67b01c5 100644
> --- a/block/blk-cgroup.c
> +++ b/block/blk-cgroup.c
> @@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)
>  	if (i >= BLKCG_MAX_POLS)
>  		goto err_unlock;
>  
> +	/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */
> +	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
> +		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
> +		goto err_unlock;

This might be cleaner (and more readable) as:

        if (!pol->cpd_alloc_fn ^ !pol->cpd_free_fn)
                goto err_unlock;

Ditto for the pd part.

-- 
Jens Axboe

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v2] blkcg: add sanity check for blkcg policy operations
  2017-10-11 16:51 ` Jens Axboe
@ 2017-10-12  6:26   ` weiping zhang
  0 siblings, 0 replies; 3+ messages in thread
From: weiping zhang @ 2017-10-12  6:26 UTC (permalink / raw)
  To: Jens Axboe; +Cc: jthumshirn, linux-block

On Wed, Oct 11, 2017 at 10:51:32AM -0600, Jens Axboe wrote:
> On 10/11/2017 03:46 AM, weiping zhang wrote:
> > blkcg policy should keep cpd/pd's alloc_fn and free_fn in pairs,
> > otherwise policy would register fail.
> > 
> > Signed-off-by: weiping zhang <zhangweiping@didichuxing.com>
> > ---
> >  block/blk-cgroup.c | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
> > index e7ec676..67b01c5 100644
> > --- a/block/blk-cgroup.c
> > +++ b/block/blk-cgroup.c
> > @@ -1419,6 +1419,16 @@ int blkcg_policy_register(struct blkcg_policy *pol)
> >  	if (i >= BLKCG_MAX_POLS)
> >  		goto err_unlock;
> >  
> > +	/* Make sure cpd_alloc_fn and cpd_free_fn in pairs */
> > +	if ((pol->cpd_alloc_fn && !pol->cpd_free_fn) ||
> > +		(!pol->cpd_alloc_fn && pol->cpd_free_fn))
> > +		goto err_unlock;
> 
> This might be cleaner (and more readable) as:
> 
>         if (!pol->cpd_alloc_fn ^ !pol->cpd_free_fn)
>                 goto err_unlock;
> 
> Ditto for the pd part.
> 
Really nice, I'll send v3.

Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2017-10-12  6:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-11  9:46 [PATCH v2] blkcg: add sanity check for blkcg policy operations weiping zhang
2017-10-11 16:51 ` Jens Axboe
2017-10-12  6:26   ` weiping zhang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.