rdma: Move QP code to separate function

Reviewed-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
Leon Romanovsky 2019-02-23 11:15:25 +02:00 committed by David Ahern
parent f9a73796d1
commit 6da9d2517c
1 changed files with 126 additions and 125 deletions

View File

@ -78,24 +78,9 @@ 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));
}
int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
static int res_qp_line(struct rd *rd, const char *name, int idx,
struct nlattr *nla_entry)
{
struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
struct nlattr *nla_table, *nla_entry;
struct rd *rd = data;
const char *name;
uint32_t idx;
mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
!tb[RDMA_NLDEV_ATTR_RES_QP])
return MNL_CB_ERROR;
name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
nla_table = tb[RDMA_NLDEV_ATTR_RES_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;
@ -118,78 +103,68 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
}
if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
port = mnl_attr_get_u32(
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;
goto out;
lqpn = mnl_attr_get_u32(nla_line[RDMA_NLDEV_ATTR_RES_LQPN]);
if (rd_check_is_filtered(rd, "lqpn", lqpn))
continue;
goto out;
if (nla_line[RDMA_NLDEV_ATTR_RES_PDN])
pdn = mnl_attr_get_u32(
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;
goto out;
if (nla_line[RDMA_NLDEV_ATTR_RES_RQPN]) {
rqpn = mnl_attr_get_u32(
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;
goto out;
} else {
if (rd_check_is_key_exist(rd, "rqpn"))
continue;
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]);
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;
goto out;
} else {
if (rd_check_is_key_exist(rd, "rq-psn"))
continue;
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))
continue;
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",
if (rd_check_is_string_filtered(rd, "path-mig-state",
path_mig_to_str(path_mig_state)))
continue;
goto out;
} else {
if (rd_check_is_key_exist(rd, "path-mig-state"))
continue;
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)))
continue;
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)))
continue;
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]);
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 (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 */
@ -216,11 +191,37 @@ int res_qp_parse_cb(const struct nlmsghdr *nlh, void *data)
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);
}
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;
mnl_attr_parse(nlh, 0, rd_attr_cb, tb);
if (!tb[RDMA_NLDEV_ATTR_DEV_INDEX] || !tb[RDMA_NLDEV_ATTR_DEV_NAME] ||
!tb[RDMA_NLDEV_ATTR_RES_QP])
return MNL_CB_ERROR;
name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
nla_table = tb[RDMA_NLDEV_ATTR_RES_QP];
mnl_attr_for_each_nested(nla_entry, nla_table) {
ret = res_qp_line(rd, name, idx, nla_entry);
if (ret != MNL_CB_OK)
break;
}
return ret;
}