idx = mnl_attr_get_u32(tb[RDMA_NLDEV_ATTR_DEV_INDEX]);
name = mnl_attr_get_str(tb[RDMA_NLDEV_ATTR_DEV_NAME]);
- if (rd->json_output) {
- jsonw_uint_field(rd->jw, "ifindex", idx);
- jsonw_string_field(rd->jw, "ifname", name);
- } else {
- pr_out("%u: %s: ", idx, name);
- }
-
+ open_json_object(NULL);
+ print_color_uint(PRINT_ANY, COLOR_NONE, "ifindex", "%u: ", idx);
+ print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "%s: ", name);
res_print_summary(rd, tb);
-
- if (!rd->json_output)
- pr_out("\n");
+ newline(rd);
return MNL_CB_OK;
}
mnl_attr_put_u32(rd->nlh, id, idx);
+ if (command == RDMA_NLDEV_CMD_STAT_GET)
+ mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES,
+ RDMA_NLDEV_ATTR_RES_MR);
+
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;
}
mnl_attr_put_u32(rd->nlh,
RDMA_NLDEV_ATTR_PORT_INDEX, rd->port_idx);
+ if (command == RDMA_NLDEV_CMD_STAT_GET)
+ mnl_attr_put_u32(rd->nlh, RDMA_NLDEV_ATTR_STAT_RES,
+ RDMA_NLDEV_ATTR_RES_MR);
+
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;
}
"UC", "UD", "RAW_IPV6",
"RAW_ETHERTYPE",
"UNKNOWN", "RAW_PACKET",
- "XRC_INI", "XRC_TGT" };
+ "XRC_INI", "XRC_TGT",
+ [0xFF] = "DRIVER",
+ };
- if (idx < ARRAY_SIZE(qp_types_str))
+ if (idx < ARRAY_SIZE(qp_types_str) && qp_types_str[idx])
return qp_types_str[idx];
return "UNKNOWN";
}
{
char tmp[18];
- if (rd->json_output) {
- /* Don't beatify output in JSON format */
- jsonw_string_field(rd->jw, "comm", str);
+ if (!str)
return;
- }
- if (nla_line[RDMA_NLDEV_ATTR_RES_PID])
+ if (nla_line[RDMA_NLDEV_ATTR_RES_PID] || rd->json_output)
snprintf(tmp, sizeof(tmp), "%s", str);
else
snprintf(tmp, sizeof(tmp), "[%s]", str);
-
- pr_out("comm %s ", tmp);
+ print_color_string(PRINT_ANY, COLOR_NONE, "comm", "comm %s ", tmp);
}
void print_dev(struct rd *rd, uint32_t idx, const char *name)
{
- if (rd->json_output) {
- jsonw_uint_field(rd->jw, "ifindex", idx);
- jsonw_string_field(rd->jw, "ifname", name);
- } else {
- pr_out("dev %s ", name);
- }
+ print_color_int(PRINT_ANY, COLOR_NONE, "ifindex", NULL, idx);
+ print_color_string(PRINT_ANY, COLOR_NONE, "ifname", "dev %s ", name);
}
void print_link(struct rd *rd, uint32_t idx, const char *name, uint32_t port,
struct nlattr **nla_line)
{
- if (rd->json_output) {
- jsonw_uint_field(rd->jw, "ifindex", idx);
+ char tmp[64] = {};
- if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
- jsonw_uint_field(rd->jw, "port", port);
-
- jsonw_string_field(rd->jw, "ifname", name);
+ print_color_uint(PRINT_JSON, COLOR_NONE, "ifindex", NULL, idx);
+ print_color_string(PRINT_ANY, COLOR_NONE, "ifname", NULL, name);
+ if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX]) {
+ print_color_uint(PRINT_ANY, COLOR_NONE, "port", NULL, port);
+ snprintf(tmp, sizeof(tmp), "%s/%d", name, port);
} else {
- if (nla_line[RDMA_NLDEV_ATTR_PORT_INDEX])
- pr_out("link %s/%u ", name, port);
- else
- pr_out("link %s/- ", name);
+ snprintf(tmp, sizeof(tmp), "%s/-", name);
}
+
+ if (!rd->json_output)
+ print_color_string(PRINT_ANY, COLOR_NONE, NULL, "link %s ",
+ tmp);
+}
+
+void print_qp_type(struct rd *rd, uint32_t val)
+{
+ print_color_string(PRINT_ANY, COLOR_NONE, "qp-type", "qp-type %s ",
+ qp_types_to_str(val));
}
char *get_task_name(uint32_t pid)
char *comm;
FILE *f;
+ if (!pid)
+ return NULL;
+
if (asprintf(&comm, "/proc/%d/comm", pid) < 0)
return NULL;
{
if (!nlattr)
return;
-
- if (rd->json_output)
- jsonw_xint_field(rd->jw, name, val);
- else
- pr_out("%s 0x%" PRIx64 " ", name, val);
+ print_color_string(PRINT_FP, COLOR_NONE, NULL, name, NULL);
+ print_color_hex(PRINT_ANY, COLOR_NONE, name, " 0x%" PRIx64 " ", val);
}
void res_print_uint(struct rd *rd, const char *name, uint64_t val,
{
if (!nlattr)
return;
-
- if (rd->json_output)
- jsonw_u64_field(rd->jw, name, val);
- else
- pr_out("%s %" PRIu64 " ", name, val);
+ print_color_uint(PRINT_ANY, COLOR_NONE, name, name, val);
+ print_color_uint(PRINT_FP, COLOR_NONE, NULL, " %d ", val);
}
RES_FUNC(res_no_args, RDMA_NLDEV_CMD_RES_GET, NULL, true, 0);