From patchwork Tue Mar 26 19:18:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Wise X-Patchwork-Id: 10872127 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 30F3D925 for ; Tue, 26 Mar 2019 19:39:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D22328C37 for ; Tue, 26 Mar 2019 19:39:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FE0E28C50; Tue, 26 Mar 2019 19:39:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA26F28C37 for ; Tue, 26 Mar 2019 19:39:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732019AbfCZTjf (ORCPT ); Tue, 26 Mar 2019 15:39:35 -0400 Received: from linode.aoot.com ([69.164.194.13]:46586 "EHLO linode.aoot.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730449AbfCZTjf (ORCPT ); Tue, 26 Mar 2019 15:39:35 -0400 Received: from work.aoot.com.com (li1110-136.members.linode.com [45.79.11.136]) by linode.aoot.com (Postfix) with ESMTP id 9A5F787BC; Tue, 26 Mar 2019 14:19:16 -0500 (CDT) From: Steve Wise To: dsahern@gmail.com, leon@kernel.org Cc: Steve Wise , stephen@networkplumber.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH v2 iproute2-next 2/4] rdma: add helper rd_sendrecv_msg() Date: Tue, 26 Mar 2019 14:18:28 -0500 Message-Id: <06a2302a1dc575a0829a5b789bb7a412adb2ce95.1553627811.git.larrystevenwise@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This function sends the constructed netlink message and then receives the response. Change rd_recv_msg() to display any error messages. Change 'rdma dev set' to use rd_sendrecv_msg(). Signed-off-by: Steve Wise Reviewed-by: Leon Romanovsky --- rdma/dev.c | 2 +- rdma/rdma.h | 2 ++ rdma/res.h | 1 + rdma/utils.c | 18 ++++++++++++++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/rdma/dev.c b/rdma/dev.c index 954e0015..33962520 100644 --- a/rdma/dev.c +++ b/rdma/dev.c @@ -268,7 +268,7 @@ static int dev_set_name(struct rd *rd) mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_DEV_INDEX, rd->dev_idx); mnl_attr_put_strz(rd->nlh, RDMA_NLDEV_ATTR_DEV_NAME, rd_argv(rd)); - return rd_send_msg(rd); + return rd_sendrecv_msg(rd, seq); } static int dev_one_set(struct rd *rd) diff --git a/rdma/rdma.h b/rdma/rdma.h index 1022e9a2..6c7f7d15 100644 --- a/rdma/rdma.h +++ b/rdma/rdma.h @@ -68,6 +68,7 @@ struct rd { json_writer_t *jw; bool json_output; bool pretty_output; + bool suppress_errors; struct list_head filter_list; }; @@ -119,6 +120,7 @@ bool rd_is_string_filtered_attr(struct rd *rd, const char *key, const char *val, */ int rd_send_msg(struct rd *rd); int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, uint32_t seq); +int rd_sendrecv_msg(struct rd *rd, unsigned int seq); void rd_prepare_msg(struct rd *rd, uint32_t cmd, uint32_t *seq, uint16_t flags); int rd_dev_init_cb(const struct nlmsghdr *nlh, void *data); int rd_attr_cb(const struct nlattr *attr, void *data); diff --git a/rdma/res.h b/rdma/res.h index b4a7e552..525171fc 100644 --- a/rdma/res.h +++ b/rdma/res.h @@ -31,6 +31,7 @@ int res_qp_idx_parse_cb(const struct nlmsghdr *nlh, void *data); if (id) { \ ret = rd_doit_index(rd, &idx); \ if (ret) { \ + rd->suppress_errors = true; \ ret = _res_send_idx_msg(rd, command, \ name##_idx_parse_cb, \ idx, id); \ diff --git a/rdma/utils.c b/rdma/utils.c index 1f6bf330..11ed8a73 100644 --- a/rdma/utils.c +++ b/rdma/utils.c @@ -693,10 +693,28 @@ int rd_recv_msg(struct rd *rd, mnl_cb_t callback, void *data, unsigned int seq) ret = mnl_cb_run(buf, ret, seq, portid, callback, data); } while (ret > 0); + if (ret < 0 && !rd->suppress_errors) + perror("error"); + mnl_socket_close(rd->nl); return ret; } +static int null_cb(const struct nlmsghdr *nlh, void *data) +{ + return MNL_CB_OK; +} + +int rd_sendrecv_msg(struct rd *rd, unsigned int seq) +{ + int ret; + + ret = rd_send_msg(rd); + if (!ret) + ret = rd_recv_msg(rd, null_cb, rd, seq); + return ret; +} + static struct dev_map *_dev_map_lookup(struct rd *rd, const char *dev_name) { struct dev_map *dev_map;