mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-05 08:43:55 -06:00
migration/multifd: Add an explicit MultiFDSendData destructor
This way if there are fields there that needs explicit disposal (like, for example, some attached buffers) they will be handled appropriately. Add a related assert to multifd_set_payload_type() in order to make sure that this function is only used to fill a previously empty MultiFDSendData with some payload, not the other way around. Reviewed-by: Fabiano Rosas <farosas@suse.de> Reviewed-by: Peter Xu <peterx@redhat.com> Signed-off-by: Maciej S. Szmigiero <maciej.szmigiero@oracle.com> Link: https://lore.kernel.org/qemu-devel/6755205f2b95abbed251f87061feee1c0e410836.1741124640.git.maciej.szmigiero@oracle.com Signed-off-by: Cédric Le Goater <clg@redhat.com>
This commit is contained in:
parent
d19cc4dca0
commit
7ecfab1ddd
3 changed files with 34 additions and 5 deletions
|
@ -42,8 +42,7 @@ void multifd_ram_save_setup(void)
|
|||
|
||||
void multifd_ram_save_cleanup(void)
|
||||
{
|
||||
g_free(multifd_ram_send);
|
||||
multifd_ram_send = NULL;
|
||||
g_clear_pointer(&multifd_ram_send, multifd_send_data_free);
|
||||
}
|
||||
|
||||
static void multifd_set_file_bitmap(MultiFDSendParams *p)
|
||||
|
|
|
@ -123,6 +123,32 @@ MultiFDSendData *multifd_send_data_alloc(void)
|
|||
return g_malloc0(size_minus_payload + max_payload_size);
|
||||
}
|
||||
|
||||
void multifd_send_data_clear(MultiFDSendData *data)
|
||||
{
|
||||
if (multifd_payload_empty(data)) {
|
||||
return;
|
||||
}
|
||||
|
||||
switch (data->type) {
|
||||
default:
|
||||
/* Nothing to do */
|
||||
break;
|
||||
}
|
||||
|
||||
data->type = MULTIFD_PAYLOAD_NONE;
|
||||
}
|
||||
|
||||
void multifd_send_data_free(MultiFDSendData *data)
|
||||
{
|
||||
if (!data) {
|
||||
return;
|
||||
}
|
||||
|
||||
multifd_send_data_clear(data);
|
||||
|
||||
g_free(data);
|
||||
}
|
||||
|
||||
static bool multifd_use_packets(void)
|
||||
{
|
||||
return !migrate_mapped_ram();
|
||||
|
@ -496,8 +522,7 @@ static bool multifd_send_cleanup_channel(MultiFDSendParams *p, Error **errp)
|
|||
qemu_sem_destroy(&p->sem_sync);
|
||||
g_free(p->name);
|
||||
p->name = NULL;
|
||||
g_free(p->data);
|
||||
p->data = NULL;
|
||||
g_clear_pointer(&p->data, multifd_send_data_free);
|
||||
p->packet_len = 0;
|
||||
g_free(p->packet);
|
||||
p->packet = NULL;
|
||||
|
@ -695,7 +720,7 @@ static void *multifd_send_thread(void *opaque)
|
|||
(uint64_t)p->next_packet_size + p->packet_len);
|
||||
|
||||
p->next_packet_size = 0;
|
||||
multifd_set_payload_type(p->data, MULTIFD_PAYLOAD_NONE);
|
||||
multifd_send_data_clear(p->data);
|
||||
|
||||
/*
|
||||
* Making sure p->data is published before saying "we're
|
||||
|
|
|
@ -149,6 +149,9 @@ static inline bool multifd_payload_empty(MultiFDSendData *data)
|
|||
static inline void multifd_set_payload_type(MultiFDSendData *data,
|
||||
MultiFDPayloadType type)
|
||||
{
|
||||
assert(multifd_payload_empty(data));
|
||||
assert(type != MULTIFD_PAYLOAD_NONE);
|
||||
|
||||
data->type = type;
|
||||
}
|
||||
|
||||
|
@ -365,6 +368,8 @@ static inline void multifd_send_prepare_header(MultiFDSendParams *p)
|
|||
void multifd_channel_connect(MultiFDSendParams *p, QIOChannel *ioc);
|
||||
bool multifd_send(MultiFDSendData **send_data);
|
||||
MultiFDSendData *multifd_send_data_alloc(void);
|
||||
void multifd_send_data_clear(MultiFDSendData *data);
|
||||
void multifd_send_data_free(MultiFDSendData *data);
|
||||
|
||||
static inline uint32_t multifd_ram_page_size(void)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue