cgroups: flatten hierarchy

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