static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)

{

    int ret = -EINVAL, idx;

    struct rdma_cm_id *listen_id;

    char ip[40] = "unknown";

    struct rdma_addrinfo *res;

    char port_str[16];



    for (idx = 0; idx < RDMA_WRID_MAX; idx++) {

        rdma->wr_data[idx].control_len = 0;

        rdma->wr_data[idx].control_curr = NULL;

    }



    if (rdma->host == NULL) {

        ERROR(errp, "RDMA host is not set!");

        rdma->error_state = -EINVAL;

        return -1;

    }

    /* create CM channel */

    rdma->channel = rdma_create_event_channel();

    if (!rdma->channel) {

        ERROR(errp, "could not create rdma event channel");

        rdma->error_state = -EINVAL;

        return -1;

    }



    /* create CM id */

    ret = rdma_create_id(rdma->channel, &listen_id, NULL, RDMA_PS_TCP);

    if (ret) {

        ERROR(errp, "could not create cm_id!");

        goto err_dest_init_create_listen_id;

    }



    snprintf(port_str, 16, "%d", rdma->port);

    port_str[15] = '\0';



    if (rdma->host && strcmp("", rdma->host)) {

        struct rdma_addrinfo *e;



        ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res);

        if (ret < 0) {

            ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host);

            goto err_dest_init_bind_addr;

        }



        for (e = res; e != NULL; e = e->ai_next) {

            inet_ntop(e->ai_family,

                &((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip);

            trace_qemu_rdma_dest_init_trying(rdma->host, ip);

            ret = rdma_bind_addr(listen_id, e->ai_dst_addr);

            if (!ret) {

                if (e->ai_family == AF_INET6) {

                    ret = qemu_rdma_broken_ipv6_kernel(errp, listen_id->verbs);

                    if (ret) {

                        continue;

                    }

                }

                    

                goto listen;

            }

        }



        ERROR(errp, "Error: could not rdma_bind_addr!");

        goto err_dest_init_bind_addr;

    } else {

        ERROR(errp, "migration host and port not specified!");

        ret = -EINVAL;

        goto err_dest_init_bind_addr;

    }

listen:



    rdma->listen_id = listen_id;

    qemu_rdma_dump_gid("dest_init", listen_id);

    return 0;



err_dest_init_bind_addr:

    rdma_destroy_id(listen_id);

err_dest_init_create_listen_id:

    rdma_destroy_event_channel(rdma->channel);

    rdma->channel = NULL;

    rdma->error_state = ret;

    return ret;



}

static int qemu_rdma_dest_init(RDMAContext *rdma, Error **errp)

{

    int ret = -EINVAL, idx;

    struct rdma_cm_id *listen_id;

    char ip[40] = "unknown";

    struct rdma_addrinfo *res;

    char port_str[16];



    for (idx = 0; idx < RDMA_WRID_MAX; idx++) {

        rdma->wr_data[idx].control_len = 0;

        rdma->wr_data[idx].control_curr = NULL;

    }



    if (rdma->host == NULL) {

        ERROR(errp, "RDMA host is not set!");

        rdma->error_state = -EINVAL;

        return -1;

    }

    

    rdma->channel = rdma_create_event_channel();

    if (!rdma->channel) {

        ERROR(errp, "could not create rdma event channel");

        rdma->error_state = -EINVAL;

        return -1;

    }



    

    ret = rdma_create_id(rdma->channel, &listen_id, NULL, RDMA_PS_TCP);

    if (ret) {

        ERROR(errp, "could not create cm_id!");

        goto err_dest_init_create_listen_id;

    }



    snprintf(port_str, 16, "%d", rdma->port);

    port_str[15] = '\0';



    if (rdma->host && strcmp("", rdma->host)) {

        struct rdma_addrinfo *e;



        ret = rdma_getaddrinfo(rdma->host, port_str, NULL, &res);

        if (ret < 0) {

            ERROR(errp, "could not rdma_getaddrinfo address %s", rdma->host);

            goto err_dest_init_bind_addr;

        }



        for (e = res; e != NULL; e = e->ai_next) {

            inet_ntop(e->ai_family,

                &((struct sockaddr_in *) e->ai_dst_addr)->sin_addr, ip, sizeof ip);

            trace_qemu_rdma_dest_init_trying(rdma->host, ip);

            ret = rdma_bind_addr(listen_id, e->ai_dst_addr);

            if (!ret) {

                if (e->ai_family == AF_INET6) {

                    ret = qemu_rdma_broken_ipv6_kernel(errp, listen_id->verbs);

                    if (ret) {

                        continue;

                    }

                }

                    

                goto listen;

            }

        }



        ERROR(errp, "Error: could not rdma_bind_addr!");

        goto err_dest_init_bind_addr;

    } else {

        ERROR(errp, "migration host and port not specified!");

        ret = -EINVAL;

        goto err_dest_init_bind_addr;

    }

listen:



    rdma->listen_id = listen_id;

    qemu_rdma_dump_gid("dest_init", listen_id);

    return 0;



err_dest_init_bind_addr:

    rdma_destroy_id(listen_id);

err_dest_init_create_listen_id:

    rdma_destroy_event_channel(rdma->channel);

    rdma->channel = NULL;

    rdma->error_state = ret;

    return ret;



}

static int FUNC_0(RDMAContext *VAR_0, Error **VAR_1)

