cgroups: flatten hierarchy

parent afb9722c
......@@ -7,10 +7,14 @@
#include <stddef.h>
#include <sys/types.h>
#include "macro.h"
#define DEFAULT_CGROUP_MOUNTPOINT "/sys/fs/cgroup"
#define PAYLOAD_CGROUP "lxc.payload"
#define MONITOR_CGROUP "lxc.monitor"
#define PIVOT_CGROUP "lxc.pivot"
#define DEFAULT_PAYLOAD_CGROUP_PREFIX "lxc.payload."
#define DEFAULT_MONITOR_CGROUP_PREFIX "lxc.monitor."
#define CGROUP_CREATE_RETRY "-NNNN"
#define CGROUP_CREATE_RETRY_LEN (STRLITERALLEN(CGROUP_CREATE_RETRY))
#define CGROUP_PIVOT "lxc.pivot"
struct lxc_handler;
struct lxc_conf;
......@@ -90,9 +94,6 @@ struct cgroup_ops {
char *container_cgroup;
char *monitor_cgroup;
/* Static memory, do not free.*/
const char *monitor_pattern;
/* @hierarchies
* - A NULL-terminated array of struct hierarchy, one per legacy
* hierarchy. No duplicates. First sufficient, writeable mounted
......
......@@ -84,7 +84,7 @@ const char *lxc_global_config_value(const char *option_name)
sprintf(user_config_path, "%s/.config/lxc/lxc.conf", user_home);
sprintf(user_default_config_path, "%s/.config/lxc/default.conf", user_home);
sprintf(user_lxc_path, "%s/.local/share/lxc/", user_home);
user_cgroup_pattern = strdup("lxc.payload/%n");
user_cgroup_pattern = strdup("%n");
}
else {
user_config_path = strdup(LXC_GLOBAL_CONF);
......
......@@ -1804,8 +1804,9 @@ static int lxc_spawn(struct lxc_handler *handler)
goto out_delete_net;
}
if (!cgroup_ops->payload_enter(cgroup_ops, handler))
if (!cgroup_ops->payload_enter(cgroup_ops, handler)) {
goto out_delete_net;
}
if (!cgroup_ops->payload_delegate_controllers(cgroup_ops)) {
ERROR("Failed to delegate controllers to payload cgroup");
......
......@@ -730,7 +730,7 @@ int lxc_safe_long_long(const char *numstr, long long int *converted)
return 0;
}
char *must_concat(const char *first, ...)
char *must_concat(size_t *len, const char *first, ...)
{
va_list args;
char *cur, *dest;
......@@ -751,6 +751,8 @@ char *must_concat(const char *first, ...)
va_end(args);
dest[cur_len] = '\0';
if (len)
*len = cur_len;
return dest;
}
......
......@@ -79,7 +79,7 @@ extern int parse_byte_size_string(const char *s, int64_t *converted);
* Concatenate all passed-in strings into one path. Do not fail. If any piece
* is not prefixed with '/', add a '/'.
*/
__attribute__((sentinel)) extern char *must_concat(const char *first, ...);
__attribute__((sentinel)) extern char *must_concat(size_t *len, const char *first, ...);
__attribute__((sentinel)) extern char *must_make_path(const char *first, ...);
__attribute__((sentinel)) extern char *must_append_path(char *first, ...);
......
......@@ -198,13 +198,6 @@ extern int run_command(char *buf, size_t buf_size, int (*child_fn)(void *),
extern int run_command_status(char *buf, size_t buf_size, int (*child_fn)(void *),
void *args);
/* Concatenate all passed-in strings into one path. Do not fail. If any piece
* is not prefixed with '/', add a '/'.
*/
__attribute__((sentinel)) extern char *must_concat(const char *first, ...);
__attribute__((sentinel)) extern char *must_make_path(const char *first, ...);
__attribute__((sentinel)) extern char *must_append_path(char *first, ...);
/* return copy of string @entry; do not fail. */
extern char *must_copy_string(const char *entry);
......
......@@ -46,11 +46,9 @@
/*
* test_running_container: test cgroup functions against a running container
*
* @group : name of the container group or NULL for default "lxc"
* @name : name of the container
*/
static int test_running_container(const char *lxcpath,
const char *group, const char *name)
static int test_running_container(const char *lxcpath, const char *name)
{
int ret = -1;
struct lxc_container *c = NULL;
......@@ -59,7 +57,7 @@ static int test_running_container(const char *lxcpath,
char value[NAME_MAX], value_save[NAME_MAX];
struct cgroup_ops *cgroup_ops;
sprintf(relpath, "%s/%s", group ? group : "lxc.payload", name);
sprintf(relpath, DEFAULT_PAYLOAD_CGROUP_PREFIX "%s", name);
if ((c = lxc_container_new(name, lxcpath)) == NULL) {
TSTERR("container %s couldn't instantiate", name);
......@@ -128,8 +126,7 @@ err1:
return ret;
}
static int test_container(const char *lxcpath,
const char *group, const char *name,
static int test_container(const char *lxcpath, const char *name,
const char *template)
{
int ret;
......@@ -165,7 +162,7 @@ static int test_container(const char *lxcpath,
goto out3;
}
ret = test_running_container(lxcpath, group, name);
ret = test_running_container(lxcpath, name);
c->stop(c);
out3:
......@@ -195,17 +192,17 @@ int main()
* the container ourselves because valgrind gets confused by lxc's
* internal calls to clone.
*/
if (test_running_container(NULL, NULL, "bb01") < 0)
if (test_running_container(NULL, "bb01") < 0)
goto out;
printf("Running container cgroup tests...Passed\n");
#else
if (test_container(NULL, NULL, MYNAME, "busybox") < 0)
if (test_container(NULL, MYNAME, "busybox") < 0)
goto out;
printf("Container creation tests...Passed\n");
if (test_container("/var/lib/lxctest2", NULL, MYNAME, "busybox") < 0)
if (test_container("/var/lib/lxctest2", MYNAME, "busybox") < 0)
goto out;
printf("Container creation with LXCPATH tests...Passed\n");
......
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