diff --git a/criu/mount.c b/criu/mount.c index 0f1f4db8e..b8e8598aa 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -35,6 +35,7 @@ * debugging. */ #define AUTODETECTED_MOUNT "CRIU:AUTOGENERATED" +#define NO_ROOT_MOUNT "CRIU:NO_ROOT" #define MS_PROPAGATE (MS_SHARED | MS_PRIVATE | MS_UNBINDABLE | MS_SLAVE) #undef LOG_PREFIX @@ -1329,17 +1330,14 @@ static int dump_one_mountpoint(struct mount_info *pm, struct cr_img *img) me.internal_sharing = true; } - if (pm->external) { + if (pm->external) /* * For external mount points dump the mapping's - * value instead of root. See collect_mnt_from_image + * value, see collect_mnt_from_image -> get_mp_root * for reverse mapping details. */ - me.root = pm->external; - me.has_ext_mount = true; - me.ext_mount = true; - } else - me.root = pm->root; + me.ext_key = pm->external; + me.root = pm->root; if (pb_write_one(img, &me, PB_MNT)) return -1; @@ -2446,11 +2444,27 @@ static int get_mp_root(MntEntry *me, struct mount_info *mi) { char *ext = NULL; + BUG_ON(me->ext_mount && me->ext_key); + + /* Forward compatibility fixup */ + if (me->ext_mount) { + me->ext_key = me->root; + /* + * Puting the id of external mount which is provided by user, + * to ->root can confuse mnt_is_external and other functions + * which expect to see the path in the file system to the root + * of these mount (mounts_equal, mnt_build_ids_tree, + * find_wider_shared, find_fsroot_mount_for, + * find_best_external_match, etc.) + */ + me->root = NO_ROOT_MOUNT; + } + mi->root = xstrdup(me->root); if (!mi->root) return -1; - if (!me->ext_mount) + if (!me->ext_key) goto out; /* @@ -2458,7 +2472,7 @@ static int get_mp_root(MntEntry *me, struct mount_info *mi) * from the command line and put into root's place */ - ext = ext_mount_lookup(me->root); + ext = ext_mount_lookup(me->ext_key); if (!ext) { if (!opts.autodetect_ext_mounts) { pr_err("No mapping for %s mountpoint\n", me->mountpoint); diff --git a/images/mnt.proto b/images/mnt.proto index 50cd8afbb..4160acbf6 100644 --- a/images/mnt.proto +++ b/images/mnt.proto @@ -53,4 +53,6 @@ message mnt_entry { optional bool deleted = 16; optional uint32 sb_flags = 17 [(criu).hex = true]; + /* user defined mapping for external mount */ + optional string ext_key = 18; }