From patchwork Wed Feb 14 21:07:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Wise X-Patchwork-Id: 10228827 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 38C86602B7 for ; Mon, 19 Feb 2018 20:13:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 299E62866F for ; Mon, 19 Feb 2018 20:13:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E42328B7B; Mon, 19 Feb 2018 20:13:02 +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=-3.5 required=2.0 tests=BAYES_00, DATE_IN_PAST_96_XX, 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 7F0B32866F for ; Mon, 19 Feb 2018 20:13:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932095AbeBSUMz (ORCPT ); Mon, 19 Feb 2018 15:12:55 -0500 Received: from opengridcomputing.com ([70.118.0.34]:48979 "EHLO smtp.opengridcomputing.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932066AbeBSUMy (ORCPT ); Mon, 19 Feb 2018 15:12:54 -0500 Received: by smtp.opengridcomputing.com (Postfix, from userid 503) id B62822B977; Mon, 19 Feb 2018 14:12:53 -0600 (CST) Message-Id: In-Reply-To: References: From: Steve Wise Date: Wed, 14 Feb 2018 13:07:01 -0800 Subject: [PATCH RFC iproute-next 5/5] rdma: Add PD resource tracking information To: dsahern@gmail.com Cc: leon@kernel.org, stephen@networkplumber.org, netdev@vger.kernel.org, linux-rdma@vger.kernel.org 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 Sample output: # rdma resource show pd link cxgb4_0/- local_dma_lkey 0x0 usecnt 4 flags 0x0 pid 30503 comm rping link cxgb4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30488 comm rping link cxgb4_0/- local_dma_lkey 0x0 usecnt 5 flags 0x0 pid 30498 comm rping link cxgb4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30501 comm rping link cxgb4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 0 comm [ib_srp] link mlx4_0/- local_dma_lkey 0x0 usecnt 4 flags 0x0 pid 30494 comm rping link mlx4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30488 comm rping link mlx4_0/- local_dma_lkey 0x0 usecnt 5 flags 0x0 pid 30489 comm rping link mlx4_0/- local_dma_lkey 0x0 usecnt 0 flags 0x0 pid 30492 comm rping link mlx4_0/- local_dma_lkey 0x8000 usecnt 0 flags 0x0 pid 0 comm [ib_srpt] link mlx4_0/- local_dma_lkey 0x8000 usecnt 0 flags 0x0 pid 0 comm [ib_srp] link mlx4_0/- local_dma_lkey 0x8000 usecnt 1 flags 0x0 pid 0 comm [ib_core] Signed-off-by: Steve Wise --- rdma/res.c | 96 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/rdma/res.c b/rdma/res.c index 2b67d25..5e6bc42 100644 --- a/rdma/res.c +++ b/rdma/res.c @@ -932,6 +932,93 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data) return MNL_CB_OK; } +static void print_flags(struct rd *rd, uint32_t val) +{ + if (rd->json_output) + jsonw_xint_field(rd->jw, "flags", val); + else + pr_out("flags 0x%x ", val); +} + +static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) +{ + struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {}; + struct nlattr *nla_table, *nla_entry; + struct rd *rd = data; + const char *name; + uint32_t idx; + + mnl_attr_parse(nlh, 0, rd_attr_cb, tb); + if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || + !tb[RDMA_NLDEV_ATTR_DEV_NAME] || + !tb[RDMA_NLDEV_ATTR_RES_PD]) + return MNL_CB_ERROR; + + name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]); + idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]); + nla_table = tb[RDMA_NLDEV_ATTR_RES_PD]; + + mnl_attr_for_each_nested(nla_entry, nla_table) { + struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX] = {}; + uint32_t local_dma_lkey, unsafe_global_rkey = 0; + uint32_t flags, pid = 0; + char *comm = NULL; + uint64_t usecnt; + int err; + + err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, nla_line); + if (err != MNL_CB_OK) + return MNL_CB_ERROR; + + if (!nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY] || + !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] || + !nla_line[RDMA_NLDEV_ATTR_RES_PD_FLAGS] || + (!nla_line[RDMA_NLDEV_ATTR_RES_PID] && + !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME])) { + return MNL_CB_ERROR; + } + + local_dma_lkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); + usecnt = mnl_attr_get_u64(nla_line[RDMA_NLDEV_ATTR_RES_USECNT]); + flags = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PD_FLAGS]); + if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) + unsafe_global_rkey = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]); + + if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) { + pid = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_PID]); + comm = get_task_name(pid); + } + + if (rd_check_is_filtered(rd, "pid", pid)) + continue; + + if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]) + /* discard const from mnl_attr_get_str */ + comm = (char *)mnl_attr_get_str(nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME]); + + if (rd->json_output) + jsonw_start_array(rd->jw); + + print_link(rd, idx, name, 0, nla_line); + print_key(rd, "local_dma_lkey", local_dma_lkey); + print_usecnt(rd, usecnt); + print_flags(rd, flags); + if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY]) + print_key(rd, "unsafe_global_rkey", unsafe_global_rkey); + print_pid(rd, pid); + print_comm(rd, comm, nla_line); + + if (nla_line[RDMA_NLDEV_ATTR_RES_PID]) + free(comm); + + if (rd->json_output) + jsonw_end_array(rd->jw); + else + pr_out("\n"); + } + return MNL_CB_OK; +} + RES_FUNC(res_no_args, RDMA_NLDEV_CMD_RES_GET, NULL, true); static const struct @@ -1005,6 +1092,14 @@ filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {{ .name = "link", RES_FUNC(res_mr, RDMA_NLDEV_CMD_RES_MR_GET, mr_valid_filters, true); +static const struct +filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {{ .name = "link", + .is_number = false }, + { .name = "pid", + .is_number = true }}; + +RES_FUNC(res_pd, RDMA_NLDEV_CMD_RES_PD_GET, pd_valid_filters, true); + static int res_show(struct rd *rd) { const struct rd_cmd cmds[] = { @@ -1013,6 +1108,7 @@ static int res_show(struct rd *rd) { "cm_id", res_cm_id }, { "cq", res_cq }, { "mr", res_mr }, + { "pd", res_pd }, { 0 } };