[CRIU] [PATCH 09/13] mounts: prepare to create a temporary directory for restoring non-root mntns

Andrew Vagin avagin at parallels.com
Wed Mar 12 06:10:38 PDT 2014


On Tue, Mar 11, 2014 at 11:45:39PM +0400, Pavel Emelyanov wrote:
> On 03/11/2014 07:18 PM, Andrey Vagin wrote:
> > All non-root namespaces will be restored as sub-trees of the root tree.
> > 
> > This patch adds helpers to create a temporary directory and mount tmpfs
> > in it, then create directories for each non-root mount namespace.
> > 
> > tmpfs is quite useful here to simplify destroying this construction,
> > we don't need to unmount each namespace separately.
> 
> Why destroying? Do we optimize the error path?

No, we don't. On error path we can do nothing. All mounts will be
destroied with the mount namespace.

When all mount namespaces are restored, we must destroy the sub-trees in
the root namespace.

> One comment below.
> 
> > @@ -1413,6 +1483,34 @@ static int populate_mnt_ns(int ns_pid, struct mount_info *mis)
> >  	return mnt_tree_for_each(pms, do_mount_one);
> >  }
> >  
> > +int fini_mnt_ns()
> > +{
> > +	char *mnt_roots = get_mnt_roots(false);
> > +	int ret = 0;
> > +
> > +	if (mnt_roots == NULL)
> > +		return 0;
> > +
> > +	if (mount("none", mnt_roots, "none", MS_REC|MS_PRIVATE, NULL)) {
> > +		pr_perror("Can't remount root with MS_PRIVATE");
> > +		ret = 1;
> > +	}
> > +	/*
> > +	 * Don't exit after a first error, becuase this function
> > +	 * can be used to rollback in a error case
> > +	 */
> > +	if (umount2(mnt_roots, MNT_DETACH)) {
> 
> I don't like the MNT_DETACH flag. It creates an impression, that we
> just let the mountpoint hang unattached in memory for undefined amount
> of time. Why are we sure this will be freed?

Files are restored after calling fini_mnt_ns(), so here is nothing
dangerous. MNT_DETACH is simple and fast way to destroy all this mounts.

I will ad a comment here.

        if (current->parent == NULL && fini_mnt_ns())
                exit (1);

        if (current->state == TASK_HELPER)
                return 0;

        return restore_one_task(current->pid.virt, ca->core);

> 
> > +		pr_perror("Can't unmount %s", mnt_roots);
> > +		ret = 1;
> > +	}
> > +	if (rmdir(mnt_roots)) {
> > +		pr_perror("Can't remove the directory %s", mnt_roots);
> > +		ret = 1;
> > +	}
> > +
> > +	return ret;
> > +}
> > +
> >  int prepare_mnt_ns(int ns_pid)
> >  {
> >  	int ret = -1;
> > 
> 
> 


More information about the CRIU mailing list