[CRIU] [PATCH] [RFC] cpt: clean up dump files

Kir Kolyshkin kir at openvz.org
Fri May 31 14:26:58 EDT 2013


On 05/30/2013 03:43 AM, Andrey Vagin wrote:
> OpenVZ checkpointing saves all data in one file.
> Currently criu is used for upstream CTs and it generates many files (one
> file for each type of objects), so we can get the following error
>
> Stale CT dump file /var/lib/vz/dump/Dump.101 found, removing
> Can't unlink /var/lib/vz/dump/Dump.101
>
> Only a tools, which checkpoints CT, knows how to delete own data,
> so lets do that in the script vzt-rst.


That looks a bit over-engineered. It's just a file or a directory
we need to get rid of.

I did this instead:
     http://git.openvz.org/?p=vzctl;a=commitdiff;h=4eeffe85fd
with less code and not only CT start, but also CT delete covered.

  include/destroy.h |  1 +
  src/lib/destroy.c |  8 ++++++--
  src/lib/env.c     | 11 ++---------
  3 files changed, 9 insertions(+), 11 deletions(-)

Andrey, can you please test and report back?
>
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>   include/cpt.h      |  3 ++-
>   scripts/vps-rst.in | 11 ++++++++++-
>   src/lib/env.c      | 10 +---------
>   src/lib/hooks_ct.c | 31 +++++++++++++++++++++++++++++--
>   src/lib/hooks_vz.c | 22 +++++++++++++++++-----
>   5 files changed, 59 insertions(+), 18 deletions(-)
>
> diff --git a/include/cpt.h b/include/cpt.h
> index 7932952..be7e0ae 100644
> --- a/include/cpt.h
> +++ b/include/cpt.h
> @@ -11,13 +11,14 @@
>   #define CMD_DUMP		3
>   #define CMD_RESTORE		4
>   #define CMD_UNDUMP		5
> +#define CMD_CLEANUP		6
>   
>   #define CMD_KILL		10
>   #define CMD_RESUME		11
>   
>   #define GET_DUMP_FILE(req_cmd)							\
>   do {										\
> -	dumpfile = param->dumpfile;						\
> +	dumpfile = param ? param->dumpfile : NULL;				\
>   	if (dumpfile == NULL) {							\
>   		if (cmd == req_cmd) {						\
>   			logger(-1,  0, "Error: dumpfile is not specified");	\
> diff --git a/scripts/vps-rst.in b/scripts/vps-rst.in
> index 91080b3..29ac014 100755
> --- a/scripts/vps-rst.in
> +++ b/scripts/vps-rst.in
> @@ -30,9 +30,18 @@
>   exec 1>&2
>   . @SCRIPTDIR@/vps-functions
>   
> +vzcheckvar CMD
> +vzcheckvar VE_DUMP_DIR
> +
> +if [ "$CMD" = "CLEANUP" ]; then
> +	[ -d $VE_DUMP_DIR ] || exit 0
> +	echo Stale CT dump directory $VE_DUMP_DIR found, removing
> +	rm -rf $VE_DUMP_DIR
> +	exit
> +fi
> +
>   vzcheckvar VE_ROOT
>   vzcheckvar VE_STATE_FILE
> -vzcheckvar VE_DUMP_DIR
>   vzcheckvar VE_VETH_DEVS
>   
>   veth_args=""
> diff --git a/src/lib/env.c b/src/lib/env.c
> index b45c878..b21f712 100644
> --- a/src/lib/env.c
> +++ b/src/lib/env.c
> @@ -779,15 +779,7 @@ int vps_start(vps_handler *h, envid_t veid, vps_param *param,
>   		/* Start was successful, remove the default dump file:
>   		 * it is now useless and inconsistent with the fs state
>   		 */
> -		char buf[STR_SIZE];
> -
> -		get_dump_file(veid, param->res.cpt.dumpdir, buf, sizeof(buf));
> -		if (stat_file(buf) == 1) {
> -			logger(0, 0, "Stale CT dump file %s found, removing",
> -					buf);
> -			if (unlink(buf) < 0)
> -				logger(-1, 0, "Can't unlink %s", buf);
> -		}
> +		h->env_restore(h, veid, param, CMD_CLEANUP, NULL, 0);
>   	}
>   
>   	return ret;
> diff --git a/src/lib/hooks_ct.c b/src/lib/hooks_ct.c
> index 18650e0..9ca34e9 100644
> --- a/src/lib/hooks_ct.c
> +++ b/src/lib/hooks_ct.c
> @@ -924,7 +924,7 @@ static int ct_chkpnt(vps_handler *h, envid_t veid,
>   static int ct_restore_fn(vps_handler *h, envid_t veid, const vps_res *res,
>   			  int wait_p, int old_wait_p, int err_p, void *data)
>   {
> -	char *argv[2], *env[5];
> +	char *argv[2], *env[6];
>   	const char *dumpfile = NULL;
>   	const char *statefile = NULL;
>   	cpt_param *param = data;
> @@ -957,8 +957,10 @@ static int ct_restore_fn(vps_handler *h, envid_t veid, const vps_res *res,
>   				"%s=%s\n", veth->dev_name_ve, veth->dev_name);
>   	}
>   	env[3] = strdup(buf);
> +	snprintf(buf, sizeof(buf), "CMD=RESUME");
> +	env[4] = strdup(buf);
>   
> -	env[4] = NULL;
> +	env[5] = NULL;
>   
>   	ret = run_script(argv[0], argv, env, 0);
>   	free_arg(env);
> @@ -985,6 +987,31 @@ err_destroy:
>   static int ct_restore(vps_handler *h, envid_t veid, vps_param *vps_p, int cmd,
>   	cpt_param *param, skipFlags skip)
>   {
> +	if (cmd == CMD_CLEANUP) {
> +		char dumpfile[STR_SIZE], buf[STR_SIZE];
> +		char *argv[2];
> +		char *env[3];
> +		int ret;
> +
> +		argv[0] = SCRIPTDIR "/vps-rst";
> +		argv[1] = NULL;
> +
> +		get_dump_file(veid, param ? param->dumpdir : NULL,
> +					dumpfile, sizeof(dumpfile));
> +		snprintf(buf, sizeof(buf), "VE_DUMP_DIR=%s", dumpfile);
> +		env[0] = strdup(buf);
> +		snprintf(buf, sizeof(buf), "CMD=CLEANUP");
> +		env[1] = strdup(buf);
> +		env[2] = NULL;
> +
> +		ret = run_script(argv[0], argv, env, 0);
> +		free_arg(env);
> +		if (ret)
> +			return VZ_RESTORE_ERROR;
> +
> +		return 0;
> +	}
> +
>   	return vps_start_custom(h, veid, vps_p,
>   			SKIP_CONFIGURE | SKIP_ACTION_SCRIPT | SKIP_VETH_CREATE | skip,
>   			NULL, ct_restore_fn, param);
> diff --git a/src/lib/hooks_vz.c b/src/lib/hooks_vz.c
> index 49ec042..86a2c92 100644
> --- a/src/lib/hooks_vz.c
> +++ b/src/lib/hooks_vz.c
> @@ -795,13 +795,25 @@ err_undump:
>   static int vz_restore(vps_handler *h, envid_t veid, vps_param *vps_p,
>   			int cmd, cpt_param *param, skipFlags skip)
>   {
> -	int ret, rst_fd;
> -	int dump_fd = -1;
> +	int ret, dump_fd = -1, rst_fd = -1;
>   	char buf[PATH_LEN];
>   	const char *dumpfile = NULL;
>   
> -	logger(0, 0, "Restoring container ...");
>   	ret = VZ_RESTORE_ERROR;
> +	GET_DUMP_FILE(CMD_UNDUMP);
> +
> +	if (cmd == CMD_CLEANUP) {
> +		if (stat_file(dumpfile) == 1) {
> +			logger(0, 0, "Stale CT dump file %s found, removing", dumpfile);
> +			if (unlink(dumpfile) < 0) {
> +				logger(-1, 0, "Can't unlink %s", dumpfile);
> +				return VZ_RESTORE_ERROR;
> +			}
> +		}
> +		return 0;
> +	}
> +
> +	logger(0, 0, "Restoring container ...");
>   	if ((rst_fd = open(PROC_RST, O_RDWR)) < 0) {
>   		if (errno == ENOENT)
>   			logger(-1, errno, "Error: No checkpointing"
> @@ -816,7 +828,6 @@ static int vz_restore(vps_handler *h, envid_t veid, vps_param *vps_p,
>   			goto err;
>   		}
>   	}
> -	GET_DUMP_FILE(CMD_UNDUMP);
>   	if (cmd == CMD_RESTORE || cmd == CMD_UNDUMP) {
>   		dump_fd = open(dumpfile, O_RDONLY);
>   		if (dump_fd < 0) {
> @@ -838,7 +849,8 @@ static int vz_restore(vps_handler *h, envid_t veid, vps_param *vps_p,
>   	if (ret)
>   		goto err;
>   err:
> -	close(rst_fd);
> +	if (rst_fd != -1)
> +		close(rst_fd);
>   	if (dump_fd != -1)
>   		close(dump_fd);
>   	if (!ret) {



More information about the CRIU mailing list