qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v11 08/10] migration: Implement MigrateChannelList to qmp mig


From: Fabiano Rosas
Subject: Re: [PATCH v11 08/10] migration: Implement MigrateChannelList to qmp migration flow.
Date: Mon, 09 Oct 2023 11:29:21 -0300

Het Gala <het.gala@nutanix.com> writes:

> On 10/4/2023 8:51 PM, Fabiano Rosas wrote:
>> Het Gala<het.gala@nutanix.com>  writes:
>>
>>> Integrate MigrateChannelList with all transport backends
>>> (socket, exec and rdma) for both src and dest migration
>>> endpoints for qmp migration.
>>>
>>> For current series, limit the size of MigrateChannelList
>>> to single element (single interface) as runtime check.
>>>
>>> Suggested-by: Aravind Retnakaran<aravind.retnakaran@nutanix.com>
>>> Signed-off-by: Het Gala<het.gala@nutanix.com>
>>> Reviewed-by: Daniel P. Berrangé<berrange@redhat.com>
>>> ---
>>>   migration/migration.c | 95 +++++++++++++++++++++++--------------------
>>>   1 file changed, 52 insertions(+), 43 deletions(-)
>>>
>>> diff --git a/migration/migration.c b/migration/migration.c
>>> index 6f948988ec..3eae32e616 100644
>>> --- a/migration/migration.c
>>> +++ b/migration/migration.c
>>> @@ -432,9 +432,10 @@ void migrate_add_address(SocketAddress *address)
>>>   }
>>>   
>>>   static bool migrate_uri_parse(const char *uri,
>>> -                              MigrationAddress **channel,
>>> +                              MigrationChannel **channel,
>>>                                 Error **errp)
>>>   {
>>> +    g_autoptr(MigrationChannel) val = g_new0(MigrationChannel, 1);
>> Here val is passed out of scope so it shouldn't be g_autoptr.
> I guess, same as for 'addr' we need to go with adding 
> g_steal_pointer(&val) here too ?

Yes, you cannot give the same pointer to *channel because this one is
already being tracked by g_autoptr and it will free the memory when it
gets the chance. So we need to steal it from g_autoptr, so to speak.

>>>       g_autoptr(MigrationAddress) addr = g_new0(MigrationAddress, 1);
>>>       SocketAddress *saddr = &addr->u.socket;
>>>       InetSocketAddress *isock = &addr->u.rdma;
>>> @@ -471,7 +472,9 @@ static bool migrate_uri_parse(const char *uri,
>>>           return false;
>>>       }
>>>   
>>> -    *channel = addr;
>>> +    val->channel_type = MIGRATION_CHANNEL_TYPE_MAIN;
>>> +    val->addr = addr;
>>> +    *channel = val;
>>>       return true;
>>>   }
>>>   
>>> @@ -479,41 +482,44 @@ static void qemu_start_incoming_migration(const char 
>>> *uri, bool has_channels,
>>>                                             MigrationChannelList *channels,
>>>                                             Error **errp)
>>>   {
>>> -    g_autoptr(MigrationAddress) channel = g_new0(MigrationAddress, 1);
>>> +    g_autoptr(MigrationChannel) channel = g_new0(MigrationChannel, 1);
>>> +    g_autoptr(MigrationAddress) addr = g_new0(MigrationAddress, 1);
>> Here we want just the pointer, no allocation, no freeing. For both
>> channel and addr.
> Ack, same as channel in patch 2.

This is actually one of the cases where we need to think about how we
are going to free that memory. You need to make sure no one is using the
'addr' after you call into the *_incoming_migration functions. All users
should either use the value and return or make a copy if they intend to
pass it forward. If you determine that no one is using 'addr' and
'channel', then we could bring the channel g_autoptr back.

>>>   
>>>       /*
>>>        * Having preliminary checks for uri and channel
>>>        */
>>> -    if (has_channels) {
>>> -        error_setg(errp, "'channels' argument should not be set yet.");
>>> -        return;
>>> -    }
>>> -
>>>       if (uri && has_channels) {
>>>           error_setg(errp, "'uri' and 'channels' arguments are mutually "
>>>                      "exclusive; exactly one of the two should be present 
>>> in "
>>>                      "'migrate-incoming' qmp command ");
>>>           return;
>>> -    }
>>> -
>>> -    if (!uri && !has_channels) {
>>> +    } else if (channels) {
>>> +        /* To verify that Migrate channel list has only item */
>>> +        if (channels->next) {
>>> +            error_setg(errp, "Channel list has more than one entries");
>>> +            return;
>>> +        }
>>> +        channel = channels->value;
>>> +    } else if (uri) {
>>> +        /* caller uses the old URI syntax */
>>> +        if (!migrate_uri_parse(uri, &channel, errp)) {
>>> +            return;
>>> +        }
>>> +    } else {
>>>           error_setg(errp, "neither 'uri' or 'channels' argument are "
>>>                      "specified in 'migrate-incoming' qmp command ");
>>>           return;
>>>       }
>>> -
>>> -    if (uri && !migrate_uri_parse(uri, &channel, errp)) {
>>> -        return;
>>> -    }
>>> +    addr = channel->addr;
>>>   
>>>       /* transport mechanism not suitable for migration? */
>>> -    if (!migration_channels_and_transport_compatible(channel, errp)) {
>>> +    if (!migration_channels_and_transport_compatible(addr, errp)) {
>>>           return;
>>>       }
>>>   
>>>       qapi_event_send_migration(MIGRATION_STATUS_SETUP);
>>> -    if (channel->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {
>>> -        SocketAddress *saddr = &channel->u.socket;
>>> +    if (addr->transport == MIGRATION_ADDRESS_TYPE_SOCKET) {
>>> +        SocketAddress *saddr = &addr->u.socket;
>>>           if (saddr->type == SOCKET_ADDRESS_TYPE_INET ||
>>>               saddr->type == SOCKET_ADDRESS_TYPE_UNIX ||
>>>               saddr->type == SOCKET_ADDRESS_TYPE_VSOCK) {
>>> @@ -522,11 +528,11 @@ static void qemu_start_incoming_migration(const char 
>>> *uri, bool has_channels,
>>>               fd_start_incoming_migration(saddr->u.fd.str, errp);
>>>           }
>>>   #ifdef CONFIG_RDMA
>>> -    } else if (channel->transport == MIGRATION_ADDRESS_TYPE_RDMA) {
>>> -        rdma_start_incoming_migration(&channel->u.rdma, errp);
>>> -#endif
>>> -    } else if (channel->transport == MIGRATION_ADDRESS_TYPE_EXEC) {
>>> -        exec_start_incoming_migration(channel->u.exec.args, errp);
>>> +    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_RDMA) {
>>> +        rdma_start_incoming_migration(&addr->u.rdma, errp);
>>> + #endif
>>> +    } else if (addr->transport == MIGRATION_ADDRESS_TYPE_EXEC) {
>>> +        exec_start_incoming_migration(addr->u.exec.args, errp);
>>>       } else {
>>>           error_setg(errp, "unknown migration protocol: %s", uri);
>>>       }
>>> @@ -1750,35 +1756,38 @@ void qmp_migrate(const char *uri, bool has_channels,
>>>       bool resume_requested;
>>>       Error *local_err = NULL;
>>>       MigrationState *s = migrate_get_current();
>>> -    g_autoptr(MigrationAddress) channel = g_new0(MigrationAddress, 1);
>>> +    g_autoptr(MigrationChannel) channel = g_new0(MigrationChannel, 1);
>>> +    g_autoptr(MigrationAddress) addr = g_new0(MigrationAddress, 1);
>> Again just the pointers.
>>
>> We'll have to make another pass and check whether we're missing freeing
>> something. But for now let's first clear all the errors then we can look
>> at the code working and do the necessary changes.
> Ack.
>>>   
>>>       /*
>>>        * Having preliminary checks for uri and channel
>>>        */
>>> -    if (has_channels) {
>>> -        error_setg(errp, "'channels' argument should not be set yet.");
>>> -        return;
>>> -    }
>>>    
> Regards,
> Het Gala



reply via email to

[Prev in Thread] Current Thread [Next in Thread]