[CRIU] Re: [PATCH 2/2] fifo: Add checkpoint/restore for fifos

Pavel Emelyanov xemul at parallels.com
Wed May 30 04:35:09 EDT 2012


> +void show_fifo(int fd, struct cr_options *o)
> +{
> +	struct fifo_file_entry e;
> +	int ret;
> +
> +	pr_img_head(CR_FD_FIFO);
> +
> +	while (1) {
> +		ret = read_img_eof(fd, &e);
> +		if (ret <= 0)
> +			goto out;
> +		pr_msg("id: 0x%8x id: 0x%8x flags: 0x%8x ",
> +		       e.id, e.id, e.flags);
> +		show_fown_cont(&e.fown);
> +
> +		if (e.len) {
> +			int ret = read(fd, local_buf, e.len);
> +
> +			if (ret != e.len) {
> +				pr_perror("Can't read %d bytes", e.len);
> +				goto out;
> +			}
> +			local_buf[e.len] = 0;
> +			pr_msg(" --> %s", local_buf);
> +		}
> +		pr_msg("\n");
> +	}

This one should call the pipe shower.

> +
> +out:
> +	pr_img_tail(CR_FD_FIFO);
> +}

> +static int fifo_open(struct file_desc *d)
> +{
> +	struct fifo_file_info *info;
> +	int tmp;
> +
> +	info = container_of(d, struct fifo_file_info, d);
> +
> +	tmp = open(info->path, info->ffe.flags);

This will hang if the opener is not O_RDWR.

> +	if (tmp < 0) {
> +		pr_perror("Can't open fifo %#08x [%s]",
> +			  info->ffe.id, info->path);
> +		return -1;
> +	}
> +
> +	lseek(tmp, info->ffe.pos, SEEK_SET);
> +
> +	if (rst_file_params(tmp, &info->ffe.fown, info->ffe.flags)) {
> +		pr_perror("Can't restore params on fifo %#08x",
> +			  info->ffe.id);
> +		goto err_close;
> +	}
> +
> +	return tmp;
> +
> +err_close:
> +	close(tmp);
> +	return -1;
> +}

> +static int dump_one_fifo(int lfd, u32 id, const struct fd_parms *p)
> +{
> +	struct fifo_file_entry e;
> +	char fd_str[128];
> +	int len, fd;
> +
> +	snprintf(fd_str, sizeof(fd_str), "/proc/self/fd/%d", lfd);
> +	len = readlink(fd_str, pathbuf, sizeof(pathbuf) - 1);
> +	if (len < 0) {
> +		pr_perror("Can't readlink %s", fd_str);
> +		return len;
> +	}
> +
> +	pathbuf[len] = '\0';
> +	pr_info("Dumping path for fifo %d fd via self %d [%s]\n",
> +		p->fd, lfd, pathbuf);
> +	pr_info("Dumping fifo %d with id %#x\n", lfd, id);
> +
> +	e.id	= id;
> +	e.flags	= p->flags;
> +	e.len	= len;
> +	e.pos	= p->pos;
> +	e.fown	= p->fown;
> +
> +	fd = fdset_fd(glob_fdset, CR_FD_FIFO);
> +	if (write_img(fd, &e))
> +		return -1;
> +	if (write_img_buf(fd, pathbuf, len))
> +		return -1;

It should call the regfile dumping code, since it's the same.
And it should call the pipe dumping code for fifo's contents.

> +	return 0;
> +}


More information about the CRIU mailing list