netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Pirko <jiri@resnulli.us>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, idosch@mellanox.com, dsahern@gmail.com,
	jakub.kicinski@netronome.com, tariqt@mellanox.com,
	saeedm@mellanox.com, kuznet@ms2.inr.ac.ru,
	yoshfuji@linux-ipv6.org, shuah@kernel.org, mlxsw@mellanox.com
Subject: [patch iproute2-next v3 1/2] devlink: introduce cmdline option to switch to a different namespace
Date: Thu,  3 Oct 2019 11:51:14 +0200	[thread overview]
Message-ID: <20191003095115.10098-1-jiri@resnulli.us> (raw)
In-Reply-To: <20191003094940.9797-1-jiri@resnulli.us>

From: Jiri Pirko <jiri@mellanox.com>

Similar to ip tool, add an option to devlink to operate under certain
network namespace. Unfortunately, "-n" is already taken, so use "-N"
instead.

Example:

$ devlink -N testns1 dev show

Signed-off-by: Jiri Pirko <jiri@mellanox.com>
---
v1->v2:
- added patch description
---
 devlink/devlink.c  | 12 ++++++++++--
 man/man8/devlink.8 |  4 ++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/devlink/devlink.c b/devlink/devlink.c
index 5e762e37540c..852e2257cb64 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -32,6 +32,7 @@
 #include "mnlg.h"
 #include "json_writer.h"
 #include "utils.h"
+#include "namespace.h"
 
 #define ESWITCH_MODE_LEGACY "legacy"
 #define ESWITCH_MODE_SWITCHDEV "switchdev"
@@ -7023,7 +7024,7 @@ static int cmd_trap(struct dl *dl)
 static void help(void)
 {
 	pr_err("Usage: devlink [ OPTIONS ] OBJECT { COMMAND | help }\n"
-	       "       devlink [ -f[orce] ] -b[atch] filename\n"
+	       "       devlink [ -f[orce] ] -b[atch] filename -N[etns] netnsname\n"
 	       "where  OBJECT := { dev | port | sb | monitor | dpipe | resource | region | health | trap }\n"
 	       "       OPTIONS := { -V[ersion] | -n[o-nice-names] | -j[son] | -p[retty] | -v[erbose] -s[tatistics] }\n");
 }
@@ -7173,6 +7174,7 @@ int main(int argc, char **argv)
 		{ "pretty",		no_argument,		NULL, 'p' },
 		{ "verbose",		no_argument,		NULL, 'v' },
 		{ "statistics",		no_argument,		NULL, 's' },
+		{ "Netns",		required_argument,	NULL, 'N' },
 		{ NULL, 0, NULL, 0 }
 	};
 	const char *batch_file = NULL;
@@ -7188,7 +7190,7 @@ int main(int argc, char **argv)
 		return EXIT_FAILURE;
 	}
 
-	while ((opt = getopt_long(argc, argv, "Vfb:njpvs",
+	while ((opt = getopt_long(argc, argv, "Vfb:njpvsN:",
 				  long_options, NULL)) >= 0) {
 
 		switch (opt) {
@@ -7217,6 +7219,12 @@ int main(int argc, char **argv)
 		case 's':
 			dl->stats = true;
 			break;
+		case 'N':
+			if (netns_switch(optarg)) {
+				ret = EXIT_FAILURE;
+				goto dl_free;
+			}
+			break;
 		default:
 			pr_err("Unknown option.\n");
 			help();
diff --git a/man/man8/devlink.8 b/man/man8/devlink.8
index 12d489440a3d..7f4eda568081 100644
--- a/man/man8/devlink.8
+++ b/man/man8/devlink.8
@@ -55,6 +55,10 @@ Turn on verbose output.
 .BR "\-s" , " --statistics"
 Output statistics.
 
+.TP
+.BR "\-N", " \-Netns " <NETNSNAME>
+Switches to the specified network namespace.
+
 .SS
 .I OBJECT
 
-- 
2.21.0


  parent reply	other threads:[~2019-10-03  9:51 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-03  9:49 [patch net-next v3 00/15] devlink: allow devlink instances to change network namespace Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 01/15] netdevsim: change fib accounting and limitations to be per-device Jiri Pirko
2019-10-03 23:03   ` Jakub Kicinski
2019-10-03  9:49 ` [patch net-next v3 02/15] net: fib_notifier: make FIB notifier per-netns Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 03/15] net: fib_notifier: propagate possible error during fib notifier registration Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 04/15] mlxsw: spectrum_router: Don't rely on missing extack to symbolize dump Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 05/15] net: fib_notifier: propagate extack down to the notifier block callback Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 06/15] net: devlink: export devlink net getter Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 07/15] mlxsw: spectrum: Take devlink net instead of init_net Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 08/15] mlxsw: Register port netdevices into net of core Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 09/15] mlxsw: Propagate extack down to register_fib_notifier() Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 10/15] netdevsim: add all ports in nsim_dev_create() and del them in destroy() Jiri Pirko
2019-10-03 23:07   ` Jakub Kicinski
2019-10-03  9:49 ` [patch net-next v3 11/15] netdevsim: implement proper devlink reload Jiri Pirko
2019-10-03 23:17   ` Jakub Kicinski
2019-10-04  6:19     ` Jiri Pirko
2019-10-04 17:42       ` Jakub Kicinski
2019-10-04 20:49         ` Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 12/15] netdevsim: register port netdevices into net of device Jiri Pirko
2019-10-03 23:21   ` Jakub Kicinski
2019-10-04  6:20     ` Jiri Pirko
2019-10-03  9:49 ` [patch net-next v3 13/15] netdevsim: take devlink net instead of init_net Jiri Pirko
2019-10-03 23:21   ` Jakub Kicinski
2019-10-03  9:49 ` [patch net-next v3 14/15] net: devlink: allow to change namespaces during reload Jiri Pirko
2019-10-03 23:23   ` Jakub Kicinski
2019-10-03  9:49 ` [patch net-next v3 15/15] selftests: netdevsim: add tests for devlink reload with resources Jiri Pirko
2019-10-03  9:51 ` Jiri Pirko [this message]
2019-10-07 22:01   ` [patch iproute2-next v3 1/2] devlink: introduce cmdline option to switch to a different namespace David Ahern
2019-10-03  9:51 ` [patch iproute2-next v3 2/2] devlink: extend reload command to add support for network namespace change Jiri Pirko
2019-10-04 18:11 ` [patch net-next v3 00/15] devlink: allow devlink instances to change network namespace David Miller
  -- strict thread matches above, loose matches on Subject: below --
2019-08-12 13:47 [patch net-next v3 0/3] net: devlink: Finish network namespace support Jiri Pirko
2019-08-12 13:51 ` [patch iproute2-next v3 1/2] devlink: introduce cmdline option to switch to a different namespace Jiri Pirko

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=20191003095115.10098-1-jiri@resnulli.us \
    --to=jiri@resnulli.us \
    --cc=davem@davemloft.net \
    --cc=dsahern@gmail.com \
    --cc=idosch@mellanox.com \
    --cc=jakub.kicinski@netronome.com \
    --cc=kuznet@ms2.inr.ac.ru \
    --cc=mlxsw@mellanox.com \
    --cc=netdev@vger.kernel.org \
    --cc=saeedm@mellanox.com \
    --cc=shuah@kernel.org \
    --cc=tariqt@mellanox.com \
    --cc=yoshfuji@linux-ipv6.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).