[lxc-devel] [lxc/master] attach: do not reload container
brauner on Github
lxc-bot at linuxcontainers.org
Thu May 16 13:34:42 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 475 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190516/51763cf3/attachment.bin>
-------------- next part --------------
From 78b44e419b009d84500361c3c9ac294cd32d2a5e Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 16 May 2019 15:29:41 +0200
Subject: [PATCH] attach: do not reload container
Let lxc_attach() reuse the already initialized container.
Closes https://github.com/lxc/lxd/issues/5755.
Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
src/lxc/attach.c | 26 +++++++++++++++++---------
src/lxc/attach.h | 2 +-
src/lxc/lxccontainer.c | 4 ++--
3 files changed, 20 insertions(+), 12 deletions(-)
diff --git a/src/lxc/attach.c b/src/lxc/attach.c
index ce51352c67..c91ff751f4 100644
--- a/src/lxc/attach.c
+++ b/src/lxc/attach.c
@@ -1008,9 +1008,9 @@ static inline void lxc_attach_terminal_close_log(struct lxc_terminal *terminal)
close_prot_errno_disarm(terminal->log_fd);
}
-int lxc_attach(const char *name, const char *lxcpath,
- lxc_attach_exec_t exec_function, void *exec_payload,
- lxc_attach_options_t *options, pid_t *attached_process)
+int lxc_attach(struct lxc_container *container, lxc_attach_exec_t exec_function,
+ void *exec_payload, lxc_attach_options_t *options,
+ pid_t *attached_process)
{
int i, ret, status;
int ipc_sockets[2];
@@ -1020,6 +1020,7 @@ int lxc_attach(const char *name, const char *lxcpath,
struct lxc_proc_context_info *init_ctx;
struct lxc_terminal terminal;
struct lxc_conf *conf;
+ char *name, *lxcpath;
struct attach_clone_payload payload = {0};
ret = access("/proc/self/ns", X_OK);
@@ -1028,21 +1029,34 @@ int lxc_attach(const char *name, const char *lxcpath,
return -1;
}
+ if (!container)
+ return minus_one_set_errno(EINVAL);
+
+ if (lxc_container_get(container))
+ return minus_one_set_errno(EINVAL);
+
+ name = container->name;
+ lxcpath = container->config_path;
+
if (!options)
options = &attach_static_default_options;
init_pid = lxc_cmd_get_init_pid(name, lxcpath);
if (init_pid < 0) {
ERROR("Failed to get init pid");
+ lxc_container_put(container);
return -1;
}
init_ctx = lxc_proc_get_context_info(init_pid);
if (!init_ctx) {
ERROR("Failed to get context of init process: %ld", (long)init_pid);
+ lxc_container_put(container);
return -1;
}
+ init_ctx->container = container;
+
personality = get_personality(name, lxcpath);
if (init_ctx->personality < 0) {
ERROR("Failed to get personality of the container");
@@ -1051,12 +1065,6 @@ int lxc_attach(const char *name, const char *lxcpath,
}
init_ctx->personality = personality;
- init_ctx->container = lxc_container_new(name, lxcpath);
- if (!init_ctx->container) {
- lxc_proc_put_context_info(init_ctx);
- return -1;
- }
-
if (!init_ctx->container->lxc_conf) {
init_ctx->container->lxc_conf = lxc_conf_init();
if (!init_ctx->container->lxc_conf) {
diff --git a/src/lxc/attach.h b/src/lxc/attach.h
index 4bf9578ee9..c576aa9fca 100644
--- a/src/lxc/attach.h
+++ b/src/lxc/attach.h
@@ -41,7 +41,7 @@ struct lxc_proc_context_info {
int ns_fd[LXC_NS_MAX];
};
-extern int lxc_attach(const char *name, const char *lxcpath,
+extern int lxc_attach(struct lxc_container *container,
lxc_attach_exec_t exec_function, void *exec_payload,
lxc_attach_options_t *options, pid_t *attached_process);
diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index cea8aa5d7b..e3262a4611 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -4064,7 +4064,7 @@ static int lxcapi_attach(struct lxc_container *c, lxc_attach_exec_t exec_functio
current_config = c->lxc_conf;
- ret = lxc_attach(c->name, c->config_path, exec_function, exec_payload, options, attached_process);
+ ret = lxc_attach(c, exec_function, exec_payload, options, attached_process);
current_config = NULL;
return ret;
}
@@ -4081,7 +4081,7 @@ static int do_lxcapi_attach_run_wait(struct lxc_container *c, lxc_attach_options
command.program = (char*)program;
command.argv = (char**)argv;
- r = lxc_attach(c->name, c->config_path, lxc_attach_run_command, &command, options, &pid);
+ r = lxc_attach(c, lxc_attach_run_command, &command, options, &pid);
if (r < 0) {
ERROR("ups");
return r;
More information about the lxc-devel
mailing list