[CRIU] [PATCH 2/2] fsnotify: merge inotify wd image into inotify image

Pavel Emelyanov xemul at parallels.com
Wed Aug 20 03:48:34 PDT 2014


On 08/20/2014 02:31 PM, Andrey Vagin wrote:
> All watch descriptors are collected in a list and then
> they are written in inotify image as a repeated field.
> 
> This images merge reduces the amount of image files criu
> generates and may simplify the fix of mentioned above issue.
> 
> Signed-off-by: Andrey Vagin <avagin at openvz.org>
> ---
>  fsnotify.c              | 75 ++++++++++++++++++++++++++++++++++++++++---------
>  include/image-desc.h    |  2 +-
>  protobuf/fsnotify.proto |  1 +
>  3 files changed, 63 insertions(+), 15 deletions(-)
> 
> diff --git a/fsnotify.c b/fsnotify.c
> index 2b18b3f..29845c2 100644
> --- a/fsnotify.c
> +++ b/fsnotify.c
> @@ -197,11 +197,17 @@ err:
>  	return -1;
>  }
>  
> +struct inotify_wd_list {
> +	struct list_head list;
> +	int n;
> +};
> +
>  static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
>  {
> -	InotifyWdEntry *we = &e->ify.e;
> +	struct inotify_wd_list *wd_list = (struct inotify_wd_list *) arg;
> +	struct inotify_wd_entry *wd_entry = (struct inotify_wd_entry *) e;;
> +	InotifyWdEntry *we = &wd_entry->e;
>  
> -	we->id = *(u32 *)arg;
>  	pr_info("wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16"PRIx64" mask 0x%08x\n",
>  			we->wd, we->s_dev, we->i_ino, we->mask);
>  	pr_info("\t[fhandle] bytes 0x%08x type 0x%08x __handle 0x%016"PRIx64":0x%016"PRIx64"\n",
> @@ -211,27 +217,45 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
>  	if (check_open_handle(we->s_dev, we->i_ino, we->f_handle))
>  		return -1;
>  
> -	if (pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we, PB_INOTIFY_WD))
> -		return -1;
> -
> -	free_inotify_wd_entry(e);
> +	list_add(&wd_entry->node, &wd_list->list);
> +	wd_list->n++;
>  
>  	return 0;
>  }
>  
>  static int dump_one_inotify(int lfd, u32 id, const struct fd_parms *p)
>  {
> +	struct inotify_wd_list wd_list = {LIST_HEAD_INIT(wd_list.list), 0};
>  	InotifyFileEntry ie = INOTIFY_FILE_ENTRY__INIT;
> +	struct inotify_wd_entry *we, *tmp;
> +	int exit_code = -1, i;
>  
>  	ie.id = id;
>  	ie.flags = p->flags;
>  	ie.fown = (FownEntry *)&p->fown;
>  
> +	if (parse_fdinfo(lfd, FD_TYPES__INOTIFY, dump_inotify_entry, &wd_list))
> +		goto free;
> +
> +	ie.wd_entry = xmalloc(sizeof(struct InotifyWdEntry *) * wd_list.n);
> +	if (!ie.wd_entry)
> +		goto free;
> +
> +	i = 0;
> +	list_for_each_entry(we, &wd_list.list, node)
> +		ie.wd_entry[i++] = &we->e;
> +	ie.n_wd_entry = wd_list.n;
> +
>  	pr_info("id 0x%08x flags 0x%08x\n", ie.id, ie.flags);
>  	if (pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY_FILE), &ie, PB_INOTIFY_FILE))
> -		return -1;
> +		goto free;
> +
> +	exit_code = 0;
> +free:
> +	list_for_each_entry_safe(we, tmp, &wd_list.list, node)
> +		xfree(we);

Shouldn't free_inotify_wd_entry() be here?

>  
> -	return parse_fdinfo(lfd, FD_TYPES__INOTIFY, dump_inotify_entry, &id);
> +	return exit_code;
>  }
>  
>  static int pre_dump_inotify_entry(union fdinfo_entries *e, void *arg)
> @@ -594,15 +618,10 @@ static struct fsnotify_file_info *find_inotify_info(unsigned id)
>  	return NULL;
>  }
>  
> -static int collect_inotify_mark(struct fsnotify_mark_info *mark)
> +static int __collect_inotify_mark(struct fsnotify_file_info *p, struct fsnotify_mark_info *mark)
>  {
> -	struct fsnotify_file_info *p;
>  	struct fsnotify_mark_info *m;
>  
> -	p = find_inotify_info(mark->iwe->id);
> -	if (!p)
> -		return -1;
> -
>  	/*
>  	 * We should put marks in wd ascending order. See comment
>  	 * in restore_one_inotify() for explanation.
> @@ -616,6 +635,17 @@ static int collect_inotify_mark(struct fsnotify_mark_info *mark)
>  	return 0;
>  }
>  
> +static int collect_inotify_mark(struct fsnotify_mark_info *mark)
> +{
> +	struct fsnotify_file_info *p;
> +
> +	p = find_inotify_info(mark->iwe->id);
> +	if (!p)
> +		return -1;
> +
> +	return __collect_inotify_mark(p, mark);
> +}
> +
>  static int collect_fanotify_mark(struct fsnotify_mark_info *mark)
>  {
>  	struct fsnotify_file_info *p;
> @@ -637,11 +667,28 @@ static int collect_fanotify_mark(struct fsnotify_mark_info *mark)
>  static int collect_one_inotify(void *o, ProtobufCMessage *msg)
>  {
>  	struct fsnotify_file_info *info = o;
> +	int i;
>  
>  	info->ife = pb_msg(msg, InotifyFileEntry);
>  	INIT_LIST_HEAD(&info->marks);
>  	list_add(&info->list, &inotify_info_head);
>  	pr_info("Collected id 0x%08x flags 0x%08x\n", info->ife->id, info->ife->flags);
> +
> +	for (i = 0; i < info->ife->n_wd_entry; i++) {
> +		struct fsnotify_mark_info *mark;
> +
> +		mark = xmalloc(sizeof(*mark));
> +		if (!mark)
> +			return -1;
> +
> +		mark->iwe = info->ife->wd_entry[i];
> +		INIT_LIST_HEAD(&mark->list);
> +		mark->remap = NULL;
> +
> +		if (__collect_inotify_mark(info, mark))
> +			return -1;
> +	}
> +
>  	return file_desc_add(&info->d, info->ife->id, &inotify_desc_ops);
>  }
>  
> diff --git a/include/image-desc.h b/include/image-desc.h
> index ab592a1..75e851c 100644
> --- a/include/image-desc.h
> +++ b/include/image-desc.h
> @@ -68,7 +68,6 @@ enum {
>  	CR_FD_EVENTPOLL_TFD,
>  	CR_FD_SIGNALFD,
>  	CR_FD_INOTIFY_FILE,
> -	CR_FD_INOTIFY_WD,
>  	CR_FD_FANOTIFY_FILE,
>  	CR_FD_FANOTIFY_MARK,
>  	CR_FD_TUNFILE,
> @@ -93,6 +92,7 @@ enum {
>  
>  	CR_FD_SIGNAL,
>  	CR_FD_PSIGNAL,
> +	CR_FD_INOTIFY_WD,
>  
>  	CR_FD_MAX
>  };
> diff --git a/protobuf/fsnotify.proto b/protobuf/fsnotify.proto
> index 073fa79..60200b9 100644
> --- a/protobuf/fsnotify.proto
> +++ b/protobuf/fsnotify.proto
> @@ -15,6 +15,7 @@ message inotify_file_entry {
>  	required uint32		id		= 1;
>  	required uint32		flags		= 2;
>  	required fown_entry	fown		= 4;
> +	repeated inotify_wd_entry wd_entry	= 5;
>  }
>  
>  enum mark_type {
> 



More information about the CRIU mailing list