util-linux.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/7] Add netnsid and nsfs columns to lsns
@ 2017-11-24 10:31 Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 1/7] lsns: add netnsid column Masatake YAMATO
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

This patch-set adds netnsid and nsfs columns to lsns command.

The new columns are useful to understand namespaces information
printed in the output of "ip link" and "ip netns".  The new columns
are visible only when --type net is specified.

Masatake YAMATO (7):
  lsns: add netnsid column
  lsns: disable netnsid column by default
  lsns: add a case for testing netnsid column
  lsns: add nsfs column
  lsns: add --nowrap(-W) option
  lsns: add a case for testing nsfs column
  man: write about using multi-line in NSFS cell of lsns

 configure.ac                |   1 +
 sys-utils/Makemodule.am     |   4 +-
 sys-utils/lsns.8            |   8 ++
 sys-utils/lsns.c            | 319 +++++++++++++++++++++++++++++++++++++++++++-
 tests/commands.sh           |   1 +
 tests/expected/lsns/netnsid |   1 +
 tests/expected/lsns/nsfs    |   1 +
 tests/ts/lsns/netnsid       |  65 +++++++++
 tests/ts/lsns/nsfs          |  68 ++++++++++
 9 files changed, 459 insertions(+), 9 deletions(-)
 create mode 100644 tests/expected/lsns/netnsid
 create mode 100644 tests/expected/lsns/nsfs
 create mode 100644 tests/ts/lsns/netnsid
 create mode 100644 tests/ts/lsns/nsfs

-- 
2.13.6


^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH v2 1/7] lsns: add netnsid column
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 2/7] lsns: disable netnsid column by default Masatake YAMATO
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

Linux network subsystem assigns an unique integer to a network
namespace.

  term0# ip netns add UTIL-LINUX-LSNS-TEST-NS
  term0# ip netns list
  UTIL-LINUX-LSNS-TEST-NS
  term0# ip link add name lsns-vetha type veth peer name lsns-vethb
  term0 # ip link set lsns-vethb netns UTIL-LINUX-LSNS-TEST-NS
  term0# ip netns list
  UTIL-LINUX-LSNS-TEST-NS (id: 0)
  term0# ip link show dev lsns-vetha
  230: lsns-vetha@if229: <BROADCAST,MULTICAST> mtu 1500 qdisc noop ...
         link/ether 3e:27:68:ba:b3:95 brd ff:ff:ff:ff:ff:ff link-netnsid 0
In this example 0 is assigned to UTIL-LINUX-LSNS-TEST-NS net namespace.
The name, UTIL-LINUX-LSNS-TEST-NS, and it semantics is given and defined
by iproute2 in userland; and nothing to do with util-linux.

However, the id, 0, is managed in linux kernel. If lsns can show
the ids, it helps users understand the state of network namespaces.

This commit adds NETNSID column to the output.

Here is an example of session:

  term0# ip netns exec UTIL-LINUX-LSNS-TEST-NS cat

  (Open another terminal)

  term1# ./lsns --type net
          NS TYPE NPROCS   PID USER     NETNSID COMMAND
  4026531993 net     383     1 root  unassigned /usr/lib/systemd/...
  4026532433 net       1  1219 rtkit unassigned /usr/libexec/rtkit-daemon
  4026532562 net       1 18201 root           0 cat

0 is shown as NETNSID for the cat process.

For the initial name space, "unassigned" is printed.
For the namespaces other type than net, "n/a" is printed.
If an error occurred during getting the id, "n/a" is printed.

Changes in V2:

* Remove wrongly used & operators.
* Make netnsid field empty if value for the column is not available.
  Suggested by Karel Zak.
* Remove redundant condtion for checking the avaiablebility of netlink
  socket. Suggested by Karel Zak.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 configure.ac     |   1 +
 sys-utils/lsns.c | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 185 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index eebe92259..b2ad5ea98 100644
