From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
To: dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org
Cc: Containers
<containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org>,
clg-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org
Subject: [PATCH 5/5][lxc] Hook up lxc_checkpoint() with app_checkpoint()
Date: Thu, 18 Mar 2010 23:41:41 -0700 [thread overview]
Message-ID: <20100319064141.GF25732@us.ibm.com> (raw)
In-Reply-To: <20100319063912.GA25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
From: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
Date: Thu, 11 Mar 2010 21:32:38 -0800
Subject: [PATCH 5/5][lxc] Hook up lxc_checkpoint() with app_checkpoint()
Have lxc_checkpoint() call app_checkpoint() implemented in checkpoint.o
in the USER-CR git tree
TODO:
- Map lxc_flags to flags in sys_checkpoint()
- Initialize app_checkpoint_args.debug and other fields based on
command line options to lxc_checkpoint rather than hard-coding
them
Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
src/lxc/checkpoint.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++-
src/lxc/commands.c | 3 ++
src/lxc/commands.h | 1 +
src/lxc/state.c | 26 ++++++++++++++
4 files changed, 120 insertions(+), 1 deletions(-)
diff --git a/src/lxc/checkpoint.c b/src/lxc/checkpoint.c
index 7e8a93e..0fbabc8 100644
--- a/src/lxc/checkpoint.c
+++ b/src/lxc/checkpoint.c
@@ -22,10 +22,99 @@
*/
#include <lxc/lxc.h>
#include <lxc/log.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <linux/checkpoint.h>
+
+#include "commands.h"
+#include "arguments.h"
+#include "app-checkpoint.h"
lxc_log_define(lxc_checkpoint, lxc);
-int lxc_checkpoint(const char *name, const char *statefile, int flags)
+find_cinit_pid(const char *name)
{
+ struct lxc_command command = {
+ .request = { .type = LXC_COMMAND_CINIT_PID },
+ };
+
+ int ret, stopped;
+
+ ret = lxc_command(name, &command, &stopped);
+ if (ret < 0) {
+ ERROR("failed to send command");
+ return -1;
+ }
+
+ ERROR("find_cinit_pid %d\n", command.answer.ret);
+
+ return command.answer.ret;
+}
+
+int lxc_checkpoint(const char *name, const char *statefile, int lxc_flags)
+{
+ int ret;
+ int pid;
+ int flags;
+ struct stat statbuf;
+ struct app_checkpoint_args crargs;
+
+ if (access(statefile, F_OK) == 0) {
+ ret = stat(statefile, &statbuf);
+ if (ret < 0) {
+ ERROR("stat(%s): %s\n", statefile, strerror(errno));
+ return -1;
+ }
+
+ if (S_ISDIR(statbuf.st_mode)) {
+ ERROR("--directory option not implemented");
+ return -1;
+ } else {
+ ERROR("Checkpoint image file %s exists\n", statefile);
+ return -1;
+ }
+ }
+
+ pid = find_cinit_pid(name);
+ if (pid < 0) {
+ ERROR("Unable to find cinit pid");
+ return -1;
+ }
+
+ memset(&crargs, 0, sizeof(crargs));
+
+ ret = open(statefile, O_CREAT|O_RDWR|O_EXCL, 0644);
+ if (ret < 0) {
+ ERROR("open(%s) failed\n", statefile);
+ return -1;
+ }
+
+ crargs.outfd = ret;
+ crargs.logfd = lxc_log_fd;
+ crargs.uerrfd = lxc_log_fd;
+ /*
+ * TODO: Set this to 0 for now - otherwise we get an objhash leak
+ * due to mismatched references to current PTY which needs to
+ * be investigated.
+ *
+ * TODO: Map @lxc_flags to user-cr flags ?
+ *
+ * TODO: We can probably drop the ->container field since @flags
+ * can provide the same selection.
+ *
+ * TODO: Do we may need a --container option to lxc_checkpoint or
+ * assume that we always work with full containers ?
+ */
+ crargs.container = 0;
+
+ flags = CHECKPOINT_SUBTREE;
+
+ ret = app_checkpoint(pid, flags, &crargs);
+ if (ret < 0) {
+ ERROR("checkpoint of %s (pid %d) failed\n", name);
+ return -1;
+ }
+
return 0;
}
diff --git a/src/lxc/commands.c b/src/lxc/commands.c
index 4c48571..af5c947 100644
--- a/src/lxc/commands.c
+++ b/src/lxc/commands.c
@@ -114,6 +114,8 @@ extern void lxc_console_remove_fd(int, struct lxc_tty_info *);
extern int lxc_console_callback(int, struct lxc_request *, struct lxc_handler *);
extern int lxc_stop_callback(int, struct lxc_request *, struct lxc_handler *);
extern int lxc_state_callback(int, struct lxc_request *, struct lxc_handler *);
+extern int lxc_cinit_pid_callback(int, struct lxc_request *,
+ struct lxc_handler *);
static int trigger_command(int fd, struct lxc_request *request,
struct lxc_handler *handler)
@@ -124,6 +126,7 @@ static int trigger_command(int fd, struct lxc_request *request,
[LXC_COMMAND_TTY] = lxc_console_callback,
[LXC_COMMAND_STOP] = lxc_stop_callback,
[LXC_COMMAND_STATE] = lxc_state_callback,
+ [LXC_COMMAND_CINIT_PID] = lxc_cinit_pid_callback,
};
if (request->type < 0 || request->type >= LXC_COMMAND_MAX)
diff --git a/src/lxc/commands.h b/src/lxc/commands.h
index 3c6c082..22b24a9 100644
--- a/src/lxc/commands.h
+++ b/src/lxc/commands.h
@@ -27,6 +27,7 @@ enum {
LXC_COMMAND_TTY,
LXC_COMMAND_STOP,
LXC_COMMAND_STATE,
+ LXC_COMMAND_CINIT_PID,
LXC_COMMAND_MAX,
};
diff --git a/src/lxc/state.c b/src/lxc/state.c
index ba63805..837d2da 100644
--- a/src/lxc/state.c
+++ b/src/lxc/state.c
@@ -168,3 +168,29 @@ out:
return ret;
}
+extern int lxc_cinit_pid_callback(int fd, struct lxc_request *request,
+ struct lxc_handler *handler)
+{
+ struct lxc_answer answer;
+ int ret;
+ FILE *fp;
+
+ answer.ret = handler->pid;
+
+ INFO("Returning pid %d\n", handler->pid);
+
+ ret = send(fd, &answer, sizeof(answer), 0);
+ if (ret < 0) {
+ WARN("failed to send answer to the peer");
+ goto out;
+ }
+
+ if (ret != sizeof(answer)) {
+ ERROR("partial answer sent");
+ goto out;
+ }
+
+out:
+ return ret;
+}
+
--
1.6.6.1
next prev parent reply other threads:[~2010-03-19 6:41 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-19 6:39 [RFC][PATCH 0/5][lxc]: Link with USERCR Sukadev Bhattiprolu
[not found] ` <20100319063912.GA25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-19 6:40 ` [PATCH 1/5][lxc] Enable static linking of some lxc binaries Sukadev Bhattiprolu
[not found] ` <20100319064024.GB25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:44 ` Daniel Lezcano
2010-03-19 6:40 ` [PATCH 2/5][lxc] lxc_restart: Add --image option Sukadev Bhattiprolu
[not found] ` <20100319064046.GC25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:45 ` Daniel Lezcano
[not found] ` <4BA78276.2040308-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-24 19:48 ` Sukadev Bhattiprolu
[not found] ` <20100324194851.GD20031-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-24 20:53 ` Daniel Lezcano
2010-03-19 6:41 ` [PATCH 3/5][lxc] lxc_checkpoint: " Sukadev Bhattiprolu
2010-03-19 6:41 ` [PATCH 4/5][lxc] Hook up lxc_restart() with app_restart() Sukadev Bhattiprolu
[not found] ` <20100319064121.GE25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:48 ` Daniel Lezcano
2010-03-19 6:41 ` Sukadev Bhattiprolu [this message]
[not found] ` <20100319064141.GF25732-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-22 14:44 ` [PATCH 5/5][lxc] Hook up lxc_checkpoint() with app_checkpoint() Daniel Lezcano
[not found] ` <4BA78262.6050109-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-24 19:35 ` Sukadev Bhattiprolu
[not found] ` <20100324193537.GB20031-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-24 20:51 ` Daniel Lezcano
2010-03-19 10:44 ` [RFC][PATCH 0/5][lxc]: Link with USERCR Michel Normand
2010-03-24 19:22 ` Sukadev Bhattiprolu
2010-03-22 14:45 ` Daniel Lezcano
[not found] ` <4BA7826D.10706-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-24 19:27 ` Oren Laadan
2010-03-24 19:47 ` Sukadev Bhattiprolu
[not found] ` <20100324194744.GC20031-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-24 20:52 ` Daniel Lezcano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100319064141.GF25732@us.ibm.com \
--to=sukadev-23vcf4htsmix0ybbhkvfkdbpr1lh4cv8@public.gmane.org \
--cc=clg-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org \
--cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
--cc=dlezcano-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox