[CRIU] [PATCH 07/22] files: Move reg files into files image

Kirill Tkhai ktkhai at virtuozzo.com
Tue Jul 4 12:17:30 MSK 2017


On Fri, Jun 30, 2017 at 13:57, Pavel Emelyanov wrote:
> 
> Signed-off-by: Pavel Emelyanov <xemul at virtuozzo.com>
> ---
>  criu/files-reg.c          | 21 +++++++++++++++------
>  criu/files.c              | 15 +++++++++++++++
>  criu/include/files-reg.h  |  1 +
>  criu/include/image-desc.h |  2 +-
>  images/fdinfo.proto       |  3 +++
>  5 files changed, 35 insertions(+), 7 deletions(-)
> 
> diff --git a/criu/files-reg.c b/criu/files-reg.c
> index 32cc8fe..6e2625e 100644
> --- a/criu/files-reg.c
> +++ b/criu/files-reg.c
> @@ -905,6 +905,7 @@ static int create_link_remap(char *path, int len, int lfd,
>  				const struct stat *st)
>  {
>  	char link_name[PATH_MAX], *tmp;
> +	FileEntry fe = FILE_ENTRY__INIT;
>  	RegFileEntry rfe = REG_FILE_ENTRY__INIT;
>  	FownEntry fwn = FOWN_ENTRY__INIT;
>  	int mntns_root;
> @@ -963,7 +964,11 @@ again:

Could you please add the below parameter in your ~/.gitconfig?

[diff "default"]
        xfuncname = "^[[:alpha:]$_].*[^:]$"

With it, git diff will contain functions names in hunks headers.
This is much more useful, than labels: functions names are uniqul,
while label names are uniqul over a function only, and it's not
always clear which function refer popular label like "out" or "again".

>  	if (note_link_remap(link_name, nsid))
>  		return -1;
>  
> -	return pb_write_one(img_from_set(glob_imgset, CR_FD_REG_FILES), &rfe, PB_REG_FILE);
> +	fe.type = FD_TYPES__REG;
> +	fe.id = rfe.id;
> +	fe.reg = &rfe;
> +
> +	return pb_write_one(img_from_set(glob_imgset, CR_FD_FILES), &fe, PB_FILE);
>  }
>  
>  static int dump_linked_remap(char *path, int len, const struct stat *ost,
> @@ -1288,7 +1293,7 @@ int dump_one_reg_file(int lfd, u32 id, const struct fd_parms *p)
>  	struct ns_id *nsid;
>  	struct cr_img *rimg;
>  	char ext_id[64];
> -
> +	FileEntry fe = FILE_ENTRY__INIT;
>  	RegFileEntry rfe = REG_FILE_ENTRY__INIT;
>  
>  	if (!p->link) {
> @@ -1348,8 +1353,12 @@ ext:
>  		rfe.size = p->stat.st_size;
>  	}
>  
> -	rimg = img_from_set(glob_imgset, CR_FD_REG_FILES);
> -	return pb_write_one(rimg, &rfe, PB_REG_FILE);
> +	fe.type = FD_TYPES__REG;
> +	fe.id = rfe.id;
> +	fe.reg = &rfe;
> +
> +	rimg = img_from_set(glob_imgset, CR_FD_FILES);
> +	return pb_write_one(rimg, &fe, PB_FILE);
>  }
>  
>  const struct fdtype_ops regfile_dump_ops = {
> @@ -1972,7 +1981,7 @@ static int collect_one_regfile(void *o, ProtobufCMessage *base, struct cr_img *i
>  	return file_desc_add(&rfi->d, rfi->rfe->id, &reg_desc_ops);
>  }
>  
> -static struct collect_image_info reg_file_cinfo = {
> +struct collect_image_info reg_file_cinfo = {
>  	.fd_type = CR_FD_REG_FILES,
>  	.pb_type = PB_REG_FILE,
>  	.priv_size = sizeof(struct reg_file_info),
> @@ -1982,7 +1991,7 @@ static struct collect_image_info reg_file_cinfo = {
>  
>  int collect_remaps_and_regfiles(void)
>  {
> -	if (collect_image(&reg_file_cinfo))
> +	if (!files_collected() && collect_image(&reg_file_cinfo))
>  		return -1;
>  
>  	if (collect_image(&remap_cinfo))
> diff --git a/criu/files.c b/criu/files.c
> index c371f8c..5d7e6c4 100644
> --- a/criu/files.c
> +++ b/criu/files.c
> @@ -1780,6 +1780,17 @@ err:
>  	return -1;
>  }
>  
> +static int collect_one_file_entry(FileEntry *fe, u_int32_t id, ProtobufCMessage *base,
> +		struct collect_image_info *cinfo)
> +{
> +	if (fe->id != id) {
> +		pr_err("ID mismatch %u != %u\n", fe->id, id);
> +		return -1;
> +	}
> +
> +	return collect_entry(base, cinfo);
> +}
> +
>  static int collect_one_file(void *o, ProtobufCMessage *base, struct cr_img *i)
>  {
>  	int ret = 0;
> @@ -1790,6 +1801,9 @@ static int collect_one_file(void *o, ProtobufCMessage *base, struct cr_img *i)
>  	default:
>  		pr_err("Unknown file type %d\n", fe->type);
>  		return -1;
> +	case FD_TYPES__REG:
> +		ret = collect_one_file_entry(fe, fe->reg->id, &fe->reg->base, &reg_file_cinfo);
> +		break;
>  	}
>  
>  	return ret;
> @@ -1800,6 +1814,7 @@ struct collect_image_info files_cinfo = {
>  	.pb_type = PB_FILE,
>  	.priv_size = 0,
>  	.collect = collect_one_file,
> +	.flags = COLLECT_NOFREE,
>  };
>  
>  int prepare_files(void)
> diff --git a/criu/include/files-reg.h b/criu/include/files-reg.h
> index 1c49be9..7a22d4d 100644
> --- a/criu/include/files-reg.h
> +++ b/criu/include/files-reg.h
> @@ -44,6 +44,7 @@ extern int collect_filemap(struct vma_area *);
>  extern void filemap_ctx_init(bool auto_close);
>  extern void filemap_ctx_fini(void);
>  
> +extern struct collect_image_info reg_file_cinfo;
>  extern int collect_remaps_and_regfiles(void);
>  
>  extern void delete_link_remaps(void);
> diff --git a/criu/include/image-desc.h b/criu/include/image-desc.h
> index 41fed0d..41896c5 100644
> --- a/criu/include/image-desc.h
> +++ b/criu/include/image-desc.h
> @@ -56,7 +56,6 @@ enum {
>  	_CR_FD_GLOB_FROM,
>  	CR_FD_FILES,
>  	CR_FD_SK_QUEUES,
> -	CR_FD_REG_FILES,
>  	CR_FD_EXT_FILES,
>  	CR_FD_NS_FILES,
>  	CR_FD_INETSK,
> @@ -106,6 +105,7 @@ enum {
>  	CR_FD_INOTIFY_WD,
>  	CR_FD_FANOTIFY_MARK,
>  	CR_FD_EVENTPOLL_TFD,
> +	CR_FD_REG_FILES,
>  
>  	CR_FD_AUTOFS,
>  	CR_FD_NS,
> diff --git a/images/fdinfo.proto b/images/fdinfo.proto
> index 9c67bab..6d62926 100644
> --- a/images/fdinfo.proto
> +++ b/images/fdinfo.proto
> @@ -1,5 +1,7 @@
>  syntax = "proto2";
>  
> +import "regfile.proto";
> +
>  enum fd_types {
>  	UND		= 0;
>  	REG		= 1;
> @@ -34,4 +36,5 @@ message fdinfo_entry {
>  message file_entry {
>  	required fd_types		type	= 1;
>  	required uint32			id	= 2;
> +	optional reg_file_entry		reg	= 3;
>  }
> -- 
> 2.1.4
> 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list