]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
rdma: add oneline flag
authorStephen Hemminger <stephen@networkplumber.org>
Tue, 2 Jan 2024 17:30:15 +0000 (09:30 -0800)
committerStephen Hemminger <stephen@networkplumber.org>
Thu, 4 Jan 2024 00:48:33 +0000 (16:48 -0800)
Add oneline output format like other commands.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
man/man8/rdma.8
rdma/dev.c
rdma/link.c
rdma/rdma.c
rdma/stat.c
rdma/sys.c
rdma/utils.c

index c9e5d50d5ad799507cc5e2f927c87fa719ca1a0b..5088b9ec3cf233821d800e311cf5900739933071 100644 (file)
@@ -25,8 +25,9 @@ rdma \- RDMA tool
 .ti -8
 .IR OPTIONS " := { "
 \fB\-V\fR[\fIersion\fR] |
-\fB\-d\fR[\fIetails\fR] }
-\fB\-j\fR[\fIson\fR] }
+\fB\-d\fR[\fIetails\fR] |
+\fB\-j\fR[\fIson\fR] |
+\fB\-o\fR[\fIneline\fR] |
 \fB\-p\fR[\fIretty\fR] }
 
 .SH OPTIONS
@@ -63,6 +64,13 @@ When combined with -j generate a pretty JSON output.
 .BR "\-j" , " --json"
 Generate JSON output.
 
+.TP
+.BR "\-o" , " \-oneline"
+output each record on a single line, replacing line feeds
+with the
+.B '\e'
+character.
+
 .SS
 .I OBJECT
 
index 7496162df9e2ad539f52757b52c381b63f224ccd..31868c6fe43e30f82f883ec7c300852558f8d800 100644 (file)
@@ -94,7 +94,7 @@ static void dev_print_caps(struct rd *rd, struct nlattr **tb)
 
        caps = mnl_attr_get_u64(tb[RDMA_NLDEV_ATTR_CAP_FLAGS]);
 
-       print_string(PRINT_FP, NULL, "\n    caps: <", NULL);
+       print_string(PRINT_FP, NULL, "%s    caps: <", _SL_);
        open_json_array(PRINT_JSON, "caps");
        for (idx = 0; caps; idx++) {
                if (caps & 0x1)
index 48f7b0877468346a6c5f3576d046c88f16994f3c..d7d9558b49f2fb3b22788c45dc3d870d06991a22 100644 (file)
@@ -96,7 +96,7 @@ static void link_print_caps(struct rd *rd, struct nlattr **tb)
 
        caps = mnl_attr_get_u64(tb[RDMA_NLDEV_ATTR_CAP_FLAGS]);
 
-       print_string(PRINT_FP, NULL, "\n    caps: <", NULL);
+       print_string(PRINT_FP, NULL, "%s    caps: <", _SL_);
        open_json_array(PRINT_JSON, "caps");
        for (idx = 0; caps; idx++) {
                if (caps & 0x1)
index bee1985f96d8a37725c2599de94f2854d9d134ef..131c6b2abd346e26452b8fb35abbfee9e87cadeb 100644 (file)
@@ -16,7 +16,7 @@ static void help(char *name)
        pr_out("Usage: %s [ OPTIONS ] OBJECT { COMMAND | help }\n"
               "       %s [ -f[orce] ] -b[atch] filename\n"
               "where  OBJECT := { dev | link | resource | system | statistic | help }\n"
-              "       OPTIONS := { -V[ersion] | -d[etails] | -j[son] | -p[retty] -r[aw]}\n", name, name);
+              "       OPTIONS := { -V[ersion] | -d[etails] | -j[son] | -p[retty] -r[aw]}\n", name, name);
 }
 
 static int cmd_help(struct rd *rd)
@@ -89,6 +89,7 @@ int main(int argc, char **argv)
                { "version",            no_argument,            NULL, 'V' },
                { "help",               no_argument,            NULL, 'h' },
                { "json",               no_argument,            NULL, 'j' },
+               { "oneline",            no_argument,            NULL, 'o' },
                { "pretty",             no_argument,            NULL, 'p' },
                { "details",            no_argument,            NULL, 'd' },
                { "raw",                no_argument,            NULL, 'r' },
@@ -101,13 +102,14 @@ int main(int argc, char **argv)
        bool show_details = false;
        bool show_raw = false;
        bool force = false;
+       bool oneline = false;
        struct rd rd = {};
        char *filename;
        int opt;
        int err;
        filename = basename(argv[0]);
 
-       while ((opt = getopt_long(argc, argv, ":Vhdrpjfb:",
+       while ((opt = getopt_long(argc, argv, ":Vhdropjfb:",
                                  long_options, NULL)) >= 0) {
                switch (opt) {
                case 'V':
@@ -126,6 +128,9 @@ int main(int argc, char **argv)
                case 'r':
                        show_raw = true;
                        break;
+               case 'o':
+                       oneline = true;
+                       break;
                case 'j':
                        ++json;
                        break;
@@ -151,6 +156,8 @@ int main(int argc, char **argv)
        argc -= optind;
        argv += optind;
 
+       _SL_ = oneline ? "\\" : "\n";
+
        rd.show_details = show_details;
        rd.show_driver_details = show_driver_details;
        rd.show_raw = show_raw;
index b428a62ac707b2c477ab8a267b24102a2c092ab2..e90b6197ceb7202a3c9dd61b7dfed14f08eef7a7 100644 (file)
@@ -291,7 +291,7 @@ static int res_counter_line(struct rd *rd, const char *name, int index,
        res_get_hwcounters(rd, hwc_table, true);
        isfirst = true;
        open_json_array(PRINT_JSON, "lqpn");
-       print_string(PRINT_FP, NULL, "\n    LQPN: <", NULL);
+       print_string(PRINT_FP, NULL, "%s    LQPN: <", _SL_);
        mnl_attr_for_each_nested(nla_entry, qp_table) {
                struct nlattr *qp_line[RDMA_NLDEV_ATTR_MAX] = {};
                err = mnl_attr_parse_nested(nla_entry, rd_attr_cb, qp_line);
index 7bb0edbfec2bcf881c7c62c41971c7df0adb3a6a..7dbe4409482043fcd01322ca15d28d19ea5a7fcd 100644 (file)
@@ -51,7 +51,8 @@ static int sys_show_parse_cb(const struct nlmsghdr *nlh, void *data)
        if (tb[RDMA_NLDEV_SYS_ATTR_COPY_ON_FORK])
                cof = mnl_attr_get_u8(tb[RDMA_NLDEV_SYS_ATTR_COPY_ON_FORK]);
 
-       print_on_off(PRINT_ANY, "copy-on-fork", "copy-on-fork %s\n", cof);
+       print_on_off(PRINT_ANY, "copy-on-fork", "copy-on-fork %s", cof);
+       print_nl();
 
        return MNL_CB_OK;
 }
index f332b2602e6fc4c02a976083f31efba438261a24..aeb627be77159e7138f3d77ab8d81dc14b98b013 100644 (file)
@@ -774,7 +774,7 @@ struct dev_map *dev_map_lookup(struct rd *rd, bool allow_port_index)
 void newline(struct rd *rd)
 {
        close_json_object();
-       print_string(PRINT_FP, NULL, "\n", NULL);
+       print_nl();
 }
 
 void newline_indent(struct rd *rd)