From fdeba04e862ceda9dd4ecc966863ed087a057a32 Mon Sep 17 00:00:00 2001 From: Andrew Vagin Date: Tue, 17 May 2016 09:39:00 +0300 Subject: [PATCH] mount: move functions to handle paths in a separate file 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 Signed-off-by: Pavel Emelyanov --- 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 cedcd5a61..931a9cd93 100644 --- a/criu/Makefile.crtools +++ b/criu/Makefile.crtools @@ -76,6 +76,7 @@ obj-y += tty.o obj-y += tun.o obj-y += util.o obj-y += uts_ns.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 000000000..497e9ef1a --- /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 d29b6a0ff..c54d233d0 100644 --- a/criu/mount.c +++ b/criu/mount.c @@ -28,6 +28,7 @@ #include "kerndat.h" #include "fs-magic.h" #include "sysfs_parse.h" +#include "path.h" #include "images/mnt.pb-c.h" #include "images/binfmt-misc.pb-c.h" @@ -91,31 +92,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) @@ -792,27 +768,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 000000000..c5ee0f0ef --- /dev/null +++ b/criu/path.c @@ -0,0 +1,36 @@ +#include +#include + +#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; +}