Commit a2f2695a by Christian Brauner Committed by Stéphane Graber

start, namespace: move ns_info to namespace.{c,h}

It's much more appropriate there and makes start.{c,h} cleaner and leaner. Signed-off-by: 's avatarChristian Brauner <christian.brauner@canonical.com>
parent c6677625
...@@ -64,29 +64,29 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags) ...@@ -64,29 +64,29 @@ pid_t lxc_clone(int (*fn)(void *), void *arg, int flags)
ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, &clone_arg); ret = clone(do_clone, stack + stack_size, flags | SIGCHLD, &clone_arg);
#endif #endif
if (ret < 0) if (ret < 0)
ERROR("failed to clone (%#x): %s", flags, strerror(errno)); ERROR("Failed to clone (%#x): %s.", flags, strerror(errno));
return ret; return ret;
} }
static const char * const namespaces_list[] = { const struct ns_info ns_info[LXC_NS_MAX] = {
"MOUNT", "PID", "UTSNAME", "IPC", [LXC_NS_MNT] = {"mnt", CLONE_NEWNS, "CLONE_NEWNS"},
"USER", "NETWORK" [LXC_NS_PID] = {"pid", CLONE_NEWPID, "CLONE_NEWPID"},
}; [LXC_NS_UTS] = {"uts", CLONE_NEWUTS, "CLONE_NEWUTS"},
static const int cloneflags_list[] = { [LXC_NS_IPC] = {"ipc", CLONE_NEWIPC, "CLONE_NEWIPC"},
CLONE_NEWNS, CLONE_NEWPID, CLONE_NEWUTS, CLONE_NEWIPC, [LXC_NS_USER] = {"user", CLONE_NEWUSER, "CLONE_NEWUSER"},
CLONE_NEWUSER, CLONE_NEWNET [LXC_NS_NET] = {"net", CLONE_NEWNET, "CLONE_NEWNET"},
[LXC_NS_CGROUP] = {"cgroup", CLONE_NEWCGROUP, "CLONE_NEWCGROUP"}
}; };
int lxc_namespace_2_cloneflag(char *namespace) int lxc_namespace_2_cloneflag(char *namespace)
{ {
int i, len; int i;
len = sizeof(namespaces_list)/sizeof(namespaces_list[0]); for (i = 0; i < LXC_NS_MAX; i++)
for (i = 0; i < len; i++) if (!strcasecmp(ns_info[i].proc_name, namespace))
if (!strcmp(namespaces_list[i], namespace)) return ns_info[i].clone_flag;
return cloneflags_list[i];
ERROR("invalid namespace name %s", namespace); ERROR("Invalid namespace name: %s.", namespace);
return -1; return -1;
} }
...@@ -96,7 +96,7 @@ int lxc_fill_namespace_flags(char *flaglist, int *flags) ...@@ -96,7 +96,7 @@ int lxc_fill_namespace_flags(char *flaglist, int *flags)
int aflag; int aflag;
if (!flaglist) { if (!flaglist) {
ERROR("need at least one namespace to unshare"); ERROR("At least one namespace is needed.");
return -1; return -1;
} }
......
...@@ -53,6 +53,23 @@ ...@@ -53,6 +53,23 @@
# define CLONE_NEWNET 0x40000000 # define CLONE_NEWNET 0x40000000
#endif #endif
enum {
LXC_NS_MNT,
LXC_NS_PID,
LXC_NS_UTS,
LXC_NS_IPC,
LXC_NS_USER,
LXC_NS_NET,
LXC_NS_CGROUP,
LXC_NS_MAX
};
extern const struct ns_info {
const char *proc_name;
int clone_flag;
const char *flag_name;
} ns_info[LXC_NS_MAX];
#if defined(__ia64__) #if defined(__ia64__)
int __clone2(int (*__fn) (void *__arg), void *__child_stack_base, int __clone2(int (*__fn) (void *__arg), void *__child_stack_base,
size_t __child_stack_size, int __flags, void *__arg, ...); size_t __child_stack_size, int __flags, void *__arg, ...);
...@@ -62,7 +79,6 @@ int clone(int (*fn)(void *), void *child_stack, ...@@ -62,7 +79,6 @@ int clone(int (*fn)(void *), void *child_stack,
/* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ ); /* pid_t *ptid, struct user_desc *tls, pid_t *ctid */ );
#endif #endif
extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags); extern pid_t lxc_clone(int (*fn)(void *), void *arg, int flags);
extern int lxc_namespace_2_cloneflag(char *namespace); extern int lxc_namespace_2_cloneflag(char *namespace);
......
...@@ -76,16 +76,6 @@ ...@@ -76,16 +76,6 @@
lxc_log_define(lxc_start, lxc); lxc_log_define(lxc_start, lxc);
const struct ns_info ns_info[LXC_NS_MAX] = {
[LXC_NS_MNT] = {"mnt", CLONE_NEWNS},
[LXC_NS_PID] = {"pid", CLONE_NEWPID},
[LXC_NS_UTS] = {"uts", CLONE_NEWUTS},
[LXC_NS_IPC] = {"ipc", CLONE_NEWIPC},
[LXC_NS_USER] = {"user", CLONE_NEWUSER},
[LXC_NS_NET] = {"net", CLONE_NEWNET},
[LXC_NS_CGROUP] = {"cgroup", CLONE_NEWCGROUP}
};
extern void mod_all_rdeps(struct lxc_container *c, bool inc); extern void mod_all_rdeps(struct lxc_container *c, bool inc);
static bool do_destroy_container(struct lxc_conf *conf); static bool do_destroy_container(struct lxc_conf *conf);
static int lxc_rmdir_onedev_wrapper(void *data); static int lxc_rmdir_onedev_wrapper(void *data);
...@@ -1148,7 +1138,9 @@ static int lxc_spawn(struct lxc_handler *handler) ...@@ -1148,7 +1138,9 @@ static int lxc_spawn(struct lxc_handler *handler)
SYSERROR("Failed to clone a new set of namespaces."); SYSERROR("Failed to clone a new set of namespaces.");
goto out_delete_net; goto out_delete_net;
} }
INFO("Cloned a set of new namespaces."); for (i = 0; i < LXC_NS_MAX; i++)
if (flags & ns_info[i].clone_flag)
INFO("Cloned %s.", ns_info[i].flag_name);
if (!preserve_ns(handler->nsfd, handler->clone_flags | preserve_mask, handler->pid)) if (!preserve_ns(handler->nsfd, handler->clone_flags | preserve_mask, handler->pid))
INFO("Failed to preserve namespace for lxc.hook.stop."); INFO("Failed to preserve namespace for lxc.hook.stop.");
......
...@@ -42,24 +42,6 @@ struct lxc_operations { ...@@ -42,24 +42,6 @@ struct lxc_operations {
struct cgroup_desc; struct cgroup_desc;
enum {
LXC_NS_MNT,
LXC_NS_PID,
LXC_NS_UTS,
LXC_NS_IPC,
LXC_NS_USER,
LXC_NS_NET,
LXC_NS_CGROUP,
LXC_NS_MAX
};
struct ns_info {
const char *proc_name;
int clone_flag;
};
extern const struct ns_info ns_info[LXC_NS_MAX];
struct lxc_handler { struct lxc_handler {
pid_t pid; pid_t pid;
char *name; char *name;
......
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