[CRIU] [PATCH] [v2] mount: move functions to handle paths in a separate file

Andrey Vagin avagin at openvz.org
Mon May 16 23:39:32 PDT 2016


From: Andrew Vagin <avagin at virtuozzo.com>

mount.c is too big already and the next patch adds one more such functions
with a few unit test, so it's better to add one more source file.

v2: fix compilation on arm and ppc
Signed-off-by: Andrew Vagin <avagin at virtuozzo.com>
---
 criu/Makefile.crtools |  1 +
 criu/include/path.h   | 31 +++++++++++++++++++++++++++++++
 criu/mount.c          | 47 +----------------------------------------------
 criu/path.c           | 36 ++++++++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 46 deletions(-)
 create mode 100644 criu/include/path.h
 create mode 100644 criu/path.c

diff --git a/criu/Makefile.crtools b/criu/Makefile.crtools
index 657b08e..9e4ec7a 100644
--- a/criu/Makefile.crtools
+++ b/criu/Makefile.crtools
@@ -78,6 +78,7 @@ obj-y			+= util.o
 obj-y			+= uts_ns.o
 obj-y			+= autofs.o
 obj-y			+= uffd.o
+obj-y			+= path.o
 
 ifeq ($(VDSO),y)
 obj-y			+= pie-util-vdso.o
diff --git a/criu/include/path.h b/criu/include/path.h
new file mode 100644
index 0000000..497e9ef
--- /dev/null
+++ b/criu/include/path.h
@@ -0,0 +1,31 @@
+#ifndef __CR_PATH_H__
+#define __CR_PATH_H__
+
+/* Asolute paths are used on dump and relative paths are used on restore */
+static inline int is_root(char *p)
+{
+	return (!strcmp(p, "/"));
+}
+
+/* True for the root mount (the topmost one) */
+static inline int is_root_mount(struct mount_info *mi)
+{
+	return is_root(mi->mountpoint + 1);
+}
+
+/*
+ * True if the mountpoint target is root on its FS.
+ *
+ * This is used to determine whether we need to postpone
+ * mounting. E.g. one can bind mount some subdir from a
+ * disk, and in this case we'll have to get the root disk
+ * mount first, then bind-mount it. See do_mount_one().
+ */
+static inline int fsroot_mounted(struct mount_info *mi)
+{
+	return is_root(mi->root);
+}
+
+char *cut_root_for_bind(char *target_root, char *source_root);
+
+#endif
diff --git a/criu/mount.c b/criu/mount.c
index 6f47655..6fd07ea 100644
--- a/criu/mount.c
+++ b/criu/mount.c
@@ -29,6 +29,7 @@
 #include "fs-magic.h"
 #include "sysfs_parse.h"
 #include "autofs.h"
+#include "path.h"
 
 #include "images/mnt.pb-c.h"
 #include "images/binfmt-misc.pb-c.h"
@@ -92,31 +93,6 @@ static int open_mountpoint(struct mount_info *pm);
 static struct mount_info *mnt_build_tree(struct mount_info *list, struct mount_info *roots_mp);
 static int validate_mounts(struct mount_info *info, bool for_dump);
 
-/* Asolute paths are used on dump and relative paths are used on restore */
-static inline int is_root(char *p)
-{
-	return (!strcmp(p, "/"));
-}
-
-/* True for the root mount (the topmost one) */
-static inline int is_root_mount(struct mount_info *mi)
-{
-	return is_root(mi->mountpoint + 1);
-}
-
-/*
- * True if the mountpoint target is root on its FS.
- *
- * This is used to determine whether we need to postpone
- * mounting. E.g. one can bind mount some subdir from a
- * disk, and in this case we'll have to get the root disk
- * mount first, then bind-mount it. See do_mount_one().
- */
-static inline int fsroot_mounted(struct mount_info *mi)
-{
-	return is_root(mi->root);
-}
-
 static struct mount_info *__lookup_overlayfs(struct mount_info *list, char *rpath,
 						unsigned int st_dev, unsigned int st_ino,
 						unsigned int mnt_id)
@@ -793,27 +769,6 @@ skip_fstype:
 	return 0;
 }
 
-static char *cut_root_for_bind(char *target_root, char *source_root)
-{
-	int tok = 0;
-	/*
-	 * Cut common part of root.
-	 * For non-root binds the source is always "/" (checked)
-	 * so this will result in this slash removal only.
-	 */
-	while (target_root[tok] == source_root[tok]) {
-		tok++;
-		if (source_root[tok] == '\0')
-			break;
-		BUG_ON(target_root[tok] == '\0');
-	}
-	if (target_root[tok] == '/')
-		tok++;
-
-	return target_root + tok;
-
-}
-
 static struct mount_info *find_best_external_match(struct mount_info *list, struct mount_info *info)
 {
 	struct mount_info *it, *candidate = NULL;
diff --git a/criu/path.c b/criu/path.c
new file mode 100644
index 0000000..c5ee0f0
--- /dev/null
+++ b/criu/path.c
@@ -0,0 +1,36 @@
+#include <string.h>
+#include <stdio.h>
+
+#include "mount.h"
+#include "path.h"
+#include "bug.h"
+
+char *cut_root_for_bind(char *target_root, char *source_root)
+{
+	int tok = 0;
+	char *path = NULL;
+	/*
+	 * Cut common part of root.
+	 * For non-root binds the source is always "/" (checked)
+	 * so this will result in this slash removal only.
+	 */
+	while (target_root[tok] == source_root[tok]) {
+		tok++;
+		if (source_root[tok] == '\0') {
+			path = target_root + tok;
+			goto out;
+		}
+		if (target_root[tok] == '\0') {
+			path = source_root + tok;
+			goto out;
+		}
+	}
+
+	return NULL;
+out:
+	BUG_ON(path == NULL);
+	if (path[0] == '/')
+		path++;
+
+	return path;
+}
-- 
2.7.4



More information about the CRIU mailing list