[CRIU] [PATCH 1/3] crtools: resurrect --pid option for dump, v2

Pavel Emelyanov xemul at virtuozzo.com
Tue Feb 28 07:24:14 PST 2017


On 02/28/2017 03:19 PM, Ruslan Kuprieiev wrote:
> This option now allows us to specify a process within specified
> process tree that needs to be checkpointed. For now only root
> process is allowed(-t and -p options should have same PID).
> 
> This behaviour is useful for dumping master processes,
> that fork it's children to do the work. I.e. one of such cases
> is php process that forks workers. When one uses this option,
> he agrees to possible consequences and is ready to handle
> recovering from such restore on a dumpee side.
> 
> v2: fixed help line length
> 
> Signed-off-by: Ruslan Kuprieiev <rkuprieiev at cloudlinux.com>
> ---
>  criu/crtools.c            | 10 +++++++---
>  criu/include/cr_options.h |  1 +
>  criu/seize.c              | 11 +++++++----
>  3 files changed, 15 insertions(+), 7 deletions(-)
> 
> diff --git a/criu/crtools.c b/criu/crtools.c
> index 927ca8e..ec02fe3 100644
> --- a/criu/crtools.c
> +++ b/criu/crtools.c
> @@ -78,6 +78,7 @@ void init_opts(void)
>  	opts.timeout = DEFAULT_TIMEOUT;
>  	opts.empty_ns = 0;
>  	opts.status_fd = -1;
> +	opts.pid = -1;
>  }
>  
>  static int parse_join_ns(const char *ptr)
> @@ -212,7 +213,7 @@ bool deprecated_ok(char *what)
>  
>  int main(int argc, char *argv[], char *envp[])
>  {
> -	pid_t pid = 0, tree_id = 0;
> +	pid_t tree_id = 0;
>  	int ret = -1;
>  	bool usage_error = true;
>  	bool has_exec_cmd = false;
> @@ -344,8 +345,8 @@ int main(int argc, char *argv[], char *envp[])
>  			opts.ext_unix_sk = true;
>  			break;
>  		case 'p':
> -			pid = atoi(optarg);
> -			if (pid <= 0)
> +			opts.pid = atoi(optarg);
> +			if (opts.pid <= 0)

I would just save the tree_id value here and set opts.one_shot = true.
Then in collect_pstree() just freeze root task and that's it.

>  				goto bad_arg;
>  			break;
>  		case 't':

BTW, right after opts parsing there should go the check for --freeze-cgroup
is not in use together with --pid.

-- Pavel

> @@ -851,6 +852,9 @@ usage:
>  "\n"
>  "* Generic:\n"
>  "  -t|--tree PID         checkpoint a process tree identified by PID\n"
> +"  -p|--pid PID          within a specified process tree, checkpoint only a\n"
> +"                        process with this PID(for now only root of a tree\n"
> +"                        is supported)\n"
>  "  -d|--restore-detached detach after restore\n"
>  "  -S|--restore-sibling  restore root task as sibling\n"
>  "  -s|--leave-stopped    leave tasks in stopped state after checkpoint\n"
> diff --git a/criu/include/cr_options.h b/criu/include/cr_options.h
> index 1c065ac..dd3bb9e 100644
> --- a/criu/include/cr_options.h
> +++ b/criu/include/cr_options.h
> @@ -108,6 +108,7 @@ struct cr_options {
>  	bool			lazy_pages;
>  	bool			tcp_skip_in_flight;
>  	char			*work_dir;
> +	int			pid;
>  
>  	/*
>  	 * When we scheduler for removal some functionality we first
> diff --git a/criu/seize.c b/criu/seize.c
> index d5079ca..5d913a8 100644
> --- a/criu/seize.c
> +++ b/criu/seize.c
> @@ -807,10 +807,13 @@ static int collect_task(struct pstree_item *item)
>  	if (ret < 0)
>  		goto err_close;
>  
> -	/* Depth-first search (DFS) is used for traversing a process tree. */
> -	ret = collect_loop(item, collect_children);
> -	if (ret < 0)
> -		goto err_close;
> +	/* FIXME: for now only root process is supported for selective dump */
> +	if (opts.pid == -1 || opts.pid != item->pid->real) {
> +		/* Depth-first search (DFS) is used for traversing a process tree. */
> +		ret = collect_loop(item, collect_children);
> +		if (ret < 0)
> +			goto err_close;
> +	}
>  
>  	if ((item->pid->state == TASK_DEAD) && !list_empty(&item->children)) {
>  		pr_err("Zombie with children?! O_o Run, run, run!\n");
> 



More information about the CRIU mailing list