提交 eff28a5c 编写于 作者: J Juan Quintela

buffered_file: reuse QEMUFile has_error field

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: NJuan Quintela <quintela@redhat.com>
Reviewed-by: NAnthony Liguori <aliguori@us.ibm.com>
上级 db448a08
...@@ -27,7 +27,6 @@ typedef struct QEMUFileBuffered ...@@ -27,7 +27,6 @@ typedef struct QEMUFileBuffered
BufferedCloseFunc *close; BufferedCloseFunc *close;
void *opaque; void *opaque;
QEMUFile *file; QEMUFile *file;
int has_error;
int freeze_output; int freeze_output;
size_t bytes_xfer; size_t bytes_xfer;
size_t xfer_limit; size_t xfer_limit;
...@@ -73,7 +72,7 @@ static void buffered_flush(QEMUFileBuffered *s) ...@@ -73,7 +72,7 @@ static void buffered_flush(QEMUFileBuffered *s)
{ {
size_t offset = 0; size_t offset = 0;
if (s->has_error) { if (qemu_file_has_error(s->file)) {
DPRINTF("flush when error, bailing\n"); DPRINTF("flush when error, bailing\n");
return; return;
} }
...@@ -93,7 +92,7 @@ static void buffered_flush(QEMUFileBuffered *s) ...@@ -93,7 +92,7 @@ static void buffered_flush(QEMUFileBuffered *s)
if (ret <= 0) { if (ret <= 0) {
DPRINTF("error flushing data, %zd\n", ret); DPRINTF("error flushing data, %zd\n", ret);
s->has_error = 1; qemu_file_set_error(s->file);
break; break;
} else { } else {
DPRINTF("flushed %zd byte(s)\n", ret); DPRINTF("flushed %zd byte(s)\n", ret);
...@@ -114,7 +113,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in ...@@ -114,7 +113,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); 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"); DPRINTF("flush when error, bailing\n");
return -EINVAL; return -EINVAL;
} }
...@@ -139,7 +138,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in ...@@ -139,7 +138,7 @@ static int buffered_put_buffer(void *opaque, const uint8_t *buf, int64_t pos, in
if (ret <= 0) { if (ret <= 0) {
DPRINTF("error putting\n"); DPRINTF("error putting\n");
s->has_error = 1; qemu_file_set_error(s->file);
offset = -EINVAL; offset = -EINVAL;
break; break;
} }
...@@ -173,7 +172,7 @@ static int buffered_close(void *opaque) ...@@ -173,7 +172,7 @@ static int buffered_close(void *opaque)
DPRINTF("closing\n"); DPRINTF("closing\n");
while (!s->has_error && s->buffer_size) { while (!qemu_file_has_error(s->file) && s->buffer_size) {
buffered_flush(s); buffered_flush(s);
if (s->freeze_output) if (s->freeze_output)
s->wait_for_unfreeze(s->opaque); s->wait_for_unfreeze(s->opaque);
...@@ -199,7 +198,7 @@ static int buffered_rate_limit(void *opaque) ...@@ -199,7 +198,7 @@ static int buffered_rate_limit(void *opaque)
{ {
QEMUFileBuffered *s = opaque; QEMUFileBuffered *s = opaque;
if (s->has_error) { if (qemu_file_has_error(s->file)) {
return -1; return -1;
} }
if (s->freeze_output) if (s->freeze_output)
...@@ -214,7 +213,7 @@ static int buffered_rate_limit(void *opaque) ...@@ -214,7 +213,7 @@ static int buffered_rate_limit(void *opaque)
static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate) static int64_t buffered_set_rate_limit(void *opaque, int64_t new_rate)
{ {
QEMUFileBuffered *s = opaque; QEMUFileBuffered *s = opaque;
if (s->has_error) if (qemu_file_has_error(s->file))
goto out; goto out;
if (new_rate > SIZE_MAX) { if (new_rate > SIZE_MAX) {
...@@ -238,7 +237,7 @@ static void buffered_rate_tick(void *opaque) ...@@ -238,7 +237,7 @@ static void buffered_rate_tick(void *opaque)
{ {
QEMUFileBuffered *s = opaque; QEMUFileBuffered *s = opaque;
if (s->has_error) { if (qemu_file_has_error(s->file)) {
buffered_close(s); buffered_close(s);
return; return;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册