]> git.ipfire.org Git - thirdparty/libcgroup.git/commitdiff
api: add helper to move threads into cgroup (v1)
authorKamalesh Babulal <kamalesh.babulal@oracle.com>
Wed, 6 Mar 2024 01:55:17 +0000 (07:25 +0530)
committerTom Hromatka <tom.hromatka@oracle.com>
Wed, 20 Mar 2024 20:40:45 +0000 (14:40 -0600)
Introduce a new helper cgroup_attach_task_tid(), which will be used to
move threads into a cgroup for legacy/hybrid controllers running setup
in cgroup v1 mode. The core of the helper is craved out of
cgroup_attach_task_pid(), now both cgroup_attach_task_pid() and
cgroup_attach_task() calls cgroup_attach_task_tid() in turn.

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

index e8b9752367bff8887f899a3e9d79029bde585b03..383bbe931536c74b955d27fb6e99e98452f67fd7 100644 (file)
--- a/src/api.c
+++ b/src/api.c
@@ -2012,16 +2012,7 @@ err:
        return ret;
 }
 
-/**
- *  cgroup_attach_task_pid is used to assign tasks to a cgroup.
- *  struct cgroup *cgroup: The cgroup to assign the thread to.
- *  pid_t tid: The thread to be assigned to the cgroup.
- *
- *  returns 0 on success.
- *  returns ECGROUPNOTOWNER if the caller does not have access to the cgroup.
- *  returns ECGROUPNOTALLOWED for other causes of failure.
- */
-int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid)
+static int cgroup_attach_task_tid(struct cgroup *cgroup, pid_t tid)
 {
        char path[FILENAME_MAX] = {0};
        char *controller_name;
@@ -2086,6 +2077,20 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid)
        return 0;
 }
 
+/**
+ *  cgroup_attach_task_pid is used to assign tasks to a cgroup.
+ *  struct cgroup *cgroup: The cgroup to assign the thread to.
+ *  pid_t tid: The thread to be assigned to the cgroup.
+ *
+ *  returns 0 on success.
+ *  returns ECGROUPNOTOWNER if the caller does not have access to the cgroup.
+ *  returns ECGROUPNOTALLOWED for other causes of failure.
+ */
+int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid)
+{
+       return cgroup_attach_task_tid(cgroup, tid);
+}
+
 /**
  * cgroup_attach_task is used to attach the current thread to a cgroup.
  * struct cgroup *cgroup: The cgroup to assign the current thread to.
@@ -2095,11 +2100,8 @@ int cgroup_attach_task_pid(struct cgroup *cgroup, pid_t tid)
 int cgroup_attach_task(struct cgroup *cgroup)
 {
        pid_t tid = cg_gettid();
-       int error;
-
-       error = cgroup_attach_task_pid(cgroup, tid);
 
-       return error;
+       return cgroup_attach_task_tid(cgroup, tid);
 }
 
 /**