Commit cb88aa88 authored by Orit Wasserman's avatar Orit Wasserman Committed by Juan Quintela
Browse files

Use writev ops if available



Update qemu_fflush and stdio_close to use writev ops if they are available
Use the buffers stored in the iovec.
Signed-off-by: default avatarOrit Wasserman <owasserm@redhat.com>
Reviewed-by: default avatarJuan Quintela <quintela@redhat.com>
Signed-off-by: default avatarJuan Quintela <quintela@redhat.com>
parent b3ea2bdb
......@@ -293,7 +293,7 @@ static int stdio_fclose(void *opaque)
QEMUFileStdio *s = opaque;
int ret = 0;
if (s->file->ops->put_buffer) {
if (s->file->ops->put_buffer || s->file->ops->writev_buffer) {
int fd = fileno(s->stdio_file);
struct stat st;
......@@ -516,20 +516,35 @@ static void qemu_file_set_error(QEMUFile *f, int ret)
}
}
/** Flushes QEMUFile buffer
/**
* Flushes QEMUFile buffer
*
* If there is writev_buffer QEMUFileOps it uses it otherwise uses
* put_buffer ops.
*/
static void qemu_fflush(QEMUFile *f)
{
int ret = 0;
ssize_t ret = 0;
int i = 0;
if (!f->ops->put_buffer) {
if (!f->ops->writev_buffer && !f->ops->put_buffer) {
return;
}
if (f->is_write && f->buf_index > 0) {
ret = f->ops->put_buffer(f->opaque, f->buf, f->pos, f->buf_index);
if (ret >= 0) {
f->pos += f->buf_index;
if (f->is_write && f->iovcnt > 0) {
if (f->ops->writev_buffer) {
ret = f->ops->writev_buffer(f->opaque, f->iov, f->iovcnt);
if (ret >= 0) {
f->pos += ret;
}
} else {
for (i = 0; i < f->iovcnt && ret >= 0; i++) {
ret = f->ops->put_buffer(f->opaque, f->iov[i].iov_base, f->pos,
f->iov[i].iov_len);
if (ret >= 0) {
f->pos += ret;
}
}
}
f->buf_index = 0;
f->iovcnt = 0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment