From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:56163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF2d5-0004QX-8d for qemu-devel@nongnu.org; Fri, 21 Sep 2012 08:46:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1TF2cv-0002Aj-LV for qemu-devel@nongnu.org; Fri, 21 Sep 2012 08:46:47 -0400 Received: from mail-pb0-f45.google.com ([209.85.160.45]:55255) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TF2cv-0002AO-El for qemu-devel@nongnu.org; Fri, 21 Sep 2012 08:46:37 -0400 Received: by pbbrp12 with SMTP id rp12so7607898pbb.4 for ; Fri, 21 Sep 2012 05:46:36 -0700 (PDT) Sender: Paolo Bonzini Message-ID: <505C61A7.3020907@redhat.com> Date: Fri, 21 Sep 2012 14:46:31 +0200 From: Paolo Bonzini MIME-Version: 1.0 References: <1348217255-22441-1-git-send-email-quintela@redhat.com> <1348217255-22441-31-git-send-email-quintela@redhat.com> In-Reply-To: <1348217255-22441-31-git-send-email-quintela@redhat.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 30/41] savevm: make qemu_fflush() return an error code List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Juan Quintela Cc: qemu-devel@nongnu.org Il 21/09/2012 10:47, Juan Quintela ha scritto: > Adjust all the callers. We moved the set of last_error from inside > qemu_fflush() to all the callers. > > Signed-off-by: Juan Quintela > --- > savevm.c | 39 +++++++++++++++++++++++---------------- > 1 file changed, 23 insertions(+), 16 deletions(-) > > diff --git a/savevm.c b/savevm.c > index 6865862..0953695 100644 > --- a/savevm.c > +++ b/savevm.c > @@ -459,23 +459,22 @@ static void qemu_file_set_if_error(QEMUFile *f, int ret) > > /** Flushes QEMUFile buffer > * > - * In case of error, last_error is set. > */ > -static void qemu_fflush(QEMUFile *f) > +static int qemu_fflush(QEMUFile *f) > { > + int ret = 0; > + > if (!f->put_buffer) > - return; > + return 0; > > if (f->is_write && f->buf_index > 0) { > - int len; > - > - len = f->put_buffer(f->opaque, f->buf, f->buf_offset, f->buf_index); > - if (len > 0) > + ret = f->put_buffer(f->opaque, f->buf, f->buf_offset, f->buf_index); > + if (ret >= 0) { > f->buf_offset += f->buf_index; > - else > - qemu_file_set_error(f, -EINVAL); > + } > f->buf_index = 0; > } > + return ret; > } > > static void qemu_fill_buffer(QEMUFile *f) > @@ -533,9 +532,13 @@ static int qemu_fclose_internal(QEMUFile *f) > */ > int qemu_fclose(QEMUFile *f) > { > - int ret; > - qemu_fflush(f); > - ret = qemu_fclose_internal(f); > + int ret, ret2; > + ret = qemu_fflush(f); > + ret2 = qemu_fclose_internal(f); > + > + if (ret >= 0) { > + ret = ret2; > + } > /* If any error was spotted before closing, we should report it > * instead of the close() return value. > */ > @@ -570,8 +573,10 @@ void qemu_put_buffer(QEMUFile *f, const uint8_t *buf, int size) > f->buf_index += l; > buf += l; > size -= l; > - if (f->buf_index >= IO_BUF_SIZE) > - qemu_fflush(f); > + if (f->buf_index >= IO_BUF_SIZE) { > + int ret = qemu_fflush(f); > + qemu_file_set_if_error(f, ret); > + } > } > } > > @@ -585,8 +590,10 @@ void qemu_put_byte(QEMUFile *f, int v) > > f->buf[f->buf_index++] = v; > f->is_write = 1; > - if (f->buf_index >= IO_BUF_SIZE) > - qemu_fflush(f); > + if (f->buf_index >= IO_BUF_SIZE) { > + int ret = qemu_fflush(f); > + qemu_file_set_if_error(f, ret); > + } > } > > static void qemu_file_skip(QEMUFile *f, int size) > Reviewed-by: Paolo Bonzini