All of lore.kernel.org
 help / color / mirror / Atom feed
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 6/6][lxc][v3] Hook up lxc_checkpoint() with app_checkpoint()
Date: Wed, 31 Mar 2010 00:10:16 -0700	[thread overview]
Message-ID: <20100331071016.GF23567@us.ibm.com> (raw)
In-Reply-To: <20100331070440.GA21570-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 6/6][lxc][v3] 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

Changelog:[v2]:
	- Drop find_cinit_pid() and use get_init_pid() from a recent checkin
	- Implement --pause and --kill options to lxc-checkpoint
	- Use -D LIBCR to fix compile error when --with-libcr config option
	  is not specified. Return ENOSYS when LIBCR is undefined.
	- Add CHECKPOINT_NONETNS to flags arg to app_checkpoint() which
	  is needed to checkpoint an application that is not in a private
	  netns (new in ckpt-v20-dev).

Signed-off-by: Sukadev Bhattiprolu <sukadev-23VcF4HTsmIX0ybBhKVfKdBPR1lH4CV8@public.gmane.org>
---
 src/lxc/checkpoint.c |   88 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/lxc/state.c      |    1 -
 2 files changed, 86 insertions(+), 3 deletions(-)

diff --git a/src/lxc/checkpoint.c b/src/lxc/checkpoint.c
index 4e75cb6..6e905ff 100644
--- a/src/lxc/checkpoint.c
+++ b/src/lxc/checkpoint.c
@@ -22,7 +22,17 @@
  */
 #include <lxc/lxc.h>
 #include <lxc/log.h>
-#include <lxc/commands.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <linux/checkpoint.h>
+
+#include "commands.h"
+#include "arguments.h"
+#include "namespace.h"
+#ifdef LIBCR
+#include "app-checkpoint.h"
+#endif
 
 lxc_log_define(lxc_checkpoint, lxc);
 
@@ -54,7 +64,81 @@ pid_t get_init_pid(const char *name)
 	return command.answer.pid;
 }
 
-int lxc_checkpoint(const char *name, const char *statefile, int flags)
+#ifdef LIBCR
+int lxc_checkpoint(const char *name, const char *statefile, int lxc_flags)
 {
+	int ret;
+	int pid;
+	int flags;
+	struct app_checkpoint_args crargs;
+
+	pid = get_init_pid(name);
+	if (pid < 0) {
+		ERROR("Unable to find cinit pid");
+		return -1;
+	}
+
+	ret = lxc_freeze(name);
+	if (ret < 0)
+		return ret;
+
+	memset(&crargs, 0, sizeof(crargs));
+
+	ret = open(statefile, O_CREAT|O_RDWR|O_EXCL, 0600);
+	if (ret < 0) {
+		ERROR("open(%s) failed, %s\n", statefile, strerror(errno));
+		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;
+
+	/*
+	 * TODO: Set the CHECKPOINT_NONETNS unconditionally for now. Otherwise
+	 * 	 it would require running the application in a private netns.
+	 * 	 Implement a command-line option to allow user selection.
+	 */
+	flags = CHECKPOINT_SUBTREE|CHECKPOINT_NONETNS;
+
+	ret = app_checkpoint(pid, flags, &crargs);
+	if (ret < 0) {
+		ERROR("checkpoint of %s (pid %d) failed\n", name, pid);
+		return -1;
+	}
+
+	if (lxc_flags & LXC_FLAG_HALT) {
+		ret = lxc_stop(name);
+		if (ret < 0)
+			return ret;
+
+		return lxc_unfreeze(name);
+	}
+
+	if (!(lxc_flags & LXC_FLAG_PAUSE))
+		return lxc_unfreeze(name);
+
 	return 0;
 }
+#else
+int lxc_checkpoint(const char *name, const char *statefile, int lxc_flags)
+{
+	ERROR("'checkpoint' not configured");
+	ERROR("Try --with-libcr option to 'configure' script");
+	return -1;
+}
+#endif
diff --git a/src/lxc/state.c b/src/lxc/state.c
index b29ae09..1e4c7e1 100644
--- a/src/lxc/state.c
+++ b/src/lxc/state.c
@@ -167,4 +167,3 @@ extern int lxc_state_callback(int fd, struct lxc_request *request,
 out:
 	return ret;
 }
-
-- 
1.6.6.1

  parent reply	other threads:[~2010-03-31  7:10 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-31  7:04 [PATCH 0/6][lxc][v3] Link LXC with USERCR Sukadev Bhattiprolu
     [not found] ` <20100331070440.GA21570-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31  7:06   ` [PATCH 1/6][lxc][v3] Add --with-libcr configure option Sukadev Bhattiprolu
     [not found]     ` <20100331070633.GA23567-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31  8:11       ` Michel Normand
2010-03-31 17:21         ` Sukadev Bhattiprolu
2010-03-31  7:07   ` [PATCH 2/6][lxc][v3] lxc_restart: Add --statefile option Sukadev Bhattiprolu
     [not found]     ` <20100331070711.GB23567-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31  8:10       ` Michel Normand
2010-03-31  7:07   ` [PATCH 3/6][lxc][v3] lxc_checkpoint: " Sukadev Bhattiprolu
2010-03-31  7:08   ` [PATCH 4/6][lxc][v3] Move get_init_pid() into checkpoint.c Sukadev Bhattiprolu
     [not found]     ` <20100331070848.GD23567-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31  8:17       ` Cedric Le Goater
2010-03-31  7:09   ` [PATCH 5/6][lxc][v3] Hook up lxc_restart() with app_restart() Sukadev Bhattiprolu
2010-03-31  7:10   ` Sukadev Bhattiprolu [this message]
     [not found]     ` <20100331071016.GF23567-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31  8:08       ` [PATCH 6/6][lxc][v3] Hook up lxc_checkpoint() with app_checkpoint() Michel Normand
2010-03-31  8:18       ` Cedric Le Goater
2010-03-31  9:29   ` [PATCH 0/6][lxc][v3] Link LXC with USERCR Michel Normand
2010-03-31  9:38   ` Cedric Le Goater
     [not found]     ` <4BB31801.4000304-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-31 12:13       ` Cedric Le Goater
     [not found]         ` <4BB33C81.9070802-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-04-01  5:03           ` Sukadev Bhattiprolu
2010-03-31 13:58   ` Daniel Lezcano
     [not found]     ` <4BB35519.8080500-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-04-01  5:37       ` Oren Laadan
2010-03-31 16:31   ` Daniel Lezcano
2010-03-31 19:58   ` Daniel Lezcano
     [not found]     ` <4BB3A981.4020709-NmTC/0ZBporQT0dZR+AlfA@public.gmane.org>
2010-03-31 20:12       ` Serge E. Hallyn
     [not found]         ` <20100331201240.GA26773-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31 20:22           ` Daniel Lezcano
2010-03-31 21:00           ` Daniel Lezcano
     [not found]             ` <4BB3B7E1.8080608-GANU6spQydw@public.gmane.org>
2010-03-31 21:23               ` Sukadev Bhattiprolu
     [not found]                 ` <20100331212359.GA18934-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31 21:30                   ` Daniel Lezcano
     [not found]                     ` <4BB3BF02.7060402-GANU6spQydw@public.gmane.org>
2010-04-02  5:54                       ` Sukadev Bhattiprolu
2010-04-01  5:43               ` Oren Laadan

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=20100331071016.GF23567@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.