[CRIU] [PATCH 2/4] mounts: use relative paths for mountpoints (v2)
Andrew Vagin
avagin at parallels.com
Fri Feb 28 04:29:50 PST 2014
On Fri, Feb 28, 2014 at 02:39:45PM +0400, Pavel Emelyanov wrote:
> On 02/24/2014 12:04 PM, Andrey Vagin wrote:
> > v2: don't use snprintf
>
> Some comment would be nice.
>
> > Signed-off-by: Andrey Vagin <avagin at openvz.org>
> > ---
> > mount.c | 13 +++++++++----
> > 1 file changed, 9 insertions(+), 4 deletions(-)
> >
> > diff --git a/mount.c b/mount.c
> > index a5436a6..795f947 100644
> > --- a/mount.c
> > +++ b/mount.c
> > @@ -45,9 +45,10 @@ static int close_mountpoint(DIR *dfd);
> > static struct mount_info *mnt_build_tree(struct mount_info *list);
> > static int validate_mounts(struct mount_info *info, bool call_plugins);
> >
> > +/* Asolute paths are used on dump and relative paths are used on restore */
> > static inline int is_root(char *p)
> > {
> > - return p[0] == '/' && p[1] == '\0';
> > + return (!strcmp(p, "/") || !strcmp(p, "./"));
> > }
> >
> > /* True for the root mount (the topmost one) */
> > @@ -78,7 +79,7 @@ int open_mount(unsigned int s_dev)
> > if (mntns_root == -1) {
> > pr_debug("mpopen %s\n", i->mountpoint);
> > return open(i->mountpoint, O_RDONLY);
> > - } else if (i->mountpoint[1] == '\0') {
> > + } else if (is_root_mount(i)) {
> > pr_debug("mpopen root\n");
> > return dup(mntns_root);
> > } else {
> > @@ -1359,6 +1360,7 @@ static struct mount_info *read_mnt_ns_img(int ns_pid)
> >
> > while (1) {
> > struct mount_info *pm;
> > + int len;
> >
> > ret = pb_read_one_eof(img, &me, PB_MNT);
> > if (ret <= 0)
> > @@ -1387,10 +1389,13 @@ static struct mount_info *read_mnt_ns_img(int ns_pid)
> > if (!pm->root)
> > goto err;
> >
> > - pr_debug("\t\tGetting mpt for %d\n", pm->mnt_id);
> > - pm->mountpoint = xstrdup(me->mountpoint);
> > + pr_debug("\t\tGetting mpt for %d:%s\n", pm->mnt_id, me->mountpoint);
> > + len = strlen(me->mountpoint) + 2;
> > + pm->mountpoint = xmalloc(len);
> > if (!pm->mountpoint)
> > goto err;
> > + pm->mountpoint[0] = '.';
> > + strcpy(pm->mountpoint + 1, me->mountpoint);
>
> How about bind mount's source? Don't we change the code from
>
> # chroot /new-root
> # mount /foo /bar --bind
>
> into
>
> # chdir /new-root
> # mount /foo ./bar --bind
>
> ?
Good question. Will check.
>
> >
> > pr_debug("\t\tGetting source for %d\n", pm->mnt_id);
> > pm->source = xstrdup(me->source);
> >
>
>
More information about the CRIU
mailing list