diff mbox series

[2/6] API/cgroup: Add cgroup_find_root helper function

Message ID f69cdd6ec3cffc8d2bd5990feb131eb6be73a33e.1641376050.git.luke.nowakowskikrijger@canonical.com
State Superseded
Headers show
Series Expand Cgroup shell library | expand

Commit Message

Luke Nowakowski-Krijger Jan. 5, 2022, 10 a.m. UTC
Add a helper function similar to cgroup_find_ctrl to make matching paths
to roots more convenient.

Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
---
 lib/tst_cgroup.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

Comments

Li Wang Jan. 12, 2022, 10:46 a.m. UTC | #1
On Wed, Jan 5, 2022 at 6:00 PM Luke Nowakowski-Krijger
<luke.nowakowskikrijger@canonical.com> wrote:
>
> Add a helper function similar to cgroup_find_ctrl to make matching paths
> to roots more convenient.
>
> Signed-off-by: Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com>
> ---
>  lib/tst_cgroup.c | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
> index 166d0f97e..b06ae6ab7 100644
> --- a/lib/tst_cgroup.c
> +++ b/lib/tst_cgroup.c
> @@ -365,6 +365,19 @@ static struct cgroup_ctrl *cgroup_find_ctrl(const char *const ctrl_name)
>         return ctrl;
>  }
>
> +static struct cgroup_root *cgroup_find_root(const char *const mnt_path)
> +{
> +       struct cgroup_root *root = roots;
> +
> +       while (root->ver && strcmp(root->mnt_path, mnt_path))
> +               root++;
> +
> +       if (!root->ver)
> +               root = NULL;
> +
> +       return root;
> +}

I suggest using for_each_root() macro here, otherwise as I commented
it can't parse root in V1.

static struct cgroup_root *cgroup_find_root(const char *const mnt_path)
{
        struct cgroup_root *root;

        for_each_root(root) {
                if (!strcmp(root->mnt_path, mnt_path))
                        return root;
        }

        return NULL;
}



> +
>  /* Determine if a mounted cgroup hierarchy is unique and record it if so.
>   *
>   * For CGroups V2 this is very simple as there is only one
> --
> 2.32.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
>
diff mbox series

Patch

diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 166d0f97e..b06ae6ab7 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -365,6 +365,19 @@  static struct cgroup_ctrl *cgroup_find_ctrl(const char *const ctrl_name)
 	return ctrl;
 }
 
+static struct cgroup_root *cgroup_find_root(const char *const mnt_path)
+{
+	struct cgroup_root *root = roots;
+
+	while (root->ver && strcmp(root->mnt_path, mnt_path))
+		root++;
+
+	if (!root->ver)
+		root = NULL;
+
+	return root;
+}
+
 /* Determine if a mounted cgroup hierarchy is unique and record it if so.
  *
  * For CGroups V2 this is very simple as there is only one