cgroups: add cgroup_get()

This is a unified hierarchy only method which doesn't need to initialize a full cgroup driver. Instead, it relies on the command socket to retrieve a cgroup2 file descriptor to the container's cgroup. Signed-off-by: 's avatarChristian Brauner <christian.brauner@ubuntu.com>
parent d2605aa8
...@@ -2500,6 +2500,31 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops, ...@@ -2500,6 +2500,31 @@ __cgfsng_ops static bool cgfsng_attach(struct cgroup_ops *ops,
return true; return true;
} }
int cgroup_get(struct lxc_conf *conf, const char *filename,
char *buf, size_t len,
const char *name, const char *lxcpath)
{
__do_close int unified_fd = -EBADF;
ssize_t ret;
if (!conf || is_empty_string(filename) || is_empty_string(name) ||
is_empty_string(lxcpath))
return ret_errno(EINVAL);
if ((buf && !len) || (len && !buf))
return ret_errno(EINVAL);
unified_fd = lxc_cmd_get_cgroup2_fd(name, lxcpath);
if (unified_fd < 0)
return ret_errno(ENOCGROUP2);
ret = lxc_read_try_buf_at(unified_fd, filename, buf, len);
if (ret < 0)
SYSERROR("Failed to read cgroup value");
return ret;
}
/* Called externally (i.e. from 'lxc-cgroup') to query cgroup limits. Here we /* Called externally (i.e. from 'lxc-cgroup') to query cgroup limits. Here we
* don't have a cgroup_data set up, so we ask the running container through the * don't have a cgroup_data set up, so we ask the running container through the
* commands API for the cgroup path. * commands API for the cgroup path.
......
...@@ -190,6 +190,9 @@ __hidden extern void prune_init_scope(char *cg); ...@@ -190,6 +190,9 @@ __hidden extern void prune_init_scope(char *cg);
__hidden extern int cgroup_attach(const struct lxc_conf *conf, const char *name, __hidden extern int cgroup_attach(const struct lxc_conf *conf, const char *name,
const char *lxcpath, pid_t pid); const char *lxcpath, pid_t pid);
__hidden extern int cgroup_get(struct lxc_conf *conf, const char *filename,
char *buf, size_t len, const char *name,
const char *lxcpath);
static inline bool pure_unified_layout(const struct cgroup_ops *ops) static inline bool pure_unified_layout(const struct cgroup_ops *ops)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment