]> git.ipfire.org Git - thirdparty/lxc.git/commitdiff
c/r: rearrange things to pass struct migrate_opts all the way down
authorTycho Andersen <tycho.andersen@canonical.com>
Fri, 6 May 2016 18:19:16 +0000 (18:19 +0000)
committerTycho Andersen <tycho.andersen@canonical.com>
Tue, 10 May 2016 22:26:20 +0000 (16:26 -0600)
If we don't do this, we'll end up changing the function signatures for the
internal __criu_* functions each time we add a new parameter, which will
get very annoying very quickly. Since we already have the user's arguments
struct, let's just pass that all the way down.

Signed-off-by: Tycho Andersen <tycho.andersen@canonical.com>
src/lxc/criu.c
src/lxc/criu.h
src/lxc/lxccontainer.c

index 3645baba91b2d0546eec55c1d8b00f55eb3f38fc..18cca3c0ecf1f02e23ee0bb3a3cfa81d35cf8e8e 100644 (file)
@@ -56,20 +56,13 @@ struct criu_opts {
        /* The type of criu invocation, one of "dump" or "restore" */
        char *action;
 
-       /* The directory to pass to criu */
-       char *directory;
+       /* the user-provided migrate options relevant to this action */
+       struct migrate_opts *user;
 
        /* The container to dump */
        struct lxc_container *c;
 
-       /* Enable criu verbose mode? */
-       bool verbose;
-
-       /* (pre-)dump: a directory for the previous dump's images */
-       char *predump_dir;
-
        /* dump: stop the container or not after dumping? */
-       bool stop;
        char tty_id[32]; /* the criu tty id for /dev/console, i.e. "tty[${rdev}:${dev}]" */
 
        /* restore: the file to write the init process' pid into */
@@ -82,10 +75,6 @@ struct criu_opts {
         * different) on the target host. NULL if lxc.console = "none".
         */
        char *console_name;
-
-       /* Address and port where a criu pageserver is listening */
-       char *pageserver_address;
-       char *pageserver_port;
 };
 
 static int load_tty_major_minor(char *directory, char *output, int len)
@@ -157,15 +146,15 @@ static void exec_criu(struct criu_opts *opts)
                static_args += 4;
 
                /* --prev-images-dir <path-to-directory-A-relative-to-B> */
-               if (opts->predump_dir)
+               if (opts->user->predump_dir)
                        static_args += 2;
 
                /* --page-server --address <address> --port <port> */
-               if (opts->pageserver_address && opts->pageserver_port)
+               if (opts->user->pageserver_address && opts->user->pageserver_port)
                        static_args += 5;
 
                /* --leave-running (only for final dump) */
-               if (strcmp(opts->action, "dump") == 0 && !opts->stop)
+               if (strcmp(opts->action, "dump") == 0 && !opts->user->stop)
                        static_args++;
 
                /* --external tty[88,4] */
@@ -179,7 +168,7 @@ static void exec_criu(struct criu_opts *opts)
                static_args += 10;
 
                tty_info[0] = 0;
-               if (load_tty_major_minor(opts->directory, tty_info, sizeof(tty_info)))
+               if (load_tty_major_minor(opts->user->directory, tty_info, sizeof(tty_info)))
                        return;
 
                /* --inherit-fd fd[%d]:tty[%s] */
@@ -189,10 +178,10 @@ static void exec_criu(struct criu_opts *opts)
                return;
        }
 
-       if (opts->verbose)
+       if (opts->user->verbose)
                static_args++;
 
