mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 15:53:54 -06:00
vfio/migration: Convert bytes_transferred counter to atomic
So it can be safety accessed from multiple threads. This variable type needs to be changed to unsigned long since 32-bit host platforms lack the necessary addition atomics on 64-bit variables. Using 32-bit counters on 32-bit host platforms should not be a problem in practice since they can't realistically address more memory anyway. Reviewed-by: Cédric Le Goater <clg@redhat.com> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com> Link: https://lore.kernel.org/qemu-devel/dc391771d2d9ad0f311994f0cb9e666da564aeaf.1741124640.git.maciej.szmigiero@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
5963c219a0
commit
bd846c5d58
1 changed files with 4 additions and 4 deletions
|
@ -55,7 +55,7 @@
|
|||
*/
|
||||
#define VFIO_MIG_DEFAULT_DATA_BUFFER_SIZE (1 * MiB)
|
||||
|
||||
static int64_t bytes_transferred;
|
||||
static unsigned long bytes_transferred;
|
||||
|
||||
static const char *mig_state_to_str(enum vfio_device_mig_state state)
|
||||
{
|
||||
|
@ -391,7 +391,7 @@ static ssize_t vfio_save_block(QEMUFile *f, VFIOMigration *migration)
|
|||
qemu_put_be64(f, VFIO_MIG_FLAG_DEV_DATA_STATE);
|
||||
qemu_put_be64(f, data_size);
|
||||
qemu_put_buffer(f, migration->data_buffer, data_size);
|
||||
bytes_transferred += data_size;
|
||||
qatomic_add(&bytes_transferred, data_size);
|
||||
|
||||
trace_vfio_save_block(migration->vbasedev->name, data_size);
|
||||
|
||||
|
@ -1013,12 +1013,12 @@ static int vfio_block_migration(VFIODevice *vbasedev, Error *err, Error **errp)
|
|||
|
||||
int64_t vfio_mig_bytes_transferred(void)
|
||||
{
|
||||
return bytes_transferred;
|
||||
return MIN(qatomic_read(&bytes_transferred), INT64_MAX);
|
||||
}
|
||||
|
||||
void vfio_reset_bytes_transferred(void)
|
||||
{
|
||||
bytes_transferred = 0;
|
||||
qatomic_set(&bytes_transferred, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue