All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leon Romanovsky <leon@kernel.org>
To: David Ahern <dsahern@gmail.com>
Cc: Leon Romanovsky <leonro@mellanox.com>,
	netdev <netdev@vger.kernel.org>,
	Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2-next 10/10] rdma: Move link execution logic to common code
Date: Wed, 27 Dec 2017 09:57:59 +0200	[thread overview]
Message-ID: <20171227075759.15289-11-leon@kernel.org> (raw)
In-Reply-To: <20171227075759.15289-1-leon@kernel.org>

From: Leon Romanovsky <leonro@mellanox.com>

Signed-off-by: Leon Romanovsky <leonro@mellanox.com>
---
 rdma/link.c  | 46 +---------------------------------------------
 rdma/rdma.h  |  1 +
 rdma/utils.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 51 insertions(+), 45 deletions(-)

diff --git a/rdma/link.c b/rdma/link.c
index d9392289..676cb21d 100644
--- a/rdma/link.c
+++ b/rdma/link.c
@@ -285,51 +285,7 @@ static int link_one_show(struct rd *rd)
 
 static int link_show(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 = 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;
+	return rd_exec_link(rd, link_one_show);
 }
 
 int cmd_link(struct rd *rd)
diff --git a/rdma/rdma.h b/rdma/rdma.h
index afc0e413..8d53d3a0 100644
--- a/rdma/rdma.h
+++ b/rdma/rdma.h
@@ -73,6 +73,7 @@ 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));
+int rd_exec_link(struct rd *rd, int (*cb)(struct rd *rd));
 void rd_free(struct rd *rd);
 
 /*
diff --git a/rdma/utils.c b/rdma/utils.c
index d7284801..7b2001e2 100644
--- a/rdma/utils.c
+++ b/rdma/utils.c
@@ -152,6 +152,55 @@ void rd_free(struct rd *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))
 {
 	struct dev_map *dev_map;
-- 
2.15.1

  parent reply	other threads:[~2017-12-27  7:58 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-27  7:57 [PATCH iproute2-next 00/10] RDMAtool cleanup and refactoring code Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 01/10] rdma: Reduce scope of _dev_map_lookup call Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 02/10] rdma: Protect dev_map_lookup from wrong input Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 03/10] rdma: Move per-device handler function to generic code Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 04/10] rdma: Fix misspelled SYS_IMAGE_GUID Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 05/10] rdma: Check that port index exists before operate on link layer Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 06/10] rdma: Print supplied device name in case of wrong name Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 07/10] rdma: Get rid of dev_map_free call Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 08/10] rdma: Rename free function to be rd_cleanup Leon Romanovsky
2017-12-27  7:57 ` [PATCH iproute2-next 09/10] rdma: Rename rd_free_devmap to be rd_free Leon Romanovsky
2017-12-27  7:57 ` Leon Romanovsky [this message]
2017-12-27 15:45 ` [PATCH iproute2-next 00/10] RDMAtool cleanup and refactoring code David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171227075759.15289-11-leon@kernel.org \
    --to=leon@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=leonro@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.