[CRIU] [RFC][PATCH 0/3] Proposal for native (w/o plugins) support for external bind mounts v2

Pavel Emelyanov xemul at parallels.com
Fri Jun 6 03:59:47 PDT 2014


On 06/06/2014 12:11 PM, Pavel Emelyanov wrote:
> On 06/06/2014 04:12 AM, Saied Kazemi wrote:
>> You're right about /fs1 /fs2 example above, it can get pretty convoluted.
>>
>> Regarding Docker container IDs, they are generated when new containers (along
>> with their new filesystems) are created.  For dump/restore, however, we need 
>> to keep the same container ID and preserve the state of its filesystem.  This 
>> requires Docker changes.  My comment was about the difficulty of specifying
>> long container root pathnames as command line arguments to CRIU.  You'd have
>> to first find the ID through docker ps and then provide it in full (64 characters)
>> in addition to the leading /var/lib/docker/vfs/root/ string.  So recording the
>> container ID during dump, as it's currently, done is advantageous.

What if we just keep last N components of the original root path in
the image. This info can later be retrieved using the 

$ criu show -f mountpoints.img -F root,orig_root_tail

command. E.g. if we bind mount /var/lib/foo/ext/file into container's
/file, launch it in /var/lib/foo/root root and dump it with the

$ criu dump --ext-mount /file=xx:3

command the output would look like

root: "xx" orig_root_tail: "/foo/ext/file" 
root: "/var/lib/foo/root" 

?

---

diff --git a/mount.c b/mount.c
index 8e23f86..1e15ab1 100644
--- a/mount.c
+++ b/mount.c
@@ -45,12 +45,14 @@
 struct ext_mount {
 	char *key;
 	char *val;
+	int orig_tail_len;
 	struct list_head l;
 };
 
 int ext_mount_add(char *key, char *val)
 {
 	struct ext_mount *em;
+	char *aux;
 
 	em = xmalloc(sizeof(*em));
 	if (!em)
@@ -58,8 +60,16 @@ int ext_mount_add(char *key, char *val)
 
 	em->key = key;
 	em->val = val;
+	em->orig_tail_len = 0;
+
+	aux = strchr(val, ':');
+	if (aux != NULL) {
+		*aux = '\0';
+		em->orig_tail_len = atoi(aux + 1);
+	}
+
 	list_add_tail(&em->l, &opts.ext_mounts);
-	pr_info("Added %s:%s ext mount mapping\n", key, val);
+	pr_info("Added %s:%s:%d ext mount mapping\n", key, val, em->orig_tail_len);
 	return 0;
 }
 
@@ -877,6 +887,32 @@ static char *strip(char *opt)
 	return opt;
 }
 
+/*
+ * Return last tail_len components from the path (or
+ * the whole path if it contains less of them).
+ */
+static char *path_get_tail(char *path, int tail_len)
+{
+	char *aux;
+
+	pr_debug("Trimming %d components from %s\n", tail_len, path);
+
+	aux = strchr(path, '\0');
+	BUG_ON(!aux);
+	while (1) {
+		if (aux == path)
+			return aux;
+
+		if (*aux == '/') {
+			tail_len--;
+			if (tail_len == 0)
+				return aux;
+		}
+
+		aux--;
+	}
+}
+
 static int dump_one_mountpoint(struct mount_info *pm, int fd)
 {
 	MntEntry me = MNT_ENTRY__INIT;
@@ -913,6 +949,8 @@ static int dump_one_mountpoint(struct mount_info *pm, int fd)
 		me.root	= pm->external->val;
 		me.has_ext_mount = true;
 		me.ext_mount = true;
+		if (pm->external->orig_tail_len)
+			me.orig_root_tail = path_get_tail(pm->root, pm->external->orig_tail_len);
 	} else
 		me.root = pm->root;
 
diff --git a/protobuf/mnt.proto b/protobuf/mnt.proto
index 44a6566..70e9deb 100644
--- a/protobuf/mnt.proto
+++ b/protobuf/mnt.proto
@@ -26,4 +26,5 @@ message mnt_entry {
 
 	optional bool		with_plugin		= 12;
 	optional bool		ext_mount		= 13;
+	optional string		orig_root_tail		= 14;
 }


More information about the CRIU mailing list