public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v5 3/7] Add new CGroups APIs
Date: Fri, 30 Apr 2021 17:48:28 +0200	[thread overview]
Message-ID: <YIwmzFbctS7F4PJu@yuki> (raw)
In-Reply-To: <20210430112649.16302-4-rpalethorpe@suse.com>

Hi!
Found last two very minor issues, otherwise the code looks good.

With the two minor issues fixed:

Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

> +static int cgroup_v1_mounted(void)
> +{
> +	return !!roots[1].ver;
> +}
> +
> +static int cgroup_mounted(void)
> +{
> +	return cgroup_v2_mounted() || cgroup_v1_mounted();
> +}
> +
> +static int cgroup_ctrl_on_v2(const struct cgroup_ctrl *const ctrl)
> +{
> +	return ctrl->ctrl_root && ctrl->ctrl_root->ver == TST_CGROUP_V2;
> +}
> +
> +int cgroup_dir_mk(const struct cgroup_dir *const parent,
^
static

> +		  const char *const dir_name,
> +		  struct cgroup_dir *const new)
> +{
> +	char *dpath;
> +
> +	new->dir_root = parent->dir_root;
> +	new->dir_name = dir_name;
> +	new->dir_parent = parent;
> +	new->ctrl_field = parent->ctrl_field;
> +	new->we_created_it = 0;
> +
> +	if (!mkdirat(parent->dir_fd, dir_name, 0777)) {
> +		new->we_created_it = 1;
> +		goto opendir;
> +	}
> +
> +	if (errno == EEXIST)
> +		goto opendir;
> +
> +	dpath = tst_decode_fd(parent->dir_fd);
> +
> +	if (errno == EACCES) {
> +		tst_brk(TCONF | TERRNO,
> +			"Lack permission to make '%s/%s'; premake it or run as root",
> +			dpath, dir_name);
> +	} else {
> +		tst_brk(TBROK | TERRNO,
> +			"mkdirat(%d<%s>, '%s', 0777)",
> +			parent->dir_fd, dpath, dir_name);
>  	}
> -	SAFE_FCLOSE(file);
>  
> -	return cg_check;
> +	return -1;
> +opendir:
> +	new->dir_fd = SAFE_OPENAT(parent->dir_fd, dir_name,
> +				  O_PATH | O_DIRECTORY);
> +
> +	return 0;
>  }

...

> -void tst_cgroup_umount(const char *cgroup_dir)
> +static void cgroup_group_init(struct tst_cgroup_group *const cg,
> +			      const char *const group_name)
>  {
> -	char *cgroup_new_dir;
> +	memset(cg, 0, sizeof(*cg));
> +
> +	if (!group_name)
> +		return;
>  
> -	cgroup_new_dir = tst_cgroup_get_path(cgroup_dir);
> -	tst_cgroupN_umount(cgroup_dir, cgroup_new_dir);
> -	tst_cgroup_del_path(cgroup_dir);
> +	if (strlen(group_name) > NAME_MAX)
> +		tst_brk(TBROK, "Group name is too long");
> +
> +	strncpy(cg->group_name, group_name, NAME_MAX);

We just checked that it will fit so just strcpy()

>  }

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2021-04-30 15:48 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-30 11:26 [LTP] [PATCH v5 0/7] CGroup API rewrite Richard Palethorpe
2021-04-30 11:26 ` [LTP] [PATCH v5 1/7] API: Add safe openat, printfat, readat and unlinkat Richard Palethorpe
2021-04-30 14:22   ` Cyril Hrubis
2021-05-04  8:31     ` Richard Palethorpe
2021-04-30 11:26 ` [LTP] [PATCH v5 2/7] API: Make tst_count_scanf_conversions public Richard Palethorpe
2021-04-30 14:23   ` Cyril Hrubis
2021-04-30 11:26 ` [LTP] [PATCH v5 3/7] Add new CGroups APIs Richard Palethorpe
2021-04-30 15:48   ` Cyril Hrubis [this message]
2021-04-30 11:26 ` [LTP] [PATCH v5 4/7] Add new CGroups API library tests Richard Palethorpe
2021-04-30 15:57   ` Cyril Hrubis
2021-04-30 11:26 ` [LTP] [PATCH v5 5/7] docs: Update CGroups API Richard Palethorpe
2021-04-30 11:26 ` [LTP] [PATCH v5 6/7] mem: Convert tests to new " Richard Palethorpe
2021-05-03 11:20   ` Cyril Hrubis
2021-05-04  9:03     ` Richard Palethorpe
2021-04-30 11:26 ` [LTP] [PATCH v5 7/7] madvise06: Convert " Richard Palethorpe
2021-05-03 13:28   ` Cyril Hrubis

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=YIwmzFbctS7F4PJu@yuki \
    --to=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox