Re: [Qemu-devel] [PATCH 8/10] Introduce a buffered QEMUFile wrapper

Blue Swirl
2008-09-12T15:16:50Z

On 9/9/08, Anthony Liguori <aliguori@us.ibm.com> wrote:
> This patch introduces a buffered QEMUFile wrapper. This allows QEMUFile's to be
> rate limited. It also allows makes it easier to implement a QEMUFile that is
> asynchronous.
>
> The only real non-obvious part of the API is the "frozen" concept. If the backend
> returns EAGAIN, the QEMUFile is said to be "frozen". This means no additional
> output will be sent to the backend until the file is unfrozen. qemu_file_put_notify
> can be used to unfreeze a frozen file.
>
> A synchronous interface is also provided to wait for an unfreeze event. This is
> used during the final part of live migration when the VM is no longer running.

> +static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, int size)
> +{
> + QEMUFileBuffered *s = opaque;
> + size_t offset = 0;
> + ssize_t ret;
> +
> + if (s->has_error)
> + return -EINVAL;
> +
> + s->freeze_output = 0;
> +
> + buffered_flush(s);
> +
> + while (offset < size) {
> + if (s->bytes_xfer > s->xfer_limit)
> + break;
> +
> + ret = s->put_buffer(s->opaque, buf + offset, size - offset);
> + if (ret == -EAGAIN) {
> + s->freeze_output = 1;
> + break;
> + }
> +
> + if (ret <= 0) {
> + s->has_error = 1;
> + break;
> + }
> +
> + offset += ret;
> + s->bytes_xfer += ret;
> + }
> +
> + buffered_append(s, buf + offset, size - offset);
> +
> + return offset;
> +}

I'd change the types of the return value and parameter "size" to ssize_t.