Skip to contentSkip to conversation

migration: Simplify initial conditionals in migration for better readability

PATCH In review Het Gala 3 participants 6 messages Dec 5, 2023 – Jan 4, 2024

lore
Share & tools
lore

Het Gala

author
#0 lore raw

PATCH 1/1 migration: Simplify initial conditionals in migration for better readability

The inital conditional statements in qmp migration functions is harder to understand than necessary. It is better to get all errors out of the way in the beginning itself to have better readability and error handling.

---
 migration/migration.c | 36 ++++++++++++++++--------------------
 1 file changed, 16 insertions(+), 20 deletions(-)
migration/migration.c +16 -20
index 3ce04b2aaf..962ee7564c 100644
@@ -523,28 +523,26 @@ static void qemu_start_incoming_migration(const char *uri, bool has_channels,
     /*
      * Having preliminary checks for uri and channel
      */
-    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 ");
+    if (!uri == !channels) {
+        error_setg(errp, "need either 'uri' or 'channels' argument");
         return;
-    } else if (channels) {
+    }
+
+    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;
         }
         addr = channels->value->addr;
-    } else if (uri) {
+    }
+
+    if (uri) {
         /* caller uses the old URI syntax */
         if (!migrate_uri_parse(uri, &channel, errp)) {
             return;
         }
         addr = channel->addr;
-    } else {
-        error_setg(errp, "neither 'uri' or 'channels' argument are "
-                   "specified in 'migrate-incoming' qmp command ");
-        return;
     }
 
     /* transport mechanism not suitable for migration? */
@@ -1939,28 +1937,26 @@ void qmp_migrate(const char *uri, bool has_channels,
     /*
      * Having preliminary checks for uri and channel
      */
-    if (uri && has_channels) {
-        error_setg(errp, "'uri' and 'channels' arguments are mutually "
-                   "exclusive; exactly one of the two should be present in "
-                   "'migrate' qmp command ");
+    if (!uri == !channels) {
+        error_setg(errp, "need either 'uri' or 'channels' argument");
         return;
-    } else if (channels) {
+    }
+
+    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;
         }
         addr = channels->value->addr;
-    } else if (uri) {
+    }
+
+    if (uri) {
         /* caller uses the old URI syntax */
         if (!migrate_uri_parse(uri, &channel, errp)) {
             return;
         }
         addr = channel->addr;
-    } else {
-        error_setg(errp, "neither 'uri' or 'channels' argument are "
-                   "specified in 'migrate' qmp command ");
-        return;
     }
 
     /* transport mechanism not suitable for migration? */
Signature · 1 line
2.22.3
author
#1 lore raw
Quoted 7 lines · Het Gala

The inital conditional statements in qmp migration functions is harder to understand than necessary. It is better to get all errors out of the way in the beginning itself to have better readability and error handling.

I have also tested this patch on the Qemu CI/CD, ref :https://gitlab.com/galahet/Qemu/-/pipelines/1094304060

Regards,

Het Gala

author
#3 lore raw

Ping? Waiting for other maintainers to respond on this patch

Quoted 11 lines · Fabiano Rosas
Quoted 7 lines · Het Gala

The inital conditional statements in qmp migration functions is harder to understand than necessary. It is better to get all errors out of the way in the beginning itself to have better readability and error handling.

Regards,

Het Gala

author
#4 lore raw

Ping. In-case this patch has been missed out. Waiting for other maintainers to respond. Thanks!

Quoted 9 lines · Het Gala

Ping? Waiting for other maintainers to respond on this patch

Quoted 7 lines · Fabiano Rosas
Quoted 5 lines · Het Gala

The inital conditional statements in qmp migration functions is harder to understand than necessary. It is better to get all errors out of the way in the beginning itself to have better readability and error handling.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

Regards,
Het Gala

Regards,

Het Gala

#5 lore raw
Quoted 18 lines · Het Gala

Ping. In-case this patch has been missed out. Waiting for other maintainers to respond. Thanks!

Quoted 15 lines · Het Gala

Ping? Waiting for other maintainers to respond on this patch

Quoted 11 lines · Fabiano Rosas
Quoted 7 lines · Het Gala

The inital conditional statements in qmp migration functions is harder to understand than necessary. It is better to get all errors out of the way in the beginning itself to have better readability and error handling.

Regards,
Het Gala

queued in staging. will be in the next pull.

https://gitlab.com/peterx/qemu/-/tree/migration-staging

Thanks,

Signature · 1 line
Peter Xu