[CRIU] [PATCH 1/2] Re-create cgroups if necessary

Andrew Vagin avagin at parallels.com
Tue Jun 24 00:27:55 PDT 2014


On Tue, Jun 24, 2014 at 11:09:56AM +0400, Pavel Emelyanov wrote:
> On 06/23/2014 10:53 PM, Andrew Vagin wrote:
> > On Mon, Jun 23, 2014 at 10:29:53PM +0400, Andrew Vagin wrote:
> >> On Mon, Jun 23, 2014 at 03:54:22PM +0000, Tycho Andersen wrote:
> >>> If a task had cgroups, these should be restored. (Also any properties of
> >>> cgroups, but this commit doesn't do that yet.)
> >>>
> >>> Signed-off-by: Tycho Andersen <tycho.andersen at canonical.com>
> >>> ---
> >>>  cgroup.c       |  6 +++++-
> >>>  include/util.h |  5 +++++
> >>>  util.c         | 26 ++++++++++++++++++++++++++
> >>>  3 files changed, 36 insertions(+), 1 deletion(-)
> >>>
> >>> diff --git a/cgroup.c b/cgroup.c
> >>> index 2d9ebad..8b2deb2 100644
> >>> --- a/cgroup.c
> >>> +++ b/cgroup.c
> >>> @@ -258,9 +258,13 @@ static int move_in_cgroup(CgSetEntry *se)
> >>>  		int fd, err;
> >>>  		ControllerEntry *ce = se->ctls[i];
> >>>  
> >>> +		sprintf(aux, "%s/%s", ce->name, ce->path);
> >>> +		if (mkdirpat(cg, aux) < 0)
> >>> +			return -1;
> >>> +
> >>>  		sprintf(aux, "%s/%s/tasks", ce->name, ce->path);
> >>>  		pr_debug("  `-> %s\n", aux);
> >>> -		err = fd = openat(cg, aux, O_WRONLY);
> >>> +		err = fd = openat(cg, aux, O_WRONLY | O_CREAT, 0700);
> >>>  		if (fd >= 0) {
> >>>  			/*
> >>>  			 * Writing zero into this file moves current
> >>> diff --git a/include/util.h b/include/util.h
> >>> index 22a0f3d..e2ec22e 100644
> >>> --- a/include/util.h
> >>> +++ b/include/util.h
> >>> @@ -303,4 +303,9 @@ static inline bool strstartswith(char *str, char *sub)
> >>>  	}
> >>>  }
> >>>  
> >>> +/*
> >>> + * mkdir -p for a file descriptor
> >>> + */
> >>> +int mkdirpat(int fd, const char* path);
> >>> +
> >>>  #endif /* __CR_UTIL_H__ */
> >>> diff --git a/util.c b/util.c
> >>> index 975af30..7d235c6 100644
> >>> --- a/util.c
> >>> +++ b/util.c
> >>> @@ -677,3 +677,29 @@ struct vma_area *alloc_vma_area(void)
> >>>  
> >>>  	return p;
> >>>  }
> >>> +
> >>> +int mkdirpat(int fd, const char* path)
> >>> +{
> >>> +	char* tok;
> >>> +	char made_path[PATH_MAX] = "", tok_path[PATH_MAX];
> >>> +
> >>> +	if (strlen(path) < PATH_MAX)
> >>> +	{
> >>> +		pr_err("path %s is longer than PATH_MAX", path);
> >>> +		return -1;
> >>> +	}
> >>> +
> >>> +	strncpy(tok_path, path, PATH_MAX);
> >>> +
> >>> +	for(tok = strtok(tok_path, "/"); tok; tok = strtok(NULL, "/")) {
> >>
> >> tok = strtok(NULL, "/") always returns NULL
> > 
> > Sorry, pls ignore this comment.
> > 
> >>
> >>> +		strcat(made_path, tok);
> >>> +		strcat(made_path, "/");
> >>> +		if (mkdirat(fd, made_path, 0755) < 0 && errno != EEXIST) {
> >>> +			pr_perror("couldn't mkdirpat directory\n");
> >>> +			return -1;
> >>> +		}
> >>> +	}
> > 
> > Look at my version. It doesn't copy a path in another place.
> > 
> > 	tok = path;
> > 	while (tok = strchr(tok + 1, "/")) {
	while (1) {
> > 		char c;

		tok = strchr(tok + 1, "/");

> > 		if (tok != NULL) {
> 
> Is this if necessary?

Yes, it's necessary to create the last part. This code is untested, it
was created to show the idea.

> 
> > 			c = *tok;
> > 			*tok = 0;
> > 		}
> > 
> > 		if (mkdirat(fd, path, 0755) < 0 && errno != EEXIST) {
> > 			pr_perror("couldn't mkdirpat directory\n");
			if (tok)
				*tok = c;
> > 			return -1;
> > 		}
> > 
> > 		if (tok == NULL)
> 
> This one?
> 
> > 			break;
> > 		else
> > 			*tok = c;
> > 	}
> > 
> > Thanks.
> > _______________________________________________
> > CRIU mailing list
> > CRIU at openvz.org
> > https://lists.openvz.org/mailman/listinfo/criu
> > .
> > 
> 


More information about the CRIU mailing list