rdma: Move link execution logic to common code
Signed-off-by: Leon Romanovsky <leonro@mellanox.com> Signed-off-by: David Ahern <dsahern@gmail.com>
This commit is contained in:
parent
5fc17280b1
commit
874c734c1c
46
rdma/link.c
46
rdma/link.c
|
|
@ -285,51 +285,7 @@ static int link_one_show(struct rd *rd)
|
||||||
|
|
||||||
static int link_show(struct rd *rd)
|
static int link_show(struct rd *rd)
|
||||||
{
|
{
|
||||||
struct dev_map *dev_map;
|
return rd_exec_link(rd, link_one_show);
|
||||||
uint32_t port;
|
|
||||||
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;
|
|
||||||
for (port = 1; port < dev_map->num_ports + 1; port++) {
|
|
||||||
rd->port_idx = port;
|
|
||||||
ret = link_one_show(rd);
|
|
||||||
if (ret)
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
dev_map = dev_map_lookup(rd, true);
|
|
||||||
port = get_port_from_argv(rd);
|
|
||||||
if (!dev_map || port > dev_map->num_ports) {
|
|
||||||
pr_err("Wrong device name\n");
|
|
||||||
ret = -ENOENT;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
rd_arg_inc(rd);
|
|
||||||
rd->dev_idx = dev_map->idx;
|
|
||||||
rd->port_idx = port ? : 1;
|
|
||||||
for (; rd->port_idx < dev_map->num_ports + 1; rd->port_idx++) {
|
|
||||||
ret = link_one_show(rd);
|
|
||||||
if (ret)
|
|
||||||
goto out;
|
|
||||||
if (port)
|
|
||||||
/*
|
|
||||||
* We got request to show link for devname
|
|
||||||
* with port index.
|
|
||||||
*/
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
out:
|
|
||||||
if (rd->json_output)
|
|
||||||
jsonw_end_array(rd->jw);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_link(struct rd *rd)
|
int cmd_link(struct rd *rd)
|
||||||
|
|
|
||||||
|
|
@ -73,6 +73,7 @@ int cmd_dev(struct rd *rd);
|
||||||
int cmd_link(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_cmd(struct rd *rd, const struct rd_cmd *c, const char *str);
|
||||||
int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
|
int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd));
|
||||||
|
int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd));
|
||||||
void rd_free(struct rd *rd);
|
void rd_free(struct rd *rd);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
||||||
49
rdma/utils.c
49
rdma/utils.c
|
|
@ -152,6 +152,55 @@ void rd_free(struct rd *rd)
|
||||||
dev_map_cleanup(rd);
|
dev_map_cleanup(rd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd))
|
||||||
|
{
|
||||||
|
struct dev_map *dev_map;
|
||||||
|
uint32_t port;
|
||||||
|
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;
|
||||||
|
for (port = 1; port < dev_map->num_ports + 1; port++) {
|
||||||
|
rd->port_idx = port;
|
||||||
|
ret = cb(rd);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
dev_map = dev_map_lookup(rd, true);
|
||||||
|
port = get_port_from_argv(rd);
|
||||||
|
if (!dev_map || port > dev_map->num_ports) {
|
||||||
|
pr_err("Wrong device name\n");
|
||||||
|
ret = -ENOENT;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
rd_arg_inc(rd);
|
||||||
|
rd->dev_idx = dev_map->idx;
|
||||||
|
rd->port_idx = port ? : 1;
|
||||||
|
for (; rd->port_idx < dev_map->num_ports + 1; rd->port_idx++) {
|
||||||
|
ret = cb(rd);
|
||||||
|
if (ret)
|
||||||
|
goto out;
|
||||||
|
if (port)
|
||||||
|
/*
|
||||||
|
* We got request to show link for devname
|
||||||
|
* with port index.
|
||||||
|
*/
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
if (rd->json_output)
|
||||||
|
jsonw_end_array(rd->jw);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd))
|
int rd_exec_dev(struct rd *rd, int (*cb)(struct rd *rd))
|
||||||
{
|
{
|
||||||
struct dev_map *dev_map;
|
struct dev_map *dev_map;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue