Received: from eggs.gnu.org ([208.118.235.92]:37165) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ0kA-00071i-J0 for qemu-devel@nongnu.org; Tue, 02 Oct 2012 07:34:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TJ0k3-00085F-LZ for qemu-devel@nongnu.org; Tue, 02 Oct 2012 07:34:30 -0400 Received: from mx1.redhat.com ([209.132.183.28]:49201) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TJ0k3-000845-C7 for qemu-devel@nongnu.org; Tue, 02 Oct 2012 07:34:23 -0400 Received: from int-mx01.intmail.prod.int.phx2.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q92BYM6p019802 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 2 Oct 2012 07:34:22 -0400 From: Juan Quintela Date: Tue, 2 Oct 2012 13:33:29 +0200 Message-Id: <1349177616-5341-35-git-send-email-quintela@redhat.com> In-Reply-To: <1349177616-5341-1-git-send-email-quintela@redhat.com> References: <1349177616-5341-1-git-send-email-quintela@redhat.com> Subject: [Qemu-devel] [PATCH 34/41] savevm: Only qemu_fflush() can generate errors List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@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); + } } } -- 1.7.11.4