]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
lxc: minimal C/R plugin
authordlezcano <dlezcano>
Tue, 25 Nov 2008 13:02:29 +0000 (13:02 +0000)
committerdlezcano <dlezcano>
Tue, 25 Nov 2008 13:02:29 +0000 (13:02 +0000)
From: Cedric Le Goater <clg@fr.ibm.com>

Plugin for columbia CR.

Signed-off-by: Cedric Le Goater <clg@fr.ibm.com>
src/lxc/Makefile.am
src/lxc/checkpoint.c
src/lxc/cr_plugin_columbia.c [new file with mode: 0644]
src/lxc/lxc.h
src/lxc/lxc_checkpoint.c
src/lxc/lxc_restart.c
src/lxc/restart.c

index 2ab5b94c57f49db9226d535c7676f59fb2297af6..464361cd042f99fdaca0487599d559e98b8c2410 100644 (file)
@@ -24,6 +24,7 @@ liblxc_la_SOURCES = \
        version.c \
        error.h error.c \
        cgroup.c cgroup.h \
+       cr_plugin_columbia.c \
        lxc.h \
        lxc_utils.h \
        lxc_lock.c lxc_lock.h \
index cec69b5ad31131d374d51eedbdc300741f534710..995de100fbd252ab53e26a210f2c197c7abdc6c4 100644 (file)
 #include <net/if.h>
 
 #include "error.h"
+#include "lxc_plugin.h"
 #include <lxc.h>
 
 #define MAXPIDLEN 20
 
