[LTP] [PATCH v3 2/3] tst_cgroup: Add safe_cg_open and safe_cg_fchown functions

Richard Palethorpe rpalethorpe@suse.de
Thu Aug 25 16:57:20 CEST 2022


Hello,

Yang Xu <xuyang2018.jy@fujitsu.com> writes:

> safe_cg_open is used to open the sub control's file ie cgroup.procs
> and returns the opened fd number. The opened fd array is stored in
> fds argument.
>
> safe_cg_fchown is used to use fchownat to change file's uid and gid.
>
> Signed-off-by: Yang Xu <xuyang2018.jy@fujitsu.com>
> ---
>  include/tst_cgroup.h | 44 +++++++++++++++++++++++++++++
>  lib/tst_cgroup.c     | 66 +++++++++++++++++++++++++++-----------------
>  2 files changed, 85 insertions(+), 25 deletions(-)
>
> diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h
> index d06847cc6..70c5b3fd4 100644
> --- a/include/tst_cgroup.h
> +++ b/include/tst_cgroup.h
> @@ -89,6 +89,32 @@ enum tst_cg_ver {
>  	TST_CG_V2 = 2,
>  };
>  
> +/* Controller sub-systems */
> +enum cgroup_ctrl_indx {
> +	CTRL_MEMORY = 1,
> +	CTRL_CPU,
> +	CTRL_CPUSET,
> +	CTRL_IO,
> +	CTRL_PIDS,
> +	CTRL_HUGETLB,
> +	CTRL_CPUACCT,
> +	CTRL_DEVICES,
> +	CTRL_FREEZER,
> +	CTRL_NETCLS,
> +	CTRL_NETPRIO,
> +	CTRL_BLKIO,
> +	CTRL_MISC,
> +	CTRL_PERFEVENT,
> +	CTRL_DEBUG
> +};
> +
> +#define CTRLS_MAX CTRL_DEBUG
> +
> +/* At most we can have one cgroup V1 tree for each controller and one
> + * (empty) v2 tree.
> + */
> +#define ROOTS_MAX (CTRLS_MAX + 1)

These need TST_CG_ prepending to them to stop name collisions.

-- 
Thank you,
Richard.


More information about the ltp mailing list