[CRIU] Re: [PATCH 4/8] restore: socket queues support

Pavel Emelyanov xemul at parallels.com
Tue Feb 28 06:40:04 EST 2012


> +static int read_sockets_queues(int fd, struct list_head *packets_list)
> +{
> +	struct sk_packet *pkt;
> +	int ret;
> +
> +	pr_info("Trying to read socket queue\n");
> +
> +	lseek(fd, MAGIC_OFFSET, SEEK_SET);
> +	while (1) {
> +		struct sk_packet_entry tmp;
> +		struct sk_packet_entry *entry;
> +
> +		ret = read_img_eof(fd, &tmp);
> +		if (ret <= 0)
> +			goto out;
> +
> +		pkt = xmalloc(sizeof(*pkt) + tmp.length);

That's bad idea. Socket queues can be VERY big. Better to collect in memory
small structures with file offsets where the data lies. And then use splice
to read the bits from file to socket buffer ;)

> +		if (!pkt) {
> +			pr_info("Failed to allocate packet header\n");
> +			return -ENOMEM;
> +		}
> +		entry = &pkt->entry;
> +		memcpy(entry, &tmp, sizeof(tmp));
> +
> +		ret = read_img_buf(fd, entry->data, entry->length);
> +		if (ret < 0)
> +			break;
> +		/*
> +		 * NOTE: packet must be added to the tail. Otherwise sequence
> +		 * will be broken.
> +		 */
> +		list_add_tail(&pkt->list, packets_list);
> +	}
> +	xfree(pkt);
> +out:
> +	return ret;
> +
> +}


More information about the CRIU mailing list