--- a/configure.ac
+++ b/configure.ac
@@ -223,6 +223,7 @@ AC_CHECK_HEADERS([ \
 	linux/tiocl.h \
 	linux/version.h \
 	linux/securebits.h \
+	linux/net_namespace.h \
 	locale.h \
 	mntent.h \
 	net/if.h \
diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index 1fb0b87f3..7ccc733a4 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -29,6 +29,14 @@
 #include <wchar.h>
 #include <libsmartcols.h>
 
+#ifdef HAVE_LINUX_NET_NAMESPACE_H
+#include <stdbool.h>
+#include <sys/socket.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <linux/net_namespace.h>
+#endif
+
 #include "pathnames.h"
 #include "nls.h"
 #include "xalloc.h"
@@ -52,6 +60,8 @@ UL_DEBUG_DEFINE_MASKNAMES(lsns) = UL_DEBUG_EMPTY_MASKNAMES;
 #define LSNS_DEBUG_NS		(1 << 3)
 #define LSNS_DEBUG_ALL		0xFFFF
 
+#define LSNS_NETNS_UNUSABLE -2
+
 #define DBG(m, x)       __UL_DBG(lsns, LSNS_DEBUG_, m, x)
 #define ON_DBG(m, x)    __UL_DBG_CALL(lsns, LSNS_DEBUG_, m, x)
 
@@ -67,7 +77,8 @@ enum {
 	COL_PPID,
 	COL_COMMAND,
 	COL_UID,
-	COL_USER
+	COL_USER,
+	COL_NETNSID
 };
 
 /* column names */
@@ -88,7 +99,8 @@ static const struct colinfo infos[] = {
 	[COL_PPID]    = { "PPID",    5, SCOLS_FL_RIGHT, N_("PPID of the PID") },
 	[COL_COMMAND] = { "COMMAND", 0, SCOLS_FL_TRUNC, N_("command line of the PID")},
 	[COL_UID]     = { "UID",     0, SCOLS_FL_RIGHT, N_("UID of the PID")},
-	[COL_USER]    = { "USER",    0, 0, N_("username of the PID")}
+	[COL_USER]    = { "USER",    0, 0, N_("username of the PID")},
+	[COL_NETNSID] = { "NETNSID", 0, SCOLS_FL_RIGHT, N_("Net namespace ID")}
 };
 
 static int columns[ARRAY_SIZE(infos) * 2];
@@ -118,6 +130,7 @@ struct lsns_namespace {
 	ino_t id;
 	int type;			/* LSNS_* */
 	int nprocs;
+	int netnsid;
 
 	struct lsns_process *proc;
 
@@ -139,6 +152,8 @@ struct lsns_process {
 
 	struct libscols_line *outline;
 	struct lsns_process *parent;
+
+	int netnsid;
 };
 
 struct lsns {
@@ -158,6 +173,16 @@ struct lsns {
 		     no_headings: 1;
 };
 
+struct netnsid_cache {
+	ino_t ino;
+	int   id;
+	struct list_head netnsids;
+};
+
+static struct list_head netnsids_cache;
+
+static int netlink_fd = -1;
+
 static void lsns_init_debug(void)
 {
 	__UL_INIT_DEBUG(lsns, LSNS_DEBUG_, 0, LSNS_DEBUG);
@@ -242,6 +267,137 @@ error:
 	return rc;
 }
 
+#ifdef HAVE_LINUX_NET_NAMESPACE_H
+static bool netnsid_cache_find(ino_t netino, int *netnsid)
+{
+	struct list_head *p;
+
+	list_for_each(p, &netnsids_cache) {
+		struct netnsid_cache *e = list_entry(p,
+						     struct netnsid_cache,
+						     netnsids);
+		if (e->ino == netino) {
+			*netnsid = e->id;
+			return true;
+		}
+	}
+
+	return false;
+}
+
+static void netnsid_cache_add(ino_t netino, int netnsid)
+{
+	struct netnsid_cache *e;
+
+	e = xcalloc(1, sizeof(*e));
+	e->ino = netino;
+	e->id  = netnsid;
+	INIT_LIST_HEAD(&e->netnsids);
+	list_add(&e->netnsids, &netnsids_cache);
+}
+
+static int get_netnsid_via_netlink_send_request(int target_fd)
+{
+	unsigned char req[NLMSG_SPACE(sizeof(struct rtgenmsg))
+			  + RTA_SPACE(sizeof(int32_t))];
+
+	struct nlmsghdr *nlh = (struct nlmsghdr *)req;
+	struct rtgenmsg *rt = NLMSG_DATA(req);
+	struct rtattr *rta = (struct rtattr *)
+		(req + NLMSG_SPACE(sizeof(struct rtgenmsg)));
+	int32_t *fd = RTA_DATA(rta);
+
+	nlh->nlmsg_len = sizeof(req);
+	nlh->nlmsg_flags = NLM_F_REQUEST;
+	nlh->nlmsg_type = RTM_GETNSID;
+	rt->rtgen_family = AF_UNSPEC;
+	rta->rta_type = NETNSA_FD;
+	rta->rta_len = RTA_SPACE(sizeof(int32_t));
+	*fd = target_fd;
+
+	if (send(netlink_fd, req, sizeof(req), 0) < 0)
+		return -1;
+	return 0;
+}
+
+static int get_netnsid_via_netlink_recv_response(int *netnsid)
+{
+	unsigned char res[NLMSG_SPACE(sizeof(struct rtgenmsg))
+			  + ((RTA_SPACE(sizeof(int32_t))
+			      < RTA_SPACE(sizeof(struct nlmsgerr)))
+			     ? RTA_SPACE(sizeof(struct nlmsgerr))
+			     : RTA_SPACE(sizeof(int32_t)))];
+	int reslen, rtalen;
+
+	struct nlmsghdr *nlh;
+	struct rtattr *rta;
+
+	reslen = recv(netlink_fd, res, sizeof(res), 0);
+	if (reslen < 0)
+		return -1;
+
+	nlh = (struct nlmsghdr *)res;
+	if (!(NLMSG_OK(nlh, reslen)
+	      && nlh->nlmsg_type == RTM_NEWNSID))
+		return -1;
+
+	rtalen = NLMSG_PAYLOAD(nlh, sizeof(struct rtgenmsg));
+	rta = (struct rtattr *)(res + NLMSG_SPACE(sizeof(struct rtgenmsg)));
+	if (!(RTA_OK(rta, rtalen)
+	      && rta->rta_type == NETNSA_NSID))
+		return -1;
+
+	*netnsid = *(int *)RTA_DATA(rta);
+
+	return 0;
+}
+
+static int get_netnsid_via_netlink(int dir, const char *path)
+{
+	int netnsid;
+	int target_fd;
+
+	if (netlink_fd < 0)
+		return LSNS_NETNS_UNUSABLE;
+
+	target_fd = openat(dir, path, O_RDONLY);
+	if (target_fd < 0)
+		return LSNS_NETNS_UNUSABLE;
+
+	if (get_netnsid_via_netlink_send_request(target_fd) < 0) {
+		netnsid = LSNS_NETNS_UNUSABLE;
+		goto out;
+	}
+
+	if (get_netnsid_via_netlink_recv_response(&netnsid) < 0) {
+		netnsid = LSNS_NETNS_UNUSABLE;
+		goto out;
+	}
+
+ out:
+	close(target_fd);
+	return netnsid;
+}
+
+static int get_netnsid(int dir, ino_t netino)
+{
+	int netnsid;
+
+	if (!netnsid_cache_find(netino, &netnsid)) {
+		netnsid = get_netnsid_via_netlink(dir, "ns/net");
+		netnsid_cache_add(netino, netnsid);
+	}
+
+	return netnsid;
+}
+#else
+static int get_netnsid(int dir __attribute__((__unused__)),
+		       ino_t netino __attribute__((__unused__)))
+{
+	return LSNS_NETNS_UNUSABLE;
+}
+#endif /* HAVE_LINUX_NET_NAMESPACE_H */
+
 static int read_process(struct lsns *ls, pid_t pid)
 {
 	struct lsns_process *p = NULL;
@@ -264,6 +420,7 @@ static int read_process(struct lsns *ls, pid_t pid)
 		rc = -ENOMEM;
 		goto done;
 	}
+	p->netnsid = LSNS_NETNS_UNUSABLE;
 
 	if (fstat(dirfd(dir), &st) == 0) {
 		p->uid = st.st_uid;
@@ -293,6 +450,8 @@ static int read_process(struct lsns *ls, pid_t pid)
 		rc = get_ns_ino(dirfd(dir), ns_names[i], &p->ns_ids[i]);
 		if (rc && rc != -EACCES && rc != -ENOENT)
 			goto done;
+		if (i == LSNS_ID_NET)
+			p->netnsid = get_netnsid(dirfd(dir), p->ns_ids[i]);
 		rc = 0;
 	}
 
@@ -413,6 +572,18 @@ static int cmp_namespaces(struct list_head *a, struct list_head *b,
 	return cmp_numbers(xa->id, xb->id);
 }
 
+static int netnsid_xasputs(char **str, int netnsid)
+{
+	if (netnsid >= 0)
+		return xasprintf(str, "%d", netnsid);
+#ifdef NETNSA_NSID_NOT_ASSIGNED
+	else if (netnsid == NETNSA_NSID_NOT_ASSIGNED)
+		return xasprintf(str, "%s", "unassigned");
+#endif
+	else
+		return 0;
+}
+
 static int read_namespaces(struct lsns *ls)
 {
 	struct list_head *p;
@@ -490,6 +661,10 @@ static void add_scols_line(struct lsns *ls, struct libscols_table *table,
 		case COL_USER:
 			xasprintf(&str, "%s", get_id(uid_cache, proc->uid)->name);
 			break;
+		case COL_NETNSID:
+			if (ns->type == LSNS_ID_NET)
+				netnsid_xasputs(&str, proc->netnsid);
+			break;
 		default:
 			break;
 		}
@@ -675,6 +850,7 @@ int main(int argc, char *argv[])
 
 	INIT_LIST_HEAD(&ls.processes);
 	INIT_LIST_HEAD(&ls.namespaces);
+	INIT_LIST_HEAD(&netnsids_cache);
 
 	while ((c = getopt_long(argc, argv,
 				"Jlp:o:nruhVt:", long_opts, NULL)) != -1) {
@@ -748,6 +924,7 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_NPROCS;
 		columns[ncolumns++] = COL_PID;
 		columns[ncolumns++] = COL_USER;
+		columns[ncolumns++] = COL_NETNSID;
 		columns[ncolumns++] = COL_COMMAND;
 	}
 
@@ -761,6 +938,9 @@ int main(int argc, char *argv[])
 	if (!uid_cache)
 		err(EXIT_FAILURE, _("failed to allocate UID cache"));
 
+#ifdef HAVE_LINUX_NET_NAMESPACE_H
+	netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+#endif
 	r = read_processes(&ls);
 	if (!r)
 		r = read_namespaces(&ls);
@@ -775,6 +955,8 @@ int main(int argc, char *argv[])
 			r = show_namespaces(&ls);
 	}
 
+	if (netlink_fd >= 0)
+		close(netlink_fd);
 	free_idcache(uid_cache);
 	return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
 }
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 2/7] lsns: disable netnsid column by default
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 1/7] lsns: add netnsid column Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 3/7] lsns: add a case for testing netnsid column Masatake YAMATO
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

Enable only when

* --type=net is given, or
* -o NETNSID is given.

Suggested by Karel Zak.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 sys-utils/lsns.c | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index 7ccc733a4..bb7d3956d 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -839,6 +839,7 @@ int main(int argc, char *argv[])
 		{ 0 }
 	};
 	int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT;
+	bool enabling_netnsid = false;
 
 	setlocale(LC_ALL, "");
 	bindtextdomain(PACKAGE, LOCALEDIR);
@@ -891,6 +892,8 @@ int main(int argc, char *argv[])
 				errx(EXIT_FAILURE, _("unknown namespace type: %s"), optarg);
 			ls.fltr_types[type] = 1;
 			ls.fltr_ntypes++;
+			if (type == LSNS_ID_NET)
+				enabling_netnsid = true;
 			break;
 		}
 		default:
@@ -900,6 +903,7 @@ int main(int argc, char *argv[])
 
 	if (!ls.fltr_ntypes) {
 		size_t i;
+
 		for (i = 0; i < ARRAY_SIZE(ns_names); i++)
 			ls.fltr_types[i] = 1;
 	}
@@ -924,14 +928,24 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_NPROCS;
 		columns[ncolumns++] = COL_PID;
 		columns[ncolumns++] = COL_USER;
-		columns[ncolumns++] = COL_NETNSID;
+		if (enabling_netnsid)
+			columns[ncolumns++] = COL_NETNSID;
 		columns[ncolumns++] = COL_COMMAND;
 	}
 
-	if (outarg && string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
-					 &ncolumns, column_name_to_id) < 0)
-		return EXIT_FAILURE;
+	if (outarg) {
+		size_t i;
 
+		if (string_add_to_idarray(outarg, columns, ARRAY_SIZE(columns),
+					  &ncolumns, column_name_to_id) < 0)
+			return EXIT_FAILURE;
+		for (i = 0; i < ncolumns; i++) {
+			if (columns[i] == COL_NETNSID) {
+				enabling_netnsid = true;
+				break;
+			}
+		}
+	}
 	scols_init_debug(0);
 
 	uid_cache = new_idcache();
@@ -939,7 +953,8 @@ int main(int argc, char *argv[])
 		err(EXIT_FAILURE, _("failed to allocate UID cache"));
 
 #ifdef HAVE_LINUX_NET_NAMESPACE_H
-	netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
+	if (enabling_netnsid)
+		netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
 #endif
 	r = read_processes(&ls);
 	if (!r)
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 3/7] lsns: add a case for testing netnsid column
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 1/7] lsns: add netnsid column Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 2/7] lsns: disable netnsid column by default Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 4/7] lsns: add nsfs column Masatake YAMATO
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 tests/commands.sh           |  1 +
 tests/expected/lsns/netnsid |  1 +
 tests/ts/lsns/netnsid       | 65 +++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+)
 create mode 100644 tests/expected/lsns/netnsid
 create mode 100644 tests/ts/lsns/netnsid

