From 700ceeda49005df6e204385c0f8522e5c2772c54 Mon Sep 17 00:00:00 2001 From: Sean Hefty Date: Fri, 20 Apr 2007 15:16:07 -0700 Subject: [PATCH] librdmacm: update datagram tests to abort if msg size > MTU If the user specifies a message size for mckey or udaddy tests that's larger than the active MTU of the bound port, the sends will fail. Detect this condition and abort the test if the message size is > the active MTU of the port. Signed-off-by: Sean Hefty --- examples/mckey.c | 25 ++++++++++++++++++++++++- examples/udaddy.c | 27 +++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/examples/mckey.c b/examples/mckey.c index 90d0873b..24514a4b 100644 --- a/examples/mckey.c +++ b/examples/mckey.c @@ -108,6 +108,25 @@ err: return -1; } +static int verify_test_params(struct cmatest_node *node) +{ + struct ibv_port_attr port_attr; + int ret; + + ret = ibv_query_port(node->cma_id->verbs, node->cma_id->port_num, + &port_attr); + if (ret) + return ret; + + if (message_count && message_size > (1 << (port_attr.active_mtu + 7))) { + printf("mckey: message_size %d is larger than active mtu %d\n", + message_size, 1 << (port_attr.active_mtu + 7)); + return -EINVAL; + } + + return 0; +} + static int init_node(struct cmatest_node *node) { struct ibv_qp_init_attr init_qp_attr; @@ -208,7 +227,7 @@ static int post_sends(struct cmatest_node *node, int signal_flag) for (i = 0; i < message_count && !ret; i++) { ret = ibv_post_send(node->cma_id->qp, &send_wr, &bad_send_wr); - if (ret) + if (ret) printf("failed to post sends: %d\n", ret); } return ret; @@ -223,6 +242,10 @@ static int addr_handler(struct cmatest_node *node) { int ret; + ret = verify_test_params(node); + if (ret) + goto err; + ret = init_node(node); if (ret) goto err; diff --git a/examples/udaddy.c b/examples/udaddy.c index 91862751..84ff16bc 100644 --- a/examples/udaddy.c +++ b/examples/udaddy.c @@ -104,6 +104,25 @@ err: return -1; } +static int verify_test_params(struct cmatest_node *node) +{ + struct ibv_port_attr port_attr; + int ret; + + ret = ibv_query_port(node->cma_id->verbs, node->cma_id->port_num, + &port_attr); + if (ret) + return ret; + + if (message_count && message_size > (1 << (port_attr.active_mtu + 7))) { + printf("udaddy: message_size %d is larger than active mtu %d\n", + message_size, 1 << (port_attr.active_mtu + 7)); + return -EINVAL; + } + + return 0; +} + static int init_node(struct cmatest_node *node) { struct ibv_qp_init_attr init_qp_attr; @@ -232,6 +251,10 @@ static int route_handler(struct cmatest_node *node) struct rdma_conn_param conn_param; int ret; + ret = verify_test_params(node); + if (ret) + goto err; + ret = init_node(node); if (ret) goto err; @@ -269,6 +292,10 @@ static int connect_handler(struct rdma_cm_id *cma_id) node->cma_id = cma_id; cma_id->context = node; + ret = verify_test_params(node); + if (ret) + goto err2; + ret = init_node(node); if (ret) goto err2; -- 2.41.0