All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <dgilbert@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org,
	Stefan Hajnoczi <stefanha@redhat.com>,
	Hailiang Zhang <zhang.zhanghailiang@huawei.com>,
	Juan Quintela <quintela@redhat.com>, Fam Zheng <fam@euphon.net>
Subject: Re: [PATCH 06/20] migration: rename qemu_ftell to qemu_file_total_transferred
Date: Thu, 9 Jun 2022 11:23:59 +0100	[thread overview]
Message-ID: <YqHKP8gSqIU/2tEn@work-vm> (raw)
In-Reply-To: <20220524110235.145079-7-berrange@redhat.com>

* Daniel P. Berrangé (berrange@redhat.com) wrote:
> The name 'ftell' gives the misleading impression that the QEMUFile
> objects are seekable. This is not the case, as in general we just
> have an opaque stream. The users of this method are only interested
> in the total bytes processed. This switches to a new name that
> reflects the intended usage.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>

Mostly,

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>

Two nits below:

> ---
>  migration/block.c     | 10 +++++-----
>  migration/migration.c |  2 +-
>  migration/qemu-file.c |  4 ++--
>  migration/qemu-file.h | 40 ++++++++++++++++++++++++++++++++++++++--
>  migration/savevm.c    |  6 +++---
>  migration/vmstate.c   |  4 ++--
>  6 files changed, 51 insertions(+), 15 deletions(-)
> 
> diff --git a/migration/block.c b/migration/block.c
> index 077a413325..823453c977 100644
> --- a/migration/block.c
> +++ b/migration/block.c
> @@ -756,8 +756,8 @@ static int block_save_setup(QEMUFile *f, void *opaque)
>  static int block_save_iterate(QEMUFile *f, void *opaque)
>  {
>      int ret;
> -    int64_t last_ftell = qemu_ftell(f);
> -    int64_t delta_ftell;
> +    int64_t last_bytes = qemu_file_total_transferred(f);
> +    int64_t delta_bytes;
>  
>      trace_migration_block_save("iterate", block_mig_state.submitted,
>                                 block_mig_state.transferred);
> @@ -809,10 +809,10 @@ static int block_save_iterate(QEMUFile *f, void *opaque)
>      }
>  
>      qemu_put_be64(f, BLK_MIG_FLAG_EOS);
> -    delta_ftell = qemu_ftell(f) - last_ftell;
> -    if (delta_ftell > 0) {
> +    delta_bytes = qemu_file_total_transferred(f) - last_bytes;
> +    if (delta_bytes > 0) {
>          return 1;
> -    } else if (delta_ftell < 0) {
> +    } else if (delta_bytes < 0) {
>          return -1;
>      } else {
>          return 0;
> diff --git a/migration/migration.c b/migration/migration.c
> index 31739b2af9..ab1e9610ef 100644
> --- a/migration/migration.c
> +++ b/migration/migration.c
> @@ -3544,7 +3544,7 @@ static MigThrError migration_detect_error(MigrationState *s)
>  /* How many bytes have we transferred since the beginning of the migration */
>  static uint64_t migration_total_bytes(MigrationState *s)
>  {
> -    return qemu_ftell(s->to_dst_file) + ram_counters.multifd_bytes;
> +    return qemu_file_total_transferred(s->to_dst_file) + ram_counters.multifd_bytes;

I think that's hit line length limits.

>  }
>  
>  static void migration_calculate_complete(MigrationState *s)
> diff --git a/migration/qemu-file.c b/migration/qemu-file.c
> index b21da4c5bf..664ac77067 100644
> --- a/migration/qemu-file.c
> +++ b/migration/qemu-file.c
> @@ -657,7 +657,7 @@ int qemu_get_byte(QEMUFile *f)
>      return result;
>  }
>  
> -int64_t qemu_ftell_fast(QEMUFile *f)
> +int64_t qemu_file_total_transferred_fast(QEMUFile *f)
>  {
>      int64_t ret = f->total_transferred;
>      int i;
> @@ -669,7 +669,7 @@ int64_t qemu_ftell_fast(QEMUFile *f)
>      return ret;
>  }
>  
> -int64_t qemu_ftell(QEMUFile *f)
> +int64_t qemu_file_total_transferred(QEMUFile *f)
>  {
>      qemu_fflush(f);
>      return f->total_transferred;
> diff --git a/migration/qemu-file.h b/migration/qemu-file.h
> index 3f36d4dc8c..febc961aa9 100644
> --- a/migration/qemu-file.h
> +++ b/migration/qemu-file.h
> @@ -124,8 +124,44 @@ QEMUFile *qemu_fopen_ops(void *opaque, const QEMUFileOps *ops, bool has_ioc);
>  void qemu_file_set_hooks(QEMUFile *f, const QEMUFileHooks *hooks);
>  int qemu_get_fd(QEMUFile *f);
>  int qemu_fclose(QEMUFile *f);
> -int64_t qemu_ftell(QEMUFile *f);
> -int64_t qemu_ftell_fast(QEMUFile *f);
> +
> +/*
> + * qemu_file_total_transferred:
> + *
> + * Report the total number of bytes transferred with 
> + * this file.
> + *
> + * For writable files, any pending buffers will be
> + * flushed, so the reported value will be equal to
> + * the number of bytes transferred on the wire.
> + *
> + * For readable files, the reported value will be
> + * equal to the number of bytes transferred on the
> + * wire.
> + *
> + * Returns: the total bytes transferred
> + */
> +int64_t qemu_file_total_transferred(QEMUFile *f);
> +
> +/*
> + * qemu_file_total_transferred_fast:
> + *
> + * Report the total number of bytes transferred with 
> + * this file.
> + *
> + * For writable files, no pending buffers will be
> + * flushed, but the reported value will include the
> + * size of any queued buffers, on top of the amount
> + * actually transferred.
> + *
> + * For readable files, the reported value will be
> + * equal to the number of bytes transferred on the
> + * wire.
> + *
> + * Returns: the total bytes transferred and queued

I think this would be clearer if it just said:
 * qemu_file_total_transferred_fast:
   As qemu_file_total_transferred except for writable
   files, where no flush is performed and the reported
   amount will include the size of any queued buffers,
   on top of the amount actually transferred.

Otherwise you're left eyeballing the two to try and spot
the difference.

Dave

> + */
> +int64_t qemu_file_total_transferred_fast(QEMUFile *f);
> +
>  /*
>   * put_buffer without copying the buffer.
>   * The buffer should be available till it is sent asynchronously.
> diff --git a/migration/savevm.c b/migration/savevm.c
> index d9076897b8..75d05f1a84 100644
> --- a/migration/savevm.c
> +++ b/migration/savevm.c
> @@ -916,9 +916,9 @@ static void vmstate_save_old_style(QEMUFile *f, SaveStateEntry *se,
>  {
>      int64_t old_offset, size;
>  
> -    old_offset = qemu_ftell_fast(f);
> +    old_offset = qemu_file_total_transferred_fast(f);
>      se->ops->save_state(f, se->opaque);
> -    size = qemu_ftell_fast(f) - old_offset;
> +    size = qemu_file_total_transferred_fast(f) - old_offset;
>  
>      if (vmdesc) {
>          json_writer_int64(vmdesc, "size", size);
> @@ -2887,7 +2887,7 @@ bool save_snapshot(const char *name, bool overwrite, const char *vmstate,
>          goto the_end;
>      }
>      ret = qemu_savevm_state(f, errp);
> -    vm_state_size = qemu_ftell(f);
> +    vm_state_size = qemu_file_total_transferred(f);
>      ret2 = qemu_fclose(f);
>      if (ret < 0) {
>          goto the_end;
> diff --git a/migration/vmstate.c b/migration/vmstate.c
> index 36ae8b9e19..b0551e82c6 100644
> --- a/migration/vmstate.c
> +++ b/migration/vmstate.c
> @@ -360,7 +360,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
>                  void *curr_elem = first_elem + size * i;
>  
>                  vmsd_desc_field_start(vmsd, vmdesc_loop, field, i, n_elems);
> -                old_offset = qemu_ftell_fast(f);
> +                old_offset = qemu_file_total_transferred_fast(f);
>                  if (field->flags & VMS_ARRAY_OF_POINTER) {
>                      assert(curr_elem);
>                      curr_elem = *(void **)curr_elem;
> @@ -390,7 +390,7 @@ int vmstate_save_state_v(QEMUFile *f, const VMStateDescription *vmsd,
>                      return ret;
>                  }
>  
> -                written_bytes = qemu_ftell_fast(f) - old_offset;
> +                written_bytes = qemu_file_total_transferred_fast(f) - old_offset;
>                  vmsd_desc_field_end(vmsd, vmdesc_loop, field, written_bytes, i);
>  
>                  /* Compressed arrays only care about the first element */
> -- 
> 2.36.1
> 
-- 
Dr. David Alan Gilbert / dgilbert@redhat.com / Manchester, UK



  reply	other threads:[~2022-06-09 12:39 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-24 11:02 [PATCH 00/20] migration: remove QEMUFileOps concept and assume use of QIOChannel Daniel P. Berrangé
2022-05-24 11:02 ` [PATCH 01/20] io: add a QIOChannelNull equivalent to /dev/null Daniel P. Berrangé
2022-05-24 21:14   ` Eric Blake
2022-06-16 16:26     ` Daniel P. Berrangé
2022-05-24 11:02 ` [PATCH 02/20] migration: switch to use QIOChannelNull for dummy channel Daniel P. Berrangé
2022-05-24 21:15   ` Eric Blake
2022-05-24 11:02 ` [PATCH 03/20] migration: remove unreachble RDMA code in save_hook impl Daniel P. Berrangé
2022-05-25 12:29   ` Eric Blake
2022-06-08 17:59   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 04/20] migration: rename rate limiting fields in QEMUFile Daniel P. Berrangé
2022-06-09  9:29   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 05/20] migration: rename 'pos' field in QEMUFile to 'bytes_processed' Daniel P. Berrangé
2022-06-09  9:51   ` Dr. David Alan Gilbert
2022-06-09  9:57     ` Daniel P. Berrangé
2022-06-09  9:59       ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 06/20] migration: rename qemu_ftell to qemu_file_total_transferred Daniel P. Berrangé
2022-06-09 10:23   ` Dr. David Alan Gilbert [this message]
2022-05-24 11:02 ` [PATCH 07/20] migration: rename qemu_update_position to qemu_file_credit_transfer Daniel P. Berrangé
2022-06-09 10:29   ` Dr. David Alan Gilbert
2022-06-09 12:56   ` Peter Maydell
2022-06-09 13:02     ` Daniel P. Berrangé
2022-06-09 13:15       ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 08/20] migration: introduce a QIOChannel impl for BlockDriverState VMState Daniel P. Berrangé
2022-05-24 11:02 ` [PATCH 09/20] migration: convert savevm to use QIOChannelBlock for VMState Daniel P. Berrangé
2022-06-09 14:57   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 10/20] migration: stop passing 'opaque' parameter to QEMUFile hooks Daniel P. Berrangé
2022-06-09 15:00   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 11/20] migration: hardcode assumption that QEMUFile is backed with QIOChannel Daniel P. Berrangé
2022-06-09 15:01   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 12/20] migration: introduce new constructors for QEMUFile Daniel P. Berrangé
2022-06-09 15:33   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 13/20] migration: remove unused QEMUFileGetFD typedef Daniel P. Berrangé
2022-06-09 16:03   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 14/20] migration: remove the QEMUFileOps 'shut_down' callback Daniel P. Berrangé
2022-06-09 16:12   ` Dr. David Alan Gilbert
2022-06-09 16:14     ` Daniel P. Berrangé
2022-06-09 16:17       ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 15/20] migration: remove the QEMUFileOps 'set_blocking' callback Daniel P. Berrangé
2022-06-09 16:21   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 16/20] migration: remove the QEMUFileOps 'close' callback Daniel P. Berrangé
2022-06-09 16:40   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 17/20] migration: remove the QEMUFileOps 'get_buffer' callback Daniel P. Berrangé
2022-06-09 16:46   ` Dr. David Alan Gilbert
2022-06-09 17:09     ` Daniel P. Berrangé
2022-05-24 11:02 ` [PATCH 18/20] migration: remove the QEMUFileOps 'writev_buffer' callback Daniel P. Berrangé
2022-06-09 16:51   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 19/20] migration: remove the QEMUFileOps 'get_return_path' callback Daniel P. Berrangé
2022-06-09 16:54   ` Dr. David Alan Gilbert
2022-05-24 11:02 ` [PATCH 20/20] migration: remove the QEMUFileOps abstraction Daniel P. Berrangé
2022-06-09 16:59   ` Dr. David Alan Gilbert
2022-06-09 17:10     ` Daniel P. Berrangé

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YqHKP8gSqIU/2tEn@work-vm \
    --to=dgilbert@redhat.com \
    --cc=berrange@redhat.com \
    --cc=fam@euphon.net \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=quintela@redhat.com \
    --cc=stefanha@redhat.com \
    --cc=zhang.zhanghailiang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.