]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - rdma/rdma.c
Merge git://git.kernel.org/pub/scm/network/iproute2/iproute2-next into main
[mirror_iproute2.git] / rdma / rdma.c
index 19608f41faa518b8e83c8508ef7323d6a82f6228..8dc2d3e344be288f00e8f28b78a35826eac3ed3e 100644 (file)
@@ -1,22 +1,19 @@
+// 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 <leonro@mellanox.com>
  */
 
 #include "rdma.h"
-#include "SNAPSHOT.h"
+#include "version.h"
+#include "color.h"
 
 static void help(char *name)
 {
        pr_out("Usage: %s [ OPTIONS ] OBJECT { COMMAND | help }\n"
-              "where  OBJECT := { dev | link | resource | help }\n"
-              "       OPTIONS := { -V[ersion] | -d[etails] | -j[son] | -p[retty]}\n", name);
+              "       %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);
 }
 
 static int cmd_help(struct rd *rd)
@@ -25,7 +22,7 @@ static int cmd_help(struct rd *rd)
        return 0;
 }
 
-static int rd_cmd(struct rd *rd)
+static int rd_cmd(struct rd *rd, int argc, char **argv)
 {
        const struct rd_cmd cmds[] = {
                { NULL,         cmd_help },
@@ -33,32 +30,38 @@ static int rd_cmd(struct rd *rd)
                { "dev",        cmd_dev },
                { "link",       cmd_link },
                { "resource",   cmd_res },
+               { "system",     cmd_sys },
+               { "statistic",  cmd_stat },
                { 0 }
        };
 
+       rd->argc = argc;
+       rd->argv = argv;
+
        return rd_exec_cmd(rd, cmds, "object");
 }
 
-static int rd_init(struct rd *rd, int argc, char **argv, char *filename)
+static int rd_batch_cmd(int argc, char *argv[], void *data)
+{
+       struct rd *rd = data;
+
+       return rd_cmd(rd, argc, argv);
+}
+
+static int rd_batch(struct rd *rd, const char *name, bool force)
+{
+       return do_batch(name, force, rd_batch_cmd, rd);
+}
+
+static int rd_init(struct rd *rd, char *filename)
 {
        uint32_t seq;
        int ret;
 
        rd->filename = filename;
-       rd->argc = argc;
-       rd->argv = argv;
        INIT_LIST_HEAD(&rd->dev_map_list);
        INIT_LIST_HEAD(&rd->filter_list);
 
-       if (rd->json_output) {
-               rd->jw = jsonw_new(stdout);
-               if (!rd->jw) {
-                       pr_err("Failed to create JSON writer\n");
-                       return -ENOMEM;
-               }
-               jsonw_pretty(rd->jw, rd->pretty_output);
-       }
-
        rd->buff = malloc(MNL_SOCKET_BUFFER_SIZE);
        if (!rd->buff)
                return -ENOMEM;
@@ -74,8 +77,6 @@ static int rd_init(struct rd *rd, int argc, char **argv, char *filename)
 
 static void rd_cleanup(struct rd *rd)
 {
-       if (rd->json_output)
-               jsonw_destroy(&rd->jw);
        rd_free(rd);
 }
 
@@ -87,37 +88,57 @@ int main(int argc, char **argv)
                { "json",               no_argument,            NULL, 'j' },
                { "pretty",             no_argument,            NULL, 'p' },
                { "details",            no_argument,            NULL, 'd' },
+               { "raw",                no_argument,            NULL, 'r' },
+               { "force",              no_argument,            NULL, 'f' },
+               { "batch",              required_argument,      NULL, 'b' },
                { NULL, 0, NULL, 0 }
        };
-       bool pretty_output = false;
+       bool show_driver_details = false;
+       const char *batch_file = NULL;
        bool show_details = false;
        bool json_output = false;
+       bool show_raw = false;
+       bool force = false;
+       struct rd rd = {};
        char *filename;
-       struct rd rd;
        int opt;
        int err;
-
        filename = basename(argv[0]);
 
-       while ((opt = getopt_long(argc, argv, "Vhdpj",
+       while ((opt = getopt_long(argc, argv, ":Vhdrpjfb:",
                                  long_options, NULL)) >= 0) {
                switch (opt) {
                case 'V':
-                       printf("%s utility, iproute2-ss%s\n",
-                              filename, SNAPSHOT);
+                       printf("%s utility, iproute2-%s\n",
+                              filename, version);
                        return EXIT_SUCCESS;
                case 'p':
-                       pretty_output = true;
+                       pretty = 1;
                        break;
                case 'd':
-                       show_details = true;
+                       if (show_details)
+                               show_driver_details = true;
+                       else
+                               show_details = true;
+                       break;
+               case 'r':
+                       show_raw = true;
                        break;
                case 'j':
-                       json_output = true;
+                       json_output = 1;
+                       break;
+               case 'f':
+                       force = true;
+                       break;
+               case 'b':
+                       batch_file = optarg;
                        break;
                case 'h':
                        help(filename);
                        return EXIT_SUCCESS;
+               case ':':
+                       pr_err("-%c option requires an argument\n", optopt);
+                       return EXIT_FAILURE;
                default:
                        pr_err("Unknown option.\n");
                        help(filename);
@@ -129,14 +150,19 @@ int main(int argc, char **argv)
        argv += optind;
 
        rd.show_details = show_details;
+       rd.show_driver_details = show_driver_details;
        rd.json_output = json_output;
-       rd.pretty_output = pretty_output;
+       rd.pretty_output = pretty;
+       rd.show_raw = show_raw;
 
-       err = rd_init(&rd, argc, argv, filename);
+       err = rd_init(&rd, filename);
        if (err)
                goto out;
 
-       err = rd_cmd(&rd);
+       if (batch_file)
+               err = rd_batch(&rd, batch_file, force);
+       else
+               err = rd_cmd(&rd, argc, argv);
 out:
        /* Always cleanup */
        rd_cleanup(&rd);