]> git.proxmox.com Git - mirror_lxc.git/commitdiff
cgroups: introduce fd-only cgroup attach
authorChristian Brauner <christian.brauner@ubuntu.com>
Tue, 23 Feb 2021 13:01:59 +0000 (14:01 +0100)
committerChristian Brauner <christian.brauner@ubuntu.com>
Tue, 23 Feb 2021 15:15:32 +0000 (16:15 +0100)
Signed-off-by: Christian Brauner <christian.brauner@ubuntu.com>
src/lxc/cgroups/cgfsng.c
src/lxc/cgroups/cgroup.h

index a20b9d1c98c12435a5695742954077716861b66f..5d4275c01387ec523f7cfa52e84c952a36bf679e 100644 (file)
@@ -3375,12 +3375,14 @@ static int __unified_attach_fd(const struct lxc_conf *conf, int fd_unified, pid_
 static int __cgroup_attach_many(const struct lxc_conf *conf, const char *name,
                                const char *lxcpath, pid_t pid)
 {
-       call_cleaner(put_unix_fds) struct unix_fds *fds = &(struct unix_fds){};
+       call_cleaner(put_cgroup_ctx) struct cgroup_ctx *ctx = &(struct cgroup_ctx){};
        int ret;
        char pidstr[INTTYPE_TO_STRLEN(pid_t)];
+       size_t idx;
        ssize_t pidstr_len;
 
-       ret = lxc_cmd_get_cgroup_fd(name, lxcpath, NULL, true, fds);
+       ret = lxc_cmd_get_cgroup_ctx(name, lxcpath, NULL, true,
+                                    sizeof(struct cgroup_ctx), ctx);
        if (ret < 0)
                return ret_errno(ENOSYS);
 
@@ -3388,8 +3390,8 @@ static int __cgroup_attach_many(const struct lxc_conf *conf, const char *name,
        if (pidstr_len < 0)
                return pidstr_len;
 
-       for (size_t idx = 0; idx < fds->fd_count_ret; idx++) {
-               int dfd_con = fds->fd[idx];
+       for (idx = 0; idx < ctx->fd_len; idx++) {
+               int dfd_con = ctx->fd[idx];
 
                if (unified_cgroup_fd(dfd_con))
                        ret = __unified_attach_fd(conf, dfd_con, pid);
@@ -3401,7 +3403,11 @@ static int __cgroup_attach_many(const struct lxc_conf *conf, const char *name,
                        TRACE("Attached to cgroup fd %d", dfd_con);
        }
 
-       return log_trace(0, "Attached to cgroups");
+       if (idx == 0)
+               return syserrno_set(-ENOENT, "Failed to attach to cgroups");
+
+       TRACE("Attached to %s cgroup layout", cgroup_layout_name(ctx->cgroup_layout));
+       return 0;
 }
 
 static int __cgroup_attach_unified(const struct lxc_conf *conf, const char *name,
index 6c4e85b1afa3c551225d65e1e60a4abef35fe74f..1aeb8fbef5fbb86fbc0f7a5f503b53508c8c9537 100644 (file)
@@ -35,6 +35,22 @@ typedef enum {
         CGROUP_LAYOUT_UNIFIED =  2,
 } cgroup_layout_t;
 
+static inline const char *cgroup_layout_name(cgroup_layout_t layout)
+{
+       switch (layout) {
+       case CGROUP_LAYOUT_LEGACY:
+               return "legacy";
+       case CGROUP_LAYOUT_HYBRID:
+               return "hybrid";
+       case CGROUP_LAYOUT_UNIFIED:
+               return "unified";
+       case CGROUP_LAYOUT_UNKNOWN:
+               break;
+       }
+
+       return "unknown";
+}
+
 typedef enum {
        LEGACY_HIERARCHY = CGROUP_SUPER_MAGIC,
        UNIFIED_HIERARCHY = CGROUP2_SUPER_MAGIC,