diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2021-05-27 14:57:00 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2021-05-27 14:57:01 +0100 |
commit | c5847f5e4e5e0aa6a3dd40c5d2ec9a70bdc990a5 (patch) | |
tree | db9f89b986099431686fac6763a107a1c17f8940 /migration | |
parent | 8385235ba99c53d1187658f2fc289b953a8090b1 (diff) | |
parent | e49e49dd73b8b17f5f341b3e11c8b6878c43d3e1 (diff) |
Merge remote-tracking branch 'remotes/dgilbert/tags/pull-migration-20210526a' into staging
Virtiofs, migration and hmp pull 2021-05-26
Fixes for a loadvm regression from Kevin,
some virtiofsd cleanups from Vivek and Mahmoud, and
some RDMA migration fixups from Li.
Signed-off-by: Dr. David Alan Gilbert <dgilbert@redhat.com>
# gpg: Signature made Wed 26 May 2021 18:43:30 BST
# gpg: using RSA key 45F5C71B4A0CB7FB977A9FA90516331EBC5BFDE7
# gpg: Good signature from "Dr. David Alan Gilbert (RH2) <dgilbert@redhat.com>" [full]
# Primary key fingerprint: 45F5 C71B 4A0C B7FB 977A 9FA9 0516 331E BC5B FDE7
* remotes/dgilbert/tags/pull-migration-20210526a:
migration/rdma: source: poll cm_event from return path
migration/rdma: destination: create the return patch after the first accept
migration/rdma: Fix rdma_addrinfo res leaks
migration/rdma: cleanup rdma in rdma_start_incoming_migration error path
migration/rdma: Fix cm_event used before being initialized
tools/virtiofsd/fuse_opt.c: Replaced a malloc with GLib's g_try_malloc
tools/virtiofsd/buffer.c: replaced a calloc call with GLib's g_try_new0
virtiofsd: Set req->reply_sent right after sending reply
virtiofsd: Check EOF before short read
virtiofsd: Simplify skip byte logic
virtiofsd: get rid of in_sg_left variable
virtiofsd: Use iov_discard_front() to skip bytes
virtiofsd: Get rid of unreachable code in read
virtiofsd: Check for EINTR in preadv() and retry
hmp: Fix loadvm to resume the VM on success instead of failure
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'migration')
-rw-r--r-- | migration/rdma.c | 83 |
1 files changed, 66 insertions, 17 deletions
diff --git a/migration/rdma.c b/migration/rdma.c index 00eac34232..1cdb4561f3 100644 --- a/migration/rdma.c +++ b/migration/rdma.c @@ -36,6 +36,7 @@ #include <rdma/rdma_cma.h> #include "trace.h" #include "qom/object.h" +#include <poll.h> /* * Print and error on both the Monitor and the Log file. @@ -316,6 +317,7 @@ typedef struct RDMALocalBlocks { typedef struct RDMAContext { char *host; int port; + char *host_port; RDMAWorkRequestData wr_data[RDMA_WRID_MAX]; @@ -987,10 +989,12 @@ static int qemu_rdma_resolve_host(RDMAContext *rdma, Error **errp) } } + rdma_freeaddrinfo(res); ERROR(errp, "could not resolve address %s", rdma->host); goto err_resolve_get_addr; route: + rdma_freeaddrinfo(res); qemu_rdma_dump_gid("source_resolve_addr", rdma->cm_id); ret = rdma_get_cm_event(rdma->channel, &cm_event); @@ -2390,7 +2394,9 @@ static void qemu_rdma_cleanup(RDMAContext *rdma) rdma->channel = NULL; } g_free(rdma->host); + g_free(rdma->host_port); rdma->host = NULL; + rdma->host_port = NULL; } @@ -2455,7 +2461,36 @@ err_rdma_source_init: return -1; } -static int qemu_rdma_connect(RDMAContext *rdma, Error **errp) +static int qemu_get_cm_event_timeout(RDMAContext *rdma, + struct rdma_cm_event **cm_event, + long msec, Error **errp) +{ + int ret; + struct pollfd poll_fd = { + .fd = rdma->channel->fd, + .events = POLLIN, + .revents = 0 + }; + + do { + ret = poll(&poll_fd, 1, msec); + } while (ret < 0 && errno == EINTR); + + if (ret == 0) { + ERROR(errp, "poll cm event timeout"); + return -1; + } else if (ret < 0) { + ERROR(errp, "failed to poll cm event, errno=%i", errno); + return -1; + } else if (poll_fd.revents & POLLIN) { + return rdma_get_cm_event(rdma->channel, cm_event); + } else { + ERROR(errp, "no POLLIN event, revent=%x", poll_fd.revents); + return -1; + } +} + +static int qemu_rdma_connect(RDMAContext *rdma, Error **errp, bool return_path) { RDMACapabilities cap = { .version = RDMA_CONTROL_VERSION_CURRENT, @@ -2493,11 +2528,14 @@ static int qemu_rdma_connect(RDMAContext *rdma, Error **errp) goto err_rdma_source_connect; } - ret = rdma_get_cm_event(rdma->channel, &cm_event); + if (return_path) { + ret = qemu_get_cm_event_timeout(rdma, &cm_event, 5000, errp); + } else { + ret = rdma_get_cm_event(rdma->channel, &cm_event); + } if (ret) { perror("rdma_get_cm_event after rdma_connect"); ERROR(errp, "connecting to destination!"); - rdma_ack_cm_event(cm_event); goto err_rdma_source_connect; } @@ -2594,6 +2632,7 @@ static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp) break; } + rdma_freeaddrinfo(res); if (!e) { ERROR(errp, "Error: could not rdma_bind_addr!"); goto err_dest_init_bind_addr; @@ -2646,6 +2685,7 @@ static void *qemu_rdma_data_init(const char *host_port, Error **errp) if (!inet_parse(addr, host_port, NULL)) { rdma->port = atoi(addr->port); rdma->host = g_strdup(addr->host); + rdma->host_port = g_strdup(host_port); } else { ERROR(errp, "bad RDMA migration address '%s'", host_port); g_free(rdma); @@ -3274,6 +3314,7 @@ static int qemu_rdma_accept(RDMAContext *rdma) .private_data = &cap, .private_data_len = sizeof(cap), }; + RDMAContext *rdma_return_path = NULL; struct rdma_cm_event *cm_event; struct ibv_context *verbs; int ret = -EINVAL; @@ -3289,6 +3330,20 @@ static int qemu_rdma_accept(RDMAContext *rdma) goto err_rdma_dest_wait; } + /* + * initialize the RDMAContext for return path for postcopy after first + * connection request reached. + */ + if (migrate_postcopy() && !rdma->is_return_path) { + rdma_return_path = qemu_rdma_data_init(rdma->host_port, NULL); + if (rdma_return_path == NULL) { + rdma_ack_cm_event(cm_event); + goto err_rdma_dest_wait; + } + + qemu_rdma_return_path_dest_init(rdma_return_path, rdma); + } + memcpy(&cap, cm_event->param.conn.private_data, sizeof(cap)); network_to_caps(&cap); @@ -3404,6 +3459,7 @@ static int qemu_rdma_accept(RDMAContext *rdma) err_rdma_dest_wait: rdma->error_state = ret; qemu_rdma_cleanup(rdma); + g_free(rdma_return_path); return ret; } @@ -4041,29 +4097,22 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp) if (ret) { ERROR(errp, "listening on socket!"); - goto err; + goto cleanup_rdma; } trace_rdma_start_incoming_migration_after_rdma_listen(); - /* initialize the RDMAContext for return path */ - if (migrate_postcopy()) { - rdma_return_path = qemu_rdma_data_init(host_port, &local_err); - - if (rdma_return_path == NULL) { - goto err; - } - - qemu_rdma_return_path_dest_init(rdma_return_path, rdma); - } - qemu_set_fd_handler(rdma->channel->fd, rdma_accept_incoming_migration, NULL, (void *)(intptr_t)rdma); return; + +cleanup_rdma: + qemu_rdma_cleanup(rdma); err: error_propagate(errp, local_err); if (rdma) { g_free(rdma->host); + g_free(rdma->host_port); } g_free(rdma); g_free(rdma_return_path); @@ -4096,7 +4145,7 @@ void rdma_start_outgoing_migration(void *opaque, } trace_rdma_start_outgoing_migration_after_rdma_source_init(); - ret = qemu_rdma_connect(rdma, errp); + ret = qemu_rdma_connect(rdma, errp, false); if (ret) { goto err; @@ -4117,7 +4166,7 @@ void rdma_start_outgoing_migration(void *opaque, goto return_path_err; } - ret = qemu_rdma_connect(rdma_return_path, errp); + ret = qemu_rdma_connect(rdma_return_path, errp, true); if (ret) { goto return_path_err; |