-#if __i386__
-#    define __NR_checkpoint 333
-static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
-{
-       return syscall(__NR_checkpoint, pid, fd, flags);
-}
-#elif __x86_64__
-#    define __NR_checkpoint 295
-static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
-{
-        return syscall(__NR_checkpoint, pid, fd, flags);
-}
-#else
-#    warning "Architecture not supported for checkpoint"
-static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
-{
-       errno = ENOSYS;
-       return -1;
-}
-
-#endif
-
-int lxc_checkpoint(const char *name, int cfd, unsigned long flags)
+int lxc_checkpoint(const char *name, const char *statefile, 
+               unsigned long flags)
 {
        char init[MAXPATHLEN];
        char val[MAXPIDLEN];
@@ -93,7 +73,7 @@ int lxc_checkpoint(const char *name, int cfd, unsigned long flags)
 
        pid = atoi(val);
 
-       if (sys_checkpoint(pid, cfd, flags) < 0) {
+       if (lxc_plugin_checkpoint(pid, statefile, flags) < 0) {
                lxc_log_syserror("failed to checkpoint %zd", pid);
                goto out_close;
        }
diff --git a/src/lxc/cr_plugin_columbia.c b/src/lxc/cr_plugin_columbia.c
new file mode 100644 (file)
index 0000000..8345e7b
--- /dev/null
@@ -0,0 +1,118 @@
+/*
+ * lxc: linux Container library
+ *
+ * (C) Copyright IBM Corp. 2007, 2008
+ *
+ * Authors:
+ * Daniel Lezcano <dlezcano at fr.ibm.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#undef _GNU_SOURCE
+#include <fcntl.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/param.h>
+#include <sys/file.h>
+
+#include "error.h"
+#include <lxc.h>
+
+#if __i386__
+#    define __NR_checkpoint 333
+#    define __NR_restart 334
+static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
+{
+       return syscall(__NR_checkpoint, pid, fd, flags);
+}
+static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
+{
+       return syscall(__NR_restart, pid, fd, flags);
+}
+#elif __x86_64__
+#    define __NR_checkpoint 295
+#    define __NR_restart 296
+static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
+{
+        return syscall(__NR_checkpoint, pid, fd, flags);
+}
+static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
+{
+        return syscall(__NR_restart, pid, fd, flags);
+}
+#else
+#    warning "Architecture not supported for checkpoint"
+static inline long sys_checkpoint(pid_t pid, int fd, unsigned long flags)
+{
+       errno = ENOSYS;
+       return -1;
+}
+static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
+{
+       errno = ENOSYS;
+       return -1;
+}
+#    warning "Architecture not supported for restart syscall"
+
+#endif
+
+
+int lxc_plugin_checkpoint(pid_t pid, const char *statefile, 
+       unsigned long flags)
+{
+       int fd, ret;
+
+       fd = open(statefile, O_RDWR);
+       if (fd < 0) {
+               lxc_log_syserror("failed to open init file for %s", statefile);
+               return -1;
+       }
+       
+       ret = sys_checkpoint(pid, fd, flags);
+       if (ret < 0) {
+               lxc_log_syserror("failed to checkpoint %zd", pid);
+               goto out_close;
+       }
+
+       ret = 0;
+
+out_close:
+       close(fd);
+       return ret;
+}
+
+int lxc_plugin_restart(pid_t pid, const char *statefile, 
+       unsigned long flags)
+{
+       int fd;
+
+       fd = open(statefile, O_RDONLY);
+       if (fd < 0) {
+               lxc_log_syserror("failed to open init file for %s", statefile);
+               return -1;
+       }
+       
+       sys_restart(pid, fd, flags);
+       lxc_log_syserror("failed to restart %zd", pid);
+       close(fd);
+       return -1;
+}
index 012ab3cc0885692b944d2523dc24c5882a6a8b85..de8c3533ca44374deadc019fcecd18f6b53e5ff1 100644 (file)
@@ -180,7 +180,8 @@ extern const char *const lxc_strerror(int error);
  * @flags : checkpoint flags
  * Returns 0 on success, < 0 otherwise
  */
-extern int lxc_checkpoint(const char *name, int fd, unsigned long flags);
+extern int lxc_checkpoint(const char *name, const char *statefile, 
+                       unsigned long flags);
 
 /*
  * Restart a container previously frozen
@@ -189,7 +190,8 @@ extern int lxc_checkpoint(const char *name, int fd, unsigned long flags);
  * @flags : restart flags
  * Returns 0 on success, < 0 otherwise
  */
-extern int lxc_restart(const char *name, int fd, unsigned long flags);
+extern int lxc_restart(const char *name, const char *statefile, 
+                       unsigned long flags);
 
 /*
  * Returns the version number of the library
index 412c138f8703a65b5db5fd38510fa553ce089177..480ffba79cbddbf095b0b964bd364f57139222ea 100644 (file)
@@ -29,7 +29,7 @@
 
 void usage(char *cmd)
 {
-       fprintf(stderr, "%s <command>\n", basename(cmd));
+       fprintf(stderr, "%s <statefile>\n", basename(cmd));
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        _exit(1);
 }
@@ -58,12 +58,15 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
+       if (!argv[1])
+               usage(argv[0]);
+
        if (lxc_freeze(name)) {
                fprintf(stderr, "failed to freeze '%s'\n", name);
                return -1;
        }
 
-       if (lxc_checkpoint(name, STDOUT_FILENO, 0)) {
+       if (lxc_checkpoint(name, argv[1], 0)) {
                fprintf(stderr, "failed to checkpoint %s\n", name);
                goto out;
        }
index a2e1cc23b92b6b51ed756673c01490a988be9860..b586f0c0a0ba7f2bfdd1cf592d9f05e55a914e57 100644 (file)
@@ -29,7 +29,7 @@
 
 void usage(char *cmd)
 {
-       fprintf(stderr, "%s <command>\n", basename(cmd));
+       fprintf(stderr, "%s <statefile>\n", basename(cmd));
        fprintf(stderr, "\t -n <name>   : name of the container\n");
        _exit(1);
 }
@@ -53,7 +53,10 @@ int main(int argc, char *argv[])
        if (!name)
                usage(argv[0]);
 
-       if (lxc_restart(name, STDIN_FILENO, 0)) {
+       if (!argv[1])
+               usage(argv[0]);
+
+       if (lxc_restart(name, argv[1], 0)) {
                fprintf(stderr, "failed to restart %s\n", name);
                return 1;
        }
index d1e9bf2831f23831abf3783920947ac37f6a8ced..28a58d89b7cd9a572ebcb06efe6814e4fe9a0e8f 100644 (file)
 #include <sys/mount.h>
 
 #include "error.h"
+#include "lxc_plugin.h"
 #include <lxc/lxc.h>
 
 LXC_TTY_HANDLER(SIGINT);
 LXC_TTY_HANDLER(SIGQUIT);
 
-
-#if __i386__
-#    define __NR_restart 334
-static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
-{
-       return syscall(__NR_restart, pid, fd, flags);
-}
-#elif __x86_64__
-#    define __NR_restart 296
-static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
-{
-        return syscall(__NR_restart, pid, fd, flags);
-}
-#else
-static inline long sys_restart(pid_t pid, int fd, unsigned long flags)
-{
-       errno = ENOSYS;
-       return -1;
-}
-#    warning "Architecture not supported for restart syscall"
-#endif
-
-int lxc_restart(const char *name, int cfd, unsigned long flags)
+int lxc_restart(const char *name, const char *statefile,
+               unsigned long flags)
 {
        char *init = NULL, *val = NULL;
        char ttyname[MAXPATHLEN];
@@ -116,6 +96,7 @@ int lxc_restart(const char *name, int cfd, unsigned long flags)
 
        if (!pid) {
 
+               char dummytty = '\0';
                close(sv[1]);
 
                /* Be sure we don't inherit this after the exec */
@@ -134,7 +115,7 @@ int lxc_restart(const char *name, int cfd, unsigned long flags)
                }
 
                /* Setup the container, ip, names, utsname, ... */
-               if (lxc_setup(name)) {
+               if (lxc_setup(name, &dummytty)) {
                        lxc_log_error("failed to setup the container");
                        if (write(sv[0], &sync, sizeof(sync)) < 0)
                                lxc_log_syserror("failed to write the socket");
@@ -146,7 +127,7 @@ int lxc_restart(const char *name, int cfd, unsigned long flags)
                        return -1;
                }
 
-               sys_restart(getpid(), cfd, flags);
+               lxc_plugin_restart(getpid(), statefile, flags);
                lxc_log_syserror("failed to restart");
   
                /* If the exec fails, tell that to our father */