mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-18 00:58:31 +00:00
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 <avagin@virtuozzo.com> Signed-off-by: Pavel Emelyanov <xemul@virtuozzo.com>
This commit is contained in:
parent
b0049beacc
commit
fdeba04e86
4 changed files with 69 additions and 46 deletions
|
|
@ -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
|
||||
|
|
|
|||
31
criu/include/path.h
Normal file
31
criu/include/path.h
Normal file
|
|
@ -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
|
||||
47
criu/mount.c
47
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;
|
||||
|
|
|
|||
36
criu/path.c
Normal file
36
criu/path.c
Normal file
|
|
@ -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;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue