[2/3] mount: Helper for auto-ext entry creation

Submitted by Pavel Emelianov on Sept. 21, 2016, 9:59 a.m.

Details

Message ID 57E259F8.1010309@virtuozzo.com
State Accepted
Series "Sanitize ext-mount-map usage in mount.c"
Commit 10e1ffd29e3c3ea79a18cde8a04fb77514cd15b7
Headers show

Commit Message

Pavel Emelianov Sept. 21, 2016, 9:59 a.m.
Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
---
 criu/mount.c | 46 +++++++++++++++++++++++++++++-----------------
 1 file changed, 29 insertions(+), 17 deletions(-)

Patch hide | download patch | download mbox

diff --git a/criu/mount.c b/criu/mount.c
index 021d041..40e871b 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -34,6 +34,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)
 
@@ -78,6 +83,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
  */
@@ -816,7 +834,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)
@@ -860,17 +877,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;
 
@@ -3085,18 +3101,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;