[CRIU] [PATCH 2/3] crtools: Introduce the --ext-mount option

Pavel Emelyanov xemul at parallels.com
Tue Jun 3 09:29:37 PDT 2014


The syntax is

--ext-mount without arguments on dump says, that mount point with the 
source sitting outside of the namespace root should be dumped "as is". 
On restore this will say to try create bind mount with unchanged source
path.

--ext-mount p<path> on restore will cause the <path> be prepended to 
any bind mount source.

--ext-mount s<delim><path1><delim><path2> on restore will case the
<path1> prefix get substituted with <path2> prefix for every external
bind mount.

Signed-off-by: Pavel Emelyanov <xemul at parallels.com>
---
 crtools.c            | 44 +++++++++++++++++++++++++++++++++++++++++++-
 include/cr_options.h | 12 ++++++++++++
 2 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/crtools.c b/crtools.c
index 38b4b0d..ebd946a 100644
--- a/crtools.c
+++ b/crtools.c
@@ -47,6 +47,7 @@ void init_opts(void)
 	INIT_LIST_HEAD(&opts.scripts);
 
 	opts.cpu_cap = CPU_CAP_ALL;
+	opts.ext_mount_mode = EXT_MOUNT_NONE;
 }
 
 static int parse_ns_string(const char *ptr)
@@ -114,6 +115,42 @@ Esyntax:
 	return -1;
 }
 
+static int parse_ext_mount(char *optarg)
+{
+	char *aux;
+
+	/*
+	 * --ext-mount means OK
+	 * --ext-mount 'ppath' means PREP
+	 * --ext-mount 'sXpath1Xpath2' means SUB
+	 */
+
+	if (!optarg) {
+		opts.ext_mount_mode = EXT_MOUNT_OK;
+		return 0;
+	}
+
+	switch (optarg[0]) {
+	case 'p':
+		opts.ext_mount_mode = EXT_MOUNT_PREP;
+		opts.em_arg_1 = optarg + 1;
+		return 0;
+	case 's':
+		opts.ext_mount_mode = EXT_MOUNT_SUB;
+		aux = strchr(optarg + 2, optarg[1]);
+		if (!aux)
+			goto err;
+		opts.em_arg_1 = optarg + 1;
+		*aux = '\0';
+		opts.em_arg_2 = aux + 1;
+		return 0;
+	}
+
+err:
+	pr_msg("Bad --ext-mount argument %s\n", optarg);
+	return -1;
+}
+
 int main(int argc, char *argv[])
 {
 	pid_t pid = 0, tree_id = 0;
@@ -124,7 +161,7 @@ int main(int argc, char *argv[])
 	int log_level = LOG_UNSET;
 	char *imgs_dir = ".";
 	char *work_dir = NULL;
-	static const char short_opts[] = "dsRf:F:t:p:hcD:o:n:v::xVr:jlW:L:";
+	static const char short_opts[] = "dsRf:F:t:p:hcD:o:n:v::xVr:jlW:L:M::";
 	static struct option long_opts[] = {
 		{ "tree", required_argument, 0, 't' },
 		{ "pid", required_argument, 0, 'p' },
@@ -164,6 +201,7 @@ int main(int argc, char *argv[])
 		{ "cpu-cap", required_argument, 0, 57},
 		{ "force-irmap", no_argument, 0, 58},
 		{ "exec-cmd", no_argument, 0, 59},
+		{ "ext-mount", optional_argument, 0, 'M' },
 		{ },
 	};
 
@@ -338,6 +376,10 @@ int main(int argc, char *argv[])
 		case 59:
 			has_exec_cmd = true;
 			break;
+		case 'M':
+			if (parse_ext_mount(optarg))
+				goto bad_arg;
+			break;
 		case 'V':
 			pr_msg("Version: %s\n", CRIU_VERSION);
 			if (strcmp(CRIU_GITID, "0"))
diff --git a/include/cr_options.h b/include/cr_options.h
index f2106b0..ed81f7f 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -49,8 +49,20 @@ struct cr_options {
 	unsigned int		cpu_cap;
 	bool			force_irmap;
 	char			**exec_cmd;
+	int			ext_mount_mode;
+	char			*em_arg_1;
+	char			*em_arg_2;
 };
 
+/*
+ * For dump only first two are valid
+ */
+
+#define EXT_MOUNT_NONE	0	/* no external mounts (use plugins) */
+#define EXT_MOUNT_OK	1	/* use the same mount source paths */
+#define EXT_MOUNT_PREP	2	/* prepend em_arg_1 to mount source */
+#define EXT_MOUNT_SUB	3	/* s/em_arg_1/em_arg_2/ prefix in mount source */
+
 extern struct cr_options opts;
 
 extern void init_opts(void);
-- 
1.8.4.2


More information about the CRIU mailing list