[CRIU] [PATCH 1/3] devmap: Introduce --device-map argument

Cyrill Gorcunov gorcunov at openvz.org
Tue Nov 24 02:12:18 PST 2015


We will need it when migration causes device numbers
being changed and we need to proceed on new hardware.

At the moment this is needed for block devices.

https://jira.sw.ru/PSBM-41357

Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
 Documentation/criu.txt |  4 ++++
 crtools.c              | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 include/cr_options.h   |  2 ++
 3 files changed, 54 insertions(+)

diff --git a/Documentation/criu.txt b/Documentation/criu.txt
index 652706ee1aaa..c5dd4e56746e 100644
--- a/Documentation/criu.txt
+++ b/Documentation/criu.txt
@@ -272,6 +272,10 @@ The '<mode>' may be one of below.
     These flags enable external shared or slave mounts to be resolved
     automatically when '*--ext-mount-map auto*' is passed.
 
+*--device-map* '<A>'*:*'<B>'[,'<C>'*:*'<D>']::
+    Specify device mappings when migrating from one environment
+    to another. Currently used for block devices.
+
 *--auto-dedup*::
     As soon as a page is restored it get punched out from image.
 
diff --git a/crtools.c b/crtools.c
index d3812a18f4f0..8a51d205d4d5 100644
--- a/crtools.c
+++ b/crtools.c
@@ -190,6 +190,48 @@ static size_t parse_size(char *optarg)
 	return (size_t)atol(optarg);
 }
 
+static int parse_device_map(struct cr_options *opts, char *optarg)
+{
+	size_t nr_alloc = 0, nr_devmap = 0;
+	unsigned int *devmap = NULL;
+	char *p = optarg;
+	int ret = -1;
+
+	if (!optarg)
+		return -EINVAL;
+
+	while (p) {
+		unsigned int s, d;
+		char *at;
+
+		if (sscanf(p, "%u:%u", &s, &d) != 2)
+			goto out;
+
+		if (nr_alloc <= nr_devmap) {
+			nr_alloc += 8;
+			if (xrealloc_safe(&devmap, sizeof(*devmap) * nr_alloc))
+				goto out;
+		}
+
+		devmap[nr_devmap + 0] = s;
+		devmap[nr_devmap + 1] = d;
+
+		nr_devmap += 2;
+
+		at = strchr(p, ',');
+		p = at ? at + 1 : NULL;
+	}
+
+	opts->devmap = devmap;
+	opts->nr_devmap = nr_devmap;
+
+	devmap = NULL;
+	ret = 0;
+out:
+	xfree(devmap);
+	return ret;
+}
+
 int main(int argc, char *argv[], char *envp[])
 {
 	pid_t pid = 0, tree_id = 0;
@@ -253,6 +295,7 @@ int main(int argc, char *argv[], char *envp[])
 		{ "freeze-cgroup",		required_argument,	0, 1068 },
 		{ "ghost-limit",		required_argument,	0, 1069 },
 		{ "irmap-scan-path",		required_argument,	0, 1070 },
+		{ "device-map",			required_argument,	0, 1071 },
 		{ },
 	};
 
@@ -498,6 +541,10 @@ int main(int argc, char *argv[], char *envp[])
 			if (irmap_scan_path_add(optarg))
 				return -1;
 			break;
+		case 1071:
+			if (parse_device_map(&opts, optarg))
+				goto bad_arg;
+			break;
 		case 'M':
 			{
 				char *aux;
@@ -747,6 +794,7 @@ usage:
 "  --enable-fs FSNAMES   a comma separated list of filesystem names or \"all\".\n"
 "                        force criu to (try to) dump/restore these filesystem's\n"
 "                        mountpoints even if fs is not supported.\n"
+"  --device-map a:b[,..] a comma separated colon splitted device mapping pairs.\n"
 "\n"
 "* Logging:\n"
 "  -o|--log-file FILE    log file name\n"
diff --git a/include/cr_options.h b/include/cr_options.h
index eac7283a4821..1451b386cce1 100644
--- a/include/cr_options.h
+++ b/include/cr_options.h
@@ -95,6 +95,8 @@ struct cr_options {
 	bool			overlayfs;
 	size_t			ghost_limit;
 	struct list_head	irmap_scan_paths;
+	unsigned int		*devmap;
+	size_t			nr_devmap;
 };
 
 extern struct cr_options opts;
-- 
2.5.0



More information about the CRIU mailing list