static int qemu_rdma_alloc_pd_cq(RDMAContext *rdma)

{

    /* allocate pd */

    rdma->pd = ibv_alloc_pd(rdma->verbs);

    if (!rdma->pd) {

        fprintf(stderr, "failed to allocate protection domain\n");

        return -1;

    }



    /* create completion channel */

    rdma->comp_channel = ibv_create_comp_channel(rdma->verbs);

    if (!rdma->comp_channel) {

        fprintf(stderr, "failed to allocate completion channel\n");

        goto err_alloc_pd_cq;

    }



    /*

     * Completion queue can be filled by both read and write work requests,

     * so must reflect the sum of both possible queue sizes.

     */

    rdma->cq = ibv_create_cq(rdma->verbs, (RDMA_SIGNALED_SEND_MAX * 3),

            NULL, rdma->comp_channel, 0);

    if (!rdma->cq) {

        fprintf(stderr, "failed to allocate completion queue\n");

        goto err_alloc_pd_cq;

    }



    return 0;



err_alloc_pd_cq:

    if (rdma->pd) {

        ibv_dealloc_pd(rdma->pd);

    }

    if (rdma->comp_channel) {

        ibv_destroy_comp_channel(rdma->comp_channel);

    }

    rdma->pd = NULL;

    rdma->comp_channel = NULL;

    return -1;



}

static int qemu_rdma_alloc_pd_cq(RDMAContext *rdma)

{

    

    rdma->pd = ibv_alloc_pd(rdma->verbs);

    if (!rdma->pd) {

        fprintf(stderr, "failed to allocate protection domain\n");

        return -1;

    }



    

    rdma->comp_channel = ibv_create_comp_channel(rdma->verbs);

    if (!rdma->comp_channel) {

        fprintf(stderr, "failed to allocate completion channel\n");

        goto err_alloc_pd_cq;

    }



    







    rdma->cq = ibv_create_cq(rdma->verbs, (RDMA_SIGNALED_SEND_MAX * 3),

            NULL, rdma->comp_channel, 0);

    if (!rdma->cq) {

        fprintf(stderr, "failed to allocate completion queue\n");

        goto err_alloc_pd_cq;

    }



    return 0;



err_alloc_pd_cq:

    if (rdma->pd) {

        ibv_dealloc_pd(rdma->pd);

    }

    if (rdma->comp_channel) {

        ibv_destroy_comp_channel(rdma->comp_channel);

    }

    rdma->pd = NULL;

    rdma->comp_channel = NULL;

    return -1;



}

static int FUNC_0(RDMAContext *VAR_0)

{

    

    VAR_0->pd = ibv_alloc_pd(VAR_0->verbs);

    if (!VAR_0->pd) {

        fprintf(stderr, "failed to allocate protection domain\n");

        return -1;

    }



    

    VAR_0->comp_channel = ibv_create_comp_channel(VAR_0->verbs);

    if (!VAR_0->comp_channel) {

        fprintf(stderr, "failed to allocate completion channel\n");

        goto err_alloc_pd_cq;

    }



    







    VAR_0->cq = ibv_create_cq(VAR_0->verbs, (RDMA_SIGNALED_SEND_MAX * 3),

            NULL, VAR_0->comp_channel, 0);

    if (!VAR_0->cq) {

        fprintf(stderr, "failed to allocate completion queue\n");

        goto err_alloc_pd_cq;

    }



    return 0;



err_alloc_pd_cq:

    if (VAR_0->pd) {

        ibv_dealloc_pd(VAR_0->pd);

    }

    if (VAR_0->comp_channel) {

        ibv_destroy_comp_channel(VAR_0->comp_channel);

    }

    VAR_0->pd = NULL;

    VAR_0->comp_channel = NULL;

    return -1;



}

static int FUNC_0(RDMAContext *VAR_0)
{ VAR_0->pd = ibv_alloc_pd(VAR_0->verbs); if (!VAR_0->pd) { fprintf(stderr, "failed to allocate protection domain\n"); return -1; } VAR_0->comp_channel = ibv_create_comp_channel(VAR_0->verbs); if (!VAR_0->comp_channel) { fprintf(stderr, "failed to allocate completion channel\n"); goto err_alloc_pd_cq; } VAR_0->cq = ibv_create_cq(VAR_0->verbs, (RDMA_SIGNALED_SEND_MAX * 3),
NULL, VAR_0->comp_channel, 0); if (!VAR_0->cq) { fprintf(stderr, "failed to allocate completion queue\n"); goto err_alloc_pd_cq; } return 0; err_alloc_pd_cq:
if (VAR_0->pd) { ibv_dealloc_pd(VAR_0->pd); } if (VAR_0->comp_channel) { ibv_destroy_comp_channel(VAR_0->comp_channel); } VAR_0->pd = NULL; VAR_0->comp_channel = NULL; return -1; }