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

{

    int ret;

    struct addrinfo *res;

    char port_str[16];

    struct rdma_cm_event *cm_event;

    char ip[40] = "unknown";

    struct addrinfo *e;



    if (rdma->host == NULL || !strcmp(rdma->host, "")) {

        ERROR(errp, "RDMA hostname has not been set");

        return -1;

    }



    /* create CM channel */

    rdma->channel = rdma_create_event_channel();

    if (!rdma->channel) {

        ERROR(errp, "could not create CM channel");

        return -1;

    }



    /* create CM id */

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

    if (ret) {

        ERROR(errp, "could not create channel id");

        goto err_resolve_create_id;

    }



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

    port_str[15] = '\0';



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

    if (ret < 0) {

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

        goto err_resolve_get_addr;

    }



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

        inet_ntop(e->ai_family,

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

        DPRINTF("Trying %s => %s\n", rdma->host, ip);



        /* resolve the first address */

        ret = rdma_resolve_addr(rdma->cm_id, NULL, e->ai_addr,

                RDMA_RESOLVE_TIMEOUT_MS);

        if (!ret) {

            goto route;

        }

    }



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

    goto err_resolve_get_addr;



route:

    qemu_rdma_dump_gid("source_resolve_addr", rdma->cm_id);



    ret = rdma_get_cm_event(rdma->channel, &cm_event);

    if (ret) {

        ERROR(errp, "could not perform event_addr_resolved");

        goto err_resolve_get_addr;

    }



    if (cm_event->event != RDMA_CM_EVENT_ADDR_RESOLVED) {

        ERROR(errp, "result not equal to event_addr_resolved %s",

                rdma_event_str(cm_event->event));

        perror("rdma_resolve_addr");

        goto err_resolve_get_addr;

    }

    rdma_ack_cm_event(cm_event);



    /* resolve route */

    ret = rdma_resolve_route(rdma->cm_id, RDMA_RESOLVE_TIMEOUT_MS);

    if (ret) {

        ERROR(errp, "could not resolve rdma route");

        goto err_resolve_get_addr;

    }



    ret = rdma_get_cm_event(rdma->channel, &cm_event);

    if (ret) {

        ERROR(errp, "could not perform event_route_resolved");

        goto err_resolve_get_addr;

    }

    if (cm_event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {

        ERROR(errp, "result not equal to event_route_resolved: %s",

                        rdma_event_str(cm_event->event));

        rdma_ack_cm_event(cm_event);

        goto err_resolve_get_addr;

    }

    rdma_ack_cm_event(cm_event);

    rdma->verbs = rdma->cm_id->verbs;

    qemu_rdma_dump_id("source_resolve_host", rdma->cm_id->verbs);

    qemu_rdma_dump_gid("source_resolve_host", rdma->cm_id);

    return 0;



err_resolve_get_addr:

    rdma_destroy_id(rdma->cm_id);

    rdma->cm_id = NULL;

err_resolve_create_id:

    rdma_destroy_event_channel(rdma->channel);

    rdma->channel = NULL;



    return -1;

}

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

{

    int ret;

    struct addrinfo *res;

    char port_str[16];

    struct rdma_cm_event *cm_event;

    char ip[40] = "unknown";

    struct addrinfo *e;



    if (rdma->host == NULL || !strcmp(rdma->host, "")) {

        ERROR(errp, "RDMA hostname has not been set");

        return -1;

    }



    

    rdma->channel = rdma_create_event_channel();

    if (!rdma->channel) {

        ERROR(errp, "could not create CM channel");

        return -1;

    }



    

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

    if (ret) {

        ERROR(errp, "could not create channel id");

        goto err_resolve_create_id;

    }



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

    port_str[15] = '\0';



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

    if (ret < 0) {

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

        goto err_resolve_get_addr;

    }



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

        inet_ntop(e->ai_family,

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

        DPRINTF("Trying %s => %s\n", rdma->host, ip);



        

        ret = rdma_resolve_addr(rdma->cm_id, NULL, e->ai_addr,

                RDMA_RESOLVE_TIMEOUT_MS);

        if (!ret) {

            goto route;

        }

    }



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

    goto err_resolve_get_addr;



route:

    qemu_rdma_dump_gid("source_resolve_addr", rdma->cm_id);



    ret = rdma_get_cm_event(rdma->channel, &cm_event);

    if (ret) {

        ERROR(errp, "could not perform event_addr_resolved");

        goto err_resolve_get_addr;

    }



    if (cm_event->event != RDMA_CM_EVENT_ADDR_RESOLVED) {

        ERROR(errp, "result not equal to event_addr_resolved %s",

                rdma_event_str(cm_event->event));

        perror("rdma_resolve_addr");

        goto err_resolve_get_addr;

    }

    rdma_ack_cm_event(cm_event);



    

    ret = rdma_resolve_route(rdma->cm_id, RDMA_RESOLVE_TIMEOUT_MS);

    if (ret) {

        ERROR(errp, "could not resolve rdma route");

        goto err_resolve_get_addr;

    }



    ret = rdma_get_cm_event(rdma->channel, &cm_event);

    if (ret) {

        ERROR(errp, "could not perform event_route_resolved");

        goto err_resolve_get_addr;

    }

    if (cm_event->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {

        ERROR(errp, "result not equal to event_route_resolved: %s",

                        rdma_event_str(cm_event->event));

        rdma_ack_cm_event(cm_event);

        goto err_resolve_get_addr;

    }

    rdma_ack_cm_event(cm_event);

    rdma->verbs = rdma->cm_id->verbs;

    qemu_rdma_dump_id("source_resolve_host", rdma->cm_id->verbs);

    qemu_rdma_dump_gid("source_resolve_host", rdma->cm_id);

    return 0;



err_resolve_get_addr:

    rdma_destroy_id(rdma->cm_id);

    rdma->cm_id = NULL;

err_resolve_create_id:

    rdma_destroy_event_channel(rdma->channel);

    rdma->channel = NULL;



    return -1;

}

    struct addrinfo *res;     struct addrinfo *e;         return -1;         return -1;     ret = getaddrinfo(rdma->host, port_str, NULL, &res);         ERROR(errp, "could not getaddrinfo address %s", rdma->host);             &((struct sockaddr_in *) e->ai_addr)->sin_addr, ip, sizeof ip);         ret = rdma_resolve_addr(rdma->cm_id, NULL, e->ai_addr,     return -1;     struct addrinfo *res;
static int FUNC_0(RDMAContext *VAR_0, Error **VAR_1)

{

    int VAR_2;

    struct addrinfo *VAR_3;

    char VAR_4[16];

    struct rdma_cm_event *VAR_5;

    char VAR_6[40] = "unknown";

    struct addrinfo *VAR_7;



    if (VAR_0->host == NULL || !strcmp(VAR_0->host, "")) {

        ERROR(VAR_1, "RDMA hostname has not been set");

        return -1;

    }



    

    VAR_0->channel = rdma_create_event_channel();

    if (!VAR_0->channel) {

        ERROR(VAR_1, "could not create CM channel");

        return -1;

    }



    

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

    if (VAR_2) {

        ERROR(VAR_1, "could not create channel id");

        goto err_resolve_create_id;

    }



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

    VAR_4[15] = '\0';



    VAR_2 = getaddrinfo(VAR_0->host, VAR_4, NULL, &VAR_3);

    if (VAR_2 < 0) {

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

        goto err_resolve_get_addr;

    }



    for (VAR_7 = VAR_3; VAR_7 != NULL; VAR_7 = VAR_7->ai_next) {

        inet_ntop(VAR_7->ai_family,

            &((struct sockaddr_in *) VAR_7->ai_addr)->sin_addr, VAR_6, sizeof VAR_6);

        DPRINTF("Trying %s => %s\n", VAR_0->host, VAR_6);



        

        VAR_2 = rdma_resolve_addr(VAR_0->cm_id, NULL, VAR_7->ai_addr,

                RDMA_RESOLVE_TIMEOUT_MS);

        if (!VAR_2) {

            goto route;

        }

    }



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

    goto err_resolve_get_addr;



route:

    qemu_rdma_dump_gid("source_resolve_addr", VAR_0->cm_id);



    VAR_2 = rdma_get_cm_event(VAR_0->channel, &VAR_5);

    if (VAR_2) {

        ERROR(VAR_1, "could not perform event_addr_resolved");

        goto err_resolve_get_addr;

    }



    if (VAR_5->event != RDMA_CM_EVENT_ADDR_RESOLVED) {

        ERROR(VAR_1, "result not equal to event_addr_resolved %s",

                rdma_event_str(VAR_5->event));

        perror("rdma_resolve_addr");

        goto err_resolve_get_addr;

    }

    rdma_ack_cm_event(VAR_5);



    

    VAR_2 = rdma_resolve_route(VAR_0->cm_id, RDMA_RESOLVE_TIMEOUT_MS);

    if (VAR_2) {

        ERROR(VAR_1, "could not resolve VAR_0 route");

        goto err_resolve_get_addr;

    }



    VAR_2 = rdma_get_cm_event(VAR_0->channel, &VAR_5);

    if (VAR_2) {

        ERROR(VAR_1, "could not perform event_route_resolved");

        goto err_resolve_get_addr;

    }

    if (VAR_5->event != RDMA_CM_EVENT_ROUTE_RESOLVED) {

        ERROR(VAR_1, "result not equal to event_route_resolved: %s",

                        rdma_event_str(VAR_5->event));

        rdma_ack_cm_event(VAR_5);

        goto err_resolve_get_addr;

    }

    rdma_ack_cm_event(VAR_5);

    VAR_0->verbs = VAR_0->cm_id->verbs;

    qemu_rdma_dump_id("source_resolve_host", VAR_0->cm_id->verbs);

    qemu_rdma_dump_gid("source_resolve_host", VAR_0->cm_id);

    return 0;



err_resolve_get_addr:

    rdma_destroy_id(VAR_0->cm_id);

    VAR_0->cm_id = NULL;

err_resolve_create_id:

    rdma_destroy_event_channel(VAR_0->channel);

    VAR_0->channel = NULL;



    return -1;

}

static int FUNC_0(RDMAContext *VAR_0, Error **VAR_1)
{ int VAR_2; struct addrinfo *VAR_3; char VAR_4[16]; struct rdma_cm_event *VAR_5; char VAR_6[40] = "unknown"; struct addrinfo *VAR_7; if (VAR_0->host == NULL || !strcmp(VAR_0->host, "")) { ERROR(VAR_1, "RDMA hostname has not been set"); return -1; } VAR_0->channel = rdma_create_event_channel(); if (!VAR_0->channel) { ERROR(VAR_1, "could not create CM channel"); return -1; } VAR_2 = rdma_create_id(VAR_0->channel, &VAR_0->cm_id, NULL, RDMA_PS_TCP); if (VAR_2) { ERROR(VAR_1, "could not create channel id"); goto err_resolve_create_id; } snprintf(VAR_4, 16, "%d", VAR_0->port); VAR_4[15] = '\0'; VAR_2 = getaddrinfo(VAR_0->host, VAR_4, NULL, &VAR_3); if (VAR_2 < 0) { ERROR(VAR_1, "could not getaddrinfo address %s", VAR_0->host); goto err_resolve_get_addr; } for (VAR_7 = VAR_3; VAR_7 != NULL; VAR_7 = VAR_7->ai_next) { inet_ntop(VAR_7->ai_family,
&((struct sockaddr_in *) VAR_7->ai_addr)->sin_addr, VAR_6, sizeof VAR_6); DPRINTF("Trying %s => %s\n", VAR_0->host, VAR_6); VAR_2 = rdma_resolve_addr(VAR_0->cm_id, NULL, VAR_7->ai_addr,
RDMA_RESOLVE_TIMEOUT_MS); if (!VAR_2) { goto route; } } ERROR(VAR_1, "could not resolve address %s", VAR_0->host); goto err_resolve_get_addr; route:
qemu_rdma_dump_gid("source_resolve_addr", VAR_0->cm_id); VAR_2 = rdma_get_cm_event(VAR_0->channel, &VAR_5); if (VAR_2) { ERROR(VAR_1, "could not perform event_addr_resolved"); goto err_resolve_get_addr; } if (VAR_5->event != RDMA_CM_EVENT_ADDR_RESOLVED) { ERROR(VAR_1, "result not equal to event_addr_resolved %s",
rdma_event_str(VAR_5->event)); perror("rdma_resolve_addr"); goto err_resolve_get_addr; } rdma_ack_cm_event(VAR_5); VAR_2 = rdma_resolve_route(VAR_0->cm_id, RDMA_RESOLVE_TIMEOUT_MS); if (VAR_2) { ERROR(VAR_1, "could not resolve VAR_0 route"); goto err_resolve_get_addr; } VAR_2 = rdma_get_cm_event(VAR_0->channel, &VAR_5); if (VAR_2) { ERROR(VAR_1, "could not perform event_route_resolved"); goto err_resolve_get_addr; } if (VAR_5->event != RDMA_CM_EVENT_ROUTE_RESOLVED) { ERROR(VAR_1, "result not equal to event_route_resolved: %s",
rdma_event_str(VAR_5->event)); rdma_ack_cm_event(VAR_5); goto err_resolve_get_addr; } rdma_ack_cm_event(VAR_5); VAR_0->verbs = VAR_0->cm_id->verbs; qemu_rdma_dump_id("source_resolve_host", VAR_0->cm_id->verbs); qemu_rdma_dump_gid("source_resolve_host", VAR_0->cm_id); return 0; err_resolve_get_addr:
rdma_destroy_id(VAR_0->cm_id); VAR_0->cm_id = NULL; err_resolve_create_id:
rdma_destroy_event_channel(VAR_0->channel); VAR_0->channel = NULL; return -1; }