Skip to content

RFC Persisting of mount namespaces along with network namespaces

Toke Høiland-Jørgensen netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest5 patches 11 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5ip: Mount netns in child process instead of from inside the new namespaceip/ipnetns.c+130 -540 replies
2/5ip: Split out code creating namespace mount dir so it can be reusedip/ipnetns.c+69 -580 replies
3/5lib/namespace: Factor out code for reuseinclude/namespace.h lib/namespace.c+54 -200 replies
4/5ip: Also create and persist mount namespace when creating netnsMakefile ip/ipnetns.c lib/namespace.c+66 -80 replies
5/5lib/namespace: Also mount a bpffs instance inside new mount namespaceslib/namespace.c+3 -00 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC PATCH iproute2-next 0/5] Persisting of mount namespaces along with network namespaces

The 'ip netns' command is used for setting up network namespaces with persistent named references, and is integrated into various other commands of iproute2 via the -n switch.

This is useful both for testing setups and for simple script-based namespacing but has one drawback: the lack of persistent mounts inside the spawned namespace. This is particularly apparent when working with BPF programs that use pinning to bpffs: by default no bpffs is available inside a namespace, and even if mounting one, that fs disappears as soon as the calling command exits.

The underlying cause for this is that iproute2 will create a new mount namespace every time it switches into a network namespace. This is needed to be able to mount a /sys filesystem that shows the correct network device information, but has the unfortunate side effect of making mounts entirely transient for any 'ip netns' invocation.

This series is an attempt to fix this situation, by persisting a mount namespace alongside the persistent network namespace (in a separate directory, /run/netns-mnt). Doing this allows us to still have a consistent /sys inside the namespace, but with persistence so any mounts survive.

This mode does come with some caveats. I'm sending this as RFC to get feedback on whether this is the right thing to do, especially considering backwards compatibility. On balance, I think that the approach taken here of unconditionally persisting the mount namespace, and using that persistent reference whenever it exists, is better than the current behaviour, and that while it does represent a change in behaviour it is backwards compatible in a way that won't cause issues. But please do comment on this; see the patch description of patch 4 for details.

The first three patches are just moving code around and should not represent any functional changes. The fourth patch introduces the mount namespace persistence, and the fifth patch adds mounting of a bpffs instance to the mount namespace preparation logic.

Cc Nicolas Dichtel <[email protected]>
Cc Christian Brauner <[email protected]>
Cc Eric W. Biederman <[email protected]>
Cc David Laight <[email protected]>

Toke Høiland-Jørgensen (5):
ip: Mount netns in child process instead of from inside the new
namespace
ip: Split out code creating namespace mount dir so it can be reused lib/namespace: Factor out code for reuse
ip: Also create and persist mount namespace when creating netns lib/namespace: Also mount a bpffs instance inside new mount namespaces

 Makefile            |   2 +
 include/namespace.h |   1 +
 ip/ipnetns.c        | 357 ++++++++++++++++++++++++++++++--------------
 lib/namespace.c     |  82 +++++++---
 4 files changed, 312 insertions(+), 130 deletions(-)
Signature · 1 line
2.42.0