[CRIU] Re: [PATCH 3/4] inotify: Add checkpoint/restore

Pavel Emelyanov xemul at parallels.com
Wed Apr 11 14:43:27 EDT 2012


> +	/*
> +	 * We could bind watchdog to self-fd directly but thi
> +	 * changes the number of file descriptors and self-test
> +	 * for amount of file descriptors dumped and restored
> +	 * fails otherwise.
> +	 */

I don't understand this. If we do

fd = open_by_handle_at();

and then

sprintf(path, "/proc/sef/fd/%d", fd);
inotify_add_watch(ifd, path);

what goes wrong? Doesn't the inotify pick up the desired
inode into its watchlist? What does it do then? Fail? Or
starts watching the /proc inode?

> +	snprintf(path, sizeof(path), "/proc/self/fd/%d", wd);
> +	ret = readlink(path, link, sizeof(link));
> +	close(wd);
> +	close(mntfd);
> +
> +	if (ret < 1) {
> +		pr_perror("Can't read self-link for %d\n", wd);
> +		return -1;
> +	}
> +
> +	link[ret] = '\0';
> +	pr_debug("\t\tRestore watch for %s (%d)\n", link, ret);
> +
> +	/*
> +	 * FIXME The kernel allocates wd-s sequentially,
> +	 * this is suboptimal, but the kernel doesn't
> +	 * provide and API for this yet :(
> +	 */
> +	wd = 1;
> +	while (wd >= 0) {
> +		wd = inotify_add_watch(i_fd, link, fe->mask);
> +		if (wd < 0) {
> +			pr_err("Can't add watch for %d with %d\n", i_fd, fe->wd);
> +			break;
> +		} else if (wd == fe->wd) {
> +			ret = 0;
> +			break;
> +		} else if (wd > fe->wd) {
> +			pr_err("Usorted watch found for %d with %d\n", i_fd, fe->wd);
> +			break;
> +		}
> +
> +		pr_debug("\t\tWatch got %d but %d expected\n", wd, fe->wd);
> +		inotify_rm_watch(i_fd, wd);
> +	}



More information about the CRIU mailing list