Vladimir Sementsov-Ogievskiy <[email protected]> writes:

> Make it symmetrical with qemu_file_put_fd() and simplify callers.
>
> Signed-off-by: Vladimir Sementsov-Ogievskiy <[email protected]>
> ---
>  migration/qemu-file.c     |  9 ++++-----
>  migration/qemu-file.h     |  2 +-
>  migration/vmstate-types.c | 10 +---------
>  3 files changed, 6 insertions(+), 15 deletions(-)
>
> diff --git a/migration/qemu-file.c b/migration/qemu-file.c
> index da701d40e4..f8394cbbb5 100644
> --- a/migration/qemu-file.c
> +++ b/migration/qemu-file.c
> @@ -385,9 +385,8 @@ int qemu_file_put_fd(QEMUFile *f, int fd)
>      return ret;
>  }
>  
> -int qemu_file_get_fd(QEMUFile *f)
> +int qemu_file_get_fd(QEMUFile *f, int *fd)
>  {
> -    int fd = -1;
>      FdEntry *fde;
>      Error *err = NULL;
>      int service_byte;
> @@ -410,12 +409,12 @@ int qemu_file_get_fd(QEMUFile *f)
>          goto fail;
>      }
>  
> -    fd = fde->fd;
> +    *fd = fde->fd;
>      QTAILQ_REMOVE(&f->fds, fde, entry);
>      g_free(fde);
>  
> -    trace_qemu_file_get_fd(f->ioc->name, fd);
> -    return fd;
> +    trace_qemu_file_get_fd(f->ioc->name, *fd);
> +    return 0;
>  
>  fail:
>      error_report_err(error_copy(err));
> diff --git a/migration/qemu-file.h b/migration/qemu-file.h
> index c13c967167..a8e9bb2ccb 100644
> --- a/migration/qemu-file.h
> +++ b/migration/qemu-file.h
> @@ -82,6 +82,6 @@ size_t qemu_get_buffer_at(QEMUFile *f, const uint8_t *buf, 
> size_t buflen,
>  
>  QIOChannel *qemu_file_get_ioc(QEMUFile *file);
>  int qemu_file_put_fd(QEMUFile *f, int fd);
> -int qemu_file_get_fd(QEMUFile *f);
> +int qemu_file_get_fd(QEMUFile *f, int *fd);
>  
>  #endif
> diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c
> index e34bf4486e..89cb211472 100644
> --- a/migration/vmstate-types.c
> +++ b/migration/vmstate-types.c
> @@ -321,7 +321,6 @@ const VMStateInfo vmstate_info_uint64 = {
>  static int get_fd(QEMUFile *f, void *pv, size_t size,
>                    const VMStateField *field)
>  {
> -    int fd;
>      int32_t *v = pv;
>  
>      if (migrate_mode() == MIG_MODE_CPR_EXEC) {
> @@ -329,14 +328,7 @@ static int get_fd(QEMUFile *f, void *pv, size_t size,
>          return 0;
>      }
>  
> -    fd = qemu_file_get_fd(f);
> -    if (fd < 0) {
> -        return -1;
> -    }
> -
> -    *v = fd;
> -
> -    return 0;
> +    return qemu_file_get_fd(f, v);
>  }
>  
>  static int put_fd(QEMUFile *f, void *pv, size_t size,

Reviewed-by: Fabiano Rosas <[email protected]>

Reply via email to