]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
cgxset: Add a flag to ignore settings that can't be converted
authorTom Hromatka <tom.hromatka@oracle.com>
Mon, 31 Jan 2022 15:21:00 +0000 (08:21 -0700)
committerTom Hromatka <tom.hromatka@oracle.com>
Thu, 3 Feb 2022 21:42:39 +0000 (14:42 -0700)
Add a flag, "-i", to cgxset to ignore settings that can't be
converted from cgroup v1 to cgroup v2 or vice versa.

Some cgroup v1 settings, e.g. cpuset.sched_relax_domain_level,
don't have a cgroup v2 equivalent and likely never will.  This
flag allows users to ignore errors from these unconvertable
settings.

Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
Reviewed-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
src/tools/cgxset.c

index efd050a5c80cd4548ea1d480f6437852a5a43203..95e7d1c09662435865a3ff5eb48c00d596c9a3a7 100644 (file)
@@ -43,6 +43,7 @@ static struct option const long_options[] =
 {
        {"v1", no_argument, NULL, '1'},
        {"v2", no_argument, NULL, '2'},
+       {"ignore-unmappable", no_argument, NULL, 'i'},
        {"rule", required_argument, NULL, 'r'},
        {"help", no_argument, NULL, 'h'},
        {"copy-from", required_argument, NULL, COPY_FROM_OPTION},
@@ -96,6 +97,8 @@ static void usage(int status, const char *program_name)
               "v1 format\n");
        printf("  -2, --v2                      Provided parameters are in "
               "v2 format\n");
+       printf("  -i, --ignore-unmappable       Do not return an error for settings "
+              "that cannot be converted\n");
        printf("  -r, --variable <name>                 Define parameter "\
                "to set\n");
        printf("  --copy-from <source_cgroup_path>      Control group whose "\
@@ -169,6 +172,7 @@ int main(int argc, char *argv[])
        struct cgroup *cgroup;
        struct cgroup *converted_src_cgroup;
        enum cg_version_t src_version = CGROUP_UNK;
+       bool ignore_unmappable = false;
 
        /* no parametr on input */
        if (argc < 2) {
@@ -179,7 +183,7 @@ int main(int argc, char *argv[])
 
        /* parse arguments */
        while ((c = getopt_long (argc, argv,
-               "r:h12", long_options, NULL)) != -1) {
+               "r:h12i", long_options, NULL)) != -1) {
                switch (c) {
                case 'h':
                        usage(0, argv[0]);
@@ -234,6 +238,9 @@ int main(int argc, char *argv[])
                case '2':
                        src_version = CGROUP_V2;
                        break;
+               case 'i':
+                       ignore_unmappable = true;
+                       break;
                default:
                        usage(1, argv[0]);
                        ret = -1;
@@ -304,7 +311,13 @@ int main(int argc, char *argv[])
 
                ret = cgroup_convert_cgroup(converted_src_cgroup, CGROUP_DISK,
                                            src_cgroup, src_version);
-               if (ret)
+               if (ret == ECGNOVERSIONCONVERT && ignore_unmappable)
+                       /* The user has specified that we should ignore
+                        * any errors due to being unable to map from v1 to
+                        * v2 or vice versa
+                        */
+                       ret = 0;
+               else if (ret)
                        goto err;
 
                cgroup_free(&cgroup);