diff --git a/tests/commands.sh b/tests/commands.sh
index 655344102..502935ede 100644
--- a/tests/commands.sh
+++ b/tests/commands.sh
@@ -74,6 +74,7 @@ TS_CMD_LOSETUP=${TS_CMD_LOSETUP:-"$top_builddir/losetup"}
 TS_CMD_LSBLK=${TS_CMD_LSBLK-"$top_builddir/lsblk"}
 TS_CMD_LSCPU=${TS_CMD_LSCPU-"$top_builddir/lscpu"}
 TS_CMD_LSMEM=${TS_CMD_LSMEM-"$top_builddir/lsmem"}
+TS_CMD_LSNS=${TS_CMD_LSNS-"$top_builddir/lsns"}
 TS_CMD_MCOOKIE=${TS_CMD_MCOOKIE-"$top_builddir/mcookie"}
 TS_CMD_MKCRAMFS=${TS_CMD_MKCRAMFS:-"$top_builddir/mkfs.cramfs"}
 TS_CMD_MKMINIX=${TS_CMD_MKMINIX:-"$top_builddir/mkfs.minix"}
diff --git a/tests/expected/lsns/netnsid b/tests/expected/lsns/netnsid
new file mode 100644
index 000000000..573541ac9
--- /dev/null
+++ b/tests/expected/lsns/netnsid
@@ -0,0 +1 @@
+0
diff --git a/tests/ts/lsns/netnsid b/tests/ts/lsns/netnsid
new file mode 100644
index 000000000..ad93dd49c
--- /dev/null
+++ b/tests/ts/lsns/netnsid
@@ -0,0 +1,65 @@
+#!/bin/bash
+#
+# Copyright (C) 2017 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file 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.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="compare NETNSID reported by lsns and that by ip-link"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSNS"
+
+ts_skip_nonroot
+
+ts_cd "$TS_OUTDIR"
+
+vetha=lsns-vetha
+vethb=lsns-vethb
+NS=UTIL-LINUX-LSNS-TEST-NS
+FIFO=$TS_OUTDIR/UTIL-LINUX-LSNS-TEST-FIFO
+NULL=/dev/null
+
+ip netns delete $NS 2> $NULL || :
+ip link delete  $vetha 2> $NULL || :
+
+rm -f $FIFO
+mkfifo $FIFO
+
+if ip netns add $NS &&
+	ip link add name $vetha type veth peer name $vethb &&
+	ip link set $vethb netns $NS; then
+    ip netns exec $NS dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
+    PID=$!
+fi
+{
+    dd if=/dev/zero bs=1 count=1 2> $NULL
+    {
+	ip -o link show dev $vetha > $NULL
+	IP_ID=$(ip -o link show dev $vetha | sed -ne 's/.* *link-netnsid *\([0-9]*\)/\1/p')
+	LSNS_ID=$($TS_CMD_LSNS -n -o NETNSID --type net --task $PID | { read VAL; echo $VAL; } )
+    }
+    dd if=/dev/zero bs=1 count=1 2> $NULL
+} > $FIFO
+
+rm $FIFO
+ip link delete $vetha
+ip netns delete $NS
+
+test "$IP_ID" = "$LSNS_ID"
+echo $? >> $TS_OUTPUT
+
+ts_finalize
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 4/7] lsns: add nsfs column
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
                   ` (2 preceding siblings ...)
  2017-11-24 10:31 ` [PATCH v2 3/7] lsns: add a case for testing netnsid column Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 10:31 ` [PATCH 5/5] lsns: add a case for testing " Masatake YAMATO
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

nsfs provides kernel level interface for assigning
logical name to a namespace. Following message is quoted
from git log of linux kernel:

    commit 0226f4923f6c9b40cfa1c1c1b19a6ac6b3924ead
    Author: Al Viro <viro@zeniv.linux.org.uk>
    Date:   Tue Dec 6 12:21:54 2011 -0500

	vfs: take /proc/*/mounts and friends to fs/proc_namespace.c

	rationale: that stuff is far tighter bound to fs/namespace.c than to
	the guts of procfs proper.

	Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>

/proc/self/mountinfo lists the logical names for namespaces:
  ...
  652 81 0:3 net:[4026532579] /tmp/XYZ rw shared:192 - nsfs nsfs rw,seclabel
  ...

In the lines /tmp/XYZ is a logical name for 4026532579 of net
namespace.

This patch adds nsfs column. It seems that the logical name is
used only in "ip netns" now. So the column is disabled by default.
Use '--type=net' or '-o NSFS' options to enable it.

This feature and the way to implementation using multi lines in a column
is Suggested by Karel Zak.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 sys-utils/Makemodule.am |   4 +-
 sys-utils/lsns.c        | 108 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 106 insertions(+), 6 deletions(-)

diff --git a/sys-utils/Makemodule.am b/sys-utils/Makemodule.am
index a85987c8e..b5b1d4f15 100644
--- a/sys-utils/Makemodule.am
+++ b/sys-utils/Makemodule.am
@@ -260,8 +260,8 @@ if BUILD_LSNS
 usrbin_exec_PROGRAMS += lsns
 dist_man_MANS += sys-utils/lsns.8
 lsns_SOURCES =	sys-utils/lsns.c
-lsns_LDADD = $(LDADD) libcommon.la libsmartcols.la
-lsns_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir)
+lsns_LDADD = $(LDADD) libcommon.la libsmartcols.la libmount.la
+lsns_CFLAGS = $(AM_CFLAGS) -I$(ul_libsmartcols_incdir) -I$(ul_libmount_incdir)
 endif
 
 
diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index bb7d3956d..c4d806e24 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -28,6 +28,7 @@
 #include <sys/types.h>
 #include <wchar.h>
 #include <libsmartcols.h>
+#include <libmount.h>
 
 #ifdef HAVE_LINUX_NET_NAMESPACE_H
 #include <stdbool.h>
@@ -78,7 +79,8 @@ enum {
 	COL_COMMAND,
 	COL_UID,
 	COL_USER,
-	COL_NETNSID
+	COL_NETNSID,
+	COL_NSFS,
 };
 
 /* column names */
@@ -100,7 +102,8 @@ static const struct colinfo infos[] = {
 	[COL_COMMAND] = { "COMMAND", 0, SCOLS_FL_TRUNC, N_("command line of the PID")},
 	[COL_UID]     = { "UID",     0, SCOLS_FL_RIGHT, N_("UID of the PID")},
 	[COL_USER]    = { "USER",    0, 0, N_("username of the PID")},
-	[COL_NETNSID] = { "NETNSID", 0, SCOLS_FL_RIGHT, N_("Net namespace ID")}
+	[COL_NETNSID] = { "NETNSID", 0, SCOLS_FL_RIGHT, N_("Net namespace ID")},
+	[COL_NSFS]    = { "NSFS",    0, SCOLS_FL_WRAP, N_("Logical name established by nsfs")}
 };
 
 static int columns[ARRAY_SIZE(infos) * 2];
@@ -171,6 +174,8 @@ struct lsns {
 		     list	: 1,
 		     notrunc	: 1,
 		     no_headings: 1;
+
+	struct libmnt_table *tab;
 };
 
 struct netnsid_cache {
@@ -612,6 +617,80 @@ static int read_namespaces(struct lsns *ls)
 	return 0;
 }
 
+static int find_nsfs_in_tab(struct libmnt_fs *fs, void *data)
+{
+	return (mnt_fs_match_fstype(fs, "nsfs") &&
+		(strcmp(mnt_fs_get_root(fs), (char *)data) == 0));
+}
+
+static bool str_includes_path(const char *path_set, const char *elt,
+			      const char sep)
+{
+	size_t elt_len;
+	size_t path_set_len;
+	char *tmp;
+
+
+	tmp = strstr(path_set, elt);
+	if (!tmp)
+		return false;
+
+	elt_len = strlen(elt);
+	path_set_len = strlen(path_set);
+
+	/* path_set includes only elt or
+	 * path_set includes elt as the first element.
+	 */
+	if (tmp == path_set
+	    && ((path_set_len == elt_len)
+		|| (path_set[elt_len] == sep)))
+		return true;
+	/* path_set includes elt at the middle
+	 * or as the last element.
+	 */
+	if ((*(tmp - 1) == sep)
+	    && ((*(tmp + elt_len) == sep)
+		|| (*(tmp + elt_len) == '\0')))
+		return true;
+
+	return false;
+}
+
+static int nsfs_xasputs(char **str,
+			struct lsns_namespace *ns,
+			struct libmnt_table *tab,
+			char sep)
+{
+	struct libmnt_iter *itr = mnt_new_iter(MNT_ITER_FORWARD);
+	char *expected_root;
+	char *tmp;
+
+	xasprintf(&expected_root, "%s:[%lu]", ns_names[ns->type], ns->id);
+
+	tmp = NULL;
+	while (1) {
+		struct libmnt_fs *fs = NULL;
+
+		if (mnt_table_find_next_fs(tab, itr, find_nsfs_in_tab,
+					   expected_root, &fs) != 0)
+			break;
+		if (tmp == NULL) {
+			xasprintf(str, "%s", mnt_fs_get_target(fs));
+			tmp = *str;
+		} else if (!str_includes_path(*str, mnt_fs_get_target(fs),
+					      sep)) {
+			*str = NULL;
+			xasprintf(str, "%s%c%s",
+				  tmp, sep, mnt_fs_get_target(fs));
+			free(tmp);
+			tmp = *str;
+		}
+	}
+	free(expected_root);
+	mnt_free_iter(itr);
+
+	return 1;
+}
 static void add_scols_line(struct lsns *ls, struct libscols_table *table,
 			   struct lsns_namespace *ns, struct lsns_process *proc)
 {
@@ -665,6 +744,10 @@ static void add_scols_line(struct lsns *ls, struct libscols_table *table,
 			if (ns->type == LSNS_ID_NET)
 				netnsid_xasputs(&str, proc->netnsid);
 			break;
+		case COL_NSFS:
+			nsfs_xasputs(&str, ns, ls->tab,
+				     ls->raw ? ',' : '\n');
+			break;
 		default:
 			break;
 		}
@@ -697,16 +780,25 @@ static struct libscols_table *init_scols_table(struct lsns *ls)
 	for (i = 0; i < ncolumns; i++) {
 		const struct colinfo *col = get_column_info(i);
 		int flags = col->flags;
+		struct libscols_column *cl;
 
 		if (ls->notrunc)
 		       flags &= ~SCOLS_FL_TRUNC;
 		if (ls->tree && get_column_id(i) == COL_COMMAND)
 			flags |= SCOLS_FL_TREE;
 
-		if (!scols_table_new_column(tab, col->name, col->whint, flags)) {
+		cl = scols_table_new_column(tab, col->name, col->whint, flags);
+		if (cl == NULL) {
 			warnx(_("failed to initialize output column"));
 			goto err;
 		}
+		if (get_column_id(i) == COL_NSFS) {
+			scols_column_set_wrapfunc(cl,
+						  scols_wrapnl_chunksize,
+						  scols_wrapnl_nextchunk,
+						  NULL);
+			scols_column_set_safechars(cl, "\n");
+		}
 	}
 
 	return tab;
@@ -928,8 +1020,10 @@ int main(int argc, char *argv[])
 		columns[ncolumns++] = COL_NPROCS;
 		columns[ncolumns++] = COL_PID;
 		columns[ncolumns++] = COL_USER;
-		if (enabling_netnsid)
+		if (enabling_netnsid) {
 			columns[ncolumns++] = COL_NETNSID;
+			columns[ncolumns++] = COL_NSFS;
+		}
 		columns[ncolumns++] = COL_COMMAND;
 	}
 
@@ -956,6 +1050,11 @@ int main(int argc, char *argv[])
 	if (enabling_netnsid)
 		netlink_fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
 #endif
+
+	ls.tab = mnt_new_table_from_file(_PATH_PROC_MOUNTINFO);
+	if (!ls.tab)
+		err(MNT_EX_FAIL, _("failed to parse %s"), _PATH_PROC_MOUNTINFO);
+
 	r = read_processes(&ls);
 	if (!r)
 		r = read_namespaces(&ls);
@@ -970,6 +1069,7 @@ int main(int argc, char *argv[])
 			r = show_namespaces(&ls);
 	}
 
+	mnt_free_table(ls.tab);
 	if (netlink_fd >= 0)
 		close(netlink_fd);
 	free_idcache(uid_cache);
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH 5/5] lsns: add a case for testing nsfs column
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
                   ` (3 preceding siblings ...)
  2017-11-24 10:31 ` [PATCH v2 4/7] lsns: add nsfs column Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 10:34   ` Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 5/7] lsns: add --nowrap(-W) option Masatake YAMATO
                   ` (4 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 tests/expected/lsns/nsfs |  1 +
 tests/ts/lsns/nsfs       | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+)
 create mode 100644 tests/expected/lsns/nsfs
 create mode 100644 tests/ts/lsns/nsfs

diff --git a/tests/expected/lsns/nsfs b/tests/expected/lsns/nsfs
new file mode 100644
index 000000000..573541ac9
--- /dev/null
+++ b/tests/expected/lsns/nsfs
@@ -0,0 +1 @@
+0
diff --git a/tests/ts/lsns/nsfs b/tests/ts/lsns/nsfs
new file mode 100644
index 000000000..cfc88e06c
--- /dev/null
+++ b/tests/ts/lsns/nsfs
@@ -0,0 +1,66 @@
+#!/bin/bash
+#
+# Copyright (C) 2017 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file 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.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="list NSFS for namespaces created by ip-netns-add"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSNS"
+
+ts_skip_nonroot
+
+ts_cd "$TS_OUTDIR"
+
+NAME1=ABC
+NAME2=XYZ
+PATH1=/run/netns/$NAME1
+PATH2=$TS_OUTDIR/$NAME2
+FIFO=$TS_OUTDIR/UTIL-LINUX-LSNS-TEST-FIFO
+NULL=/dev/null
+
+ip netns delete $NAME1 2> /dev/null || :
+umount $PATH2 2>/dev/null || :
+rm -f $PATH2
+
+rm -f $FIFO
+mkfifo $FIFO
+
+if ip netns add $NAME1 &&
+	touch ${PATH2} &&
+	mount -o bind ${PATH1} ${PATH2}; then
+    ip netns exec $NAME1 dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
+    PID=$!
+fi
+{
+    dd if=/dev/zero bs=1 count=1 2> $NULL
+    NSFS_NAMES=$($TS_CMD_LSNS -n -o NSFS --type net --task $PID | { while read VAL; do echo $VAL; done; } )
+    dd if=/dev/zero bs=1 count=1 2> $NULL
+} > $FIFO
+
+rm $FIFO
+
+umount $PATH2
+rm -f $PATH2
+ip netns delete $NAME1
+
+test "$NSFS_NAMES" = "$PATH1
+$PATH2"
+echo $? >> $TS_OUTPUT
+
+ts_finalize
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 5/7] lsns: add --nowrap(-W) option
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
                   ` (4 preceding siblings ...)
  2017-11-24 10:31 ` [PATCH 5/5] lsns: add a case for testing " Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 6/7] lsns: add a case for testing nsfs column Masatake YAMATO
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

This option forces lsns command not use
multi-line presentation when printing a cell.

Currently, it affects only NSFS column.

Implementing this option is suggested by Karl Zak.

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 sys-utils/lsns.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/sys-utils/lsns.c b/sys-utils/lsns.c
index c4d806e24..8af363317 100644
--- a/sys-utils/lsns.c
+++ b/sys-utils/lsns.c
@@ -173,7 +173,8 @@ struct lsns {
 		     tree	: 1,
 		     list	: 1,
 		     notrunc	: 1,
-		     no_headings: 1;
+		     no_headings: 1,
+		     no_wrap    : 1;
 
 	struct libmnt_table *tab;
 };
@@ -746,7 +747,7 @@ static void add_scols_line(struct lsns *ls, struct libscols_table *table,
 			break;
 		case COL_NSFS:
 			nsfs_xasputs(&str, ns, ls->tab,
-				     ls->raw ? ',' : '\n');
+				     (ls->raw || ls->no_wrap) ? ',' : '\n');
 			break;
 		default:
 			break;
@@ -786,6 +787,8 @@ static struct libscols_table *init_scols_table(struct lsns *ls)
 		       flags &= ~SCOLS_FL_TRUNC;
 		if (ls->tree && get_column_id(i) == COL_COMMAND)
 			flags |= SCOLS_FL_TREE;
+		if (ls->no_wrap)
+			flags &= ~SCOLS_FL_WRAP;
 
 		cl = scols_table_new_column(tab, col->name, col->whint, flags);
 		if (cl == NULL) {
@@ -891,6 +894,7 @@ static void __attribute__((__noreturn__)) usage(void)
 	fputs(_(" -p, --task <pid>       print process namespaces\n"), out);
 	fputs(_(" -r, --raw              use the raw output format\n"), out);
 	fputs(_(" -u, --notruncate       don't truncate text in columns\n"), out);
+	fputs(_(" -W, --nowrap           don't use multi-line representation\n"), out);
 	fputs(_(" -t, --type <name>      namespace type (mnt, net, ipc, user, pid, uts, cgroup)\n"), out);
 
 	fputs(USAGE_SEPARATOR, out);
@@ -920,6 +924,7 @@ int main(int argc, char *argv[])
 		{ "notruncate", no_argument,       NULL, 'u' },
 		{ "version",    no_argument,       NULL, 'V' },
 		{ "noheadings", no_argument,       NULL, 'n' },
+		{ "nowrap",     no_argument,       NULL, 'W' },
 		{ "list",       no_argument,       NULL, 'l' },
 		{ "raw",        no_argument,       NULL, 'r' },
 		{ "type",       required_argument, NULL, 't' },
@@ -988,6 +993,9 @@ int main(int argc, char *argv[])
 				enabling_netnsid = true;
 			break;
 		}
+		case 'W':
+			ls.no_wrap = 1;
+			break;
 		default:
 			errtryhelp(EXIT_FAILURE);
 		}
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 6/7] lsns: add a case for testing nsfs column
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
                   ` (5 preceding siblings ...)
  2017-11-24 10:31 ` [PATCH v2 5/7] lsns: add --nowrap(-W) option Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 10:31 ` [PATCH v2 7/7] man: write about using multi-line in NSFS cell of lsns Masatake YAMATO
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 tests/expected/lsns/nsfs |  1 +
 tests/ts/lsns/nsfs       | 68 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 69 insertions(+)
 create mode 100644 tests/expected/lsns/nsfs
 create mode 100644 tests/ts/lsns/nsfs

diff --git a/tests/expected/lsns/nsfs b/tests/expected/lsns/nsfs
new file mode 100644
index 000000000..573541ac9
--- /dev/null
+++ b/tests/expected/lsns/nsfs
@@ -0,0 +1 @@
+0
diff --git a/tests/ts/lsns/nsfs b/tests/ts/lsns/nsfs
new file mode 100644
index 000000000..7f2b46bbe
--- /dev/null
+++ b/tests/ts/lsns/nsfs
@@ -0,0 +1,68 @@
+#!/bin/bash
+#
+# Copyright (C) 2017 Masatake YAMATO <yamato@redhat.com>
+#
+# This file is part of util-linux.
+#
+# This file 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.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="list NSFS for namespaces created by ip-netns-add"
+
+. $TS_TOPDIR/functions.sh
+ts_init "$*"
+
+ts_check_test_command "$TS_CMD_LSNS"
+
+ts_skip_nonroot
+
+ts_cd "$TS_OUTDIR"
+
+NAME1=ABC
+NAME2=XYZ
+PATH1=/run/netns/$NAME1
+PATH2=$TS_OUTDIR/$NAME2
+FIFO=$TS_OUTDIR/UTIL-LINUX-LSNS-TEST-FIFO
+NULL=/dev/null
+
+ip netns delete $NAME1 2> /dev/null || :
+umount $PATH2 2>/dev/null || :
+rm -f $PATH2
+
+rm -f $FIFO
+mkfifo $FIFO
+
+if ip netns add $NAME1 &&
+	touch ${PATH2} &&
+	mount -o bind ${PATH1} ${PATH2}; then
+    ip netns exec $NAME1 dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
+    PID=$!
+fi
+{
+    dd if=/dev/zero bs=1 count=1 2> $NULL
+    NSFS_NAMES_MLINES=$($TS_CMD_LSNS -n -o NSFS --type net --task $PID | { while read VAL; do echo $VAL; done; } )
+    NSFS_NAMES_1LINE=$($TS_CMD_LSNS -n -o NSFS --nowrap --type net --task $PID | { while read VAL; do echo $VAL; done; } )
+    dd if=/dev/zero bs=1 count=1 2> $NULL
+} > $FIFO
+
+rm $FIFO
+
+umount $PATH2
+rm -f $PATH2
+ip netns delete $NAME1
+
+test "$NSFS_NAMES_MLINES" = "$PATH1
+$PATH2" && test "$NSFS_NAMES_1LINE" = "$PATH1,$PATH2"
+
+echo $? >> $TS_OUTPUT
+
+ts_finalize
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* [PATCH v2 7/7] man: write about using multi-line in NSFS cell of lsns
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
                   ` (6 preceding siblings ...)
  2017-11-24 10:31 ` [PATCH v2 6/7] lsns: add a case for testing nsfs column Masatake YAMATO
