From 5af9e2b1899ac75e5ebcb7f2cf6ac4042c61617c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 21 Sep 2016 12:59:20 +0300 Subject: [PATCH] mount: Helper for auto-ext entry creation Signed-off-by: Pavel Emelyanov --- criu/mount.c | 46 +++++++++++++++++++++++++++++----------------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/criu/mount.c b/criu/mount.c index ce58804f9..f96958a79 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -35,6 +35,11 @@ #include "images/mnt.pb-c.h" #include "images/binfmt-misc.pb-c.h" +/* + * Put a : in here since those are invalid on + * the cli, so we know it's autogenerated in + * debugging. + */ #define AUTODETECTED_MOUNT "CRIU:AUTOGENERATED" #define MS_PROPAGATE (MS_SHARED | MS_PRIVATE | MS_UNBINDABLE | MS_SLAVE) @@ -79,6 +84,19 @@ static struct ext_mount *ext_mount_lookup(char *key) return NULL; } +static struct ext_mount *ext_mount_make_auto(char *key, char *val) +{ + struct ext_mount *em; + + em = xmalloc(sizeof(*em)); + if (em) { + em->key = key; + em->val = val; + } + + return em; +} + /* * Single linked list of mount points get from proc/images */ @@ -817,7 +835,6 @@ static int resolve_external_mounts(struct mount_info *info) for (m = info; m; m = m->next) { int ret; char *p, *cut_root; - struct ext_mount *em; struct mount_info *match; if (m->parent == NULL || m->is_ns_root) @@ -861,17 +878,16 @@ static int resolve_external_mounts(struct mount_info *info) if (!p) return -1; - em = xmalloc(sizeof(struct ext_mount)); - if (!em) { + m->external = ext_mount_make_auto(p, AUTODETECTED_MOUNT); + if (!m->external) { free(p); return -1; } - em->val = AUTODETECTED_MOUNT; - em->key = p; - - m->external = em; - + /* + * Put the guessed name in source. It will be picked up + * as auto-root in get_mp_root() on restore. + */ xfree(m->source); m->source = p; @@ -3086,18 +3102,14 @@ static int get_mp_root(MntEntry *me, struct mount_info *mi) * Make up an external mount entry for this * mount point, since we couldn't find a user * supplied one. + * + * The 'val' was put into mi->source during + * dump by resolve_external_mounts(). */ - em = xmalloc(sizeof(struct ext_mount)); + + em = ext_mount_make_auto(AUTODETECTED_MOUNT, mi->source); if (!em) return -1; - - /* - * Put a : in here since those are invalid on - * the cli, so we know it's autogenerated in - * debugging. - */ - em->key = AUTODETECTED_MOUNT; - em->val = mi->source; } mi->external = em;