[LTP] [PATCH 4/6] API/cgroup: Implement tst_cgroup_load_config()
Li Wang
liwang@redhat.com
Fri Jan 14 07:57:04 CET 2022
Luke Nowakowski-Krijger <luke.nowakowskikrijger@canonical.com> wrote:
> +static int parse_root_config(char *config_entry)
> +{
> + char *key;
> + char *value;
> + struct cgroup_root *root;
> +
> + for (key = strtok(config_entry, " "); key; key = strtok(NULL, " ")) {
> + if (!(value = strchr(key, '='))) {
> + if (!(root = cgroup_find_root(key)))
> + tst_brk(TBROK, "Could not find root from config. Roots changing between calls?");
> +
> + continue;
> + }
> +
> + *value = '\0';
> + value = value + 1;
> +
> + if (!strcmp(key, CONFIG_MOUNTROOT_KEY) && !strcmp(value, "yes")) {
> + root->we_mounted_it = 1;
> +
> + } else if (!strcmp(key, CONFIG_LTPDIR_KEY) && !root->ltp_dir.dir_name) {
> + cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir);
> + if (!strcmp(value, "yes"))
> + root->ltp_dir.we_created_it = 1;
> +
> + } else if (!strcmp(key, CONFIG_DRAINDIR_KEY) && !root->drain_dir.dir_name) {
> + cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
> + if (!strcmp(value, "yes"))
> + root->ltp_dir.we_created_it = 1;
I think that parsing the CONFIG_DRAINDIR_KEY from '$_cgroup_state'
is superfluous. Because from the tst_cgroup_cleanup, if
root->ltp_dir.we_created_it
is 1 then both of the two directories will be removed, so just using
CONFIG_LTPDIR_KE
to track the status is enough.
And maybe it is not necessary to print "Created_Drain_Dir=xx" in
tst_cgroup_print_config at all.
Then, the code snippet could be as:
} else if (!strcmp(key, CONFIG_LTPDIR_KEY) &&
!root->ltp_dir.dir_name) {
cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir,
&root->ltp_dir);
cgroup_dir_mk(&root->ltp_dir,
cgroup_ltp_drain_dir, &root->drain_dir);
if (!strcmp(value, "yes"))
root->ltp_dir.we_created_it = 1;
> +
> + } else if (!strcmp(key, CONFIG_TESTID_KEY) && strcmp(value, "NULL") &&
> + !root->test_dir.dir_name) {
> + cgroup_dir_mk(&root->ltp_dir, value, &root->test_dir);
> + root->test_dir.we_created_it = 1;
> + }
> + }
> +
> + return 0;
> +}
--
Regards,
Li Wang
More information about the ltp
mailing list