@@ -316,6 +316,7 @@ typedef struct RDMALocalBlocks {
typedef struct RDMAContext {
char *host;
int port;
+ const char *host_port;
RDMAWorkRequestData wr_data[RDMA_WRID_MAX];
@@ -2648,6 +2649,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 = host_port;
} else {
ERROR(errp, "bad RDMA migration address '%s'", host_port);
g_free(rdma);
@@ -3276,6 +3278,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;
@@ -3291,6 +3294,20 @@ static int qemu_rdma_accept(RDMAContext *rdma)
goto err_rdma_dest_wait;
}
+ /*
+ * initialize the RDMAContext for return path for postcopy after first
+ * connection is accepted.
+ */
+ 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);
@@ -3406,6 +3423,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;
}
@@ -4048,17 +4066,6 @@ void rdma_start_incoming_migration(const char *host_port, Error **errp)
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 cleanup_rdma;
- }
-
- 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;