Export object IDs to users
Subsystems (3)
cover Export object IDs to users
From: Leon Romanovsky <[email protected]>
Hi,
This is complementary part of two RDMA kernel series (not accepted yet).
https://patchwork.kernel.org/project/linux-rdma/list/?series=69901
https://patchwork.kernel.org/project/linux-rdma/list/?series=69903
This series add those IDs, refactor code and unifies "resource" command implementation.
Thanks
Leon Romanovsky (19):
rdma: update uapi headers
rdma: Remove duplicated print code
rdma: Provide unique indexes for all visible objects
rdma: Provide parent context index for all objects except CM_ID
rdma: Move resource PD logic to separate file
rdma: Refactor out resource MR logic to separate file
rdma: Move out resource CQ logic to separate file
rdma: Move out resource CM-ID logic to separate file
rdma: Move resource PD logic to separate file
rdma: Properly mark RDMAtool license
rdma: Simplify code to reuse existing functions
rdma: Simplify CM_ID print code
rdma: Refactor CQ prints
rdma: Separate MR code
rdma: Separate PD code
rdma: Move QP code to separate function
rdma: Unify netlink attribute checks prior to prints
rdma: Perform single .doit call to query specific objects
rdma: Provide and reuse filter functions
rdma/Makefile | 5 +- rdma/dev.c | 7 +- rdma/include/uapi/rdma/rdma_netlink.h | 10 + rdma/link.c | 7 +- rdma/rdma.c | 7 +- rdma/rdma.h | 24 +- rdma/res-cmid.c | 275 ++++++++ rdma/res-cq.c | 160 +++++ rdma/res-mr.c | 133 ++++ rdma/res-pd.c | 136 ++++ rdma/res-qp.c | 240 +++++++ rdma/res.c | 932 ++------------------------ rdma/res.h | 148 ++++ rdma/utils.c | 53 +- 14 files changed, 1217 insertions(+), 920 deletions(-) create mode 100644 rdma/res-cmid.c create mode 100644 rdma/res-cq.c create mode 100644 rdma/res-mr.c create mode 100644 rdma/res-pd.c create mode 100644 rdma/res-qp.c create mode 100644 rdma/res.h
PATCH 1/19 rdma: update uapi headers
From: Leon Romanovsky <[email protected]>
--- rdma/include/uapi/rdma/rdma_netlink.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
rdma/include/uapi/rdma/rdma_netlink.h +10 -0
@@ -430,6 +430,16 @@ enum rdma_nldev_attr {RDMA_NLDEV_ATTR_DRIVER_S64 ,/* s64 */ RDMA_NLDEV_ATTR_DRIVER_U64 ,/* u64 */ +/* +* Indexes to get/set secific entry, +* for QP use RDMA_NLDEV_ATTR_RES_LQPN +*/ +RDMA_NLDEV_ATTR_RES_PDN ,/* u32 */ +RDMA_NLDEV_ATTR_RES_CQN ,/* u32 */ +RDMA_NLDEV_ATTR_RES_MRN ,/* u32 */ +RDMA_NLDEV_ATTR_RES_CM_IDN ,/* u32 */ +RDMA_NLDEV_ATTR_RES_CTXN ,/* u32 */ +/* * Always the end */
Signature · 1 line
2.19.1
PATCH 2/19 rdma: Remove duplicated print code
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
There is no need to keep same print functions for uint32_t and uint64_t, unify them into one function.
--- rdma/res.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-)
rdma/res.c +7 -15
@@ -808,28 +808,20 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)return MNL_CB_OK ; } -static void print_key (struct rd *rd,const char *name,uint32_t val) +static void print_key (struct rd *rd,const char *name,uint64_t val) {if (rd->json_output)jsonw_xint_field (rd->jw, name, val);else -pr_out ("%s 0x%x " , name, val); +pr_out ("%s 0x%" PRIx64" " , name, val); } -static void print_iova (struct rd *rd,uint64_t val) +static void res_print_uint (struct rd *rd,const char *name,uint64_t val) {if (rd->json_output) -jsonw_xint_field (rd->jw,"iova" , val); +jsonw_uint_field (rd->jw, name, val);else -pr_out ("iova 0x%" PRIx64" " , val); -} - -static void print_mrlen (struct rd *rd,uint64_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw,"mrlen" , val); -else -pr_out ("mrlen %" PRIu64" " , val); +pr_out ("%s %" PRIu64" " , name, val); }static int res_mr_parse_cb (const struct nlmsghdr *nlh,void *data)
@@ -907,8 +899,8 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY ])print_key (rd,"lkey" , lkey);if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]) -print_iova (rd, iova); -print_mrlen (rd, mrlen); +print_key (rd,"iova" , iova); +res_print_uint (rd,"mrlen" , mrlen);print_pid (rd, pid);print_comm (rd, comm, nla_line);
Signature · 1 line
2.19.1
PATCH 3/19 rdma: Provide unique indexes for all visible objects
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
--- rdma/res.c | 83 +++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 63 insertions(+), 20 deletions(-)
rdma/res.c +63 -20
@@ -549,6 +549,22 @@ static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port)return 0 ; } +static void print_key (struct rd *rd,const char *name,uint64_t val) +{ +if (rd->json_output) +jsonw_xint_field (rd->jw, name, val); +else +pr_out ("%s 0x%" PRIx64" " , name, val); +} + +static void res_print_uint (struct rd *rd,const char *name,uint64_t val) +{ +if (rd->json_output) +jsonw_uint_field (rd->jw, name, val); +else +pr_out ("%s %" PRIu64" " , name, val); +} +static int res_cm_id_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -574,6 +590,7 @@ static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)uint32_t port =0 , pid =0 ;uint8_t type =0 , state;uint32_t lqpn =0 , ps; +uint32_t cm_idn =0 ;char *comm =NULL ;int err;
@@ -651,6 +668,12 @@ static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)continue ; } +if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]) + cm_idn =mnl_attr_get_u32 ( + nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]); +if (rd_check_is_filtered (rd,"cm-idn" , cm_idn)) +continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ]) {/* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str(
@@ -669,6 +692,8 @@ static int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)print_ps (rd, ps);print_pid (rd, pid);print_comm (rd, comm, nla_line); +if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]) +res_print_uint (rd,"cm-idn" , cm_idn);if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ])print_ipaddr (rd,"src-addr" , src_addr_str, src_port);
@@ -743,6 +768,7 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)char *comm =NULL ;uint32_t pid =0 ;uint8_t poll_ctx =0 ; +uint32_t cqn =0 ;uint64_t users;uint32_t cqe;int err;
@@ -783,6 +809,12 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)continue ; } +if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) + cqn =mnl_attr_get_u32 ( + nla_line[RDMA_NLDEV_ATTR_RES_CQN ]); +if (rd_check_is_filtered (rd,"cqn" , cqn)) +continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])/* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str(
@@ -799,6 +831,9 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)print_pid (rd, pid);print_comm (rd, comm, nla_line); +if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) +res_print_uint (rd,"cqn" , cqn); +if (nla_line[RDMA_NLDEV_ATTR_RES_PID ])free (comm);
@@ -808,22 +843,6 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)return MNL_CB_OK ; } -static void print_key (struct rd *rd,const char *name,uint64_t val) -{ -if (rd->json_output) -jsonw_xint_field (rd->jw, name, val); -else -pr_out ("%s 0x%" PRIx64" " , name, val); -} - -static void res_print_uint (struct rd *rd,const char *name,uint64_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw, name, val); -else -pr_out ("%s %" PRIu64" " , name, val); -} -static int res_mr_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -847,6 +866,7 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)uint32_t rkey =0 , lkey =0 ;uint64_t iova =0 , mrlen;char *comm =NULL ; +uint32_t mrn =0 ;uint32_t pid =0 ;int err;
@@ -885,6 +905,12 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)continue ; } +if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) + mrn =mnl_attr_get_u32 ( + nla_line[RDMA_NLDEV_ATTR_RES_MRN ]); +if (rd_check_is_filtered (rd,"mrn" , mrn)) +continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])/* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str(
@@ -904,6 +930,9 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)print_pid (rd, pid);print_comm (rd, comm, nla_line); +if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) +res_print_uint (rd,"mrn" , mrn); +if (nla_line[RDMA_NLDEV_ATTR_RES_PID ])free (comm);
@@ -936,6 +965,7 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {};char *comm =NULL ;uint32_t pid =0 ; +uint32_t pdn =0 ;uint64_t users;int err;
@@ -970,6 +1000,12 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)if (rd_check_is_filtered (rd,"pid" , pid))continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) + pdn =mnl_attr_get_u32 ( + nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +if (rd_check_is_filtered (rd,"pdn" , pdn)) +continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])/* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str(
@@ -987,6 +1023,9 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)print_pid (rd, pid);print_comm (rd, comm, nla_line); +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) +res_print_uint (rd,"pdn" , pdn); +if (nla_line[RDMA_NLDEV_ATTR_RES_PID ])free (comm);
@@ -1033,7 +1072,8 @@ struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = { { .name = "src-addr", .is_number = false }, { .name = "src-port", .is_number = true }, { .name = "dst-addr", .is_number = false }, - { .name = "dst-port", .is_number = true } + { .name = "dst-port", .is_number = true }, + { .name = "cm-idn", .is_number = true } };RES_FUNC (res_cm_id,RDMA_NLDEV_CMD_RES_CM_ID_GET , cm_id_valid_filters, false);
@@ -1043,7 +1083,8 @@ struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = { { .name = "dev", .is_number = false }, { .name = "users", .is_number = true }, { .name = "poll-ctx", .is_number = false }, - { .name = "pid", .is_number = true } + { .name = "pid", .is_number = true }, + { .name = "cqn", .is_number = true } };RES_FUNC (res_cq,RDMA_NLDEV_CMD_RES_CQ_GET , cq_valid_filters, true);
@@ -1054,7 +1095,8 @@ struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = { { .name = "rkey", .is_number = true }, { .name = "lkey", .is_number = true }, { .name = "mrlen", .is_number = true }, - { .name = "pid", .is_number = true } + { .name = "pid", .is_number = true }, + { .name = "mrn", .is_number = true } };RES_FUNC (res_mr,RDMA_NLDEV_CMD_RES_MR_GET , mr_valid_filters, true);
@@ -1063,7 +1105,8 @@ static conststruct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS ] = { { .name ="dev" , .is_number = false }, { .name ="users" , .is_number = true }, - { .name ="pid" , .is_number = true } + { .name ="pid" , .is_number = true }, + { .name ="pdn" , .is_number = true } };RES_FUNC (res_pd,RDMA_NLDEV_CMD_RES_PD_GET , pd_valid_filters, true);
Signature · 1 line
2.19.1
PATCH 4/19 rdma: Provide parent context index for all objects except CM_ID
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Allow users to correlate allocated object with relevant parent
[leonro@server ~]$ rdma res show pd
dev mlx5_0 users 5 pid 0 comm [ib_core] pdn 1
dev mlx5_0 users 7 pid 0 comm [ib_ipoib] pdn 2
dev mlx5_0 users 0 pid 0 comm [mlx5_ib] pdn 3
dev mlx5_0 users 2 pid 548 comm ibv_rc_pingpong ctxn 0 pdn 4
[leonro@server ~]$ rdma res show cq cqn 0-100
dev mlx5_0 cqe 2047 users 6 poll-ctx UNBOUND_WORKQUEUE pid 0 comm [ib_core] cqn 2 dev mlx5_0 cqe 255 users 2 poll-ctx SOFTIRQ pid 0 comm [mlx5_ib] cqn 3 dev mlx5_0 cqe 511 users 1 poll-ctx DIRECT pid 0 comm [ib_ipoib] cqn 4 dev mlx5_0 cqe 255 users 1 poll-ctx DIRECT pid 0 comm [ib_ipoib] cqn 5 dev mlx5_0 cqe 255 users 0 poll-ctx SOFTIRQ pid 0 comm [mlx5_ib] cqn 6 dev mlx5_0 cqe 511 users 2 pid 548 comm ibv_rc_pingpong cqn 7 ctxn 0
[leonro@server ~]$ rdma res show mr
dev mlx5_0 mrlen 4096 pid 548 comm ibv_rc_pingpong mrn 4 pdn 0
[leonro@nps-server-14-015 ~]$ /images/leonro/src/iproute2/rdma/rdma res show qp
link mlx5_0/1 lqpn 0 type SMI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_0/1 lqpn 1 type GSI state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_0/1 lqpn 7 type UD state RTS sq-psn 0 pid 0 comm [ib_core]
link mlx5_0/1 lqpn 8 type UD state RTS sq-psn 0 pid 0 comm [ib_ipoib]
link mlx5_0/1 lqpn 9 pdn 4 rqpn 0 type RC state INIT rq-psn 0 sq-psn 0 path-mig-state MIGRATED pid 548 comm ibv_rc_pingpong
--- rdma/res.c | 110 +++++++++++++++++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 38 deletions(-)
rdma/res.c +72 -38
@@ -320,6 +320,22 @@ static char *get_task_name(uint32_t pid)return comm; } +static void print_key (struct rd *rd,const char *name,uint64_t val) +{ +if (rd->json_output) +jsonw_xint_field (rd->jw, name, val); +else +pr_out ("%s 0x%" PRIx64" " , name, val); +} + +static void res_print_uint (struct rd *rd,const char *name,uint64_t val) +{ +if (rd->json_output) +jsonw_uint_field (rd->jw, name, val); +else +pr_out ("%s %" PRIu64" " , name, val); +} +static int res_qp_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -343,6 +359,7 @@ static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)uint32_t lqpn, rqpn =0 , rq_psn =0 , sq_psn;uint8_t type, state, path_mig_state =0 ;uint32_t port =0 , pid =0 ; +uint32_t pdn =0 ;char *comm =NULL ;int err;
@@ -369,6 +386,11 @@ static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)if (rd_check_is_filtered (rd,"lqpn" , lqpn))continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) + pdn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +if (rd_check_is_filtered (rd,"pdn" , pdn)) +continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN ]) { rqpn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_RQPN ]);if (rd_check_is_filtered (rd,"rqpn" , rqpn))
@@ -428,6 +450,8 @@ static int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)print_link (rd, idx, name, port, nla_line);print_lqpn (rd, lqpn); +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) +res_print_uint (rd,"pdn" , pdn);print_rqpn (rd, rqpn, nla_line);print_type (rd, type);
@@ -549,22 +573,6 @@ static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port)return 0 ; } -static void print_key (struct rd *rd,const char *name,uint64_t val) -{ -if (rd->json_output) -jsonw_xint_field (rd->jw, name, val); -else -pr_out ("%s 0x%" PRIx64" " , name, val); -} - -static void res_print_uint (struct rd *rd,const char *name,uint64_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw, name, val); -else -pr_out ("%s %" PRIu64" " , name, val); -} -static int res_cm_id_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -768,6 +776,7 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)char *comm =NULL ;uint32_t pid =0 ;uint8_t poll_ctx =0 ; +uint32_t ctxn =0 ;uint32_t cqn =0 ;uint64_t users;uint32_t cqe;
@@ -815,6 +824,12 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)if (rd_check_is_filtered (rd,"cqn" , cqn))continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) + ctxn =mnl_attr_get_u32 ( + nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); +if (rd_check_is_filtered (rd,"ctxn" , ctxn)) +continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])/* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str(
@@ -833,6 +848,8 @@ static int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ])res_print_uint (rd,"cqn" , cqn); +if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) +res_print_uint (rd,"ctxn" , ctxn);if (nla_line[RDMA_NLDEV_ATTR_RES_PID ])free (comm);
@@ -866,6 +883,7 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)uint32_t rkey =0 , lkey =0 ;uint64_t iova =0 , mrlen;char *comm =NULL ; +uint32_t pdn =0 ;uint32_t mrn =0 ;uint32_t pid =0 ;int err;
@@ -911,6 +929,12 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)if (rd_check_is_filtered (rd,"mrn" , mrn))continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) + pdn =mnl_attr_get_u32 ( + nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +if (rd_check_is_filtered (rd,"pdn" , pdn)) +continue ; +if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])/* discard const from mnl_attr_get_str */ comm = (char *)mnl_attr_get_str(
@@ -933,6 +957,9 @@ static int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ])res_print_uint (rd,"mrn" , mrn); +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) +res_print_uint (rd,"pdn" , pdn); +if (nla_line[RDMA_NLDEV_ATTR_RES_PID ])free (comm);
@@ -964,6 +991,7 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)uint32_t local_dma_lkey =0 , unsafe_global_rkey =0 ;struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {};char *comm =NULL ; +uint32_t ctxn =0 ;uint32_t pid =0 ;uint32_t pdn =0 ;uint64_t users;
@@ -997,7 +1025,13 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) comm =get_task_name (pid); } -if (rd_check_is_filtered (rd,"pid" , pid)) +if (rd_check_is_filtered (rd,"pid" , pid)) +continue ; + +if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) + ctxn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); + +if (rd_check_is_filtered (rd,"ctxn" , ctxn))continue ;if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ])
@@ -1022,6 +1056,8 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)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_CTXN ]) +res_print_uint (rd,"ctxn" , ctxn);if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ])res_print_uint (rd,"pdn" , pdn);
@@ -1038,24 +1074,18 @@ static int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)RES_FUNC (res_no_args,RDMA_NLDEV_CMD_RES_GET ,NULL , true);static const struct -filters qp_valid_filters[MAX_NUMBER_OF_FILTERS ] = {{ .name ="link" , - .is_number = false }, - { .name ="lqpn" , - .is_number = true }, - { .name ="rqpn" , - .is_number = true }, - { .name ="pid" , - .is_number = true }, - { .name ="sq-psn" , - .is_number = true }, - { .name ="rq-psn" , - .is_number = true }, - { .name ="type" , - .is_number = false }, - { .name ="path-mig-state" , - .is_number = false }, - { .name ="state" , - .is_number = false } }; +filters qp_valid_filters[MAX_NUMBER_OF_FILTERS ] = { + { .name ="link" , .is_number = false }, + { .name ="lqpn" , .is_number = true }, + { .name ="rqpn" , .is_number = true }, + { .name ="pid" , .is_number = true }, + { .name ="sq-psn" , .is_number = true }, + { .name ="rq-psn" , .is_number = true }, + { .name ="type" , .is_number = false }, + { .name ="path-mig-state" , .is_number = false }, + { .name ="state" , .is_number = false }, + { .name ="pdn" , .is_number = true }, +};RES_FUNC (res_qp,RDMA_NLDEV_CMD_RES_QP_GET , qp_valid_filters, false);
@@ -1084,7 +1114,8 @@ struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = { { .name = "users", .is_number = true }, { .name = "poll-ctx", .is_number = false }, { .name = "pid", .is_number = true }, - { .name = "cqn", .is_number = true } + { .name = "cqn", .is_number = true }, + { .name = "ctxn", .is_number = true } };RES_FUNC (res_cq,RDMA_NLDEV_CMD_RES_CQ_GET , cq_valid_filters, true);
@@ -1096,7 +1127,8 @@ struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = { { .name = "lkey", .is_number = true }, { .name = "mrlen", .is_number = true }, { .name = "pid", .is_number = true }, - { .name = "mrn", .is_number = true } + { .name = "mrn", .is_number = true }, + { .name = "pdn", .is_number = true } };RES_FUNC (res_mr,RDMA_NLDEV_CMD_RES_MR_GET , mr_valid_filters, true);
@@ -1106,7 +1138,9 @@ struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = { { .name = "dev", .is_number = false }, { .name = "users", .is_number = true }, { .name = "pid", .is_number = true }, - { .name = "pdn", .is_number = true } + { .name = "ctxn", .is_number = true }, + { .name = "pdn", .is_number = true }, + { .name = "ctxn", .is_number = true } };RES_FUNC (res_pd,RDMA_NLDEV_CMD_RES_PD_GET , pd_valid_filters, true);
Signature · 1 line
2.19.1
PATCH 5/19 rdma: Move resource PD logic to separate file
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Logically separate resource PD logic to separate file, in order to make PD specific logic self-contained.
--- rdma/Makefile | 2 +- rdma/res-pd.c | 110 ++++++++++++++++++++++++++++++++++++ rdma/res.c | 154 +++----------------------------------------------- rdma/res.h | 55 ++++++++++++++++++ 4 files changed, 175 insertions(+), 146 deletions(-) create mode 100644 rdma/res-pd.c create mode 100644 rdma/res.h
rdma/Makefile +1 -1
@@ -6,7 +6,7 @@ TARGETS := ifeq ($(HAVE_MNL),y) CFLAGS += -I./include/uapi/ -RDMA_OBJ = rdma.o utils.o dev.o link.o res.o +RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o TARGETS += rdma endif
rdma/res-pd.c new file +110 -0
110 lines not on this page · raw message
rdma/res.c +9 -145
226 lines not on this page · raw message
rdma/res.h new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.19.1
PATCH 6/19 rdma: Refactor out resource MR logic to separate file
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Logically separate resource MR logic to separate file, in order to make MR specific logic self-contained.
--- rdma/Makefile | 2 +- rdma/res-mr.c | 117 +++++++++++++++++++++++++++++++++++++++++++++++ rdma/res.c | 122 -------------------------------------------------- rdma/res.h | 14 ++++++ 4 files changed, 132 insertions(+), 123 deletions(-) create mode 100644 rdma/res-mr.c
rdma/Makefile +1 -1
@@ -6,7 +6,7 @@ TARGETS := ifeq ($(HAVE_MNL),y) CFLAGS += -I./include/uapi/ -RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o +RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o TARGETS += rdma endif
rdma/res-mr.c new file +117 -0
117 lines not on this page · raw message
rdma/res.c +0 -122
134 lines not on this page · raw message
rdma/res.h +14 -0
@@ -10,6 +10,7 @@int _res_send_msg (struct rd *rd,uint32_t command,mnl_cb_t callback);int res_pd_parse_cb (const struct nlmsghdr *nlh,void *data); +int res_mr_parse_cb (const struct nlmsghdr *nlh,void *data);#define RES_FUNC (name, command, valid_filters, strict_port) \ static inline int _##name(struct rd *rd)\
@@ -44,6 +45,19 @@ struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS] = {RES_FUNC (res_pd,RDMA_NLDEV_CMD_RES_PD_GET , pd_valid_filters, true); +static const +struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS ] = { + { .name ="dev" , .is_number = false }, + { .name ="rkey" , .is_number = true }, + { .name ="lkey" , .is_number = true }, + { .name ="mrlen" , .is_number = true }, + { .name ="pid" , .is_number = true }, + { .name ="mrn" , .is_number = true }, + { .name ="pdn" , .is_number = true } +}; + +RES_FUNC (res_mr,RDMA_NLDEV_CMD_RES_MR_GET , mr_valid_filters, true); +char *get_task_name (uint32_t pid);void print_dev (struct rd *rd,uint32_t idx,const char *name);void print_users (struct rd *rd,uint64_t val);
Signature · 1 line
2.19.1
PATCH 7/19 rdma: Move out resource CQ logic to separate file
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Logically separate resource CQ logic to separate file, in order to make CQ specific logic self-contained.
--- rdma/Makefile | 2 +- rdma/res-cq.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++ rdma/res.c | 147 -------------------------------------------------- rdma/res.h | 13 +++++ 4 files changed, 157 insertions(+), 148 deletions(-) create mode 100644 rdma/res-cq.c
rdma/Makefile +1 -1
@@ -6,7 +6,7 @@ TARGETS := ifeq ($(HAVE_MNL),y) CFLAGS += -I./include/uapi/ -RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o +RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o res-cq.o TARGETS += rdma endif
rdma/res-cq.c new file +143 -0
143 lines not on this page · raw message
rdma/res.c +0 -147
165 lines not on this page · raw message
rdma/res.h +13 -0
@@ -11,6 +11,7 @@int _res_send_msg (struct rd *rd,uint32_t command,mnl_cb_t callback);int res_pd_parse_cb (const struct nlmsghdr *nlh,void *data);int res_mr_parse_cb (const struct nlmsghdr *nlh,void *data); +int res_cq_parse_cb (const struct nlmsghdr *nlh,void *data);#define RES_FUNC (name, command, valid_filters, strict_port) \ static inline int _##name(struct rd *rd)\
@@ -58,6 +59,18 @@ struct filters mr_valid_filters[MAX_NUMBER_OF_FILTERS] = {RES_FUNC (res_mr,RDMA_NLDEV_CMD_RES_MR_GET , mr_valid_filters, true); +static const +struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS ] = { + { .name ="dev" , .is_number = false }, + { .name ="users" , .is_number = true }, + { .name ="poll-ctx" , .is_number = false }, + { .name ="pid" , .is_number = true }, + { .name ="cqn" , .is_number = true }, + { .name ="ctxn" , .is_number = true } +}; + +RES_FUNC (res_cq,RDMA_NLDEV_CMD_RES_CQ_GET , cq_valid_filters, true); +char *get_task_name (uint32_t pid);void print_dev (struct rd *rd,uint32_t idx,const char *name);void print_users (struct rd *rd,uint64_t val);
Signature · 1 line
2.19.1
PATCH 8/19 rdma: Move out resource CM-ID logic to separate file
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Logically separate resource CM-ID logic to separate file, in order to make CM-ID specific logic self-contained.
--- rdma/Makefile | 3 +- rdma/res-cmid.c | 252 ++++++++++++++++++++++++++++++++++++++++++++ rdma/res.c | 271 +----------------------------------------------- rdma/res.h | 24 +++++ 4 files changed, 282 insertions(+), 268 deletions(-) create mode 100644 rdma/res-cmid.c
rdma/Makefile +2 -1
@@ -6,7 +6,8 @@ TARGETS := ifeq ($(HAVE_MNL),y) CFLAGS += -I./include/uapi/ -RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o res-cq.o +RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o res-cq.o \ + res-cmid.o TARGETS += rdma endif
rdma/res-cmid.c new file +252 -0
252 lines not on this page · raw message
rdma/res.c +4 -267
301 lines not on this page · raw message
rdma/res.h +24 -0
@@ -12,6 +12,7 @@ int _res_send_msg(struct rd *rd, uint32_t command, mnl_cb_t callback);int res_pd_parse_cb (const struct nlmsghdr *nlh,void *data);int res_mr_parse_cb (const struct nlmsghdr *nlh,void *data);int res_cq_parse_cb (const struct nlmsghdr *nlh,void *data); +int res_cm_id_parse_cb (const struct nlmsghdr *nlh,void *data);#define RES_FUNC (name, command, valid_filters, strict_port) \ static inline int _##name(struct rd *rd)\
@@ -71,12 +72,35 @@ struct filters cq_valid_filters[MAX_NUMBER_OF_FILTERS] = {RES_FUNC (res_cq,RDMA_NLDEV_CMD_RES_CQ_GET , cq_valid_filters, true); +static const +struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS ] = { + { .name ="link" , .is_number = false }, + { .name ="lqpn" , .is_number = true }, + { .name ="qp-type" , .is_number = false }, + { .name ="state" , .is_number = false }, + { .name ="ps" , .is_number = false }, + { .name ="dev-type" , .is_number = false }, + { .name ="transport-type" , .is_number = false }, + { .name ="pid" , .is_number = true }, + { .name ="src-addr" , .is_number = false }, + { .name ="src-port" , .is_number = true }, + { .name ="dst-addr" , .is_number = false }, + { .name ="dst-port" , .is_number = true }, + { .name ="cm-idn" , .is_number = true } +}; + +RES_FUNC (res_cm_id,RDMA_NLDEV_CMD_RES_CM_ID_GET , cm_id_valid_filters, false); +char *get_task_name (uint32_t pid);void print_dev (struct rd *rd,uint32_t idx,const char *name); +void print_link (struct rd *rd,uint32_t idx,const char *name,uint32_t port, +struct nlattr **nla_line);void print_users (struct rd *rd,uint64_t val);void print_key (struct rd *rd,const char *name,uint64_t val);void res_print_uint (struct rd *rd,const char *name,uint64_t val);void print_pid (struct rd *rd,uint32_t val);void print_comm (struct rd *rd,const char *str,struct nlattr **nla_line); +const char *qp_types_to_str (uint8_t idx); +void print_lqpn (struct rd *rd,uint32_t val);#endif /* _RDMA_TOOL_RES_H_ */
Signature · 1 line
2.19.1
PATCH 9/19 rdma: Move resource PD logic to separate file
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Logically separate resource PD logic to separate file, in order to make PD specific logic self-contained.
--- rdma/Makefile | 2 +- rdma/res-qp.c | 234 +++++++++++++++++++++++++++++++++++++++++++++++++ rdma/res.c | 236 -------------------------------------------------- rdma/res.h | 17 ++++ 4 files changed, 252 insertions(+), 237 deletions(-) create mode 100644 rdma/res-qp.c
rdma/Makefile +1 -1
@@ -7,7 +7,7 @@ ifeq ($(HAVE_MNL),y) CFLAGS += -I./include/uapi/ RDMA_OBJ = rdma.o utils.o dev.o link.o res.o res-pd.o res-mr.o res-cq.o \ - res-cmid.o + res-cmid.o res-qp.o TARGETS += rdma endif
rdma/res-qp.c new file +234 -0
234 lines not on this page · raw message
rdma/res.c +0 -236
260 lines not on this page · raw message
rdma/res.h +17 -0
@@ -13,6 +13,7 @@ int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data);int res_mr_parse_cb (const struct nlmsghdr *nlh,void *data);int res_cq_parse_cb (const struct nlmsghdr *nlh,void *data);int res_cm_id_parse_cb (const struct nlmsghdr *nlh,void *data); +int res_qp_parse_cb (const struct nlmsghdr *nlh,void *data);#define RES_FUNC (name, command, valid_filters, strict_port) \ static inline int _##name(struct rd *rd)\
@@ -91,6 +92,22 @@ struct filters cm_id_valid_filters[MAX_NUMBER_OF_FILTERS] = {RES_FUNC (res_cm_id,RDMA_NLDEV_CMD_RES_CM_ID_GET , cm_id_valid_filters, false); +static const struct +filters qp_valid_filters[MAX_NUMBER_OF_FILTERS ] = { + { .name ="link" , .is_number = false }, + { .name ="lqpn" , .is_number = true }, + { .name ="rqpn" , .is_number = true }, + { .name ="pid" , .is_number = true }, + { .name ="sq-psn" , .is_number = true }, + { .name ="rq-psn" , .is_number = true }, + { .name ="type" , .is_number = false }, + { .name ="path-mig-state" , .is_number = false }, + { .name ="state" , .is_number = false }, + { .name ="pdn" , .is_number = true }, +}; + +RES_FUNC (res_qp,RDMA_NLDEV_CMD_RES_QP_GET , qp_valid_filters, false); +char *get_task_name (uint32_t pid);void print_dev (struct rd *rd,uint32_t idx,const char *name); void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
Signature · 1 line
2.19.1
PATCH 10/19 rdma: Properly mark RDMAtool license
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
RDMA subsystem is dual-licensed with "GPL-2.0 OR Linux-OpenIB" proper license and Mellanox submission are supposed to have this type of license.
--- rdma/Makefile | 2 +- rdma/dev.c | 7 +------ rdma/link.c | 7 +------ rdma/rdma.c | 7 +------ rdma/rdma.h | 7 +------ rdma/res.c | 7 +------ rdma/utils.c | 7 +------ 7 files changed, 7 insertions(+), 37 deletions(-)
rdma/Makefile +1 -1
@@ -1,4 +1,4 @@ -# SPDX-License-Identifier: GPL-2.0 +# SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB include ../config.mk TARGETS :=
rdma/dev.c +1 -6
@@ -1,11 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* * dev.c RDMA tool -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version -* 2 of the License, or (at your option) any later version. -* * Authors: Leon Romanovsky <[email protected]> */
rdma/link.c +1 -6
@@ -1,11 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* * link.c RDMA tool -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version -* 2 of the License, or (at your option) any later version. -* * Authors: Leon Romanovsky <[email protected]> */
rdma/rdma.c +1 -6
@@ -1,11 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* * rdma.c RDMA tool -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version -* 2 of the License, or (at your option) any later version. -* * Authors: Leon Romanovsky <[email protected]> */
rdma/rdma.h +1 -6
@@ -1,11 +1,6 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ /* * rdma.c RDMA tool -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version -* 2 of the License, or (at your option) any later version. -* * Authors: Leon Romanovsky <[email protected]> */ #ifndef _RDMA_TOOL_H_
rdma/res.c +1 -6
@@ -1,11 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* * res.c RDMA tool -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version -* 2 of the License, or (at your option) any later version. -* * Authors: Leon Romanovsky <[email protected]> */
rdma/utils.c +1 -6
@@ -1,11 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB /* * utils.c RDMA tool -* -* This program is free software; you can redistribute it and/or -* modify it under the terms of the GNU General Public License -* as published by the Free Software Foundation; either version -* 2 of the License, or (at your option) any later version. -* * Authors: Leon Romanovsky <[email protected]> */
Signature · 1 line
2.19.1
PATCH 11/19 rdma: Simplify code to reuse existing functions
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Remove duplicated functions in favour general res_print_uint() call.
--- rdma/res-cmid.c | 4 ++-- rdma/res-cq.c | 14 +++----------- rdma/res-mr.c | 2 +- rdma/res-pd.c | 4 ++-- rdma/res-qp.c | 14 +++----------- rdma/res.c | 34 ++-------------------------------- rdma/res.h | 3 --- 7 files changed, 13 insertions(+), 62 deletions(-)
rdma/res-cmid.c +2 -2
@@ -227,12 +227,12 @@ int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data)print_link (rd, idx, name, port, nla_line);if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]) -print_lqpn (rd, lqpn); +res_print_uint (rd,"lqpn" , lqpn);if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ])print_qp_type (rd, type);print_cm_id_state (rd, state);print_ps (rd, ps); -print_pid (rd, pid); +res_print_uint (rd,"pid" , pid);print_comm (rd, comm, nla_line);if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ])res_print_uint (rd,"cm-idn" , cm_idn);
rdma/res-cq.c +3 -11
@@ -7,14 +7,6 @@#include "res.h" #include <inttypes.h> -static void print_cqe (struct rd *rd,uint32_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw,"cqe" , val); -else -pr_out ("cqe %u " , val); -} -static const char *poll_ctx_to_str (uint8_t idx) {static const char *const cm_id_states_str[] = {
@@ -120,11 +112,11 @@ int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data)jsonw_start_array (rd->jw);print_dev (rd, idx, name); -print_cqe (rd, cqe); -print_users (rd, users); +res_print_uint (rd,"cqe" , cqe); +res_print_uint (rd,"users" , users);if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ])print_poll_ctx (rd, poll_ctx); -print_pid (rd, pid); +res_print_uint (rd,"pid" , pid);print_comm (rd, comm, nla_line);if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ])
rdma/res-mr.c +1 -1
@@ -97,7 +97,7 @@ int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data)if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ])print_key (rd,"iova" , iova);res_print_uint (rd,"mrlen" , mrlen); -print_pid (rd, pid); +res_print_uint (rd,"pid" , pid);print_comm (rd, comm, nla_line);if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ])
rdma/res-pd.c +2 -2
@@ -89,10 +89,10 @@ int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data)print_dev (rd, idx, name);if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ])print_key (rd,"local_dma_lkey" , local_dma_lkey); -print_users (rd, users); +res_print_uint (rd,"users" , users);if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY ])print_key (rd,"unsafe_global_rkey" , unsafe_global_rkey); -print_pid (rd, pid); +res_print_uint (rd,"pid" , pid);print_comm (rd, comm, nla_line);if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ])res_print_uint (rd,"ctxn" , ctxn);
rdma/res-qp.c +3 -11
@@ -66,14 +66,6 @@ static void print_rqpsn(struct rd *rd, uint32_t val, struct nlattr **nla_line)pr_out ("rq-psn %u " , val); } -static void print_sqpsn (struct rd *rd,uint32_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw,"sq-psn" , val); -else -pr_out ("sq-psn %u " , val); -} -static void print_pathmig (struct rd *rd,uint32_t val,struct nlattr **nla_line) {if (!nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE ])
@@ -209,7 +201,7 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)print_link (rd, idx, name, port, nla_line); -print_lqpn (rd, lqpn); +res_print_uint (rd,"lqpn" , lqpn);if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ])res_print_uint (rd,"pdn" , pdn);print_rqpn (rd, rqpn, nla_line);
@@ -218,10 +210,10 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)print_state (rd, state);print_rqpsn (rd, rq_psn, nla_line); -print_sqpsn (rd, sq_psn); +res_print_uint (rd,"sq-psn" , sq_psn);print_pathmig (rd, path_mig_state, nla_line); -print_pid (rd, pid); +res_print_uint (rd,"pid" , pid);print_comm (rd, comm, nla_line);if (nla_line[RDMA_NLDEV_ATTR_RES_PID ])
rdma/res.c +2 -32
@@ -35,7 +35,6 @@ static int res_print_summary(struct rd *rd, struct nlattr **tb)mnl_attr_for_each_nested (nla_entry, nla_table) {struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; -char json_name[32 ]; err =mnl_attr_parse_nested (nla_entry, rd_attr_cb, nla_line);if (err !=MNL_CB_OK )
@@ -48,12 +47,7 @@ static int res_print_summary(struct rd *rd, struct nlattr **tb) name =mnl_attr_get_str (nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME ]); curr =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR ]); -if (rd->json_output) { -snprintf (json_name,32 ,"%s" , name); -jsonw_lluint_field (rd->jw, json_name, curr); - }else { -pr_out ("%s %" PRId64" " , name, curr); - } +res_print_uint (rd, name, curr); }return 0 ; }
@@ -127,22 +121,6 @@ const char *qp_types_to_str(uint8_t idx)return "UNKNOWN" ; } -void print_lqpn (struct rd *rd,uint32_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw,"lqpn" , val); -else -pr_out ("lqpn %u " , val); -} - -void print_pid (struct rd *rd,uint32_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw,"pid" , val); -else -pr_out ("pid %u " , val); -} -void print_comm (struct rd *rd,const char *str,struct nlattr **nla_line) {char tmp[18 ];
@@ -221,19 +199,11 @@ void print_key(struct rd *rd, const char *name, uint64_t val)void res_print_uint (struct rd *rd,const char *name,uint64_t val) {if (rd->json_output) -jsonw_uint_field (rd->jw, name, val); +jsonw_u64_field (rd->jw, name, val);else pr_out ("%s %" PRIu64" " , name, val); } -void print_users (struct rd *rd,uint64_t val) -{ -if (rd->json_output) -jsonw_uint_field (rd->jw,"users" , val); -else -pr_out ("users %" PRIu64" " , val); -} -RES_FUNC (res_no_args,RDMA_NLDEV_CMD_RES_GET ,NULL , true);static int res_show (struct rd *rd)
rdma/res.h +0 -3
@@ -112,12 +112,9 @@ char *get_task_name(uint32_t pid);void print_dev (struct rd *rd,uint32_t idx,const char *name);void print_link (struct rd *rd,uint32_t idx,const char *name,uint32_t port,struct nlattr **nla_line); -void print_users (struct rd *rd,uint64_t val);void print_key (struct rd *rd,const char *name,uint64_t val);void res_print_uint (struct rd *rd,const char *name,uint64_t val); -void print_pid (struct rd *rd,uint32_t val);void print_comm (struct rd *rd,const char *str,struct nlattr **nla_line);const char *qp_types_to_str (uint8_t idx); -void print_lqpn (struct rd *rd,uint32_t val);#endif /* _RDMA_TOOL_RES_H_ */
Signature · 1 line
2.19.1
PATCH 12/19 rdma: Simplify CM_ID print code
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Refactor our the CM_ID print code.
--- rdma/res-cmid.c | 246 ++++++++++++++++++++++++------------------------ 1 file changed, 124 insertions(+), 122 deletions(-)
rdma/res-cmid.c +124 -122
@@ -108,11 +108,130 @@ static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port)return 0 ; } +static int res_cm_id_line (struct rd *rd,const char *name,int idx, +struct nlattr *nla_entry) +{ +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; +char src_addr_str[INET6_ADDRSTRLEN ]; +char dst_addr_str[INET6_ADDRSTRLEN ]; +uint16_t src_port, dst_port; +uint32_t port =0 , pid =0 ; +uint8_t type =0 , state; +uint32_t lqpn =0 , ps; +uint32_t cm_idn =0 ; +char *comm =NULL ; +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_STATE ] || + !nla_line[RDMA_NLDEV_ATTR_RES_PS ] || + (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && + !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { +return MNL_CB_ERROR ; + } + +if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]) + port =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]); + +if (port && port != rd->port_idx) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]) { + lqpn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]); +if (rd_check_is_filtered (rd,"lqpn" , lqpn)) + goto out; + } +if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]) { + type =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]); +if (rd_check_is_string_filtered (rd,"qp-type" , +qp_types_to_str (type))) + goto out; + } + + ps =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PS ]); +if (rd_check_is_string_filtered (rd,"ps" ,cm_id_ps_to_str (ps))) + goto out; + + state =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_STATE ]); +if (rd_check_is_string_filtered (rd,"state" ,cm_id_state_to_str (state))) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ]) { +if (ss_ntop (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ], + src_addr_str, &src_port)) + goto out; +if (rd_check_is_string_filtered (rd,"src-addr" , src_addr_str)) + goto out; +if (rd_check_is_filtered (rd,"src-port" , src_port)) + goto out; + } + +if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR ]) { +if (ss_ntop (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR ], + dst_addr_str, &dst_port)) + goto out; +if (rd_check_is_string_filtered (rd,"dst-addr" , dst_addr_str)) + goto out; +if (rd_check_is_filtered (rd,"dst-port" , dst_port)) + goto out; + } + +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)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]) + cm_idn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]); +if (rd_check_is_filtered (rd,"cm-idn" , cm_idn)) + goto out; + +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, port, nla_line); +if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]) +res_print_uint (rd,"lqpn" , lqpn); +if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]) +print_qp_type (rd, type); +print_cm_id_state (rd, state); +print_ps (rd, ps); +res_print_uint (rd,"pid" , pid); +print_comm (rd, comm, nla_line); +if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]) +res_print_uint (rd,"cm-idn" , cm_idn); + +if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ]) +print_ipaddr (rd,"src-addr" , src_addr_str, src_port); +if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR ]) +print_ipaddr (rd,"dst-addr" , dst_addr_str, dst_port); + +print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); +newline (rd); + +out:if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) +free (comm); +return MNL_CB_OK ; +} +int res_cm_id_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; +int ret =MNL_CB_OK ;const char *name;int idx;
@@ -124,129 +243,12 @@ int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data) 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_CM_ID ]; +mnl_attr_for_each_nested (nla_entry, nla_table) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; -char src_addr_str[INET6_ADDRSTRLEN ]; -char dst_addr_str[INET6_ADDRSTRLEN ]; -uint16_t src_port, dst_port; -uint32_t port =0 , pid =0 ; -uint8_t type =0 , state; -uint32_t lqpn =0 , ps; -uint32_t cm_idn =0 ; -char *comm =NULL ; -int err; - - err =mnl_attr_parse_nested (nla_entry, rd_attr_cb, nla_line); -if (err !=MNL_CB_OK ) -return -EINVAL ; + ret =res_cm_id_line (rd, name, idx, nla_entry); -if (!nla_line[RDMA_NLDEV_ATTR_RES_STATE ] || - !nla_line[RDMA_NLDEV_ATTR_RES_PS ] || - (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && - !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { -return MNL_CB_ERROR ; - } - -if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]) - port =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]); - -if (port && port != rd->port_idx) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]) { - lqpn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]); -if (rd_check_is_filtered (rd,"lqpn" , lqpn)) -continue ; - } -if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]) { - type =mnl_attr_get_u8 ( - nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]); -if (rd_check_is_string_filtered (rd,"qp-type" , -qp_types_to_str (type))) -continue ; - } - - ps =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PS ]); -if (rd_check_is_string_filtered (rd,"ps" ,cm_id_ps_to_str (ps))) -continue ; - - state =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_STATE ]); -if (rd_check_is_string_filtered (rd,"state" , -cm_id_state_to_str (state))) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ]) { -if (ss_ntop (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ], - src_addr_str, &src_port)) -continue ; -if (rd_check_is_string_filtered (rd,"src-addr" , - src_addr_str)) -continue ; -if (rd_check_is_filtered (rd,"src-port" , src_port)) -continue ; - } - -if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR ]) { -if (ss_ntop (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR ], - dst_addr_str, &dst_port)) -continue ; -if (rd_check_is_string_filtered (rd,"dst-addr" , - dst_addr_str)) -continue ; -if (rd_check_is_filtered (rd,"dst-port" , dst_port)) -continue ; - } - -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)) { -free (comm); -continue ; - } - -if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]) - cm_idn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]); -if (rd_check_is_filtered (rd,"cm-idn" , cm_idn)) -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, port, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]) -res_print_uint (rd,"lqpn" , lqpn); -if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]) -print_qp_type (rd, type); -print_cm_id_state (rd, state); -print_ps (rd, ps); -res_print_uint (rd,"pid" , pid); -print_comm (rd, comm, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]) -res_print_uint (rd,"cm-idn" , cm_idn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ]) -print_ipaddr (rd,"src-addr" , src_addr_str, src_port); -if (nla_line[RDMA_NLDEV_ATTR_RES_DST_ADDR ]) -print_ipaddr (rd,"dst-addr" , dst_addr_str, dst_port); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) -free (comm); - -print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); -newline (rd); +if (ret !=MNL_CB_OK ) +break ; } -return MNL_CB_OK ; +return ret; }
Signature · 1 line
2.19.1
PATCH 13/19 rdma: Refactor CQ prints
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
--- rdma/res-cq.c | 177 ++++++++++++++++++++++++++------------------------ 1 file changed, 91 insertions(+), 86 deletions(-)
rdma/res-cq.c +91 -86
@@ -27,11 +27,97 @@ static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx)pr_out ("poll-ctx %s " ,poll_ctx_to_str (poll_ctx)); } +static int res_cq_line (struct rd *rd,const char *name,int idx, +struct nlattr *nla_entry) +{ +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; +char *comm =NULL ; +uint32_t pid =0 ; +uint8_t poll_ctx =0 ; +uint32_t ctxn =0 ; +uint32_t cqn =0 ; +uint64_t users; +uint32_t cqe; +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_CQE ] || + !nla_line[RDMA_NLDEV_ATTR_RES_USECNT ] || + (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && + !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { +return MNL_CB_ERROR ; + } + + cqe =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CQE ]); + + users =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); +if (rd_check_is_filtered (rd,"users" , users)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]) { + poll_ctx = +mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]); +if (rd_check_is_string_filtered (rd,"poll-ctx" , +poll_ctx_to_str (poll_ctx))) + goto out; + } + +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)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) + cqn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]); +if (rd_check_is_filtered (rd,"cqn" , cqn)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) + ctxn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); +if (rd_check_is_filtered (rd,"ctxn" , ctxn)) + goto out; + +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_dev (rd, idx, name); +res_print_uint (rd,"cqe" , cqe); +res_print_uint (rd,"users" , users); +if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]) +print_poll_ctx (rd, poll_ctx); +res_print_uint (rd,"pid" , pid); +print_comm (rd, comm, nla_line); + +if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) +res_print_uint (rd,"cqn" , cqn); +if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) +res_print_uint (rd,"ctxn" , ctxn); + +print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); +newline (rd); + +out:if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) +free (comm); +return MNL_CB_OK ; +} +int res_cq_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; +int ret =MNL_CB_OK ;const char *name;uint32_t idx;
@@ -45,91 +131,10 @@ int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ ];mnl_attr_for_each_nested (nla_entry, nla_table) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; -char *comm =NULL ; -uint32_t pid =0 ; -uint8_t poll_ctx =0 ; -uint32_t ctxn =0 ; -uint32_t cqn =0 ; -uint64_t users; -uint32_t cqe; -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_CQE ] || - !nla_line[RDMA_NLDEV_ATTR_RES_USECNT ] || - (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && - !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { -return MNL_CB_ERROR ; - } - - cqe =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CQE ]); - - users =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); -if (rd_check_is_filtered (rd,"users" , users)) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]) { - poll_ctx =mnl_attr_get_u8 ( - nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]); -if (rd_check_is_string_filtered ( - rd,"poll-ctx" ,poll_ctx_to_str (poll_ctx))) -continue ; - } - -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)) { -free (comm); -continue ; - } - -if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) - cqn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_CQN ]); -if (rd_check_is_filtered (rd,"cqn" , cqn)) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) - ctxn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); -if (rd_check_is_filtered (rd,"ctxn" , ctxn)) -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_dev (rd, idx, name); -res_print_uint (rd,"cqe" , cqe); -res_print_uint (rd,"users" , users); -if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]) -print_poll_ctx (rd, poll_ctx); -res_print_uint (rd,"pid" , pid); -print_comm (rd, comm, nla_line); - -if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) -res_print_uint (rd,"cqn" , cqn); -if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) -res_print_uint (rd,"ctxn" , ctxn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) -free (comm); - -print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); -newline (rd); + ret =res_cq_line (rd, name, idx, nla_entry); + +if (ret !=MNL_CB_OK ) +break ; } -return MNL_CB_OK ; +return ret; } -
Signature · 1 line
2.19.1
PATCH 14/19 rdma: Separate MR code
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
--- rdma/res-mr.c | 178 +++++++++++++++++++++++++------------------------- 1 file changed, 90 insertions(+), 88 deletions(-)
rdma/res-mr.c +90 -88
@@ -7,11 +7,96 @@#include "res.h" #include <inttypes.h> +static int res_mr_line (struct rd *rd,const char *name,int idx, +struct nlattr *nla_entry) +{ +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; +uint32_t rkey =0 , lkey =0 ; +uint64_t iova =0 , mrlen; +char *comm =NULL ; +uint32_t pdn =0 ; +uint32_t mrn =0 ; +uint32_t pid =0 ; +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_MRLEN ] || + (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && + !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { +return MNL_CB_ERROR ; + } + +if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]) + rkey =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]); +if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]) + lkey =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]); +if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]) + iova =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]); + + mrlen =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_MRLEN ]); +if (rd_check_is_filtered (rd,"mrlen" , mrlen)) + goto out; + +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)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) + mrn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]); +if (rd_check_is_filtered (rd,"mrn" , mrn)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) + pdn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +if (rd_check_is_filtered (rd,"pdn" , pdn)) + goto out; + +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_dev (rd, idx, name); +if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]) +print_key (rd,"rkey" , rkey); +if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]) +print_key (rd,"lkey" , lkey); +if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]) +print_key (rd,"iova" , iova); +res_print_uint (rd,"mrlen" , mrlen); +res_print_uint (rd,"pid" , pid); +print_comm (rd, comm, nla_line); + +if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) +res_print_uint (rd,"mrn" , mrn); + +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) +res_print_uint (rd,"pdn" , pdn); + +print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); +newline (rd); + +out: +if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) +free (comm); +return MNL_CB_OK ; +}int res_mr_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; +int ret =MNL_CB_OK ;const char *name;uint32_t idx;
@@ -25,93 +110,10 @@ int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_MR ];mnl_attr_for_each_nested (nla_entry, nla_table) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; -uint32_t rkey =0 , lkey =0 ; -uint64_t iova =0 , mrlen; -char *comm =NULL ; -uint32_t pdn =0 ; -uint32_t mrn =0 ; -uint32_t pid =0 ; -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_MRLEN ] || - (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && - !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { -return MNL_CB_ERROR ; - } - -if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]) - rkey =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]); -if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]) - lkey =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]); -if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]) - iova =mnl_attr_get_u64 ( - nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]); - - mrlen =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_MRLEN ]); -if (rd_check_is_filtered (rd,"mrlen" , mrlen)) -continue ; - -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)) { -free (comm); -continue ; - } - -if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) - mrn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_MRN ]); -if (rd_check_is_filtered (rd,"mrn" , mrn)) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) - pdn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); -if (rd_check_is_filtered (rd,"pdn" , pdn)) -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_dev (rd, idx, name); -if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]) -print_key (rd,"rkey" , rkey); -if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]) -print_key (rd,"lkey" , lkey); -if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]) -print_key (rd,"iova" , iova); -res_print_uint (rd,"mrlen" , mrlen); -res_print_uint (rd,"pid" , pid); -print_comm (rd, comm, nla_line); - -if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) -res_print_uint (rd,"mrn" , mrn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) -res_print_uint (rd,"pdn" , pdn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) -free (comm); - -print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); -newline (rd); + ret =res_mr_line (rd, name, idx, nla_entry); + +if (ret !=MNL_CB_OK ) +break ; } -return MNL_CB_OK ; +return ret; } -
Signature · 1 line
2.19.1
PATCH 15/19 rdma: Separate PD code
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
--- rdma/res-pd.c | 170 ++++++++++++++++++++++++++------------------------ 1 file changed, 89 insertions(+), 81 deletions(-)
rdma/res-pd.c +89 -81
@@ -7,11 +7,95 @@#include "res.h" #include <inttypes.h> +static int res_pd_line (struct rd *rd,const char *name,int idx, +struct nlattr *nla_entry) +{ +uint32_t local_dma_lkey =0 , unsafe_global_rkey =0 ; +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; +char *comm =NULL ; +uint32_t ctxn =0 ; +uint32_t pid =0 ; +uint32_t pdn =0 ; +uint64_t users; +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_USECNT ] || + (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && + !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { +return MNL_CB_ERROR ; + } + +if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]) + local_dma_lkey =mnl_attr_get_u32 ( + nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]); + + users =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); +if (rd_check_is_filtered (rd,"users" , users)) + goto out; + +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)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) + ctxn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); + +if (rd_check_is_filtered (rd,"ctxn" , ctxn)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) + pdn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +if (rd_check_is_filtered (rd,"pdn" , pdn)) + goto out; + +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_dev (rd, idx, name); +if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]) +print_key (rd,"local_dma_lkey" , local_dma_lkey); +res_print_uint (rd,"users" , users); +if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY ]) +print_key (rd,"unsafe_global_rkey" , unsafe_global_rkey); +res_print_uint (rd,"pid" , pid); +print_comm (rd, comm, nla_line); +if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) +res_print_uint (rd,"ctxn" , ctxn); + +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) +res_print_uint (rd,"pdn" , pdn); + +print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); +newline (rd); + +out:if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) +free (comm); +return MNL_CB_OK ; +} +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; +int ret =MNL_CB_OK ;const char *name;uint32_t idx;
@@ -25,86 +109,10 @@ int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_PD ];mnl_attr_for_each_nested (nla_entry, nla_table) { -uint32_t local_dma_lkey =0 , unsafe_global_rkey =0 ; -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; -char *comm =NULL ; -uint32_t ctxn =0 ; -uint32_t pid =0 ; -uint32_t pdn =0 ; -uint64_t users; -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_USECNT ] || - (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && - !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { -return MNL_CB_ERROR ; - } - -if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]) - local_dma_lkey =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]); - - users =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); -if (rd_check_is_filtered (rd,"users" , users)) -continue ; - -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_CTXN ]) - ctxn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); - -if (rd_check_is_filtered (rd,"ctxn" , ctxn)) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) - pdn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); -if (rd_check_is_filtered (rd,"pdn" , pdn)) -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_dev (rd, idx, name); -if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]) -print_key (rd,"local_dma_lkey" , local_dma_lkey); -res_print_uint (rd,"users" , users); -if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY ]) -print_key (rd,"unsafe_global_rkey" , unsafe_global_rkey); -res_print_uint (rd,"pid" , pid); -print_comm (rd, comm, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) -res_print_uint (rd,"ctxn" , ctxn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) -res_print_uint (rd,"pdn" , pdn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) -free (comm); - -print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); -newline (rd); + ret =res_pd_line (rd, name, idx, nla_entry); + +if (ret !=MNL_CB_OK ) +break ; } -return MNL_CB_OK ; +return ret; }
Signature · 1 line
2.19.1
PATCH 16/19 rdma: Move QP code to separate function
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
--- rdma/res-qp.c | 253 +++++++++++++++++++++++++------------------------- 1 file changed, 127 insertions(+), 126 deletions(-)
rdma/res-qp.c +127 -126
@@ -78,11 +78,133 @@ static void print_pathmig(struct rd *rd, uint32_t val, struct nlattr **nla_line)pr_out ("path-mig-state %s " ,path_mig_to_str (val)); } +static int res_qp_line (struct rd *rd,const char *name,int idx, +struct nlattr *nla_entry) +{ +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; +uint32_t lqpn, rqpn =0 , rq_psn =0 , sq_psn; +uint8_t type, state, path_mig_state =0 ; +uint32_t port =0 , pid =0 ; +uint32_t pdn =0 ; +char *comm =NULL ; +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_LQPN ] || + !nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN ] || + !nla_line[RDMA_NLDEV_ATTR_RES_TYPE ] || + !nla_line[RDMA_NLDEV_ATTR_RES_STATE ] || + (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && + !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { +return MNL_CB_ERROR ; + } + +if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]) + port =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]); + +if (port != rd->port_idx) + goto out; + + lqpn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]); +if (rd_check_is_filtered (rd,"lqpn" , lqpn)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) + pdn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +if (rd_check_is_filtered (rd,"pdn" , pdn)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN ]) { + rqpn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_RQPN ]); +if (rd_check_is_filtered (rd,"rqpn" , rqpn)) + goto out; + }else { +if (rd_check_is_key_exist (rd,"rqpn" )) + goto out; + } + +if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN ]) { + rq_psn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN ]); +if (rd_check_is_filtered (rd,"rq-psn" , rq_psn)) + goto out; + }else { +if (rd_check_is_key_exist (rd,"rq-psn" )) + goto out; + } + + sq_psn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN ]); +if (rd_check_is_filtered (rd,"sq-psn" , sq_psn)) + goto out; + +if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE ]) { + path_mig_state =mnl_attr_get_u8 ( + nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE ]); +if (rd_check_is_string_filtered (rd,"path-mig-state" , +path_mig_to_str (path_mig_state))) + goto out; + }else { +if (rd_check_is_key_exist (rd,"path-mig-state" )) + goto out; + } + + type =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]); +if (rd_check_is_string_filtered (rd,"type" ,qp_types_to_str (type))) + goto out; + + state =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_STATE ]); +if (rd_check_is_string_filtered (rd,"state" ,qp_states_to_str (state))) + goto out; + +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)) + goto out; + +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, port, nla_line); + +res_print_uint (rd,"lqpn" , lqpn); +if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) +res_print_uint (rd,"pdn" , pdn); +print_rqpn (rd, rqpn, nla_line); + +print_type (rd, type); +print_state (rd, state); + +print_rqpsn (rd, rq_psn, nla_line); +res_print_uint (rd,"sq-psn" , sq_psn); + +print_pathmig (rd, path_mig_state, nla_line); +res_print_uint (rd,"pid" , pid); +print_comm (rd, comm, nla_line); + +print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); +newline (rd); +out: +if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) +free (comm); +return MNL_CB_OK ; +} +int res_qp_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; +int ret =MNL_CB_OK ;const char *name;uint32_t idx;
@@ -96,131 +218,10 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_QP ];mnl_attr_for_each_nested (nla_entry, nla_table) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; -uint32_t lqpn, rqpn =0 , rq_psn =0 , sq_psn; -uint8_t type, state, path_mig_state =0 ; -uint32_t port =0 , pid =0 ; -uint32_t pdn =0 ; -char *comm =NULL ; -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_LQPN ] || - !nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN ] || - !nla_line[RDMA_NLDEV_ATTR_RES_TYPE ] || - !nla_line[RDMA_NLDEV_ATTR_RES_STATE ] || - (!nla_line[RDMA_NLDEV_ATTR_RES_PID ] && - !nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])) { -return MNL_CB_ERROR ; - } - -if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]) - port =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_PORT_INDEX ]); - -if (port != rd->port_idx) -continue ; - - lqpn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]); -if (rd_check_is_filtered (rd,"lqpn" , lqpn)) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) - pdn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); -if (rd_check_is_filtered (rd,"pdn" , pdn)) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN ]) { - rqpn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_RQPN ]); -if (rd_check_is_filtered (rd,"rqpn" , rqpn)) -continue ; - }else { -if (rd_check_is_key_exist (rd,"rqpn" )) -continue ; - } - -if (nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN ]) { - rq_psn =mnl_attr_get_u32 ( - nla_line[RDMA_NLDEV_ATTR_RES_RQ_PSN ]); -if (rd_check_is_filtered (rd,"rq-psn" , rq_psn)) -continue ; - }else { -if (rd_check_is_key_exist (rd,"rq-psn" )) -continue ; - } - - sq_psn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN ]); -if (rd_check_is_filtered (rd,"sq-psn" , sq_psn)) -continue ; - -if (nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE ]) { - path_mig_state =mnl_attr_get_u8 ( - nla_line[RDMA_NLDEV_ATTR_RES_PATH_MIG_STATE ]); -if (rd_check_is_string_filtered ( - rd,"path-mig-state" , -path_mig_to_str (path_mig_state))) -continue ; - }else { -if (rd_check_is_key_exist (rd,"path-mig-state" )) -continue ; - } - - type =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ]); -if (rd_check_is_string_filtered (rd,"type" , -qp_types_to_str (type))) -continue ; - - state =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_STATE ]); -if (rd_check_is_string_filtered (rd,"state" , -qp_states_to_str (state))) -continue ; - -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)) { -free (comm); -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, port, nla_line); - -res_print_uint (rd,"lqpn" , lqpn); -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) -res_print_uint (rd,"pdn" , pdn); -print_rqpn (rd, rqpn, nla_line); - -print_type (rd, type); -print_state (rd, state); - -print_rqpsn (rd, rq_psn, nla_line); -res_print_uint (rd,"sq-psn" , sq_psn); - -print_pathmig (rd, path_mig_state, nla_line); -res_print_uint (rd,"pid" , pid); -print_comm (rd, comm, nla_line); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) -free (comm); - -print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]); -newline (rd); + ret =res_qp_line (rd, name, idx, nla_entry); + +if (ret !=MNL_CB_OK ) +break ; } -return MNL_CB_OK ; +return ret; }
Signature · 1 line
2.19.1
PATCH 17/19 rdma: Unify netlink attribute checks prior to prints
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Place check if netlink attribute available in general place, instead of doing the same check in many paces.
--- rdma/res-cmid.c | 9 ++++----- rdma/res-cq.c | 22 +++++++++++----------- rdma/res-mr.c | 21 +++++++-------------- rdma/res-pd.c | 20 +++++++++----------- rdma/res-qp.c | 10 +++++----- rdma/res.c | 16 +++++++++++++--- rdma/res.h | 6 ++++-- 7 files changed, 53 insertions(+), 51 deletions(-)
rdma/res-cmid.c +4 -5
@@ -202,16 +202,15 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,jsonw_start_array (rd->jw);print_link (rd, idx, name, port, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]) -res_print_uint (rd,"lqpn" , lqpn); +res_print_uint (rd,"cm-idn" , cm_idn, + nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]); +res_print_uint (rd,"lqpn" , lqpn, nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]);if (nla_line[RDMA_NLDEV_ATTR_RES_TYPE ])print_qp_type (rd, type);print_cm_id_state (rd, state);print_ps (rd, ps); -res_print_uint (rd,"pid" , pid); +res_print_uint (rd,"pid" , pid, nla_line[RDMA_NLDEV_ATTR_RES_PID ]);print_comm (rd, comm, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_CM_IDN ]) -res_print_uint (rd,"cm-idn" , cm_idn);if (nla_line[RDMA_NLDEV_ATTR_RES_SRC_ADDR ])print_ipaddr (rd,"src-addr" , src_addr_str, src_port);
rdma/res-cq.c +11 -11
@@ -17,8 +17,11 @@ static const char *poll_ctx_to_str(uint8_t idx)return "UNKNOWN" ; } -static void print_poll_ctx (struct rd *rd,uint8_t poll_ctx) +static void print_poll_ctx (struct rd *rd,uint8_t poll_ctx,struct nlattr *attr) { +if (!attr) +return ; +if (rd->json_output) {jsonw_string_field (rd->jw,"poll-ctx" ,poll_ctx_to_str (poll_ctx));
@@ -92,18 +95,15 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,jsonw_start_array (rd->jw);print_dev (rd, idx, name); -res_print_uint (rd,"cqe" , cqe); -res_print_uint (rd,"users" , users); -if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]) -print_poll_ctx (rd, poll_ctx); -res_print_uint (rd,"pid" , pid); +res_print_uint (rd,"cqn" , cqn, nla_line[RDMA_NLDEV_ATTR_RES_CQN ]); +res_print_uint (rd,"cqe" , cqe, nla_line[RDMA_NLDEV_ATTR_RES_CQE ]); +res_print_uint (rd,"users" , users, + nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); +print_poll_ctx (rd, poll_ctx, nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]); +res_print_uint (rd,"ctxn" , ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); +res_print_uint (rd,"pid" , pid, nla_line[RDMA_NLDEV_ATTR_RES_PID ]);print_comm (rd, comm, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) -res_print_uint (rd,"cqn" , cqn); -if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) -res_print_uint (rd,"ctxn" , ctxn); -print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]);newline (rd);
rdma/res-mr.c +7 -14
@@ -67,22 +67,15 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,jsonw_start_array (rd->jw);print_dev (rd, idx, name); -if (nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]) -print_key (rd,"rkey" , rkey); -if (nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]) -print_key (rd,"lkey" , lkey); -if (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]) -print_key (rd,"iova" , iova); -res_print_uint (rd,"mrlen" , mrlen); -res_print_uint (rd,"pid" , pid); +res_print_uint (rd,"mrn" , mrn, nla_line[RDMA_NLDEV_ATTR_RES_MRN ]); +print_key (rd,"rkey" , rkey, nla_line[RDMA_NLDEV_ATTR_RES_RKEY ]); +print_key (rd,"lkey" , lkey, nla_line[RDMA_NLDEV_ATTR_RES_LKEY ]); +print_key (rd,"iova" , iova, nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]); +res_print_uint (rd,"mrlen" , mrlen, nla_line[RDMA_NLDEV_ATTR_RES_MRLEN ]); +res_print_uint (rd,"pdn" , pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +res_print_uint (rd,"pid" , pid, nla_line[RDMA_NLDEV_ATTR_RES_PID ]);print_comm (rd, comm, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) -res_print_uint (rd,"mrn" , mrn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) -res_print_uint (rd,"pdn" , pdn); -print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]);newline (rd);
rdma/res-pd.c +9 -11
@@ -69,18 +69,16 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,jsonw_start_array (rd->jw);print_dev (rd, idx, name); -if (nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]) -print_key (rd,"local_dma_lkey" , local_dma_lkey); -res_print_uint (rd,"users" , users); -if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY ]) -print_key (rd,"unsafe_global_rkey" , unsafe_global_rkey); -res_print_uint (rd,"pid" , pid); +res_print_uint (rd,"pdn" , pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +print_key (rd,"local_dma_lkey" , local_dma_lkey, + nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY ]); +res_print_uint (rd,"users" , users, + nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); +print_key (rd,"unsafe_global_rkey" , unsafe_global_rkey, + nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY ]); +res_print_uint (rd,"ctxn" , ctxn, nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); +res_print_uint (rd,"pid" , pid, nla_line[RDMA_NLDEV_ATTR_RES_PID ]);print_comm (rd, comm, nla_line); -if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) -res_print_uint (rd,"ctxn" , ctxn); - -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) -res_print_uint (rd,"pdn" , pdn);print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]);newline (rd);
rdma/res-qp.c +5 -5
@@ -176,19 +176,19 @@ static int res_qp_line(struct rd *rd, const char *name, int idx,print_link (rd, idx, name, port, nla_line); -res_print_uint (rd,"lqpn" , lqpn); -if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) -res_print_uint (rd,"pdn" , pdn); +res_print_uint (rd,"lqpn" , lqpn, nla_line[RDMA_NLDEV_ATTR_RES_LQPN ]);print_rqpn (rd, rqpn, nla_line);print_type (rd, type);print_state (rd, state);print_rqpsn (rd, rq_psn, nla_line); -res_print_uint (rd,"sq-psn" , sq_psn); +res_print_uint (rd,"sq-psn" , sq_psn, + nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN ]);print_pathmig (rd, path_mig_state, nla_line); -res_print_uint (rd,"pid" , pid); +res_print_uint (rd,"pdn" , pdn, nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); +res_print_uint (rd,"pid" , pid, nla_line[RDMA_NLDEV_ATTR_RES_PID ]);print_comm (rd, comm, nla_line);print_driver_table (rd, nla_line[RDMA_NLDEV_ATTR_DRIVER ]);
rdma/res.c +13 -3
@@ -47,7 +47,9 @@ static int res_print_summary(struct rd *rd, struct nlattr **tb) name =mnl_attr_get_str (nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_NAME ]); curr =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR ]); -res_print_uint (rd, name, curr); +res_print_uint ( + rd, name, curr, + nla_line[RDMA_NLDEV_ATTR_RES_SUMMARY_ENTRY_CURR ]); }return 0 ; }
@@ -188,16 +190,24 @@ char *get_task_name(uint32_t pid)return comm; } -void print_key (struct rd *rd,const char *name,uint64_t val) +void print_key (struct rd *rd,const char *name,uint64_t val, +struct nlattr *nlattr) { +if (!nlattr) +return ; +if (rd->json_output)jsonw_xint_field (rd->jw, name, val);else pr_out ("%s 0x%" PRIx64" " , name, val); } -void res_print_uint (struct rd *rd,const char *name,uint64_t val) +void res_print_uint (struct rd *rd,const char *name,uint64_t val, +struct nlattr *nlattr) { +if (!nlattr) +return ; +if (rd->json_output)jsonw_u64_field (rd->jw, name, val);else
rdma/res.h +4 -2
@@ -112,8 +112,10 @@ char *get_task_name(uint32_t pid);void print_dev (struct rd *rd,uint32_t idx,const char *name);void print_link (struct rd *rd,uint32_t idx,const char *name,uint32_t port,struct nlattr **nla_line); -void print_key (struct rd *rd,const char *name,uint64_t val); -void res_print_uint (struct rd *rd,const char *name,uint64_t val); +void print_key (struct rd *rd,const char *name,uint64_t val, +struct nlattr *nlattr); +void res_print_uint (struct rd *rd,const char *name,uint64_t val, +struct nlattr *nlattr);void print_comm (struct rd *rd,const char *str,struct nlattr **nla_line);const char *qp_types_to_str (uint8_t idx);
Signature · 1 line
2.19.1
PATCH 18/19 rdma: Perform single .doit call to query specific objects
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
If user provides specific index, we can speedup query by using .doit callback and save full dump and filtering after that.
--- rdma/rdma.h | 10 +++++- rdma/res-cmid.c | 33 +++++++++++++------ rdma/res-cq.c | 34 ++++++++++++++------ rdma/res-mr.c | 33 ++++++++++++++----- rdma/res-pd.c | 32 ++++++++++++++----- rdma/res-qp.c | 32 ++++++++++++++----- rdma/res.c | 34 +++++++++++++++++++- rdma/res.h | 84 ++++++++++++++++++++++++++++++++----------------- rdma/utils.c | 20 ++++++++++++ 9 files changed, 239 insertions(+), 73 deletions(-)
rdma/rdma.h +9 -1
@@ -30,13 +30,20 @@#define MAX_NUMBER_OF_FILTERS 64struct filters {const char *name; -bool is_number; +uint8_t is_number:1 ; +uint8_t is_doit:1 ; };struct filter_entry {struct list_head list;char *key;char *value; +/* +* This field menas that we can try to issue .doit calback +* on value above. This value can be converted to integer +* with simple atoi(). Otherwise "is_doit" will be false. +*/ +uint8_t is_doit:1 ; };struct dev_map {
@@ -101,6 +108,7 @@ struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);/* * Filter manipulation */ +bool rd_doit_index (struct rd *rd,uint32_t *idx);int rd_build_filter (struct rd *rd,const struct filters valid_filters[]);bool rd_check_is_filtered (struct rd *rd,const char *key,uint32_t val);bool rd_check_is_string_filtered (struct rd *rd,const char *key,const char *val);
rdma/res-cmid.c +24 -9
@@ -107,11 +107,9 @@ static int ss_ntop(struct nlattr *nla_line, char *addr_str, uint16_t *port) }return 0 ; } -static int res_cm_id_line (struct rd *rd,const char *name,int idx, -struct nlattr *nla_entry) +struct nlattr **nla_line) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {};char src_addr_str[INET6_ADDRSTRLEN ];char dst_addr_str[INET6_ADDRSTRLEN ];uint16_t src_port, dst_port;
@@ -120,11 +118,6 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,uint32_t lqpn =0 , ps;uint32_t cm_idn =0 ;char *comm =NULL ; -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_STATE] || !nla_line[RDMA_NLDEV_ATTR_RES_PS] ||
@@ -225,6 +218,23 @@ out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID])return MNL_CB_OK ; } +int res_cm_id_idx_parse_cb (const struct nlmsghdr *nlh,void *data) +{ +struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {}; +struct rd *rd = data; +const char *name; +int idx; + +mnl_attr_parse (nlh,0 , rd_attr_cb, tb); +if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX ] || !tb[RDMA_NLDEV_ATTR_DEV_NAME ]) +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 ]); + +return res_cm_id_line (rd, name, idx, tb); +} +int res_cm_id_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -244,8 +254,13 @@ int res_cm_id_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_CM_ID ];mnl_attr_for_each_nested (nla_entry, nla_table) { - ret =res_cm_id_line (rd, name, idx, nla_entry); +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; + + ret =mnl_attr_parse_nested (nla_entry, rd_attr_cb, nla_line); +if (ret !=MNL_CB_OK ) +break ; + ret =res_cm_id_line (rd, name, idx, nla_line);if (ret !=MNL_CB_OK )break ; }
rdma/res-cq.c +25 -9
@@ -31,9 +31,8 @@ static void print_poll_ctx(struct rd *rd, uint8_t poll_ctx, struct nlattr *attr) }static int res_cq_line (struct rd *rd,const char *name,int idx, -struct nlattr *nla_entry) +struct nlattr **nla_line) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {};char *comm =NULL ;uint32_t pid =0 ;uint8_t poll_ctx =0 ;
@@ -41,11 +40,6 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,uint32_t cqn =0 ;uint64_t users;uint32_t cqe; -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_CQE] || !nla_line[RDMA_NLDEV_ATTR_RES_USECNT] ||
@@ -80,7 +74,6 @@ static int res_cq_line(struct rd *rd, const char *name, int idx, cqn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]);if (rd_check_is_filtered (rd,"cqn" , cqn)) goto out; -if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) ctxn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]);if (rd_check_is_filtered (rd,"ctxn" , ctxn))
@@ -112,6 +105,23 @@ out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID])return MNL_CB_OK ; } +int res_cq_idx_parse_cb (const struct nlmsghdr *nlh,void *data) +{ +struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {}; +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 ]) +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 ]); + +return res_cq_line (rd, name, idx, tb); +} +int res_cq_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -131,7 +141,13 @@ int res_cq_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_CQ ];mnl_attr_for_each_nested (nla_entry, nla_table) { - ret =res_cq_line (rd, name, idx, nla_entry); +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; + + ret =mnl_attr_parse_nested (nla_entry, rd_attr_cb, nla_line); +if (ret !=MNL_CB_OK ) +break ; + + ret =res_cq_line (rd, name, idx, nla_line);if (ret !=MNL_CB_OK )break ;
rdma/res-mr.c +25 -8
@@ -8,20 +8,14 @@#include <inttypes.h> static int res_mr_line (struct rd *rd,const char *name,int idx, -struct nlattr *nla_entry) +struct nlattr **nla_line) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {};uint32_t rkey =0 , lkey =0 ;uint64_t iova =0 , mrlen;char *comm =NULL ;uint32_t pdn =0 ;uint32_t mrn =0 ;uint32_t pid =0 ; -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_MRLEN] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
@@ -84,6 +78,24 @@ out:free (comm);return MNL_CB_OK ; } + +int res_mr_idx_parse_cb (const struct nlmsghdr *nlh,void *data) +{ +struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {}; +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 ]) +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 ]); + +return res_mr_line (rd, name, idx, tb); +} +int res_mr_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -103,8 +115,13 @@ int res_mr_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_MR ];mnl_attr_for_each_nested (nla_entry, nla_table) { - ret =res_mr_line (rd, name, idx, nla_entry); +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; + + ret =mnl_attr_parse_nested (nla_entry, rd_attr_cb, nla_line); +if (ret !=MNL_CB_OK ) +break ; + ret =res_mr_line (rd, name, idx, nla_line);if (ret !=MNL_CB_OK )break ; }
rdma/res-pd.c +24 -8
@@ -8,20 +8,14 @@#include <inttypes.h> static int res_pd_line (struct rd *rd,const char *name,int idx, -struct nlattr *nla_entry) +struct nlattr **nla_line) {uint32_t local_dma_lkey =0 , unsafe_global_rkey =0 ; -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {};char *comm =NULL ;uint32_t ctxn =0 ;uint32_t pid =0 ;uint32_t pdn =0 ;uint64_t users; -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_USECNT] || (!nla_line[RDMA_NLDEV_ATTR_RES_PID] &&
@@ -88,6 +82,23 @@ out: if (nla_line[RDMA_NLDEV_ATTR_RES_PID])return MNL_CB_OK ; } +int res_pd_idx_parse_cb (const struct nlmsghdr *nlh,void *data) +{ +struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {}; +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 ]) +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 ]); + +return res_pd_line (rd, name, idx, tb); +} +int res_pd_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -107,8 +118,13 @@ int res_pd_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_PD ];mnl_attr_for_each_nested (nla_entry, nla_table) { - ret =res_pd_line (rd, name, idx, nla_entry); +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; + + ret =mnl_attr_parse_nested (nla_entry, rd_attr_cb, nla_line); +if (ret !=MNL_CB_OK ) +break ; + ret =res_pd_line (rd, name, idx, nla_line);if (ret !=MNL_CB_OK )break ; }
rdma/res-qp.c +24 -8
@@ -79,19 +79,13 @@ static void print_pathmig(struct rd *rd, uint32_t val, struct nlattr **nla_line) }static int res_qp_line (struct rd *rd,const char *name,int idx, -struct nlattr *nla_entry) +struct nlattr **nla_line) { -struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {};uint32_t lqpn, rqpn =0 , rq_psn =0 , sq_psn;uint8_t type, state, path_mig_state =0 ;uint32_t port =0 , pid =0 ;uint32_t pdn =0 ;char *comm =NULL ; -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_LQPN] || !nla_line[RDMA_NLDEV_ATTR_RES_SQ_PSN] ||
@@ -199,6 +193,23 @@ out:return MNL_CB_OK ; } +int res_qp_idx_parse_cb (const struct nlmsghdr *nlh,void *data) +{ +struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {}; +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 ]) +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 ]); + +return res_qp_line (rd, name, idx, tb); +} +int res_qp_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -218,8 +229,13 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data) nla_table = tb[RDMA_NLDEV_ATTR_RES_QP ];mnl_attr_for_each_nested (nla_entry, nla_table) { - ret =res_qp_line (rd, name, idx, nla_entry); +struct nlattr *nla_line[RDMA_NLDEV_ATTR_MAX ] = {}; + + ret =mnl_attr_parse_nested (nla_entry, rd_attr_cb, nla_line); +if (ret !=MNL_CB_OK ) +break ; + ret =res_qp_line (rd, name, idx, nla_line);if (ret !=MNL_CB_OK )break ; }
rdma/res.c +33 -1
@@ -54,6 +54,11 @@ static int res_print_summary(struct rd *rd, struct nlattr **tb)return 0 ; } +static int res_no_args_idx_parse_cb (const struct nlmsghdr *nlh,void *data) +{ +return MNL_CB_OK ; +} +static int res_no_args_parse_cb (const struct nlmsghdr *nlh,void *data) {struct nlattr *tb[RDMA_NLDEV_ATTR_MAX ] = {};
@@ -83,6 +88,33 @@ static int res_no_args_parse_cb(const struct nlmsghdr *nlh, void *data)return MNL_CB_OK ; } +int _res_send_idx_msg (struct rd *rd,uint32_t command,mnl_cb_t callback, +uint32_t idx,uint32_t id) +{ +uint32_t flags =NLM_F_REQUEST |NLM_F_ACK ; +uint32_t seq; +int ret; + +rd_prepare_msg (rd, command, &seq, flags); +mnl_attr_put_u32 (rd->nlh,RDMA_NLDEV_ATTR_DEV_INDEX , rd->dev_idx); +if (rd->port_idx) +mnl_attr_put_u32 (rd->nlh, +RDMA_NLDEV_ATTR_PORT_INDEX , rd->port_idx); + +mnl_attr_put_u32 (rd->nlh, id, idx); + + ret =rd_send_msg (rd); +if (ret) +return ret; + +if (rd->json_output) +jsonw_start_object (rd->jw); + ret =rd_recv_msg (rd, callback, rd, seq); +if (rd->json_output) +jsonw_end_object (rd->jw); +return ret; +} +int _res_send_msg (struct rd *rd,uint32_t command,mnl_cb_t callback) {uint32_t flags =NLM_F_REQUEST |NLM_F_ACK ;
@@ -214,7 +246,7 @@ void res_print_uint(struct rd *rd, const char *name, uint64_t val,pr_out ("%s %" PRIu64" " , name, val); } -RES_FUNC (res_no_args,RDMA_NLDEV_CMD_RES_GET ,NULL , true); +RES_FUNC (res_no_args,RDMA_NLDEV_CMD_RES_GET ,NULL , true,0 );static int res_show (struct rd *rd) {
rdma/res.h +55 -29
141 lines not on this page · raw message
rdma/utils.c +20 -0
@@ -121,6 +121,7 @@ static int add_filter(struct rd *rd, char *key, char *value,struct filter_entry *fe;bool key_found = false;int idx =0 ; +char *endp;int ret; fe =calloc (1 ,sizeof (*fe));
@@ -163,6 +164,11 @@ static int add_filter(struct rd *rd, char *key, char *value, goto err_alloc; } + errno =0 ; +strtol (fe->value, &endp,10 ); +if (valid_filters[idx].is_doit && !errno && *endp =='\0' ) + fe->is_doit = true; +for (idx =0 ; idx <strlen (fe->value); idx++) fe->value[idx] =tolower (fe->value[idx]);
@@ -177,6 +183,20 @@ err:return ret; } +bool rd_doit_index (struct rd *rd,uint32_t *idx) +{ +struct filter_entry *fe; + +list_for_each_entry (fe, &rd->filter_list, list) { +if (fe->is_doit) { + *idx =atoi (fe->value); +return true; + } + } + +return false; +} +int rd_build_filter (struct rd *rd,const struct filters valid_filters[]) {int ret =0 ;
Signature · 1 line
2.19.1
PATCH 19/19 rdma: Provide and reuse filter functions
In reply to Leon RomanovskyFrom: Leon Romanovsky <[email protected]>
Globally replace all filter function in safer variants of those is_filterred functions, which take into account the availability/lack of netlink attributes.
Such conversion allowed to fix a number of places in the code, where the previous implementation didn't honor filter requests if netlink attribute wasn't present.
--- rdma/rdma.h | 7 +++--- rdma/res-cmid.c | 57 +++++++++++++++++++++++++++---------------------- rdma/res-cq.c | 22 +++++++++++-------- rdma/res-mr.c | 12 +++++++---- rdma/res-pd.c | 12 +++++++---- rdma/res-qp.c | 53 ++++++++++++++++++++++----------------------- rdma/utils.c | 26 ++++++++++++++++++---- 7 files changed, 112 insertions(+), 77 deletions(-)
rdma/rdma.h +4 -3
@@ -110,9 +110,10 @@ struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index);*/ bool rd_doit_index (struct rd *rd,uint32_t *idx);int rd_build_filter (struct rd *rd,const struct filters valid_filters[]); -bool rd_check_is_filtered (struct rd *rd,const char *key,uint32_t val); -bool rd_check_is_string_filtered (struct rd *rd,const char *key,const char *val); -bool rd_check_is_key_exist (struct rd *rd,const char *key); +bool rd_is_filtered_attr (struct rd *rd,const char *key,uint32_t val, +struct nlattr *attr); +bool rd_is_string_filtered_attr (struct rd *rd,const char *key,const char *val, +struct nlattr *attr);/* * Netlink */
rdma/res-cmid.c +32 -25
89 lines not on this page · raw message
rdma/res-cq.c +13 -9
@@ -51,32 +51,36 @@ static int res_cq_line(struct rd *rd, const char *name, int idx, cqe =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CQE ]); users =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); -if (rd_check_is_filtered (rd,"users" , users)) +if (rd_is_filtered_attr (rd,"users" , users, + nla_line[RDMA_NLDEV_ATTR_RES_USECNT ])) goto out; -if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]) { +if (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]) poll_ctx =mnl_attr_get_u8 (nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ]); -if (rd_check_is_string_filtered (rd,"poll-ctx" , -poll_ctx_to_str (poll_ctx))) - goto out; - } +if (rd_is_string_filtered_attr (rd,"poll-ctx" , +poll_ctx_to_str (poll_ctx), + nla_line[RDMA_NLDEV_ATTR_RES_POLL_CTX ])) + goto out;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)) +if (rd_is_filtered_attr (rd,"pid" , pid, + nla_line[RDMA_NLDEV_ATTR_RES_PID ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]) cqn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CQN ]); -if (rd_check_is_filtered (rd,"cqn" , cqn)) +if (rd_is_filtered_attr (rd,"cqn" , cqn, + nla_line[RDMA_NLDEV_ATTR_RES_CQN ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) ctxn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); -if (rd_check_is_filtered (rd,"ctxn" , ctxn)) +if (rd_is_filtered_attr (rd,"ctxn" , ctxn, + nla_line[RDMA_NLDEV_ATTR_RES_CTXN ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])
rdma/res-mr.c +8 -4
@@ -31,7 +31,8 @@ static int res_mr_line(struct rd *rd, const char *name, int idx, iova =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_IOVA ]); mrlen =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_MRLEN ]); -if (rd_check_is_filtered (rd,"mrlen" , mrlen)) +if (rd_is_filtered_attr (rd,"mrlen" , mrlen, + nla_line[RDMA_NLDEV_ATTR_RES_MRLEN ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_PID ]) {
@@ -39,17 +40,20 @@ static int res_mr_line(struct rd *rd, const char *name, int idx, comm =get_task_name (pid); } -if (rd_check_is_filtered (rd,"pid" , pid)) +if (rd_is_filtered_attr (rd,"pid" , pid, + nla_line[RDMA_NLDEV_ATTR_RES_PID ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]) mrn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_MRN ]); -if (rd_check_is_filtered (rd,"mrn" , mrn)) +if (rd_is_filtered_attr (rd,"mrn" , mrn, + nla_line[RDMA_NLDEV_ATTR_RES_MRN ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) pdn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); -if (rd_check_is_filtered (rd,"pdn" , pdn)) +if (rd_is_filtered_attr (rd,"pdn" , pdn, + nla_line[RDMA_NLDEV_ATTR_RES_PDN ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])
rdma/res-pd.c +8 -4
@@ -28,7 +28,8 @@ static int res_pd_line(struct rd *rd, const char *name, int idx, nla_line[RDMA_NLDEV_ATTR_RES_LOCAL_DMA_LKEY]); users =mnl_attr_get_u64 (nla_line[RDMA_NLDEV_ATTR_RES_USECNT ]); -if (rd_check_is_filtered (rd,"users" , users)) +if (rd_is_filtered_attr (rd,"users" , users, + nla_line[RDMA_NLDEV_ATTR_RES_USECNT ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_UNSAFE_GLOBAL_RKEY ])
@@ -40,18 +41,21 @@ static int res_pd_line(struct rd *rd, const char *name, int idx, comm =get_task_name (pid); } -if (rd_check_is_filtered (rd,"pid" , pid)) +if (rd_is_filtered_attr (rd,"pid" , pid, + nla_line[RDMA_NLDEV_ATTR_RES_PID ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]) ctxn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_CTXN ]); -if (rd_check_is_filtered (rd,"ctxn" , ctxn)) +if (rd_is_filtered_attr (rd,"ctxn" , ctxn, + nla_line[RDMA_NLDEV_ATTR_RES_CTXN ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]) pdn =mnl_attr_get_u32 (nla_line[RDMA_NLDEV_ATTR_RES_PDN ]); -if (rd_check_is_filtered (rd,"pdn" , pdn)) +if (rd_is_filtered_attr (rd,"pdn" , pdn, + nla_line[RDMA_NLDEV_ATTR_RES_PDN ])) goto out;if (nla_line[RDMA_NLDEV_ATTR_RES_KERN_NAME ])
rdma/res-qp.c +25 -28
85 lines not on this page · raw message
rdma/utils.c +22 -4
@@ -233,7 +233,7 @@ out:return ret; } -bool rd_check_is_key_exist (struct rd *rd,const char *key) +static bool rd_check_is_key_exist (struct rd *rd,const char *key) {struct filter_entry *fe;
@@ -249,8 +249,8 @@ bool rd_check_is_key_exist(struct rd *rd, const char *key)* Check if string entry is filtered: * * key doesn't exist -> user didn't request -> not filtered */ -bool rd_check_is_string_filtered (struct rd *rd, -const char *key,const char *val) +static bool rd_check_is_string_filtered (struct rd *rd,const char *key, +const char *val) {bool key_is_filtered = false;struct filter_entry *fe;
@@ -300,7 +300,7 @@ out:* Check if key is filtered: * key doesn't exist -> user didn't request -> not filtered */ -bool rd_check_is_filtered (struct rd *rd,const char *key,uint32_t val) +static bool rd_check_is_filtered (struct rd *rd,const char *key,uint32_t val) {bool key_is_filtered = false;struct filter_entry *fe;
@@ -349,6 +349,24 @@ out:return key_is_filtered; } +bool rd_is_filtered_attr (struct rd *rd,const char *key,uint32_t val, +struct nlattr *attr) +{ +if (!attr) +return rd_check_is_key_exist (rd, key); + +return rd_check_is_filtered (rd, key, val); +} + +bool rd_is_string_filtered_attr (struct rd *rd,const char *key,const char *val, +struct nlattr *attr) +{ +if (!attr) +rd_check_is_key_exist (rd, key); + +return rd_check_is_string_filtered (rd, key, val); +} +static void filters_cleanup (struct rd *rd) {struct filter_entry *fe, *tmp;
Signature · 1 line
2.19.1
Re: [PATCH iproute2-next 05/19] rdma: Move resource PD logic to separate file
In reply to Leon Romanovskyrdma/res.h line 43
Quoted 9 lines · Leon Romanovsky
rdma/res.h new file +9
-0+static const +struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS ] = { + { .name ="dev" , .is_number = false }, + { .name ="users" , .is_number = true }, + { .name ="pid" , .is_number = true }, + { .name ="ctxn" , .is_number = true }, + { .name ="pdn" , .is_number = true }, + { .name ="ctxn" , .is_number = true } +};
These should not be in a header file. Looks like you have done this in other patches as well.
Re: [PATCH iproute2-next 05/19] rdma: Move resource PD logic to separate file
Quoted 13 lines · David Ahern
rdma/res.h line 43
Quoted 9 lines · Leon Romanovsky
rdma/res.h new file +9
-0+static const +struct filters pd_valid_filters[MAX_NUMBER_OF_FILTERS ] = { + { .name ="dev" , .is_number = false }, + { .name ="users" , .is_number = true }, + { .name ="pid" , .is_number = true }, + { .name ="ctxn" , .is_number = true }, + { .name ="pdn" , .is_number = true }, + { .name ="ctxn" , .is_number = true } +};These should not be in a header file. Looks like you have done this in other patches as well.
This is the outcome of how we build command line with single struct *rd, see res_show(). While I refactored the code, I saw your comment is coming, but decided to proceed anyway to make this series a little bit sane.
I'll definitely continue to refactor it, but for now, there is a need to see valid_filters structure in RES_FUNC() macro.
Thanks