[CRIU] [PATCH 01/13] crtools: close all desriptors only for the root task

Andrew Vagin avagin at parallels.com
Wed Mar 12 03:18:55 PDT 2014


On Tue, Mar 11, 2014 at 11:34:53PM +0400, Pavel Emelyanov wrote:
> On 03/11/2014 07:18 PM, Andrey Vagin wrote:
> > For all other tasks only unsed service descriptors will be closed.
> > 
> > This change allows to have file descriptors, which may be used for
> > restoring namespaces. All non-server descriptors must be closed before
> > restoring files.
> 
> Wait. Before this patch service descriptors survived the
> point in restore_task_with_children() you patch. Now they
> don't. Why?

They did. I close only unused service descriptors. We may have more than
one set of service descriptors. For example if tasks shares fdtable. So
when we want to keep only one set of services descriptors, we need to
close all others.

I'm going to rework this patch a bit.
> 
> > Signed-off-by: Andrey Vagin <avagin at openvz.org>
> > ---
> >  cr-restore.c        | 11 ++++++-----
> >  include/servicefd.h |  1 +
> >  util.c              | 13 +++++++++++++
> >  3 files changed, 20 insertions(+), 5 deletions(-)
> > 
> > diff --git a/cr-restore.c b/cr-restore.c
> > index ab8fa77..84aaccc 100644
> > --- a/cr-restore.c
> > +++ b/cr-restore.c
> > @@ -1238,6 +1238,9 @@ static int restore_task_with_children(void *_arg)
> >  		if (restore_finish_stage(CR_STATE_RESTORE_NS) < 0)
> >  			exit(1);
> >  
> > +		if (close_old_fds(current))
> > +			exit(1);
> > +
> >  		if (collect_mount_info(getpid()))
> >  			exit(1);
> >  
> > @@ -1272,11 +1275,9 @@ static int restore_task_with_children(void *_arg)
> >  	if (prepare_mappings(pid))
> >  		exit(1);
> >  
> > -	if (!(ca->clone_flags & CLONE_FILES)) {
> > -		ret = close_old_fds(current);
> > -		if (ret)
> > -			exit(1);
> > -	}
> > +	if ((!(ca->clone_flags & CLONE_FILES)) &&
> > +	    current->parent && current->parent->rst->fdt)
> > +		close_old_servie_fd(current->parent->rst->fdt->nr);
> >  
> >  	if (create_children_and_session())
> >  		exit(1);
> > diff --git a/include/servicefd.h b/include/servicefd.h
> > index 2a2542c..f855fe8 100644
> > --- a/include/servicefd.h
> > +++ b/include/servicefd.h
> > @@ -25,6 +25,7 @@ extern int get_service_fd(enum sfd_type type);
> >  extern int reserve_service_fd(enum sfd_type type);
> >  extern int install_service_fd(enum sfd_type type, int fd);
> >  extern int close_service_fd(enum sfd_type type);
> > +extern void close_old_servie_fd(int nr);
> >  extern bool is_service_fd(int fd, enum sfd_type type);
> >  extern bool is_any_service_fd(int fd);
> >  
> > diff --git a/util.c b/util.c
> > index 4304a91..66d72a2 100644
> > --- a/util.c
> > +++ b/util.c
> > @@ -341,6 +341,19 @@ int close_service_fd(enum sfd_type type)
> >  	return 0;
> >  }
> >  
> > +/* Close all unused service descriptors on a depth of nr. */
> > +void close_old_servie_fd(int nr)
> > +{
> > +	int level, i;
> > +	for (level = 0; level < nr; level++) {
> > +		if (level == service_fd_id)
> > +			continue;
> > +		for (i = SERVICE_FD_MIN + 1; i < SERVICE_FD_MAX; i++) {
> > +			close(__get_service_fd(i, level));
> > +		}
> > +	}
> > +}
> > +
> >  int clone_service_fd(int id)
> >  {
> >  	int ret = -1, i;
> > 
> 
> 


More information about the CRIU mailing list