From patchwork Fri Sep 21 08:47:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Juan Quintela X-Patchwork-Id: 185668 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 D0B3C2C0086 for ; Fri, 21 Sep 2012 20:12:32 +1000 (EST) Received: from localhost ([::1]:32860 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF0Dm-0002uo-Qj for incoming@patchwork.ozlabs.org; Fri, 21 Sep 2012 06:12:30 -0400 Received: from eggs.gnu.org ([208.118.235.92]:45038) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEyuT-0008DA-HG for qemu-devel@nongnu.org; Fri, 21 Sep 2012 04:48:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TEyuN-0004tL-Ma for qemu-devel@nongnu.org; Fri, 21 Sep 2012 04:48:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:25402) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TEyuN-0004tA-Du for qemu-devel@nongnu.org; Fri, 21 Sep 2012 04:48:23 -0400 Received: from int-mx02.intmail.prod.int.phx2.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8L8mMuY012424 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 21 Sep 2012 04:48:22 -0400 Received: from trasno.mitica (ovpn-116-55.ams2.redhat.com [10.36.116.55]) by int-mx02.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id q8L8lZNh001998; Fri, 21 Sep 2012 04:48:21 -0400 From: Juan Quintela To: qemu-devel@nongnu.org Date: Fri, 21 Sep 2012 10:47:28 +0200 Message-Id: <1348217255-22441-35-git-send-email-quintela@redhat.com> In-Reply-To: <1348217255-22441-1-git-send-email-quintela@redhat.com> References: <1348217255-22441-1-git-send-email-quintela@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.12 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH 34/41] savevm: Only qemu_fflush() can generate errors 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 Move the error check to the beggining of the callers. Once this is fixed qemu_file_set_if_error() is not used anymore, so remove it. Signed-off-by: Juan Quintela Reviewed-by: Paolo Bonzini --- savevm.c | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/savevm.c b/savevm.c index 4e4aa3c..59ec8bf 100644 --- a/savevm.c +++ b/savevm.c @@ -445,18 +445,6 @@ void qemu_file_set_error(QEMUFile *f, int ret) f->last_error = ret; } -/** Sets last_error conditionally - * - * Sets last_error only if ret is negative _and_ no error - * was set before. - */ -static void qemu_file_set_if_error(QEMUFile *f, int ret) -{ - if (ret < 0 && !f->last_error) { - qemu_file_set_error(f, ret); - } -} - /** Flushes QEMUFile buffer * */ @@ -544,13 +532,17 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) { int l; - if (!f->last_error && f->is_write == 0 && f->buf_index > 0) { + if (f->last_error) { + return; + } + + if (f->is_write == 0 && f->buf_index > 0) { fprintf(stderr, "Attempted to write to buffer while read buffer is not empty\n"); abort(); } - while (!f->last_error && size > 0) { + while (size > 0) { l = IO_BUF_SIZE - f->buf_index; if (l > size) l = size; @@ -561,14 +553,21 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) size -= l; if (f->buf_index >= IO_BUF_SIZE) { int ret = qemu_fflush(f); - qemu_file_set_if_error(f, ret); + if (ret < 0) { + qemu_file_set_error(f, ret); + break; + } } } } void qemu_put_byte(QEMUFile *f, int v) { - if (!f->last_error && f->is_write == 0 && f->buf_index > 0) { + if (f->last_error) { + return; + } + + if (f->is_write == 0 && f->buf_index > 0) { fprintf(stderr, "Attempted to write to buffer while read buffer is not empty\n"); abort(); @@ -578,7 +577,9 @@ void qemu_put_byte(QEMUFile *f, int v) f->is_write = 1; if (f->buf_index >= IO_BUF_SIZE) { int ret = qemu_fflush(f); - qemu_file_set_if_error(f, ret); + if (ret < 0) { + qemu_file_set_error(f, ret); + } } }