[CRIU] [PATCH 1/3] dump: Introduce "post-dump" script action

Andrew Vagin avagin at parallels.com
Mon Jul 15 07:16:49 EDT 2013


On Mon, Jul 15, 2013 at 11:53:02AM +0400, Cyrill Gorcunov wrote:
> 
> This is usefull if one needs to do some final action before checkpoint
> is complete. For example in case of online migration one may provide
> a script which would check the restore procedure on remote note
> ended without errors, thus the script returns zero code and criu
> simply kills running instance of application.
> 
> In turn, if migration failed, the script can return nonzero code
> and criu won't kill the application but continue its execution
> instead.
> 
> There are two kind of non-zero code recognized:
> 
>  1) Code with value 32 tells criu to drop repair mode from
>     tcp connections and continue execution of a program, but
>     criu itself exits with zero code, iow like in case of
>     successed checkpoint procedure

I don't like this. What is a use case for that? Can crtools returns the
exit code of a post-dump script? In this case the user can handle this
magic code.

> 
>  2) Any other non-zero code treated as error case, criu exits
>     reporting error happened during checkpoint and continue
>     execution of a dumpee.
> 
> https://bugzilla.openvz.org/show_bug.cgi?id=2583
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  cr-dump.c | 33 +++++++++++++++++++++++++++++++--
>  util.c    |  2 ++
>  2 files changed, 33 insertions(+), 2 deletions(-)
> 

> diff --git a/cr-dump.c b/cr-dump.c
> index 863bffd..ef72b12 100644
> --- a/cr-dump.c
> +++ b/cr-dump.c
> @@ -1636,6 +1636,7 @@ err:
>  
>  int cr_dump_tasks(pid_t pid)
>  {
> +	bool post_dump_exit = false;
>  	struct pstree_item *item;
>  	int ret = -1;
>  
> @@ -1717,15 +1718,43 @@ int cr_dump_tasks(pid_t pid)
>  err:
>  	close_cr_fdset(&glob_fdset);
>  
> +	if (!ret) {
> +		/*
> +		 * It might be a migration case, where we're asked
> +		 * to dump everything, then some script transfer
> +		 * image on a new node and we're supposed to kill
> +		 * dumpee because it continue running somewhere
> +		 * else.
> +		 *
> +		 * Thus ask user via script if we're to break
> +		 * checkpoint. Note if a special return code
> +		 * obtained, we don't treat the result as error
> +		 * case but unlock
> +		 */
> +		ret = run_scripts("post-dump");
> +		if (ret > 0) {
> +			ret = WEXITSTATUS(ret);
> +			if (ret == 32) {
> +				pr_msg("Post dump script passed with %d\n", ret);
> +				post_dump_exit = true;
> +				ret = 0;
> +			} else {
> +				pr_msg("Post dump script passed with %d\n", ret);
> +				ret = -1;
> +			}
> +		}
> +	}
> +
>  	/*
>  	 * If we've failed to do anything -- unlock all TCP sockets
>  	 * so that the connections can go on. But if we succeeded --
>  	 * don't, just close them silently.
>  	 */
> -	if (ret)
> +	if (ret || post_dump_exit)
>  		network_unlock();
>  	pstree_switch_state(root_item,
> -			ret ? TASK_ALIVE : opts.final_state);
> +			    (ret || post_dump_exit) ?
> +			    TASK_ALIVE : opts.final_state);
>  	timing_stop(TIME_FROZEN);
>  	free_pstree(root_item);
>  	free_file_locks();
> diff --git a/util.c b/util.c
> index 69ecf5d..74c14ac 100644
> --- a/util.c
> +++ b/util.c
> @@ -1,3 +1,5 @@
> +#define _XOPEN_SOURCE
> +
>  #include <stdlib.h>
>  #include <stdio.h>
>  #include <stdarg.h>



More information about the CRIU mailing list