* [PATCH libibverbs 2/3] Add helpers to deal with new InfiniBand link speeds
[not found] ` <1348173034-11929-1-git-send-email-ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2012-09-20 20:30 ` [PATCH libibverbs 1/3] Add raw packet QP type Or Gerlitz
@ 2012-09-20 20:30 ` Or Gerlitz
2012-09-20 20:30 ` [PATCH libibverbs 3/3] Fix resource leaks in the pingpong examples present in the failure/error flows Or Gerlitz
2 siblings, 0 replies; 5+ messages in thread
From: Or Gerlitz @ 2012-09-20 20:30 UTC (permalink / raw)
To: roland-DgEjT+Ai2ygdnm+yROfE0A
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Dotan Barak, Or Gerlitz
From: Dotan Barak <dotanb-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
Introduce support for the following extended speeds:
FDR: IBA extended speed 14.0625 Gbps.
EDR: IBA extended speed 25.78125 Gbps.
Signed-off-by: Dotan Barak <dotanb-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
Reviewed-by: Hal Rosenstock <hal-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
Signed-off-by: Or Gerlitz <ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
Makefile.am | 6 +++-
include/infiniband/verbs.h | 23 ++++++++++++++++++++-
man/ibv_rate_to_mbps.3 | 45 +++++++++++++++++++++++++++++++++++++++++
src/libibverbs.map | 3 ++
src/verbs.c | 48 ++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 122 insertions(+), 3 deletions(-)
create mode 100644 man/ibv_rate_to_mbps.3
diff --git a/Makefile.am b/Makefile.am
index cd00a65..40e83be 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -54,7 +54,7 @@ man_MANS = man/ibv_asyncwatch.1 man/ibv_devices.1 man/ibv_devinfo.1 \
man/ibv_post_srq_recv.3 man/ibv_query_device.3 man/ibv_query_gid.3 \
man/ibv_query_pkey.3 man/ibv_query_port.3 man/ibv_query_qp.3 \
man/ibv_query_srq.3 man/ibv_rate_to_mult.3 man/ibv_reg_mr.3 \
- man/ibv_req_notify_cq.3 man/ibv_resize_cq.3
+ man/ibv_req_notify_cq.3 man/ibv_resize_cq.3 man/ibv_rate_to_mbps.3
DEBIAN = debian/changelog debian/compat debian/control debian/copyright \
debian/ibverbs-utils.install debian/libibverbs1.install \
@@ -88,6 +88,7 @@ install-data-hook:
$(RM) mult_to_ibv_rate.3 && \
$(RM) ibv_node_type_str.3 && \
$(RM) ibv_port_state_str.3 && \
+ $(RM) mbps_to_ibv_rate.3 && \
$(LN_S) ibv_get_async_event.3 ibv_ack_async_event.3 && \
$(LN_S) ibv_get_cq_event.3 ibv_ack_cq_events.3 && \
$(LN_S) ibv_open_device.3 ibv_close_device.3 && \
@@ -103,4 +104,5 @@ install-data-hook:
$(LN_S) ibv_create_ah_from_wc.3 ibv_init_ah_from_wc.3 && \
$(LN_S) ibv_rate_to_mult.3 mult_to_ibv_rate.3 && \
$(LN_S) ibv_event_type_str.3 ibv_node_type_str.3 && \
- $(LN_S) ibv_event_type_str.3 ibv_port_state_str.3
+ $(LN_S) ibv_event_type_str.3 ibv_port_state_str.3 && \
+ $(LN_S) ibv_rate_to_mbps.3 mbps_to_ibv_rate.3
diff --git a/include/infiniband/verbs.h b/include/infiniband/verbs.h
index 8ed8a66..4b1ab57 100644
--- a/include/infiniband/verbs.h
+++ b/include/infiniband/verbs.h
@@ -353,7 +353,15 @@ enum ibv_rate {
IBV_RATE_40_GBPS = 7,
IBV_RATE_60_GBPS = 8,
IBV_RATE_80_GBPS = 9,
- IBV_RATE_120_GBPS = 10
+ IBV_RATE_120_GBPS = 10,
+ IBV_RATE_14_GBPS = 11,
+ IBV_RATE_56_GBPS = 12,
+ IBV_RATE_112_GBPS = 13,
+ IBV_RATE_168_GBPS = 14,
+ IBV_RATE_25_GBPS = 15,
+ IBV_RATE_100_GBPS = 16,
+ IBV_RATE_200_GBPS = 17,
+ IBV_RATE_300_GBPS = 18
};
/**
@@ -370,6 +378,19 @@ int ibv_rate_to_mult(enum ibv_rate rate) __attribute_const;
*/
enum ibv_rate mult_to_ibv_rate(int mult) __attribute_const;
+/**
+ * ibv_rate_to_mbps - Convert the IB rate enum to Mbit/sec.
+ * For example, IBV_RATE_5_GBPS will return the value 5000.
+ * @rate: rate to convert.
+ */
+int ibv_rate_to_mbps(enum ibv_rate rate) __attribute_const;
+
+/**
+ * mbps_to_ibv_rate - Convert a Mbit/sec value to an IB rate enum.
+ * @mbps: value to convert.
+ */
+enum ibv_rate mbps_to_ibv_rate(int mbps) __attribute_const;
+
struct ibv_ah_attr {
struct ibv_global_route grh;
uint16_t dlid;
diff --git a/man/ibv_rate_to_mbps.3 b/man/ibv_rate_to_mbps.3
new file mode 100644
index 0000000..089db01
--- /dev/null
+++ b/man/ibv_rate_to_mbps.3
@@ -0,0 +1,45 @@
+.\" -*- nroff -*-
+.\"
+.TH IBV_RATE_TO_MBPS 3 2012-03-31 libibverbs "Libibverbs Programmer's Manual"
+.SH "NAME"
+.nf
+ibv_rate_to_mbps \- convert IB rate enumeration to Mbit/sec
+.sp
+mbps_to_ibv_rate \- convert Mbit/sec to an IB rate enumeration
+.SH "SYNOPSIS"
+.nf
+.B #include <infiniband/verbs.h>
+.sp
+.BI "int ibv_rate_to_mbps(enum ibv_rate " "rate" ");
+.sp
+.BI "enum ibv_rate mbps_to_ibv_rate(int " "mbps" ");
+.fi
+.SH "DESCRIPTION"
+.B ibv_rate_to_mbps()
+converts the IB transmission rate enumeration
+.I rate
+to a number of Mbit/sec. For example, if
+.I rate
+is
+.BR IBV_RATE_5_GBPS\fR,
+the value 5000 will be returned (5 Gbit/sec = 5000 Mbit/sec).
+.PP
+.B mbps_to_ibv_rate()
+converts the number of Mbit/sec
+.I mult
+to an IB transmission rate enumeration. For example, if
+.I mult
+is 5000, the rate enumeration
+.BR IBV_RATE_5_GBPS
+will be returned.
+.SH "RETURN VALUE"
+.B ibv_rate_to_mbps()
+returns the number of Mbit/sec.
+.PP
+.B mbps_to_ibv_rate()
+returns the enumeration representing the IB transmission rate.
+.SH "SEE ALSO"
+.BR ibv_query_port (3)
+.SH "AUTHORS"
+.TP
+Dotan Barak <dotanb-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
diff --git a/src/libibverbs.map b/src/libibverbs.map
index 1827da0..7e722f4 100644
--- a/src/libibverbs.map
+++ b/src/libibverbs.map
@@ -96,4 +96,7 @@ IBVERBS_1.1 {
ibv_port_state_str;
ibv_event_type_str;
ibv_wc_status_str;
+
+ ibv_rate_to_mbps;
+ mbps_to_ibv_rate;
} IBVERBS_1.0;
diff --git a/src/verbs.c b/src/verbs.c
index b5938f2..a6aae70 100644
--- a/src/verbs.c
+++ b/src/verbs.c
@@ -76,6 +76,54 @@ enum ibv_rate mult_to_ibv_rate(int mult)
}
}
+int ibv_rate_to_mbps(enum ibv_rate rate)
+{
+ switch (rate) {
+ case IBV_RATE_2_5_GBPS: return 2500;
+ case IBV_RATE_5_GBPS: return 5000;
+ case IBV_RATE_10_GBPS: return 10000;
+ case IBV_RATE_20_GBPS: return 20000;
+ case IBV_RATE_30_GBPS: return 30000;
+ case IBV_RATE_40_GBPS: return 40000;
+ case IBV_RATE_60_GBPS: return 60000;
+ case IBV_RATE_80_GBPS: return 80000;
+ case IBV_RATE_120_GBPS: return 120000;
+ case IBV_RATE_14_GBPS: return 14062;
+ case IBV_RATE_56_GBPS: return 56250;
+ case IBV_RATE_112_GBPS: return 112500;
+ case IBV_RATE_168_GBPS: return 168750;
+ case IBV_RATE_25_GBPS: return 25781;
+ case IBV_RATE_100_GBPS: return 103125;
+ case IBV_RATE_200_GBPS: return 206250;
+ case IBV_RATE_300_GBPS: return 309375;
+ default: return -1;
+ }
+}
+
+enum ibv_rate mbps_to_ibv_rate(int mbps)
+{
+ switch (mbps) {
+ case 2500: return IBV_RATE_2_5_GBPS;
+ case 5000: return IBV_RATE_5_GBPS;
+ case 10000: return IBV_RATE_10_GBPS;
+ case 20000: return IBV_RATE_20_GBPS;
+ case 30000: return IBV_RATE_30_GBPS;
+ case 40000: return IBV_RATE_40_GBPS;
+ case 60000: return IBV_RATE_60_GBPS;
+ case 80000: return IBV_RATE_80_GBPS;
+ case 120000: return IBV_RATE_120_GBPS;
+ case 14062: return IBV_RATE_14_GBPS;
+ case 56250: return IBV_RATE_56_GBPS;
+ case 112500: return IBV_RATE_112_GBPS;
+ case 168750: return IBV_RATE_168_GBPS;
+ case 25781: return IBV_RATE_25_GBPS;
+ case 103125: return IBV_RATE_100_GBPS;
+ case 206250: return IBV_RATE_200_GBPS;
+ case 309375: return IBV_RATE_300_GBPS;
+ default: return IBV_RATE_MAX;
+ }
+}
+
int __ibv_query_device(struct ibv_context *context,
struct ibv_device_attr *device_attr)
{
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH libibverbs 3/3] Fix resource leaks in the pingpong examples present in the failure/error flows.
[not found] ` <1348173034-11929-1-git-send-email-ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
2012-09-20 20:30 ` [PATCH libibverbs 1/3] Add raw packet QP type Or Gerlitz
2012-09-20 20:30 ` [PATCH libibverbs 2/3] Add helpers to deal with new InfiniBand link speeds Or Gerlitz
@ 2012-09-20 20:30 ` Or Gerlitz
2 siblings, 0 replies; 5+ messages in thread
From: Or Gerlitz @ 2012-09-20 20:30 UTC (permalink / raw)
To: roland-DgEjT+Ai2ygdnm+yROfE0A
Cc: linux-rdma-u79uwXL29TY76Z2rM5mHXA, Dotan Barak, Or Gerlitz
From: Dotan Barak <dotanb-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
Signed-off-by: Dotan Barak <dotanb-LDSdmyG8hGV8YrgS2mwiifqBs+8SCbDb@public.gmane.org>
Signed-off-by: Or Gerlitz <ogerlitz-VPRAkNaXOzVWk0Htik3J/w@public.gmane.org>
---
examples/rc_pingpong.c | 43 ++++++++++++++++++++++++++++++++-------
examples/srq_pingpong.c | 51 ++++++++++++++++++++++++++++++++++++++--------
examples/uc_pingpong.c | 43 ++++++++++++++++++++++++++++++++-------
examples/ud_pingpong.c | 43 ++++++++++++++++++++++++++++++++-------
4 files changed, 147 insertions(+), 33 deletions(-)
diff --git a/examples/rc_pingpong.c b/examples/rc_pingpong.c
index 0b7f3e0..15494a1 100644
--- a/examples/rc_pingpong.c
+++ b/examples/rc_pingpong.c
@@ -325,7 +325,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->buf = memalign(page_size, size);
if (!ctx->buf) {
fprintf(stderr, "Couldn't allocate work buf.\n");
- return NULL;
+ goto clean_ctx;
}
/* FIXME memset(ctx->buf, 0, size); */
@@ -335,14 +335,14 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
if (!ctx->context) {
fprintf(stderr, "Couldn't get context for %s\n",
ibv_get_device_name(ib_dev));
- return NULL;
+ goto clean_buffer;
}
if (use_event) {
ctx->channel = ibv_create_comp_channel(ctx->context);
if (!ctx->channel) {
fprintf(stderr, "Couldn't create completion channel\n");
- return NULL;
+ goto clean_device;
}
} else
ctx->channel = NULL;
@@ -350,20 +350,20 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->pd = ibv_alloc_pd(ctx->context);
if (!ctx->pd) {
fprintf(stderr, "Couldn't allocate PD\n");
- return NULL;
+ goto clean_comp_channel;
}
ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size, IBV_ACCESS_LOCAL_WRITE);
if (!ctx->mr) {
fprintf(stderr, "Couldn't register MR\n");
- return NULL;
+ goto clean_pd;
}
ctx->cq = ibv_create_cq(ctx->context, rx_depth + 1, NULL,
ctx->channel, 0);
if (!ctx->cq) {
fprintf(stderr, "Couldn't create CQ\n");
- return NULL;
+ goto clean_mr;
}
{
@@ -382,7 +382,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->qp = ibv_create_qp(ctx->pd, &attr);
if (!ctx->qp) {
fprintf(stderr, "Couldn't create QP\n");
- return NULL;
+ goto clean_cq;
}
}
@@ -400,11 +400,38 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
IBV_QP_PORT |
IBV_QP_ACCESS_FLAGS)) {
fprintf(stderr, "Failed to modify QP to INIT\n");
- return NULL;
+ goto clean_qp;
}
}
return ctx;
+
+clean_qp:
+ ibv_destroy_qp(ctx->qp);
+
+clean_cq:
+ ibv_destroy_cq(ctx->cq);
+
+clean_mr:
+ ibv_dereg_mr(ctx->mr);
+
+clean_pd:
+ ibv_dealloc_pd(ctx->pd);
+
+clean_comp_channel:
+ if (ctx->channel)
+ ibv_destroy_comp_channel(ctx->channel);
+
+clean_device:
+ ibv_close_device(ctx->context);
+
+clean_buffer:
+ free(ctx->buf);
+
+clean_ctx:
+ free(ctx);
+
+ return NULL;
}
int pp_close_ctx(struct pingpong_context *ctx)
diff --git a/examples/srq_pingpong.c b/examples/srq_pingpong.c
index 298dca4..6e00f8c 100644
--- a/examples/srq_pingpong.c
+++ b/examples/srq_pingpong.c
@@ -357,7 +357,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->buf = memalign(page_size, size);
if (!ctx->buf) {
fprintf(stderr, "Couldn't allocate work buf.\n");
- return NULL;
+ goto clean_ctx;
}
memset(ctx->buf, 0, size);
@@ -366,14 +366,14 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
if (!ctx->context) {
fprintf(stderr, "Couldn't get context for %s\n",
ibv_get_device_name(ib_dev));
- return NULL;
+ goto clean_buffer;
}
if (use_event) {
ctx->channel = ibv_create_comp_channel(ctx->context);
if (!ctx->channel) {
fprintf(stderr, "Couldn't create completion channel\n");
- return NULL;
+ goto clean_device;
}
} else
ctx->channel = NULL;
@@ -381,20 +381,20 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->pd = ibv_alloc_pd(ctx->context);
if (!ctx->pd) {
fprintf(stderr, "Couldn't allocate PD\n");
- return NULL;
+ goto clean_comp_channel;
}
ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size, IBV_ACCESS_LOCAL_WRITE);
if (!ctx->mr) {
fprintf(stderr, "Couldn't register MR\n");
- return NULL;
+ goto clean_pd;
}
ctx->cq = ibv_create_cq(ctx->context, rx_depth + num_qp, NULL,
ctx->channel, 0);
if (!ctx->cq) {
fprintf(stderr, "Couldn't create CQ\n");
- return NULL;
+ goto clean_mr;
}
{
@@ -408,7 +408,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->srq = ibv_create_srq(ctx->pd, &attr);
if (!ctx->srq) {
fprintf(stderr, "Couldn't create SRQ\n");
- return NULL;
+ goto clean_cq;
}
}
@@ -427,7 +427,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->qp[i] = ibv_create_qp(ctx->pd, &attr);
if (!ctx->qp[i]) {
fprintf(stderr, "Couldn't create QP[%d]\n", i);
- return NULL;
+ goto clean_qps;
}
}
@@ -445,11 +445,44 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
IBV_QP_PORT |
IBV_QP_ACCESS_FLAGS)) {
fprintf(stderr, "Failed to modify QP[%d] to INIT\n", i);
- return NULL;
+ goto clean_qps_full;
}
}
return ctx;
+
+clean_qps_full:
+ i = num_qp;
+
+clean_qps:
+ for (--i; i >= 0; --i)
+ ibv_destroy_qp(ctx->qp[i]);
+
+ ibv_destroy_srq(ctx->srq);
+
+clean_cq:
+ ibv_destroy_cq(ctx->cq);
+
+clean_mr:
+ ibv_dereg_mr(ctx->mr);
+
+clean_pd:
+ ibv_dealloc_pd(ctx->pd);
+
+clean_comp_channel:
+ if (ctx->channel)
+ ibv_destroy_comp_channel(ctx->channel);
+
+clean_device:
+ ibv_close_device(ctx->context);
+
+clean_buffer:
+ free(ctx->buf);
+
+clean_ctx:
+ free(ctx);
+
+ return NULL;
}
int pp_close_ctx(struct pingpong_context *ctx, int num_qp)
diff --git a/examples/uc_pingpong.c b/examples/uc_pingpong.c
index 4c3fa32..52c6c28 100644
--- a/examples/uc_pingpong.c
+++ b/examples/uc_pingpong.c
@@ -313,7 +313,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->buf = memalign(page_size, size);
if (!ctx->buf) {
fprintf(stderr, "Couldn't allocate work buf.\n");
- return NULL;
+ goto clean_ctx;
}
/* FIXME memset(ctx->buf, 0, size); */
@@ -323,14 +323,14 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
if (!ctx->context) {
fprintf(stderr, "Couldn't get context for %s\n",
ibv_get_device_name(ib_dev));
- return NULL;
+ goto clean_buffer;
}
if (use_event) {
ctx->channel = ibv_create_comp_channel(ctx->context);
if (!ctx->channel) {
fprintf(stderr, "Couldn't create completion channel\n");
- return NULL;
+ goto clean_device;
}
} else
ctx->channel = NULL;
@@ -338,20 +338,20 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->pd = ibv_alloc_pd(ctx->context);
if (!ctx->pd) {
fprintf(stderr, "Couldn't allocate PD\n");
- return NULL;
+ goto clean_comp_channel;
}
ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size, IBV_ACCESS_LOCAL_WRITE);
if (!ctx->mr) {
fprintf(stderr, "Couldn't register MR\n");
- return NULL;
+ goto clean_pd;
}
ctx->cq = ibv_create_cq(ctx->context, rx_depth + 1, NULL,
ctx->channel, 0);
if (!ctx->cq) {
fprintf(stderr, "Couldn't create CQ\n");
- return NULL;
+ goto clean_mr;
}
{
@@ -370,7 +370,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->qp = ibv_create_qp(ctx->pd, &attr);
if (!ctx->qp) {
fprintf(stderr, "Couldn't create QP\n");
- return NULL;
+ goto clean_cq;
}
}
@@ -388,11 +388,38 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
IBV_QP_PORT |
IBV_QP_ACCESS_FLAGS)) {
fprintf(stderr, "Failed to modify QP to INIT\n");
- return NULL;
+ goto clean_qp;
}
}
return ctx;
+
+clean_qp:
+ ibv_destroy_qp(ctx->qp);
+
+clean_cq:
+ ibv_destroy_cq(ctx->cq);
+
+clean_mr:
+ ibv_dereg_mr(ctx->mr);
+
+clean_pd:
+ ibv_dealloc_pd(ctx->pd);
+
+clean_comp_channel:
+ if (ctx->channel)
+ ibv_destroy_comp_channel(ctx->channel);
+
+clean_device:
+ ibv_close_device(ctx->context);
+
+clean_buffer:
+ free(ctx->buf);
+
+clean_ctx:
+ free(ctx);
+
+ return NULL;
}
int pp_close_ctx(struct pingpong_context *ctx)
diff --git a/examples/ud_pingpong.c b/examples/ud_pingpong.c
index 71b152d..c279ddb 100644
--- a/examples/ud_pingpong.c
+++ b/examples/ud_pingpong.c
@@ -311,7 +311,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->buf = memalign(page_size, size + 40);
if (!ctx->buf) {
fprintf(stderr, "Couldn't allocate work buf.\n");
- return NULL;
+ goto clean_ctx;
}
/* FIXME memset(ctx->buf, 0, size + 40); */
@@ -321,14 +321,14 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
if (!ctx->context) {
fprintf(stderr, "Couldn't get context for %s\n",
ibv_get_device_name(ib_dev));
- return NULL;
+ goto clean_buffer;
}
if (use_event) {
ctx->channel = ibv_create_comp_channel(ctx->context);
if (!ctx->channel) {
fprintf(stderr, "Couldn't create completion channel\n");
- return NULL;
+ goto clean_device;
}
} else
ctx->channel = NULL;
@@ -336,20 +336,20 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->pd = ibv_alloc_pd(ctx->context);
if (!ctx->pd) {
fprintf(stderr, "Couldn't allocate PD\n");
- return NULL;
+ goto clean_comp_channel;
}
ctx->mr = ibv_reg_mr(ctx->pd, ctx->buf, size + 40, IBV_ACCESS_LOCAL_WRITE);
if (!ctx->mr) {
fprintf(stderr, "Couldn't register MR\n");
- return NULL;
+ goto clean_pd;
}
ctx->cq = ibv_create_cq(ctx->context, rx_depth + 1, NULL,
ctx->channel, 0);
if (!ctx->cq) {
fprintf(stderr, "Couldn't create CQ\n");
- return NULL;
+ goto clean_mr;
}
{
@@ -368,7 +368,7 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
ctx->qp = ibv_create_qp(ctx->pd, &attr);
if (!ctx->qp) {
fprintf(stderr, "Couldn't create QP\n");
- return NULL;
+ goto clean_cq;
}
}
@@ -386,11 +386,38 @@ static struct pingpong_context *pp_init_ctx(struct ibv_device *ib_dev, int size,
IBV_QP_PORT |
IBV_QP_QKEY)) {
fprintf(stderr, "Failed to modify QP to INIT\n");
- return NULL;
+ goto clean_qp;
}
}
return ctx;
+
+clean_qp:
+ ibv_destroy_qp(ctx->qp);
+
+clean_cq:
+ ibv_destroy_cq(ctx->cq);
+
+clean_mr:
+ ibv_dereg_mr(ctx->mr);
+
+clean_pd:
+ ibv_dealloc_pd(ctx->pd);
+
+clean_comp_channel:
+ if (ctx->channel)
+ ibv_destroy_comp_channel(ctx->channel);
+
+clean_device:
+ ibv_close_device(ctx->context);
+
+clean_buffer:
+ free(ctx->buf);
+
+clean_ctx:
+ free(ctx);
+
+ return NULL;
}
int pp_close_ctx(struct pingpong_context *ctx)
--
1.7.1
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 5+ messages in thread