]> git.proxmox.com Git - mirror_iproute2.git/commitdiff
rdma: Move per-device handler function to generic code
authorLeon Romanovsky <leonro@mellanox.com>
Wed, 27 Dec 2017 07:57:52 +0000 (09:57 +0200)
committerDavid Ahern <dsahern@gmail.com>
Wed, 27 Dec 2017 15:47:35 +0000 (07:47 -0800)
Most of the proposed objects are working in the scope "dev"
and will implement the same logic. Move the code to utils.c,
so other objects will be able to reuse the code.

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
Signed-off-by: David Ahern <dsahern@gmail.com>
rdma/dev.c
rdma/rdma.h
rdma/utils.c

index 9fadf3ac3b9cd45388d962b35dc99694c551c642..03ab8683332d661c9cc69faa75e7722782fd892a 100644 (file)
@@ -241,33 +241,7 @@ static int dev_one_show(struct rd *rd)
 
 static int dev_show(struct rd *rd)
 {
-       struct dev_map *dev_map;
-       int ret = 0;
-
-       if (rd->json_output)
-               jsonw_start_array(rd->jw);
-       if (rd_no_arg(rd)) {
-               list_for_each_entry(dev_map, &rd->dev_map_list, list) {
-                       rd->dev_idx = dev_map->idx;
-                       ret = dev_one_show(rd);
-                       if (ret)
-                               goto out;
-               }
-       } else {
-               dev_map = dev_map_lookup(rd, false);
-               if (!dev_map) {
-                       pr_err("Wrong device name\n");
-                       ret = -ENOENT;
-                       goto out;
-               }
-               rd_arg_inc(rd);
-               rd->dev_idx = dev_map->idx;
-               ret = dev_one_show(rd);
-       }
-out:
-       if (rd->json_output)
-               jsonw_end_array(rd->jw);
-       return ret;
+       return rd_exec_dev(rd, dev_one_show);
 }
 
 int cmd_dev(struct rd *rd)
index c07493c91242370d37fe1c08322581ac6c1370ba..b85e3748596e05a8506aab22140557ea39f3d7df 100644 (file)
@@ -72,6 +72,7 @@ uint32_t get_port_from_argv(struct rd *rd);
 int cmd_dev(struct rd *rd);
 int cmd_link(struct rd *rd);
 int rd_exec_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
+int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
 
 /*
  * Device manipulation
index bb29fa1a2386eb678244fa9b232955cc801da60c..5c0f021a63003b937df4ac9333065bec01d9d6dd 100644 (file)
@@ -159,6 +159,37 @@ void rd_free_devmap(struct rd *rd)
        dev_map_cleanup(rd);
 }
 
+int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd))
+{
+       struct dev_map *dev_map;
+       int ret = 0;
+
+       if (rd->json_output)
+               jsonw_start_array(rd->jw);
+       if (rd_no_arg(rd)) {
+               list_for_each_entry(dev_map, &rd->dev_map_list, list) {
+                       rd->dev_idx = dev_map->idx;
+                       ret = cb(rd);
+                       if (ret)
+                               goto out;
+               }
+       } else {
+               dev_map = dev_map_lookup(rd, false);
+               if (!dev_map) {
+                       pr_err("Wrong device name\n");
+                       ret = -ENOENT;
+                       goto out;
+               }
+               rd_arg_inc(rd);
+               rd->dev_idx = dev_map->idx;
+               ret = cb(rd);
+       }
+out:
+       if (rd->json_output)
+               jsonw_end_array(rd->jw);
+       return ret;
+}
+
 int rd_exec_cmd(struct rd *rd, const struct rd_cmd *cmds, const char *str)
 {
        const struct rd_cmd *c;