[CRIU] [PATCH 12/17] proc_parse: Add parsing of fanotify entries

Pavel Emelyanov xemul at parallels.com
Mon Dec 24 08:28:04 EST 2012


On 12/11/2012 01:34 AM, Cyrill Gorcunov wrote:
> 
> Since fanotify entries do need more than one @id
> passed across the calls we define struct fsnotify_params
> which will hold @id and flags needed for fanotify entries.
> 
> Other than that -- we incorporate fanotify/inotify in one
> parsing if() statement since they look similar in format
> scanned from procfs.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  fsnotify.c         | 10 ++++--
>  include/fsnotify.h |  6 ++++
>  proc_parse.c       | 96 +++++++++++++++++++++++++++++++++++++++++++-----------
>  3 files changed, 91 insertions(+), 21 deletions(-)
> 


> @@ -890,37 +891,94 @@ int parse_fdinfo(int fd, int type,
>  			entry_met = true;
>  			continue;
>  		}
> -		if (fdinfo_field(str, "inotify wd")) {
> +		if (fdinfo_field(str, "fanotify flags")) {
> +			struct fsnotify_params *p = arg;
> +
> +			if (type != FD_TYPES__FSNOTIFY)
> +				goto parse_err;
> +
> +			ret = sscanf(str, "fanotify flags:%x event-flags:%x",
> +				     &p->flags, &p->eflags);
> +			if (ret != 2)
> +				goto parse_err;
> +			entry_met = true;
> +			continue;
> +		}
> +		if (fdinfo_field(str, "inotify wd")	||
> +		    fdinfo_field(str, "fanotify ino")	||
> +		    fdinfo_field(str, "fanotify mnt_id")) {
>  			FhEntry f_handle = FH_ENTRY__INIT;
> +			struct fsnotify_params *p = arg;
>  			int hoff;
>  
>  			fsnotify_wd_entry__init(&entry.fsy);
>  			entry.fsy.f_handle = &f_handle;
>  			entry.fsy.has_type = true;
> -			entry.fsy.type = FSNOTIFY_TYPE__INOTIFY;
>  
>  			if (type != FD_TYPES__FSNOTIFY)
>  				goto parse_err;
> -			ret = sscanf(str,
> -					"inotify wd:%x ino:%lx sdev:%x "
> -					"mask:%x ignored_mask:%x "
> -					"fhandle-bytes:%x fhandle-type:%x "
> -					"f_handle: %n",
> -					&entry.fsy.wd, &entry.fsy.i_ino, &entry.fsy.s_dev,
> -					&entry.fsy.mask, &entry.fsy.ignored_mask,
> -					&entry.fsy.f_handle->bytes, &entry.fsy.f_handle->type,
> -					&hoff);
> -			if (ret != 7)
> -				goto parse_err;
>  
> -			f_handle.n_handle = FH_ENTRY_SIZES__min_entries;
> -			f_handle.handle = xmalloc(pb_repeated_size(&f_handle, handle));
> -			if (!f_handle.handle)
> -				return -1;
> +			entry.fsy.has_type = true;
> +			switch (str[9]) {
> +			case 'd':
> +			case 'i':
> +				if (str[9] == 'd') {
> +					entry.fsy.type = FSNOTIFY_TYPE__INOTIFY;
> +					ret = sscanf(&str[11],
> +						     "%x ino:%lx sdev:%x "
> +						     "mask:%x ignored_mask:%x "
> +						     "fhandle-bytes:%x fhandle-type:%x "
> +						     "f_handle: %n",
> +						     &entry.fsy.wd, &entry.fsy.i_ino, &entry.fsy.s_dev,
> +						     &entry.fsy.mask, &entry.fsy.ignored_mask,
> +						     &entry.fsy.f_handle->bytes, &entry.fsy.f_handle->type,
> +						     &hoff);
> +					if (ret != 7)
> +						goto parse_err;
> +					hoff += 11;
> +				} else {
> +					entry.fsy.type = FSNOTIFY_TYPE__FANOTIFY;
> +					ret = sscanf(&str[13],
> +						     "%lx sdev:%x "
> +						     "mflags:%x mask:%x ignored_mask:%x "
> +						     "fhandle-bytes:%x fhandle-type:%x "
> +						     "f_handle: %n",
> +						     &entry.fsy.i_ino, &entry.fsy.s_dev,
> +						     &entry.fsy.wd, &entry.fsy.mask, &entry.fsy.ignored_mask,
> +						     &entry.fsy.f_handle->bytes, &entry.fsy.f_handle->type,
> +						     &hoff);
> +					if (ret != 7)
> +						goto parse_err;
> +					hoff += 13;
> +				}
>  
> -			parse_fhandle_encoded(str + hoff, entry.fsy.f_handle);
> +				f_handle.n_handle = FH_ENTRY_SIZES__min_entries;
> +				f_handle.handle = xmalloc(pb_repeated_size(&f_handle, handle));
> +				if (!f_handle.handle)
> +					return -1;
>  
> -			ret = cb(&entry, arg);
> +				parse_fhandle_encoded(str + hoff, entry.fsy.f_handle);
> +				break;
> +			case 'm':
> +				/*
> +				 * In real it's not @s_dev parsed here but
> +				 * @mnt_id. Thus the caller must be ready
> +				 * for that and handle this trick accordingly.
> +				 */
> +				entry.fsy.type = FSNOTIFY_TYPE__FANOTIFY;
> +				ret = sscanf(&str[16],
> +					     "%x mflags:%x mask:%x ignored_mask:%x",
> +					     &entry.fsy.s_dev, &entry.fsy.wd,
> +					     &entry.fsy.mask, &entry.fsy.ignored_mask);
> +				if (ret != 4)
> +					goto parse_err;
> +				break;
> +			default:
> +				BUG();
> +				break;
> +			}
> +
> +			ret = cb(&entry, p);
>  
>  			xfree(f_handle.handle);
>  

Why adding _new_ stuff to parse results in rewriting the _existing_ stuff parsing?


More information about the CRIU mailing list