Skip to content

Commit

Permalink
migration: rename qemu_ftell to qemu_file_total_transferred
Browse files Browse the repository at this point in the history
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.

Reviewed-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
   dgilbert: Wrapped long line
  • Loading branch information
berrange authored and dagrh committed Jun 22, 2022
1 parent 154d87b commit fbfa640
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
10 changes: 5 additions & 5 deletions migration/block.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion migration/migration.c
Original file line number Diff line number Diff line change
Expand Up @@ -3539,7 +3539,8 @@ 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;
}

static void migration_calculate_complete(MigrationState *s)
Expand Down
4 changes: 2 additions & 2 deletions migration/qemu-file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
33 changes: 31 additions & 2 deletions migration/qemu-file.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,37 @@ 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:
*
* 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.
*
* Returns: the total bytes transferred and queued
*/
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.
Expand Down
6 changes: 3 additions & 3 deletions migration/savevm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions migration/vmstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -390,7 +390,8 @@ 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 */
Expand Down

0 comments on commit fbfa640

Please sign in to comment.