mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-30 22:05:36 +00:00
mount: cut a common part of sources for bind-mounts
The source of the root mount may be not equal to "/" and we need to take this fact into account, when we bind-mount it to somewhere. For example: 11877 ? Ss 0:00 ./bind-mount --pidfile=bind-mount.pid --outfile=bind-mount.out --dirname=bind-mount.test 11880 ? Ss 0:00 \_ ./bind-mount --pidfile=bind-mount.pid --outfile=bind-mount.out --dirname=bind-mount.test [root@avagin-fc19-cr crtools]# cat /proc/11880/mountinfo 68 42 8:3 /root/git/crtools/test / rw,relatime - ext4 /dev/sda3 rw,data=ordered 43 68 0:33 / /proc rw,relatime - proc proc rw 44 68 0:34 / /dev/pts rw,relatime - devpts pts rw,mode=666,ptmxmode=666 45 68 8:3 /root/git/crtools/test/zdtm/live/static/bind-mount.test/test /zdtm/live/static/bind-mount.test/bind rw,relatime - ext4 /dev/sda3 rw,data=ordered The 45 mount is bind-mount of the 68 mount. mi(45)->root = /root/git/crtools/test/zdtm/live/static/bind-mount.test/test mi(68)->root = /root/git/crtools/test so the comman part is "/root/git/crtools/test" and the command is mount --bind /zdtm/live/static/bind-mount.test/test /zdtm/live/static/bind-mount.test/bind Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
8135116a71
commit
a19643e643
19
mount.c
19
mount.c
@@ -1137,11 +1137,26 @@ static int restore_ext_mount(struct mount_info *mi)
|
||||
|
||||
static int do_bind_mount(struct mount_info *mi)
|
||||
{
|
||||
char rpath[PATH_MAX];
|
||||
bool shared = mi->shared_id && mi->shared_id == mi->bind->shared_id;
|
||||
|
||||
if (!mi->need_plugin) {
|
||||
snprintf(rpath, sizeof(rpath), "%s%s", mi->bind->mountpoint, mi->root);
|
||||
char rpath[PATH_MAX];
|
||||
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 (mi->root[tok] == mi->bind->root[tok]) {
|
||||
tok++;
|
||||
if (mi->bind->root[tok] == '\0')
|
||||
break;
|
||||
BUG_ON(mi->root[tok] == '\0');
|
||||
}
|
||||
|
||||
snprintf(rpath, sizeof(rpath), "%s/%s",
|
||||
mi->bind->mountpoint, mi->root + tok);
|
||||
pr_info("\tBind %s to %s\n", rpath, mi->mountpoint);
|
||||
|
||||
if (mount(rpath, mi->mountpoint, NULL,
|
||||
|
Reference in New Issue
Block a user