From: Het Gala <het.gala@nutanix.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, prerna.saxena@nutanix.com,
quintela@redhat.com, dgilbert@redhat.com, pbonzini@redhat.com,
armbru@redhat.com, eblake@redhat.com, manish.mishra@nutanix.com,
aravind.retnakaran@nutanix.com
Subject: Re: [PATCH v4 2/8] migration: Converts uri parameter into 'MigrateAddress' struct
Date: Mon, 15 May 2023 17:15:35 +0530 [thread overview]
Message-ID: <5351a3e1-e2e5-9c30-431c-0ce6fff4c0c7@nutanix.com> (raw)
In-Reply-To: <ZGIFmofD8CPJVM/g@redhat.com>
Just so that, there is a wider attention, I will try to address and
discuss the comments from Daniel and Juan both here, as many of them
seems to be overlapping. I hope that is fine with the maintainers.
On 15/05/23 3:42 pm, Daniel P. Berrangé wrote:
> On Fri, May 12, 2023 at 02:32:34PM +0000, Het Gala wrote:
>> This patch introduces code that can parse 'uri' string parameter and
>> spit out 'MigrateAddress' struct. All the required migration parameters
>> are stored in the struct.
>>
>> Suggested-by: Aravind Retnakaran <aravind.retnakaran@nutanix.com>
>> Signed-off-by: Het Gala <het.gala@nutanix.com>
>> ---
>> migration/migration.c | 63 +++++++++++++++++++++++++++++++++++++++++--
>> 1 file changed, 61 insertions(+), 2 deletions(-)
>>
>> diff --git a/migration/migration.c b/migration/migration.c
>> index 0ee07802a5..a7e4e286aa 100644
>> --- a/migration/migration.c
>> +++ b/migration/migration.c
>> @@ -64,6 +64,7 @@
>> #include "yank_functions.h"
>> #include "sysemu/qtest.h"
>> #include "options.h"
>> +#include "qemu/sockets.h"
>>
>> static NotifierList migration_state_notifiers =
>> NOTIFIER_LIST_INITIALIZER(migration_state_notifiers);
>> @@ -408,13 +409,58 @@ void migrate_add_address(SocketAddress *address)
>> QAPI_CLONE(SocketAddress, address));
>> }
>>
>> +static bool migrate_uri_parse(const char *uri,
>> + MigrateAddress **channel,
>> + Error **errp)
>> +{
>> + Error *local_err = NULL;
>> + MigrateAddress *addrs = g_new0(MigrateAddress, 1);
>> + SocketAddress *saddr;
>> + InetSocketAddress *isock = &addrs->u.rdma;
>> + strList **tail = &addrs->u.exec.args;
>> +
>> + if (strstart(uri, "exec:", NULL)) {
>> + addrs->transport = MIGRATE_TRANSPORT_EXEC;
>> + QAPI_LIST_APPEND(tail, g_strdup("/bin/sh"));
>> + QAPI_LIST_APPEND(tail, g_strdup("-c"));
>> + QAPI_LIST_APPEND(tail, g_strdup(uri + strlen("exec:")));
>> + } else if (strstart(uri, "rdma:", NULL) &&
>> + !inet_parse(isock, uri + strlen("rdma:"), errp)) {
>> + addrs->transport = MIGRATE_TRANSPORT_RDMA;
> I would have this as
>
> } else if (strstart(uri, "rdma:", NULL)) {
> if (inet_parse(isock, uri + strlen("rdma:"), errp)) {
> addrs->transport = MIGRATE_TRANSPORT_RDMA;
> }
>
> as IMHO it is bad practice to have control pass to the next
> else if clause when inet_parse() fails, as we know this is
> only an RDMA addr
Ack. I will change in the next patch.
> Also you need to use '&local_err' not 'errp' in the inet_parse
> call, otherwise the later code block for cleanup won't run.
Yes, thanks for pointing it out Daniel. Will modify that.
Also, Juan is of the opinion that we could omit 'local_error' variable
and try to address and free the memory there itself. For ex:
if (saddr == NULL) {
qapi_free_MigrateAddress(addrs);
return false;
}
Or, Daniel, can I also define here the variables like you suggested down
in the patch ? or is it used in some special case or I am missing
something ?
g_autoptr(MigrateAddress) addrs = g_new0(MigrateAddress, 1);
So we would not have to worry to free MigrateAddress struct.
>> + } else if (strstart(uri, "tcp:", NULL) ||
>> + strstart(uri, "unix:", NULL) ||
>> + strstart(uri, "vsock:", NULL) ||
>> + strstart(uri, "fd:", NULL)) {
>> + addrs->transport = MIGRATE_TRANSPORT_SOCKET;
>> + saddr = socket_parse(uri, &local_err);
>> + addrs->u.socket = *saddr;
> Protect with
>
> if (saddr != NULL) {
> addrs->u.socket = *saddr;
> }
>
>> + }
>> +
>> + if (local_err) {
>> + qapi_free_MigrateAddress(addrs);
>> + qapi_free_SocketAddress(saddr);
>> + qapi_free_InetSocketAddress(isock);
>> + error_propagate(errp, local_err);
>> + return false;
>> + }
>> +
>> + *channel = addrs;
>> + return true;
>> +}
>> +
>> static void qemu_start_incoming_migration(const char *uri, Error **errp)
>> {
>> const char *p = NULL;
>> + MigrateAddress *channel = g_new0(MigrateAddress, 1);
> Avoid the later 'out:' cleanup block by using:
>
> g_autoptr(MigrateAddress) channel = g_new0(MigrateAddress, 1);
Ack. I think this also solves the doubt raised by Juan "I wish, I really
wish, that there was a way to free things on error". Am I right ?
>>
>> /* URI is not suitable for migration? */
>> if (!migration_channels_and_uri_compatible(uri, errp)) {
>> - return;
>> + goto out;
>> + }
>> +
>> + if (uri && !migrate_uri_parse(uri, &channel, errp)) {
>> + error_setg(errp, "Error parsing uri");
> This error_setg() is overwriting the error migrate_uri_parse already
> set, so just drop it.
Okay, I got the point. I thought error_setg() would add error statement
on top of errp, but I was incorrect.
Juan also made the same point I believe. I will remove error_setg() in
the next version of patchset series.
>> + goto out;
>> }
>>
>> qapi_event_send_migration(MIGRATION_STATUS_SETUP);
>> @@ -433,6 +479,9 @@ static void qemu_start_incoming_migration(const char *uri, Error **errp)
>> } else {
>> error_setg(errp, "unknown migration protocol: %s", uri);
>> }
>> +
>> +out:
>> + qapi_free_MigrateAddress(channel);
>> }
>>
>> static void process_incoming_migration_bh(void *opaque)
>> @@ -1638,10 +1687,16 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
>> Error *local_err = NULL;
>> MigrationState *s = migrate_get_current();
>> const char *p = NULL;
>> + MigrateAddress *channel = g_new0(MigrateAddress, 1);
> Here too, use g_autoptr(MigrateAddress) and drop the 'out:' block
Ack.
>>
>> /* URI is not suitable for migration? */
>> if (!migration_channels_and_uri_compatible(uri, errp)) {
>> - return;
>> + goto out;
>> + }
>> +
>> + if (!migrate_uri_parse(uri, &channel, &local_err)) {
>> + error_setg(errp, "Error parsing uri");
>> + goto out;
>> }
>>
>> if (!migrate_prepare(s, has_blk && blk, has_inc && inc,
>> @@ -1688,6 +1743,10 @@ void qmp_migrate(const char *uri, bool has_blk, bool blk,
>> error_propagate(errp, local_err);
>> return;
>> }
>> +
>> +out:
>> + qapi_free_MigrateAddress(channel);
>> + return;
>> }
>>
>> void qmp_migrate_cancel(Error **errp)
>> --
>> 2.22.3
>>
> With regards,
> Daniel
Regards,
Het Gala
next prev parent reply other threads:[~2023-05-15 11:46 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-12 14:32 [PATCH v4 0/8] migration: Modified 'migrate' and 'migrate-incoming' QAPI commands for migration Het Gala
2023-05-12 14:32 ` [PATCH v4 1/8] migration: introduced 'MigrateAddress' in QAPI for migration wire protocol Het Gala
2023-05-15 8:37 ` Juan Quintela
2023-05-15 10:06 ` Daniel P. Berrangé
2023-05-12 14:32 ` [PATCH v4 2/8] migration: Converts uri parameter into 'MigrateAddress' struct Het Gala
2023-05-15 8:43 ` Juan Quintela
2023-05-15 10:12 ` Daniel P. Berrangé
2023-05-15 11:45 ` Het Gala [this message]
2023-05-15 11:55 ` Juan Quintela
2023-05-15 12:17 ` Daniel P. Berrangé
2023-05-15 12:25 ` Juan Quintela
2023-05-12 14:32 ` [PATCH v4 3/8] migration: converts socket backend to accept MigrateAddress struct Het Gala
2023-05-15 8:55 ` Juan Quintela
2023-05-15 10:17 ` Daniel P. Berrangé
2023-05-15 14:22 ` Het Gala
2023-05-15 14:46 ` Juan Quintela
2023-05-15 15:16 ` Het Gala
2023-05-15 16:28 ` Het Gala
2023-05-15 16:42 ` Daniel P. Berrangé
2023-05-12 14:32 ` [PATCH v4 4/8] migration: converts rdma " Het Gala
2023-05-15 9:51 ` Juan Quintela
2023-05-15 10:24 ` Daniel P. Berrangé
2023-05-15 14:38 ` Het Gala
2023-05-15 14:58 ` Daniel P. Berrangé
2023-05-15 15:17 ` Het Gala
2023-05-12 14:32 ` [PATCH v4 5/8] migration: converts exec " Het Gala
2023-05-15 9:58 ` Juan Quintela
2023-05-15 10:29 ` Daniel P. Berrangé
2023-05-15 15:04 ` Het Gala
2023-05-12 14:32 ` [PATCH v4 6/8] migration: modified 'migrate' QAPI to accept 'channels' argument for migration Het Gala
2023-05-15 10:36 ` Daniel P. Berrangé
2023-05-16 5:48 ` Het Gala
2023-05-16 8:57 ` Daniel P. Berrangé
2023-05-16 10:14 ` Het Gala
2023-05-12 14:32 ` [PATCH v4 7/8] migration: modified 'migrate-incoming' " Het Gala
2023-05-15 10:01 ` Juan Quintela
2023-05-15 10:38 ` Daniel P. Berrangé
2023-05-12 14:32 ` [PATCH v4 8/8] migration: Introduced MigrateChannelList struct to migration code flow Het Gala
2023-05-15 10:04 ` Juan Quintela
2023-05-15 10:42 ` Daniel P. Berrangé
2023-05-16 17:18 ` Het Gala
2023-05-17 8:34 ` Juan Quintela
2023-05-16 10:32 ` [PATCH v4 0/8] migration: Modified 'migrate' and 'migrate-incoming' QAPI commands for migration Markus Armbruster
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=5351a3e1-e2e5-9c30-431c-0ce6fff4c0c7@nutanix.com \
--to=het.gala@nutanix.com \
--cc=aravind.retnakaran@nutanix.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=eblake@redhat.com \
--cc=manish.mishra@nutanix.com \
--cc=pbonzini@redhat.com \
--cc=prerna.saxena@nutanix.com \
--cc=qemu-devel@nongnu.org \
--cc=quintela@redhat.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).