[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 31/65] migration/rdma: Fix rdma_getaddrinfo() error checking
|
From: |
Juan Quintela |
|
Subject: |
[PULL 31/65] migration/rdma: Fix rdma_getaddrinfo() error checking |
|
Date: |
Wed, 11 Oct 2023 11:21:29 +0200 |
From: Markus Armbruster <armbru@redhat.com>
rdma_getaddrinfo() returns 0 on success. On error, it returns one of
the EAI_ error codes like getaddrinfo() does, or -1 with errno set.
This is broken by design: POSIX implicitly specifies the EAI_ error
codes to be non-zero, no more. They could clash with -1. Nothing we
can do about this design flaw.
Both callers of rdma_getaddrinfo() only recognize negative values as
error. Works only because systems elect to make the EAI_ error codes
negative.
Best not to rely on that: change the callers to treat any non-zero
value as failure. Also change them to return -1 instead of the value
received from getaddrinfo() on failure, to avoid positive error
values.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Li Zhijian <lizhijian@fujitsu.com>
Reviewed-by: Juan Quintela <quintela@redhat.com>
Signed-off-by: Juan Quintela <quintela@redhat.com>
Message-ID: <20230928132019.2544702-25-armbru@redhat.com>
---
migration/rdma.c | 14 ++++++--------
1 file changed, 6 insertions(+), 8 deletions(-)
diff --git a/migration/rdma.c b/migration/rdma.c
index 974edde6a3..dd0b073792 100644
--- a/migration/rdma.c
+++ b/migration/rdma.c
@@ -941,14 +941,14 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma,
Error **errp)
if (rdma->host == NULL || !strcmp(rdma->host, "")) {
ERROR(errp, "RDMA hostname has not been set");
- return -EINVAL;
+ return -1;
}
/* create CM channel */
rdma->channel = rdma_create_event_channel();
if (!rdma->channel) {
ERROR(errp, "could not create CM channel");
- return -EINVAL;
+ return -1;
}
/* create CM id */
@@ -962,7 +962,7 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error
**errp)
port_str[15] = '\0';
ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res);
- if (ret < 0) {
+ if (ret) {
ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host);
goto err_resolve_get_addr;
}
@@ -1004,7 +1004,6 @@ route:
rdma_event_str(cm_event->event));
error_report("rdma_resolve_addr");
rdma_ack_cm_event(cm_event);
- ret = -EINVAL;
goto err_resolve_get_addr;
}
rdma_ack_cm_event(cm_event);
@@ -1025,7 +1024,6 @@ route:
ERROR(errp, "result not equal to event_route_resolved: %s",
rdma_event_str(cm_event->event));
rdma_ack_cm_event(cm_event);
- ret = -EINVAL;
goto err_resolve_get_addr;
}
rdma_ack_cm_event(cm_event);
@@ -1040,7 +1038,7 @@ err_resolve_get_addr:
err_resolve_create_id:
rdma_destroy_event_channel(rdma->channel);
rdma->channel = NULL;
- return ret;
+ return -1;
}
/*
@@ -2695,7 +2693,7 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error
**errp)
port_str[15] = '\0';
ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res);
- if (ret < 0) {
+ if (ret) {
ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host);
goto err_dest_init_bind_addr;
}
@@ -2739,7 +2737,7 @@ err_dest_init_create_listen_id:
rdma_destroy_event_channel(rdma->channel);
rdma->channel = NULL;
rdma->error_state = ret;
- return ret;
+ return -1;
}
--
2.41.0
- [PULL 15/65] migration/rdma: Give qio_channel_rdma_source_funcs internal linkage, (continued)
- [PULL 15/65] migration/rdma: Give qio_channel_rdma_source_funcs internal linkage, Juan Quintela, 2023/10/11
- [PULL 16/65] migration/rdma: Fix qemu_rdma_accept() to return failure on errors, Juan Quintela, 2023/10/11
- [PULL 17/65] migration/rdma: Put @errp parameter last, Juan Quintela, 2023/10/11
- [PULL 18/65] migration/rdma: Eliminate error_propagate(), Juan Quintela, 2023/10/11
- [PULL 19/65] migration/rdma: Drop rdma_add_block() error handling, Juan Quintela, 2023/10/11
- [PULL 20/65] migration/rdma: Drop qemu_rdma_search_ram_block() error handling, Juan Quintela, 2023/10/11
- [PULL 21/65] migration/rdma: Make qemu_rdma_buffer_mergeable() return bool, Juan Quintela, 2023/10/11
- [PULL 28/65] migration/rdma: Fix qemu_get_cm_event_timeout() to always set error, Juan Quintela, 2023/10/11
- [PULL 23/65] migration/rdma: Fix or document problematic uses of errno, Juan Quintela, 2023/10/11
- [PULL 24/65] migration/rdma: Ditch useless numeric error codes in error messages, Juan Quintela, 2023/10/11
- [PULL 31/65] migration/rdma: Fix rdma_getaddrinfo() error checking,
Juan Quintela <=
- [PULL 34/65] migration/rdma: Replace int error_state by bool errored, Juan Quintela, 2023/10/11
- [PULL 33/65] migration/rdma: Dumb down remaining int error values to -1, Juan Quintela, 2023/10/11
- [PULL 22/65] migration/rdma: Use bool for two RDMAContext flags, Juan Quintela, 2023/10/11
- [PULL 25/65] migration/rdma: Fix io_writev(), io_readv() methods to obey contract, Juan Quintela, 2023/10/11
- [PULL 29/65] migration/rdma: Drop dead qemu_rdma_data_init() code for !@host_port, Juan Quintela, 2023/10/11
- [PULL 30/65] migration/rdma: Fix QEMUFileHooks method return values, Juan Quintela, 2023/10/11
- [PULL 26/65] migration/rdma: Replace dangerous macro CHECK_ERROR_STATE(), Juan Quintela, 2023/10/11
- [PULL 32/65] migration/rdma: Return -1 instead of negative errno code, Juan Quintela, 2023/10/11
- [PULL 27/65] migration/rdma: Fix qemu_rdma_broken_ipv6_kernel() to set error, Juan Quintela, 2023/10/11
- [PULL 37/65] migration/rdma: Plug a memory leak and improve a message, Juan Quintela, 2023/10/11