[CRIU] [PATCH 2/2] fsnotify: Do not track deleted watchees

Andrew Vagin avagin at parallels.com
Tue Feb 25 01:28:40 PST 2014


On Tue, Feb 25, 2014 at 12:21:06PM +0400, Cyrill Gorcunov wrote:
> 
> If the watchee is deleted we might be able to
> open in by file handle at checkpoint time but
> fail on restore. And since we don't have any kernel's
> interface to fetch and restore fsnotify event queue
> simply ignore such watchees.
> 
> Once fsnotify queue c/r implemented need to revisit
> this place.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  fsnotify.c | 38 ++++++++++++++++++++++++++++++++++----
>  1 file changed, 34 insertions(+), 4 deletions(-)
> 

> diff --git a/fsnotify.c b/fsnotify.c
> index 476fb2620bd0..eb635da39157 100644
> --- a/fsnotify.c
> +++ b/fsnotify.c
> @@ -132,9 +132,31 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino,
>  
>  	fd = open_handle(s_dev, i_ino, f_handle);
>  	if (fd >= 0) {
> +		struct stat st;

FYI: This hack doesn't work for tmpfs
mount -t tmpfs test test/
git checkout test/
bash -x test/zdtm.sh -r static/inotify00
+ cat /root/crtools/test/dump/inotify00/2779/1/dump.log
+ grep Error
(00.000260) Error (image.c:197): Unable to open irmap-cache: No such file or directory
(00.009159) Error (fsnotify.c:123): fsnotify: Can't open file handle for 0x00000023:0x00000000000048d5: Stale file handle


> +
> +		/*
> +		 * WARNING
> +		 *
> +		 * The file might be accessible via dentry
> +		 * cache but still deleted, which means we
> +		 * might be fail on restore procedure. Thus
> +		 * check for number of links. If the file
> +		 * is deleted then we should simply ignore
> +		 * it.
> +		 *
> +		 * FIXME Once the kernel will be updated
> +		 * and c/r for fsnotify queue is implemented
> +		 * need to fix this place as well.
> +		 */
> +		if (fstat(fd, &st) < 0) {
> +			pr_perror("Can't stat fd %d", fd);
> +			close(fd);
> +			return -1;
> +		}
>  		close(fd);
> -		pr_debug("\tHandle %x:%lx is openable\n", s_dev, i_ino);
> -		return 0;
> +		pr_debug("\tHandle %x:%lx is openable (st_nlink %lu)\n",
> +			 s_dev, i_ino, st.st_nlink);
> +		return st.st_nlink > 0 ? 0 : 1;
>  	}
>  
>  	pr_warn("\tHandle %x:%lx cannot be opened\n", s_dev, i_ino);
> @@ -152,6 +174,7 @@ int check_open_handle(unsigned int s_dev, unsigned long i_ino,
>  static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
>  {
>  	InotifyWdEntry *we = &e->ify;
> +	int ret;
>  
>  	we->id = *(u32 *)arg;
>  	pr_info("wd: wd 0x%08x s_dev 0x%08x i_ino 0x%16"PRIx64" mask 0x%08x\n",
> @@ -160,8 +183,11 @@ static int dump_inotify_entry(union fdinfo_entries *e, void *arg)
>  			we->f_handle->bytes, we->f_handle->type,
>  			we->f_handle->handle[0], we->f_handle->handle[1]);
>  
> -	if (check_open_handle(we->s_dev, we->i_ino, we->f_handle))
> +	ret = check_open_handle(we->s_dev, we->i_ino, we->f_handle);
> +	if (ret < 0)
>  		return -1;
> +	else if (ret == 1)
> +		return 0;
>  
>  	return pb_write_one(fdset_fd(glob_fdset, CR_FD_INOTIFY_WD), we, PB_INOTIFY_WD);
>  }
> @@ -206,6 +232,7 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
>  	fme->id = fsn_params->id;
>  
>  	if (fme->type == MARK_TYPE__INODE) {
> +		int ret;
>  
>  		BUG_ON(!fme->ie);
>  
> @@ -216,8 +243,11 @@ static int dump_fanotify_entry(union fdinfo_entries *e, void *arg)
>  			fme->ie->f_handle->bytes, fme->ie->f_handle->type,
>  			fme->ie->f_handle->handle[0], fme->ie->f_handle->handle[1]);
>  
> -		if (check_open_handle(fme->s_dev, fme->ie->i_ino, fme->ie->f_handle))
> +		ret = check_open_handle(fme->s_dev, fme->ie->i_ino, fme->ie->f_handle);
> +		if (ret < 0)
>  			return -1;
> +		else if (ret == 1)
> +			return 0;
>  	}
>  
>  	if (fme->type == MARK_TYPE__MOUNT) {



More information about the CRIU mailing list