Skip to contentSkip to conversation

netns: make /var/run/netns bind-mount recursive

PATCH In review Casey Callendrello 3 participants 3 messages Aug 1, 2017 – Aug 4, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 netns: make /var/run/netns bind-mount recursive

When ip netns {add|delete} is first run, it bind-mounts /var/run/netns on top of itself, then marks it as shared. However, if there are already bind-mounts in the directory from other tools, these would not be propagated. Fix this by recursively bind-mounting.

---
 ip/ipnetns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
ip/ipnetns.c +1 -1
index 198e9de8..9ee1fe6a 100644
@@ -636,7 +636,7 @@ static int netns_add(int argc, char **argv)
 		}
 
 		/* Upgrade NETNS_RUN_DIR to a mount point */
-		if (mount(NETNS_RUN_DIR, NETNS_RUN_DIR, "none", MS_BIND, NULL)) {
+		if (mount(NETNS_RUN_DIR, NETNS_RUN_DIR, "none", MS_BIND | MS_REC, NULL)) {
 			fprintf(stderr, "mount --bind %s %s failed: %s\n",
 				NETNS_RUN_DIR, NETNS_RUN_DIR, strerror(errno));
 			return -1;
Signature · 1 line
2.13.3
#1 lore raw
Quoted 10 lines · On Tue, 1 Aug 2017 17:46:09 +0200 Casey Callendrello…

When ip netns {add|delete} is first run, it bind-mounts /var/run/netns on top of itself, then marks it as shared. However, if there are already bind-mounts in the directory from other tools, these would not be propagated. Fix this by recursively bind-mounting.

---
 ip/ipnetns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Looks good, but I want a review by Eric to make sure this doesn't break other things.

#2 lore raw
Quoted 8 lines · Stephen Hemminger
Quoted 5 lines · On Tue, 1 Aug 2017 17:46:09 +0200 Casey Callendrello…

When ip netns {add|delete} is first run, it bind-mounts /var/run/netns on top of itself, then marks it as shared. However, if there are already bind-mounts in the directory from other tools, these would not be propagated. Fix this by recursively bind-mounting.

Quoted 8 lines
Quoted 5 lines
---
 ip/ipnetns.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Looks good, but I want a review by Eric to make sure this doesn't break other things.

I don't see any possible problems with this. This will just keep all of the mounts showing up.

It would be really nice if we could at some point detect that a parent directory is shared (which happens with a common init system) and skip the steps of the bind mount and making them shared as they are redundant. However while that might also solve this issue that is something for another day.

Eric