[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 01/20] migration: Simplify initial conditionals in migration for b
|
From: |
peterx |
|
Subject: |
[PULL 01/20] migration: Simplify initial conditionals in migration for better readability |
|
Date: |
Tue, 16 Jan 2024 11:19:28 +0800 |
From: Het Gala <het.gala@nutanix.com>
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.
Signed-off-by: Het Gala <het.gala@nutanix.com>
Suggested-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Fabiano Rosas <farosas@suse.de>
Link: https://lore.kernel.org/r/20231205080039.197615-1-het.gala@nutanix.com
Signed-off-by: Peter Xu <peterx@redhat.com>
---
migration/migration.c | 36 ++++++++++++++++--------------------
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/migration/migration.c b/migration/migration.c
index 98c5c3e140..2365a3a13c 100644
--- a/migration/migration.c
+++ b/migration/migration.c
@@ -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? */
@@ -1924,28 +1922,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? */
--
2.43.0
- [PULL 00/20] Migration 20240116 patches, peterx, 2024/01/15
- [PULL 01/20] migration: Simplify initial conditionals in migration for better readability,
peterx <=
- [PULL 02/20] migration/multifd: Remove MultiFDPages_t::packet_num, peterx, 2024/01/15
- [PULL 04/20] migration/multifd: Change multifd_pages_init argument, peterx, 2024/01/15
- [PULL 09/20] tests/qtest: Re-enable multifd cancel test, peterx, 2024/01/15
- [PULL 03/20] migration/multifd: Remove QEMUFile from where it is not needed, peterx, 2024/01/15
- [PULL 06/20] tests/qtest/migration: Print migration incoming errors, peterx, 2024/01/15
- [PULL 07/20] tests/qtest/migration: Add a wrapper to print test names, peterx, 2024/01/15
- [PULL 08/20] tests/qtest/migration: Use the new migration_test_add, peterx, 2024/01/15
- [PULL 10/20] docs/migration: Create migration/ directory, peterx, 2024/01/15
- [PULL 11/20] docs/migration: Create index page, peterx, 2024/01/15
- [PULL 12/20] docs/migration: Convert virtio.txt into rST, peterx, 2024/01/15