From patchwork Tue Oct 25 15:27:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [3/5] mount: Turn into --external From: Pavel Emelyanov X-Patchwork-Id: 2208 Message-Id: <580F79DD.4030801@virtuozzo.com> To: CRIU Date: Tue, 25 Oct 2016 18:27:25 +0300 Make --external support --ext-mount-map. The syntax is --ext-mount-map KEY:VAL == --external mnt[KEY]:VAL Old option is kept for backward compatibility. Signed-off-by: Pavel Emelyanov --- criu/crtools.c | 4 ++-- criu/include/mount.h | 18 ------------------ criu/mount.c | 37 ++++++++++++++++++++++++------------- 3 files changed, 26 insertions(+), 33 deletions(-) diff --git a/criu/crtools.c b/criu/crtools.c index 3e8d68f..8e35e67 100644 --- a/criu/crtools.c +++ b/criu/crtools.c @@ -850,10 +850,12 @@ usage: " file[mnt_id:inode]\n" " dev[maj:min]:VAL\n" " unix[ino]\n" +" mnt[MOUNTPOINT]:COOKIE\n" " Formats of RES on restore:\n" " dev[VAL]:DEVPATH\n" " veth[IFNAME]:OUTNAME{@BRIDGE}\n" " macvlan[IFNAME]:OUTNAME\n" +" mnt[COOKIE]:ROOT\n" "\n" "* Special resources support:\n" " --" SK_EST_PARAM " checkpoint/restore established TCP connections\n" @@ -870,8 +872,6 @@ usage: " --force-irmap force resolving names for inotify/fsnotify watches\n" " --irmap-scan-path FILE\n" " add a path the irmap hints to scan\n" -" -M|--ext-mount-map KEY:VALUE\n" -" add external mount mapping\n" " -M|--ext-mount-map auto\n" " attempt to autodetect external mount mappings\n" " --enable-external-sharing\n" diff --git a/criu/include/mount.h b/criu/include/mount.h index d4a7c04..c9a958a 100644 --- a/criu/include/mount.h +++ b/criu/include/mount.h @@ -10,24 +10,6 @@ struct pstree_item; struct fstype; struct ns_id; -/* - * Structure to keep external mount points resolving info. - * - * On dump the key is the mountpoint as seen from the mount - * namespace, the val is some name that will be put into image - * instead of the mount point's root path. - * - * On restore the key is the name from the image (the one - * mentioned above) and the val is the path in criu's mount - * namespace that will become the mount point's root, i.e. -- - * be bind mounted to the respective mountpoint. - */ -struct ext_mount { - struct list_head list; - char *key; - char *val; -}; - #define MOUNT_INVALID_DEV (0) struct mount_info { diff --git a/criu/mount.c b/criu/mount.c index 02fec0f..e3f33a4 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -45,29 +45,40 @@ int ext_mount_add(char *key, char *val) { - struct ext_mount *em; + char *e_str; - em = xmalloc(sizeof(*em)); - if (!em) + e_str = xmalloc(strlen(key) + strlen(val) + 8); + if (!e_str) return -1; - em->key = key; - em->val = val; - list_add_tail(&em->list, &opts.ext_mounts); - pr_info("Added %s:%s ext mount mapping\n", key, val); - return 0; + /* + * On dump the key is the mountpoint as seen from the mount + * namespace, the val is some name that will be put into image + * instead of the mount point's root path. + * + * On restore the key is the name from the image (the one + * mentioned above) and the val is the path in criu's mount + * namespace that will become the mount point's root, i.e. -- + * be bind mounted to the respective mountpoint. + */ + + sprintf(e_str, "mnt[%s]:%s", key, val); + return add_external(e_str); } /* Lookup ext_mount by key field */ static char *ext_mount_lookup(char *key) { - struct ext_mount *em; + char *v; + int len = strlen(key); + char mkey[len + 8]; - list_for_each_entry(em, &opts.ext_mounts, list) - if (!strcmp(em->key, key)) - return em->val; + sprintf(mkey, "mnt[%s]", key); + v = external_lookup_by_key(mkey); + if (IS_ERR(v)) + v = NULL; - return NULL; + return v; } /*