-       ret = snprintf(log, PATH_MAX, "%s/%s.log", opts->directory, opts->action);
+       ret = snprintf(log, PATH_MAX, "%s/%s.log", opts->user->directory, opts->action);
        if (ret < 0 || ret >= PATH_MAX) {
                ERROR("logfile name too long\n");
                return;
@@ -236,11 +225,11 @@ static void exec_criu(struct criu_opts *opts)
        DECLARE_ARG("--enable-fs");
        DECLARE_ARG("tracefs");
        DECLARE_ARG("-D");
-       DECLARE_ARG(opts->directory);
+       DECLARE_ARG(opts->user->directory);
        DECLARE_ARG("-o");
        DECLARE_ARG(log);
 
-       if (opts->verbose)
+       if (opts->user->verbose)
                DECLARE_ARG("-vvvvvv");
 
        if (strcmp(opts->action, "dump") == 0 || strcmp(opts->action, "pre-dump") == 0) {
@@ -275,21 +264,21 @@ static void exec_criu(struct criu_opts *opts)
                        DECLARE_ARG(opts->tty_id);
                }
 
-               if (opts->predump_dir) {
+               if (opts->user->predump_dir) {
                        DECLARE_ARG("--prev-images-dir");
-                       DECLARE_ARG(opts->predump_dir);
+                       DECLARE_ARG(opts->user->predump_dir);
                }
 
-               if (opts->pageserver_address && opts->pageserver_port) {
+               if (opts->user->pageserver_address && opts->user->pageserver_port) {
                        DECLARE_ARG("--page-server");
                        DECLARE_ARG("--address");
-                       DECLARE_ARG(opts->pageserver_address);
+                       DECLARE_ARG(opts->user->pageserver_address);
                        DECLARE_ARG("--port");
-                       DECLARE_ARG(opts->pageserver_port);
+                       DECLARE_ARG(opts->user->pageserver_port);
                }
 
                /* only for final dump */
-               if (strcmp(opts->action, "dump") == 0 && !opts->stop)
+               if (strcmp(opts->action, "dump") == 0 && !opts->user->stop)
                        DECLARE_ARG("--leave-running");
        } else if (strcmp(opts->action, "restore") == 0) {
                void *m;
@@ -556,7 +545,7 @@ out_unlock:
 
 // do_restore never returns, the calling process is used as the
 // monitor process. do_restore calls exit() if it fails.
-void do_restore(struct lxc_container *c, int status_pipe, char *directory, bool verbose)
+void do_restore(struct lxc_container *c, int status_pipe, struct migrate_opts *opts)
 {
        pid_t pid;
        char pidfile[L_tmpnam];
@@ -642,10 +631,9 @@ void do_restore(struct lxc_container *c, int status_pipe, char *directory, bool
                }
 
                os.action = "restore";
-               os.directory = directory;
+               os.user = opts;
                os.c = c;
                os.pidfile = pidfile;
-               os.verbose = verbose;
                os.cgroup_path = cgroup_canonical_path(handler);
                os.console_fd = c->lxc_conf->console.slave;
 
@@ -829,16 +817,14 @@ static int save_tty_major_minor(char *directory, struct lxc_container *c, char *
 }
 
 /* do one of either predump or a regular dump */
-static bool do_dump(struct lxc_container *c, char *mode, char *directory,
-                   bool stop, bool verbose, char *predump_dir,
-                   char *pageserver_address, char *pageserver_port)
+static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *opts)
 {
        pid_t pid;
 
        if (!criu_ok(c))
                return false;
 
-       if (mkdir_p(directory, 0700) < 0)
+       if (mkdir_p(opts->directory, 0700) < 0)
                return false;
 
        pid = fork();
@@ -851,16 +837,11 @@ static bool do_dump(struct lxc_container *c, char *mode, char *directory,
                struct criu_opts os;
 
                os.action = mode;
-               os.directory = directory;
+               os.user = opts;
                os.c = c;
-               os.stop = stop;
-               os.verbose = verbose;
-               os.predump_dir = predump_dir;
                os.console_name = c->lxc_conf->console.path;
-               os.pageserver_address = pageserver_address;
-               os.pageserver_port = pageserver_port;
 
-               if (save_tty_major_minor(directory, c, os.tty_id, sizeof(os.tty_id)) < 0)
+               if (save_tty_major_minor(opts->directory, c, os.tty_id, sizeof(os.tty_id)) < 0)
                        exit(1);
 
                /* exec_criu() returning is an error */
@@ -891,17 +872,17 @@ static bool do_dump(struct lxc_container *c, char *mode, char *directory,
        }
 }
 
-bool __criu_pre_dump(struct lxc_container *c, char *directory, bool verbose, char *predump_dir, char *pageserver_address, char *pageserver_port)
+bool __criu_pre_dump(struct lxc_container *c, struct migrate_opts *opts)
 {
-       return do_dump(c, "pre-dump", directory, false, verbose, predump_dir, pageserver_address, pageserver_port);
+       return do_dump(c, "pre-dump", opts);
 }
 
-bool __criu_dump(struct lxc_container *c, char *directory, bool stop, bool verbose, char *predump_dir, char *pageserver_address, char *pageserver_port)
+bool __criu_dump(struct lxc_container *c, struct migrate_opts *opts)
 {
        char path[PATH_MAX];
        int ret;
 
-       ret = snprintf(path, sizeof(path), "%s/inventory.img", directory);
+       ret = snprintf(path, sizeof(path), "%s/inventory.img", opts->directory);
        if (ret < 0 || ret >= sizeof(path))
                return false;
 
@@ -910,10 +891,10 @@ bool __criu_dump(struct lxc_container *c, char *directory, bool stop, bool verbo
                return false;
        }
 
-       return do_dump(c, "dump", directory, stop, verbose, predump_dir, pageserver_address, pageserver_port);
+       return do_dump(c, "dump", opts);
 }
 
-bool __criu_restore(struct lxc_container *c, char *directory, bool verbose)
+bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts)
 {
        pid_t pid;
        int status, nread;
@@ -942,7 +923,7 @@ bool __criu_restore(struct lxc_container *c, char *directory, bool verbose)
        if (pid == 0) {
                close(pipefd[0]);
                // this never returns
-               do_restore(c, pipefd[1], directory, verbose);
+               do_restore(c, pipefd[1], opts);
        }
 
        close(pipefd[1]);
index db2ab1199583c66db16f0ae9260b86699bfea5ec..ce94b31777aa26f87a6cfef0f459b5242994641a 100644 (file)
@@ -27,8 +27,8 @@
 
 #include <lxc/lxccontainer.h>
 
-bool __criu_pre_dump(struct lxc_container *c, char *directory, bool verbose, char *predump_dir, char *pageserver_address, char *pageserver_port);
-bool __criu_dump(struct lxc_container *c, char *directory, bool stop, bool verbose, char *predump_dir, char *pageserver_address, char *pageserver_port);
-bool __criu_restore(struct lxc_container *c, char *directory, bool verbose);
+bool __criu_pre_dump(struct lxc_container *c, struct migrate_opts *opts);
+bool __criu_dump(struct lxc_container *c, struct migrate_opts *opts);
+bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts);
 
 #endif
index 50cfc69ab775485403c83d2e4b35b1e09f89d97d..8bd9b8e0f8d65bc6dca4a53bdc55b987166b0fff 100644 (file)
@@ -3968,13 +3968,13 @@ static int do_lxcapi_migrate(struct lxc_container *c, unsigned int cmd,
 
        switch (cmd) {
        case MIGRATE_PRE_DUMP:
-               ret = !__criu_pre_dump(c, opts->directory, opts->verbose, opts->predump_dir, opts->pageserver_address, opts->pageserver_port);
+               ret = !__criu_pre_dump(c, opts);
                break;
        case MIGRATE_DUMP:
-               ret = !__criu_dump(c, opts->directory, opts->stop, opts->verbose, opts->predump_dir, opts->pageserver_address, opts->pageserver_port);
+               ret = !__criu_dump(c, opts);
                break;
        case MIGRATE_RESTORE:
-               ret = !__criu_restore(c, opts->directory, opts->verbose);
+               ret = !__criu_restore(c, opts);
                break;
        default:
                ERROR("invalid migrate command %u", cmd);