From patchwork Thu Mar 21 18:34:35 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Orit Wasserman X-Patchwork-Id: 229803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 3B9AA2C00CC for ; Fri, 22 Mar 2013 05:35:57 +1100 (EST) Received: from localhost ([::1]:46854 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIkLD-0008Gd-0L for incoming@patchwork.ozlabs.org; Thu, 21 Mar 2013 14:35:55 -0400 Received: from eggs.gnu.org ([208.118.235.92]:38982) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIkJ4-0005O6-UG for qemu-devel@nongnu.org; Thu, 21 Mar 2013 14:33:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1UIkJ3-0003HJ-4n for qemu-devel@nongnu.org; Thu, 21 Mar 2013 14:33:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:14168) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1UIkJ2-0003Gt-Qr for qemu-devel@nongnu.org; Thu, 21 Mar 2013 14:33:41 -0400 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id r2LIXdxe001571 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 21 Mar 2013 14:33:39 -0400 Received: from dhcp-1-120.tlv.redhat.com (vpn-200-38.tlv.redhat.com [10.35.200.38]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id r2LIXPPT030096; Thu, 21 Mar 2013 14:33:37 -0400 From: Orit Wasserman To: qemu-devel@nongnu.org Date: Thu, 21 Mar 2013 20:34:35 +0200 Message-Id: <1363890878-8161-6-git-send-email-owasserm@redhat.com> In-Reply-To: <1363890878-8161-1-git-send-email-owasserm@redhat.com> References: <1363890878-8161-1-git-send-email-owasserm@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.25 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Orit Wasserman , pbonzini@redhat.com, mst@redhat.com, chegu_vinod@hp.com, quintela@redhat.com Subject: [Qemu-devel] [PATCH v4 5/8] Use writev ops if available X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Update qemu_fflush and stdio_close to use writev ops if they are available Use the buffers stored in the iovec. Signed-off-by: Orit Wasserman Reviewed-by: Juan Quintela --- savevm.c | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/savevm.c b/savevm.c index fb20f13..6c0cc7b 100644 --- a/savevm.c +++ b/savevm.c @@ -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,24 +516,40 @@ 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; + 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; } + if (ret < 0) { qemu_file_set_error(f, ret); }