All of lore.kernel.org
 help / color / mirror / Atom feed
From: Richard Palethorpe <rpalethorpe@suse.de>
To: Li Wang <liwang@redhat.com>
Cc: ltp@lists.linux.it, luke.nowakowskikrijger@canonical.com
Subject: Re: [LTP] [PATCH] lib: rewrite cgroup_find_ctrl with using for_each_ctrl
Date: Mon, 17 Jan 2022 09:05:40 +0000	[thread overview]
Message-ID: <87wniyzpj8.fsf@suse.de> (raw)
In-Reply-To: <20220113123418.1911231-1-liwang@redhat.com>

Hello Li,

Li Wang <liwang@redhat.com> writes:

> It is safe to start from controllers[0] to traverse each of
> the controller whatever V2 or V1, then we can make use of it
> in the cgroup_find_ctrl() function.

Right, it seems we never set ctrl_root on "cgroup" nor is it added to
ctrl_field. So it will be skipped in other loops. This might not be what
people expect, but I'm not sure what to do about that.

>
> Signed-off-by: Li Wang <liwang@redhat.com>
> ---
>  lib/tst_cgroup.c | 15 +++++++--------
>  1 file changed, 7 insertions(+), 8 deletions(-)
>
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> index 2ef599d9e..10b65364b 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -214,7 +214,7 @@ static const char *cgroup_v2_ltp_mount = "unified";
>  #define for_each_v1_root(r)			\
>  	for ((r) = roots + 1; (r)->ver; (r)++)
>  #define for_each_ctrl(ctrl)			\
> -	for ((ctrl) = controllers + 1; (ctrl)->ctrl_name; (ctrl)++)
> +	for ((ctrl) = controllers; (ctrl)->ctrl_name; (ctrl)++)
>  
>  /* In all cases except one, this only loops once.
>   *
> @@ -325,15 +325,14 @@ void tst_cgroup_print_config(void)
>  __attribute__ ((nonnull, warn_unused_result))
>  static struct cgroup_ctrl *cgroup_find_ctrl(const char *const ctrl_name)
>  {
> -	struct cgroup_ctrl *ctrl = controllers;
> -
> -	while (ctrl->ctrl_name && strcmp(ctrl_name, ctrl->ctrl_name))
> -		ctrl++;
> +	struct cgroup_ctrl *ctrl;
>  
> -	if (!ctrl->ctrl_name)
> -		ctrl = NULL;
> +	for_each_ctrl(ctrl) {
> +		if (!strcmp(ctrl_name, ctrl->ctrl_name))
> +			return ctrl;
> +	}
>  
> -	return ctrl;
> +	return NULL;
>  }
>  
>  /* Determine if a mounted cgroup hierarchy is unique and record it if so.

Nice simplification!

Reviewed-by: Richard Palethorpe <rpalethorpe@suse.com>

-- 
Thank you,
Richard.

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2022-01-17  9:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-13 12:34 [LTP] [PATCH] lib: rewrite cgroup_find_ctrl with using for_each_ctrl Li Wang
2022-01-17  9:05 ` Richard Palethorpe [this message]
2022-01-18  9:02   ` Li Wang
2022-01-21  5:23 ` Petr Vorel
2022-01-24  0:28   ` Li Wang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87wniyzpj8.fsf@suse.de \
    --to=rpalethorpe@suse.de \
    --cc=liwang@redhat.com \
    --cc=ltp@lists.linux.it \
    --cc=luke.nowakowskikrijger@canonical.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.