{

    int VAR_2 = -EINVAL, VAR_3;

    struct rdma_cm_id *VAR_4;

    char VAR_5[40] = "unknown";

    struct rdma_addrinfo *VAR_6;

    char VAR_7[16];



    for (VAR_3 = 0; VAR_3 < RDMA_WRID_MAX; VAR_3++) {

        VAR_0->wr_data[VAR_3].control_len = 0;

        VAR_0->wr_data[VAR_3].control_curr = NULL;

    }



    if (VAR_0->host == NULL) {

        ERROR(VAR_1, "RDMA host is not set!");

        VAR_0->error_state = -EINVAL;

        return -1;

    }

    

    VAR_0->channel = rdma_create_event_channel();

    if (!VAR_0->channel) {

        ERROR(VAR_1, "could not create VAR_0 event channel");

        VAR_0->error_state = -EINVAL;

        return -1;

    }



    

    VAR_2 = rdma_create_id(VAR_0->channel, &VAR_4, NULL, RDMA_PS_TCP);

    if (VAR_2) {

        ERROR(VAR_1, "could not create cm_id!");

        goto err_dest_init_create_listen_id;

    }



    snprintf(VAR_7, 16, "%d", VAR_0->port);

    VAR_7[15] = '\0';



    if (VAR_0->host && strcmp("", VAR_0->host)) {

        struct rdma_addrinfo *VAR_8;



        VAR_2 = rdma_getaddrinfo(VAR_0->host, VAR_7, NULL, &VAR_6);

        if (VAR_2 < 0) {

            ERROR(VAR_1, "could not rdma_getaddrinfo address %s", VAR_0->host);

            goto err_dest_init_bind_addr;

        }



        for (VAR_8 = VAR_6; VAR_8 != NULL; VAR_8 = VAR_8->ai_next) {

            inet_ntop(VAR_8->ai_family,

                &((struct sockaddr_in *) VAR_8->ai_dst_addr)->sin_addr, VAR_5, sizeof VAR_5);

            trace_qemu_rdma_dest_init_trying(VAR_0->host, VAR_5);

            VAR_2 = rdma_bind_addr(VAR_4, VAR_8->ai_dst_addr);

            if (!VAR_2) {

                if (VAR_8->ai_family == AF_INET6) {

                    VAR_2 = qemu_rdma_broken_ipv6_kernel(VAR_1, VAR_4->verbs);

                    if (VAR_2) {

                        continue;

                    }

                }

                    

                goto listen;

            }

        }



        ERROR(VAR_1, "Error: could not rdma_bind_addr!");

        goto err_dest_init_bind_addr;

    } else {

        ERROR(VAR_1, "migration host and port not specified!");

        VAR_2 = -EINVAL;

        goto err_dest_init_bind_addr;

    }

listen:



    VAR_0->VAR_4 = VAR_4;

    qemu_rdma_dump_gid("dest_init", VAR_4);

    return 0;



err_dest_init_bind_addr:

    rdma_destroy_id(VAR_4);

err_dest_init_create_listen_id:

    rdma_destroy_event_channel(VAR_0->channel);

    VAR_0->channel = NULL;

    VAR_0->error_state = VAR_2;

    return VAR_2;



}

static int FUNC_0(RDMAContext *VAR_0, Error **VAR_1)
{ int VAR_2 = -EINVAL, VAR_3; struct rdma_cm_id *VAR_4; char VAR_5[40] = "unknown"; struct rdma_addrinfo *VAR_6; char VAR_7[16]; for (VAR_3 = 0; VAR_3 < RDMA_WRID_MAX; VAR_3++) { VAR_0->wr_data[VAR_3].control_len = 0; VAR_0->wr_data[VAR_3].control_curr = NULL; } if (VAR_0->host == NULL) { ERROR(VAR_1, "RDMA host is not set!"); VAR_0->error_state = -EINVAL; return -1; } VAR_0->channel = rdma_create_event_channel(); if (!VAR_0->channel) { ERROR(VAR_1, "could not create VAR_0 event channel"); VAR_0->error_state = -EINVAL; return -1; } VAR_2 = rdma_create_id(VAR_0->channel, &VAR_4, NULL, RDMA_PS_TCP); if (VAR_2) { ERROR(VAR_1, "could not create cm_id!"); goto err_dest_init_create_listen_id; } snprintf(VAR_7, 16, "%d", VAR_0->port); VAR_7[15] = '\0'; if (VAR_0->host && strcmp("", VAR_0->host)) { struct rdma_addrinfo *VAR_8; VAR_2 = rdma_getaddrinfo(VAR_0->host, VAR_7, NULL, &VAR_6); if (VAR_2 < 0) { ERROR(VAR_1, "could not rdma_getaddrinfo address %s", VAR_0->host); goto err_dest_init_bind_addr; } for (VAR_8 = VAR_6; VAR_8 != NULL; VAR_8 = VAR_8->ai_next) { inet_ntop(VAR_8->ai_family,
&((struct sockaddr_in *) VAR_8->ai_dst_addr)->sin_addr, VAR_5, sizeof VAR_5); trace_qemu_rdma_dest_init_trying(VAR_0->host, VAR_5); VAR_2 = rdma_bind_addr(VAR_4, VAR_8->ai_dst_addr); if (!VAR_2) { if (VAR_8->ai_family == AF_INET6) { VAR_2 = qemu_rdma_broken_ipv6_kernel(VAR_1, VAR_4->verbs); if (VAR_2) { continue; } } goto listen; } } ERROR(VAR_1, "Error: could not rdma_bind_addr!"); goto err_dest_init_bind_addr; } else { ERROR(VAR_1, "migration host and port not specified!"); VAR_2 = -EINVAL; goto err_dest_init_bind_addr; } listen:
VAR_0->VAR_4 = VAR_4; qemu_rdma_dump_gid("dest_init", VAR_4); return 0; err_dest_init_bind_addr:
rdma_destroy_id(VAR_4); err_dest_init_create_listen_id:
rdma_destroy_event_channel(VAR_0->channel); VAR_0->channel = NULL; VAR_0->error_state = VAR_2; return VAR_2; }