]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: Add is_tid parameter to cgroup_get_cg_type()
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Thu, 26 Sep 2024 10:45:09 +0000 (16:15 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Mon, 7 Oct 2024 19:50:21 +0000 (13:50 -0600)
Add new parameter bool is_tid to cgroup_get_cg_type(), this parameter
gets set, when called from cgroup_attach_thread_tid() path. When set and
cgroup.type is 'domain threaded', it returns 'cgroup.threads' instead of
'cgroup.procs'.

Fixes: https://github.com/libcgroup/libcgroup/issues/441
Reported-by: Adriaan Schmidt <adriaan.schmidt@siemens.com>
Signed-off-by: Kamalesh Babulal <kamalesh.babulal@oracle.com>
Signed-off-by: Tom Hromatka <tom.hromatka@oracle.com>
src/api.c

index 47b5b9a572a5e918c28dfe25413e312f710cb1b7..49ee1501c9e42616bae6a157e42990ab0a7d0b94 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -1829,7 +1829,7 @@ char *cg_build_path(const char *name, char *path, const char *type)
 }
 
 static int cgroup_get_cg_type(const char * const path, char * const type,
-                             size_t type_sz)
+                             size_t type_sz, bool is_tid)
 {
        char cg_type_path[FILENAME_MAX];
        char cg_type[CGV2_CONTROLLERS_LL_MAX];
@@ -1858,17 +1858,24 @@ static int cgroup_get_cg_type(const char * const path, char * const type,
 
        len = strlen(cg_type) - 1;
        /*
-        * Append cgroup.threads to the path, if the cgroup.type is threaded
-        * and cgroup.procs for type domain, domain threaded. domain type is
-        * used for regular cgroup and domain threaded for root of threaded
-        * cgroup v2 subtree.  Another possible type is domain invalid, it's
-        * an invalid state, under the threaded subtree.
+        * Append cgroup.threads to the path, if the cgroup.type is 'threaded'
+        * or 'domain threaded', with is_tid set. For cgroup.type 'domain' or
+        * 'domain invalid' or 'domain threaded', with is_tid is unset, append
+        * cgroup.procs to the path.
+        *
+        * domain type is used for regular cgroup and domain threaded for root
+        * of threaded cgroup v2 subtree. Another possible type is domain invalid,
+        * it's an invalid state, under the threaded subtree. is_tid is set when
+        * called from cgroup_attach_thread_tid() or unset other wise.
+        * Refer to Kernel's cgroup v2 documentation for more detailed explanation
+        * on domains types.
         */
-       if (strncmp(cg_type, "domain", len) == 0 ||
-           strncmp(cg_type, "domain threaded", len) == 0 ||
-           strncmp(cg_type, "domain invalid", len) == 0) {
+       if (strncmp(cg_type, "domain", len) == 0         ||
+           strncmp(cg_type, "domain invalid", len) == 0 ||
+           (!is_tid && strncmp(cg_type, "domain threaded", len) == 0)) {
                snprintf(type, type_sz, "cgroup.procs");
-       } else if (strncmp(cg_type, "threaded", len) == 0) {
+       } else if (strncmp(cg_type, "threaded", len) == 0 ||
+                  (is_tid && strncmp(cg_type, "domain threaded", len) == 0)) {
                snprintf(type, type_sz, "cgroup.threads");
        } else {
                cgroup_warn("invalid %scgroup.type: %s\n", path, cg_type);
@@ -1902,7 +1909,7 @@ int cgroup_build_tasks_procs_path(char * const path, size_t path_sz, const char
                err = 0;
                break;
        case CGROUP_V2:
-               err = cgroup_get_cg_type(path, cg_type, sizeof(cg_type));
+               err = cgroup_get_cg_type(path, cg_type, sizeof(cg_type), 0);
                if (err)
                        goto error;