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/6][lxc][v3] Hook up lxc_restart() with app_restart()
Date: Wed, 31 Mar 2010 00:09:39 -0700 [thread overview]
Message-ID: <20100331070939.GE23567@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 20:47:56 -0800
Subject: [PATCH 5/6][lxc][v3] Hook up lxc_restart() with app_restart()
Have lxc_restart() call app_restart() implemented in the 'restart.o' from
USER-CR git tree.
Changelog[v3]:
- (Daniel Lezcano) Remove unnecessary check for 'statefile' before
opening it
- [Daniel Lezcano] Rebase to more recent version and use
lxc_check_inherited() instead of lxc_close_inherited_fd().
- Have lxc_restart unfreeze the container if the --pause option
was not specified.
- Use -D LIBCR to fix compile error when --with-libcr config is
not specified. Return ENOSYS if built with LIBCR undefined.
- Implement the --pause option to set the RESTART_FROZEN flag.
Changelog[v2]:
- Link with restart.o from usercr rather than libcheckpoint.a
- rename 'struct restart_args' to 'struct app_restart_args'
- Initialize the new field app_restart_args->uerrfd
- (Oren Laadan)Remove ->send_sigint field from 'struct app_restart_args'
---
src/lxc/restart.c | 129 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 128 insertions(+), 1 deletions(-)
diff --git a/src/lxc/restart.c b/src/lxc/restart.c
index 467489e..220acbf 100644
--- a/src/lxc/restart.c
+++ b/src/lxc/restart.c
@@ -22,11 +22,138 @@
*/
#include <lxc/lxc.h>
#include <lxc/log.h>
+#include <lxc/start.h>
+#include <lxc/namespace.h>
+#include <lxc/cgroup.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/prctl.h>
+#include <sys/wait.h>
+#include "error.h"
+#ifdef LIBCR
+#include <app-checkpoint.h>
+#endif
lxc_log_define(lxc_restart, lxc);
+#ifdef LIBCR
+
+struct lxc_restart_arg {
+ const char *name;
+ const char *statefile;
+ char *const argv;
+ struct lxc_handler *handler;
+ int lxc_flags;
+};
+
+static int do_restart(struct lxc_restart_arg *lxcarg)
+{
+ int pid;
+ int lxc_flags = lxcarg->lxc_flags;
+ struct lxc_handler *handler = lxcarg->handler;
+ const char *statefile = lxcarg->statefile;
+ struct app_restart_args restart_args;
+
+ if (sigprocmask(SIG_SETMASK, &handler->oldmask, NULL)) {
+ SYSERROR("failed to set sigprocmask");
+ return -1;
+ }
+
+ if (prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0)) {
+ SYSERROR("failed to set pdeath signal");
+ return -1;
+ }
+
+ memset(&restart_args, 0, sizeof(restart_args));
+
+ restart_args.infd = open(statefile, O_RDONLY, 0);
+ if (restart_args.infd < 0) {
+ SYSERROR("Failed to open statefile %s\n", statefile);
+ return -1;
+ }
+
+ restart_args.pids = 1;
+ restart_args.pidns = 1;
+ restart_args.mnt_pty = 1;
+ restart_args.mntns = 1;
+ restart_args.klogfd = -1;
+ restart_args.ulogfd = lxc_log_fd;
+ restart_args.uerrfd = fileno(stderr);
+ restart_args.debug = 1;
+ restart_args.wait = 0;
+
+ if (lxc_flags & LXC_FLAG_PAUSE)
+ restart_args.keep_frozen = 1;
+
+ pid = app_restart(&restart_args);
+
+ return pid;
+}
+
int lxc_restart(const char *name, const char *statefile, struct lxc_conf *conf,
- int flags)
+ int lxc_flags)
{
+ int err;
+ int status;
+ struct lxc_handler *handler;
+ struct lxc_restart_arg lxcarg = {
+ .name = name,
+ .statefile = statefile,
+ .lxc_flags = lxc_flags,
+ .handler = NULL,
+ };
+
+ if (lxc_check_inherited())
+ return -1;
+
+ handler = lxc_init(name, conf);
+ if (!handler) {
+ ERROR("failed to initialize the container");
+ return -1;
+ }
+
+ lxcarg.handler = handler;
+ handler->pid = do_restart(&lxcarg);
+
+ INFO("do_restart(): returns pid %d\n", handler->pid);
+ lxc_rename_nsgroup(name, handler);
+
+ err = lxc_poll(name, handler);
+ if (err) {
+ ERROR("mainloop exited with an error");
+ goto out_abort;
+ }
+
+ while (waitpid(handler->pid, &status, 0) < 0 && errno == EINTR)
+ continue;
+
+ if (!(lxc_flags & LXC_FLAG_PAUSE)) {
+ err = lxc_unfreeze(name);
+ if (err) {
+ ERROR("lxc_restart(): Unable to unfreeze\n");
+ goto out_fini;
+ }
+ }
+
+ err = lxc_error_set_and_log(handler->pid, status);
+
+out_fini:
+ lxc_fini(name, handler);
+ return err;
+
+out_abort:
+ lxc_abort(name, handler);
+ goto out_fini;
+
return 0;
}
+#else
+int lxc_restart(const char *name, const char *statefile, struct lxc_conf *conf,
+ int lxc_flags)
+{
+ ERROR("'restart' function not configured");
+ ERROR("Try --with-libcr option to 'configure' script");
+ return -1;
+}
+#endif
--
1.6.6.1
next prev parent reply other threads:[~2010-03-31 7:09 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 ` Sukadev Bhattiprolu [this message]
2010-03-31 7:10 ` [PATCH 6/6][lxc][v3] Hook up lxc_checkpoint() with app_checkpoint() Sukadev Bhattiprolu
[not found] ` <20100331071016.GF23567-r/Jw6+rmf7HQT0dZR+AlfA@public.gmane.org>
2010-03-31 8:08 ` 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=20100331070939.GE23567@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