qemu-file: Make qemu_fflush() return errors

This let us simplify code of this shape.

   qemu_fflush(f);
   int ret = qemu_file_get_error(f);
   if (ret) {
      return ret;
   }

into:

   int ret = qemu_fflush(f);
   if (ret) {
      return ret;
   }

I updated all callers where there is any error check.
qemu_fclose() don't need to check for f->last_error because
qemu_fflush() returns it at the beggining of the function.

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Signed-off-by: Juan Quintela <quintela@redhat.com>

Message-ID: <20231025091117.6342-13-quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
This commit is contained in:
Juan Quintela 2023-10-25 11:11:17 +02:00
parent 0f8596180a
commit be07a0ed22
7 changed files with 21 additions and 51 deletions

View file

@ -262,14 +262,14 @@ static void qemu_iovec_release_ram(QEMUFile *f)
* This will flush all pending data. If data was only partially flushed, it
* will set an error state.
*/
void qemu_fflush(QEMUFile *f)
int qemu_fflush(QEMUFile *f)
{
if (!qemu_file_is_writable(f)) {
return;
return f->last_error;
}
if (qemu_file_get_error(f)) {
return;
if (f->last_error) {
return f->last_error;
}
if (f->iovcnt > 0) {
Error *local_error = NULL;
@ -287,6 +287,7 @@ void qemu_fflush(QEMUFile *f)
f->buf_index = 0;
f->iovcnt = 0;
return f->last_error;
}
/*
@ -353,22 +354,12 @@ static ssize_t coroutine_mixed_fn qemu_fill_buffer(QEMUFile *f)
*/
int qemu_fclose(QEMUFile *f)
{
int ret, ret2;
qemu_fflush(f);
ret = qemu_file_get_error(f);
ret2 = qio_channel_close(f->ioc, NULL);
int ret = qemu_fflush(f);
int ret2 = qio_channel_close(f->ioc, NULL);
if (ret >= 0) {
ret = ret2;
}
g_clear_pointer(&f->ioc, object_unref);
/* If any error was spotted before closing, we should report it
* instead of the close() return value.
*/
if (f->last_error) {
ret = f->last_error;
}
error_free(f->last_error_obj);
g_free(f);
trace_qemu_file_fclose();