From 912d2adb51b84174c679bed189f5a9f92fc2eabe Mon Sep 17 00:00:00 2001 From: Juan Quintela Date: Wed, 19 Oct 2011 23:47:43 +0200 Subject: [PATCH 08/19] buffered_file: reuse QEMUFile has_error field RH-Author: Juan Quintela Message-id: <46189c0da4ee763fc068602108d351d11f7022c0.1319066771.git.quintela@redhat.com> Patchwork-id: 34433 O-Subject: [PATCH qemu-kvm RHEL-6.2 08/16] buffered_file: reuse QEMUFile has_error field Bugzilla: 669581 RH-Acked-by: Amit Shah RH-Acked-by: Markus Armbruster RH-Acked-by: Orit Wasserman Instead of having two has_error fields in QEMUFile & QEMUBufferedFile, reuse the 1st one. Notice that the one in buffered_file is only set after a file operation. Signed-off-by: Juan Quintela Reviewed-by: Anthony Liguori Conflicts: buffered_file.c Missing SIZE_MAX check --- buffered_file.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-) Signed-off-by: Michal Novotny --- buffered_file.c | 17 ++++++++--------- 1 files changed, 8 insertions(+), 9 deletions(-) diff --git a/buffered_file.c b/buffered_file.c index d62bc37..fab9a41 100644 --- a/buffered_file.c +++ b/buffered_file.c @@ -28,7 +28,6 @@ typedef struct QEMUFileBuffered BufferedCloseFunc *close; void *opaque; QEMUFile *file; - int has_error; int freeze_output; size_t bytes_xfer; size_t xfer_limit; @@ -74,7 +73,7 @@ static void buffered_flush(QEMUFileBuffered *s) { size_t offset = 0; - if (s->has_error) { + if (qemu_file_has_error(s->file)) { DPRINTF("flush when error, bailing\n"); return; } @@ -94,7 +93,7 @@ static void buffered_flush(QEMUFileBuffered *s) if (ret <= 0) { DPRINTF("error flushing data, %zd\n", ret); - s->has_error = 1; + qemu_file_set_error(s->file); break; } else { DPRINTF("flushed %zd byte(s)\n", ret); @@ -115,7 +114,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in DPRINTF("putting %d bytes at %" PRId64 "\n", size, pos); - if (s->has_error) { + if (qemu_file_has_error(s->file)) { DPRINTF("flush when error, bailing\n"); return -EINVAL; } @@ -140,7 +139,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in if (ret <= 0) { DPRINTF("error putting\n"); - s->has_error = 1; + qemu_file_set_error(s->file); offset = -EINVAL; break; } @@ -174,7 +173,7 @@ static int buffered_close(void *opaque) DPRINTF("closing\n"); - while (!s->has_error && s->buffer_size) { + while (!qemu_file_has_error(s->file) && s->buffer_size) { buffered_flush(s); if (s->freeze_output) s->wait_for_unfreeze(s->opaque); @@ -200,7 +199,7 @@ static int buffered_rate_limit(void *opaque) { QEMUFileBuffered *s = opaque; - if (s->has_error) { + if (qemu_file_has_error(s->file)) { return -1; } if (s->freeze_output) @@ -216,7 +215,7 @@ static size_t buffered_set_rate_limit(void *opaque, size_t new_rate) { QEMUFileBuffered *s = opaque; - if (s->has_error) + if (qemu_file_has_error(s->file)) goto out; s->xfer_limit = new_rate / 10; @@ -236,7 +235,7 @@ static void buffered_rate_tick(void *opaque) { QEMUFileBuffered *s = opaque; - if (s->has_error) { + if (qemu_file_has_error(s->file)) { buffered_close(s); return; } -- 1.7.4.4