[CRIU] [PATCH 02/39] mounts: initialize root before dumping mount namespace

Andrew Vagin avagin at parallels.com
Mon Apr 21 11:49:11 PDT 2014


On Mon, Apr 21, 2014 at 10:21:29PM +0400, Pavel Emelyanov wrote:
> On 04/21/2014 06:23 PM, Andrey Vagin wrote:
> > Currently it's initialized for the root mount namespace, but we are
> > going to dump nested mount namespaces.
> > 
> > It's used in open_mountpoint(), which is used in dump_tmpfs() and in
> > other callbacks.
> 
> The mntns root is also required in dumping files, but the
> fn you put the collect to is executed in a subprocess. How
> are we going to deal with that?

Actually here is two series. The first one 1-14 dumps nested mount
namespaces. The second one 14-39 dumps opened files.

In the first series mntns_root is a global variable and we initialize it
once for each namespace. In the second series the global mntns_root will
be removed and mntns_collect_root() will be called each time, when we
will need a root for a specified namspace.

For example:

static int __open_mountpoint(struct mount_info *pm, int mnt_fd)
{
        dev_t dev;
        struct stat st;
        int ret;

        if (mnt_fd == -1) {
                int mntns_root;

                mntns_root = mntns_collect_root(pm->nsid->pid);
                if (mntns_root < 0)
                        return -1;

                mnt_fd = openat(mntns_root, pm->mountpoint, O_RDONLY);
                if (mnt_fd < 0) {
                        pr_perror("Can't open %s", pm->mountpoint);
                        return -1;
                }
        }


> 
> > Signed-off-by: Andrey Vagin <avagin at openvz.org>
> > ---
> >  mount.c | 3 +++
> >  1 file changed, 3 insertions(+)
> > 
> > diff --git a/mount.c b/mount.c
> > index 93b3fe3..91a3e3c 100644
> > --- a/mount.c
> > +++ b/mount.c
> > @@ -821,6 +821,9 @@ int dump_mnt_ns(int ns_pid, int ns_id)
> >  	if (img_fd < 0)
> >  		return -1;
> >  
> > +	if (mntns_collect_root(ns_pid))
> > +		goto err;
> > +
> >  	pm = parse_mountinfo(ns_pid);
> >  	if (!pm) {
> >  		pr_err("Can't parse %d's mountinfo\n", ns_pid);
> > 
> 
> 


More information about the CRIU mailing list