@@ -224,7 +224,8 @@ static int dev_parse_cb(const struct nlmsghdr *nlh, void *data)
dev_print_caps(rd, tb);
}
- newline(rd);
+ close_json_object();
+ print_nl();
return MNL_CB_OK;
}
@@ -252,7 +252,9 @@ static int link_parse_cb(const struct nlmsghdr *nlh, void *data)
if (rd->show_details)
link_print_caps(rd, tb);
- newline(rd);
+ close_json_object();
+ print_nl();
+
return MNL_CB_OK;
}
@@ -135,9 +135,10 @@ int rd_attr_cb(const struct nlattr *attr, void *data);
*/
void print_driver_table(struct rd *rd, struct nlattr *tb);
void print_raw_data(struct rd *rd, struct nlattr **nla_line);
-void newline(struct rd *rd);
-void newline_indent(struct rd *rd);
void print_raw_data(struct rd *rd, struct nlattr **nla_line);
+void print_nl_indent(void);
+
#define MAX_LINE_LENGTH 80
+
#endif /* _RDMA_TOOL_H_ */
@@ -198,7 +198,8 @@ static int res_cm_id_line(struct rd *rd, const char *name, int idx,
print_ipaddr(rd, "dst-addr", dst_addr_str, dst_port);
print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
- newline(rd);
+ close_json_object();
+ print_nl();
out:
return MNL_CB_OK;
@@ -47,7 +47,8 @@ static int res_cq_line_raw(struct rd *rd, const char *name, int idx,
open_json_object(NULL);
print_dev(rd, idx, name);
print_raw_data(rd, nla_line);
- newline(rd);
+ close_json_object();
+ print_nl();
return MNL_CB_OK;
}
@@ -122,7 +123,9 @@ static int res_cq_line(struct rd *rd, const char *name, int idx,
print_comm(rd, comm, nla_line);
print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
- newline(rd);
+ close_json_object();
+ print_nl();
+
out:
return MNL_CB_OK;
@@ -47,7 +47,8 @@ static int res_ctx_line(struct rd *rd, const char *name, int idx,
print_comm(rd, comm, nla_line);
print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
- newline(rd);
+ close_json_object();
+ print_nl();
out:
return MNL_CB_OK;
@@ -16,7 +16,8 @@ static int res_mr_line_raw(struct rd *rd, const char *name, int idx,
open_json_object(NULL);
print_dev(rd, idx, name);
print_raw_data(rd, nla_line);
- newline(rd);
+ close_json_object();
+ print_nl();
return MNL_CB_OK;
}
@@ -87,7 +88,8 @@ static int res_mr_line(struct rd *rd, const char *name, int idx,
print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
print_raw_data(rd, nla_line);
- newline(rd);
+ close_json_object();
+ print_nl();
out:
return MNL_CB_OK;
@@ -76,8 +76,8 @@ static int res_pd_line(struct rd *rd, const char *name, int idx,
print_comm(rd, comm, nla_line);
print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
- newline(rd);
-
+ close_json_object();
+ print_nl();
out:
return MNL_CB_OK;
}
@@ -70,7 +70,8 @@ static int res_qp_line_raw(struct rd *rd, const char *name, int idx,
open_json_object(NULL);
print_link(rd, idx, name, rd->port_idx, nla_line);
print_raw_data(rd, nla_line);
- newline(rd);
+ close_json_object();
+ print_nl();
return MNL_CB_OK;
}
@@ -176,7 +177,8 @@ static int res_qp_line(struct rd *rd, const char *name, int idx,
print_comm(rd, comm, nla_line);
print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
- newline(rd);
+ close_json_object();
+ print_nl();
out:
return MNL_CB_OK;
}
@@ -170,7 +170,8 @@ static int res_srq_line_raw(struct rd *rd, const char *name, int idx,
open_json_object(NULL);
print_dev(rd, idx, name);
print_raw_data(rd, nla_line);
- newline(rd);
+ close_json_object();
+ print_nl();
return MNL_CB_OK;
}
@@ -241,7 +242,8 @@ static int res_srq_line(struct rd *rd, const char *name, int idx,
print_comm(rd, comm, nla_line);
print_driver_table(rd, nla_line[RDMA_NLDEV_ATTR_DRIVER]);
- newline(rd);
+ close_json_object();
+ print_nl();
out:
return MNL_CB_OK;
@@ -81,7 +81,9 @@ static int res_no_args_parse_cb(const struct nlmsghdr *nlh, void *data)
print_uint(PRINT_ANY, "ifindex", "%u: ", idx);
print_string(PRINT_ANY, "ifname", "%s: ", name);
res_print_summary(rd, tb);
- newline(rd);
+ close_json_object();
+ print_nl();
+
return MNL_CB_OK;
}
@@ -31,7 +31,8 @@ static int stat_mr_line(struct rd *rd, const char *name, int idx,
return ret;
}
- newline(rd);
+ close_json_object();
+ print_nl();
out:
return MNL_CB_OK;
}
@@ -136,7 +136,8 @@ static int qp_link_get_mode_parse_cb(const struct nlmsghdr *nlh, void *data)
open_json_object(NULL);
print_link(rd, idx, name, port, tb);
print_string(PRINT_ANY, "mode", "mode %s ", output);
- newline(rd);
+ close_json_object();
+ print_nl();
return MNL_CB_OK;
}
@@ -208,7 +209,7 @@ int res_get_hwcounters(struct rd *rd, struct nlattr *hwc_table, bool print)
nm = mnl_attr_get_str(hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_NAME]);
v = mnl_attr_get_u64(hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_VALUE]);
- newline_indent(rd);
+ print_nl_indent();
res_print_u64(rd, nm, v, hw_line[RDMA_NLDEV_ATTR_STAT_HWCOUNTER_ENTRY_NAME]);
}
@@ -308,7 +309,8 @@ static int res_counter_line(struct rd *rd, const char *name, int index,
isfirst = false;
}
close_json_array(PRINT_ANY, ">");
- newline(rd);
+ close_json_object();
+ print_nl();
return MNL_CB_OK;
}
@@ -757,7 +759,6 @@ static int do_stat_mode_parse_cb(const struct nlmsghdr *nlh, void *data,
struct nlattr *tb[RDMA_NLDEV_ATTR_MAX] = {};
struct nlattr *nla_entry;
const char *dev, *name;
- struct rd *rd = data;
int enabled, err = 0;
bool isfirst = true;
uint32_t port;
@@ -801,7 +802,7 @@ static int do_stat_mode_parse_cb(const struct nlmsghdr *nlh, void *data,
} else {
print_string(PRINT_FP, NULL, ",", NULL);
}
- newline_indent(rd);
+ print_nl_indent();
print_string(PRINT_ANY, NULL, "%s", name);
}
@@ -809,7 +810,8 @@ static int do_stat_mode_parse_cb(const struct nlmsghdr *nlh, void *data,
if (!isfirst) {
close_json_array(PRINT_JSON, NULL);
- newline(rd);
+ close_json_object();
+ print_nl();
}
return 0;
@@ -1070,7 +1072,8 @@ static int stat_show_parse_cb(const struct nlmsghdr *nlh, void *data)
print_uint(PRINT_ANY, "port", "%u ", port);
ret = res_get_hwcounters(rd, tb[RDMA_NLDEV_ATTR_STAT_HWCOUNTERS], true);
- newline(rd);
+ close_json_object();
+ print_nl();
return ret;
}
@@ -771,16 +771,10 @@ struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index)
#define nla_type(attr) ((attr)->nla_type & NLA_TYPE_MASK)
-void newline(struct rd *rd)
+void print_nl_indent(void)
{
- close_json_object();
- print_nl();
-}
-
-void newline_indent(struct rd *rd)
-{
- newline(rd);
- print_string(PRINT_FP, NULL, " ", NULL);
+ if (!is_json_context())
+ printf("%s ", _SL_);
}
static int print_driver_string(struct rd *rd, const char *key_str,
@@ -920,7 +914,7 @@ void print_driver_table(struct rd *rd, struct nlattr *tb)
if (!rd->show_driver_details || !tb)
return;
- newline_indent(rd);
+ print_nl_indent();
/*
* Driver attrs are tuples of {key, [print-type], value}.
@@ -932,7 +926,7 @@ void print_driver_table(struct rd *rd, struct nlattr *tb)
mnl_attr_for_each_nested(tb_entry, tb) {
if (cc > MAX_LINE_LENGTH) {
- newline_indent(rd);
+ print_nl_indent();
cc = 0;
}
if (rd_attr_check(tb_entry, &type) != MNL_CB_OK)
Mixing the semantics of ending lines with the json object leads to several bugs where json object is closed twice, etc. Replace by breaking the meaning of newline() function into two parts. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- rdma/dev.c | 3 ++- rdma/link.c | 4 +++- rdma/rdma.h | 5 +++-- rdma/res-cmid.c | 3 ++- rdma/res-cq.c | 7 +++++-- rdma/res-ctx.c | 3 ++- rdma/res-mr.c | 6 ++++-- rdma/res-pd.c | 4 ++-- rdma/res-qp.c | 6 ++++-- rdma/res-srq.c | 6 ++++-- rdma/res.c | 4 +++- rdma/stat-mr.c | 3 ++- rdma/stat.c | 17 ++++++++++------- rdma/utils.c | 16 +++++----------- 14 files changed, 51 insertions(+), 36 deletions(-)