@ 2017-11-24 10:31 ` Masatake YAMATO
  2017-11-24 12:04 ` [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Karel Zak
  2017-11-27 16:46 ` Karel Zak
  9 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:31 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
---
 sys-utils/lsns.8 | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/sys-utils/lsns.8 b/sys-utils/lsns.8
index ebdc1df04..4d108a48c 100644
--- a/sys-utils/lsns.8
+++ b/sys-utils/lsns.8
@@ -20,6 +20,11 @@ avoid using default outputs in your scripts.  Always explicitly define expected
 columns by using the \fB\-\-output\fR option together with a columns list in
 environments where a stable output is required.
 
+\fBNSFS\fP column, printed when \fBnet\fP is specified for
+\fB\-\-type\fR option, is specifal; it uses multi-line cells.
+\fB\-\-nowrap\fR is for switching to "," separated single-line
+representation.
+
 Note that \fBlsns\fR reads information directly from the /proc filesystem and
 for non-root users it may return incomplete information.  The current /proc
 filesystem may be unshared and affected by a PID namespace
@@ -60,6 +65,9 @@ Display the specified \fItype\fP of namespaces only.  The supported types are
 .BR \-u , " \-\-notruncate"
 Do not truncate text in columns.
 .TP
+.BR \-W , " \-\-nowrap"
+Do not use multi-line text in columns.
+.TP
 .BR \-V , " \-\-version"
 Display version information and exit.
 .TP
-- 
2.13.6


^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [PATCH 5/5] lsns: add a case for testing nsfs column
  2017-11-24 10:31 ` [PATCH 5/5] lsns: add a case for testing " Masatake YAMATO
@ 2017-11-24 10:34   ` Masatake YAMATO
  0 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-24 10:34 UTC (permalink / raw)
  To: util-linux; +Cc: yamato

I'm sorry.
I took a mistake for sending a patch set.
Please, ignore this

	[PATCH 5/5] lsns: add a case for testing nsfs column

one.

Masatake YAMATO

On Fri, 24 Nov 2017 19:31:07 +0900, Masatake YAMATO <yamato@redhat.com> wrote:
> Signed-off-by: Masatake YAMATO <yamato@redhat.com>
> ---
>  tests/expected/lsns/nsfs |  1 +
>  tests/ts/lsns/nsfs       | 66 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 67 insertions(+)
>  create mode 100644 tests/expected/lsns/nsfs
>  create mode 100644 tests/ts/lsns/nsfs
> 
> diff --git a/tests/expected/lsns/nsfs b/tests/expected/lsns/nsfs
> new file mode 100644
> index 000000000..573541ac9
> --- /dev/null
> +++ b/tests/expected/lsns/nsfs
> @@ -0,0 +1 @@
> +0
> diff --git a/tests/ts/lsns/nsfs b/tests/ts/lsns/nsfs
> new file mode 100644
> index 000000000..cfc88e06c
> --- /dev/null
> +++ b/tests/ts/lsns/nsfs
> @@ -0,0 +1,66 @@
> +#!/bin/bash
> +#
> +# Copyright (C) 2017 Masatake YAMATO <yamato@redhat.com>
> +#
> +# This file is part of util-linux.
> +#
> +# This file 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.
> +#
> +# This file is distributed in the hope that it will be useful,
> +# but WITHOUT ANY WARRANTY; without even the implied warranty of
> +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> +# GNU General Public License for more details.
> +#
> +
> +TS_TOPDIR="${0%/*}/../.."
> +TS_DESC="list NSFS for namespaces created by ip-netns-add"
> +
> +. $TS_TOPDIR/functions.sh
> +ts_init "$*"
> +
> +ts_check_test_command "$TS_CMD_LSNS"
> +
> +ts_skip_nonroot
> +
> +ts_cd "$TS_OUTDIR"
> +
> +NAME1=ABC
> +NAME2=XYZ
> +PATH1=/run/netns/$NAME1
> +PATH2=$TS_OUTDIR/$NAME2
> +FIFO=$TS_OUTDIR/UTIL-LINUX-LSNS-TEST-FIFO
> +NULL=/dev/null
> +
> +ip netns delete $NAME1 2> /dev/null || :
> +umount $PATH2 2>/dev/null || :
> +rm -f $PATH2
> +
> +rm -f $FIFO
> +mkfifo $FIFO
> +
> +if ip netns add $NAME1 &&
> +	touch ${PATH2} &&
> +	mount -o bind ${PATH1} ${PATH2}; then
> +    ip netns exec $NAME1 dd if=$FIFO bs=1 count=2 of=$NULL 2> $NULL &
> +    PID=$!
> +fi
> +{
> +    dd if=/dev/zero bs=1 count=1 2> $NULL
> +    NSFS_NAMES=$($TS_CMD_LSNS -n -o NSFS --type net --task $PID | { while read VAL; do echo $VAL; done; } )
> +    dd if=/dev/zero bs=1 count=1 2> $NULL
> +} > $FIFO
> +
> +rm $FIFO
> +
> +umount $PATH2
> +rm -f $PATH2
> +ip netns delete $NAME1
> +
> +test "$NSFS_NAMES" = "$PATH1
> +$PATH2"
> +echo $? >> $TS_OUTPUT
> +
> +ts_finalize
> -- 
> 2.13.6
> 

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/7] Add netnsid and nsfs columns to lsns
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
                   ` (7 preceding siblings ...)
  2017-11-24 10:31 ` [PATCH v2 7/7] man: write about using multi-line in NSFS cell of lsns Masatake YAMATO
@ 2017-11-24 12:04 ` Karel Zak
  2017-11-27 16:46 ` Karel Zak
  9 siblings, 0 replies; 13+ messages in thread
From: Karel Zak @ 2017-11-24 12:04 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: util-linux

On Fri, Nov 24, 2017 at 07:31:02PM +0900, Masatake YAMATO wrote:
> This patch-set adds netnsid and nsfs columns to lsns command.
> 
> The new columns are useful to understand namespaces information
> printed in the output of "ip link" and "ip netns".  The new columns
> are visible only when --type net is specified.
> 
> Masatake YAMATO (7):
>   lsns: add netnsid column
>   lsns: disable netnsid column by default
>   lsns: add a case for testing netnsid column
>   lsns: add nsfs column
>   lsns: add --nowrap(-W) option
>   lsns: add a case for testing nsfs column
>   man: write about using multi-line in NSFS cell of lsns

Cool, I'll merge it next week. Thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/7] Add netnsid and nsfs columns to lsns
  2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
                   ` (8 preceding siblings ...)
  2017-11-24 12:04 ` [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Karel Zak
@ 2017-11-27 16:46 ` Karel Zak
  2017-11-27 17:06   ` Masatake YAMATO
  9 siblings, 1 reply; 13+ messages in thread
From: Karel Zak @ 2017-11-27 16:46 UTC (permalink / raw)
  To: Masatake YAMATO; +Cc: util-linux

On Fri, Nov 24, 2017 at 07:31:02PM +0900, Masatake YAMATO wrote:
>   lsns: add netnsid column
>   lsns: disable netnsid column by default
>   lsns: add a case for testing netnsid column
>   lsns: add nsfs column
>   lsns: add --nowrap(-W) option
>   lsns: add a case for testing nsfs column
>   man: write about using multi-line in NSFS cell of lsns

Merged; I have merged also some additional changes to cleanup a little
bit the code. Thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH v2 0/7] Add netnsid and nsfs columns to lsns
  2017-11-27 16:46 ` Karel Zak
@ 2017-11-27 17:06   ` Masatake YAMATO
  0 siblings, 0 replies; 13+ messages in thread
From: Masatake YAMATO @ 2017-11-27 17:06 UTC (permalink / raw)
  To: kzak; +Cc: util-linux

Thank you!

Masatake YAMATO

> On Fri, Nov 24, 2017 at 07:31:02PM +0900, Masatake YAMATO wrote:
>>   lsns: add netnsid column
>>   lsns: disable netnsid column by default
>>   lsns: add a case for testing netnsid column
>>   lsns: add nsfs column
>>   lsns: add --nowrap(-W) option
>>   lsns: add a case for testing nsfs column
>>   man: write about using multi-line in NSFS cell of lsns
> 
> Merged; I have merged also some additional changes to cleanup a little
> bit the code. Thanks!
> 
>     Karel
> 
> -- 
>  Karel Zak  <kzak@redhat.com>
>  http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-11-27 17:06 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-24 10:31 [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 1/7] lsns: add netnsid column Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 2/7] lsns: disable netnsid column by default Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 3/7] lsns: add a case for testing netnsid column Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 4/7] lsns: add nsfs column Masatake YAMATO
2017-11-24 10:31 ` [PATCH 5/5] lsns: add a case for testing " Masatake YAMATO
2017-11-24 10:34   ` Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 5/7] lsns: add --nowrap(-W) option Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 6/7] lsns: add a case for testing nsfs column Masatake YAMATO
2017-11-24 10:31 ` [PATCH v2 7/7] man: write about using multi-line in NSFS cell of lsns Masatake YAMATO
2017-11-24 12:04 ` [PATCH v2 0/7] Add netnsid and nsfs columns to lsns Karel Zak
2017-11-27 16:46 ` Karel Zak
2017-11-27 17:06   ` Masatake YAMATO

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).