@@ -22,7 +22,6 @@ import (
2222 "go.podman.io/common/pkg/netns"
2323 "go.podman.io/common/pkg/systemd"
2424 "go.podman.io/storage/pkg/fileutils"
25- "go.podman.io/storage/pkg/homedir"
2625 "go.podman.io/storage/pkg/lockfile"
2726 "golang.org/x/sys/unix"
2827)
@@ -39,9 +38,6 @@ const (
3938 // rootlessNetNsConnPidFile is the name of the rootless netns pasta pid file.
4039 rootlessNetNsConnPidFile = "rootless-netns-conn.pid"
4140
42- // persistentCNIDir is the directory where the CNI files are stored.
43- persistentCNIDir = "/var/lib/cni"
44-
4541 tmpfs = "tmpfs"
4642 none = "none"
4743 resolvConfName = "resolv.conf"
@@ -288,11 +284,9 @@ func (n *Netns) setupMounts() error {
288284 // Because the plugins also need access to XDG_RUNTIME_DIR/netns some special setup is needed.
289285
290286 // The following bind mounts are needed
291- // 1. XDG_RUNTIME_DIR -> XDG_RUNTIME_DIR/rootless-netns/XDG_RUNTIME_DIR
292- // 2. /run/systemd -> XDG_RUNTIME_DIR/rootless-netns/run/systemd (only if it exists)
293- // 3. XDG_RUNTIME_DIR/rootless-netns/resolv.conf -> /etc/resolv.conf or XDG_RUNTIME_DIR/rootless-netns/run/symlink/target
294- // 4. XDG_RUNTIME_DIR/rootless-netns/var/lib/cni -> /var/lib/cni (if /var/lib/cni does not exist, use the parent dir)
295- // 5. XDG_RUNTIME_DIR/rootless-netns/run -> /run
287+ // 1. /run/systemd -> XDG_RUNTIME_DIR/rootless-netns/run/systemd (only if it exists)
288+ // 2. XDG_RUNTIME_DIR/rootless-netns/resolv.conf -> /etc/resolv.conf or XDG_RUNTIME_DIR/rootless-netns/run/symlink/target
289+ // 3. XDG_RUNTIME_DIR/rootless-netns/run -> /run
296290
297291 // Create a new mount namespace,
298292 // this must happen inside the netns thread.
@@ -313,19 +307,7 @@ func (n *Netns) setupMounts() error {
313307 return wrapError ("set mount propagation to slave in new mount namespace" , err )
314308 }
315309
316- xdgRuntimeDir , err := homedir .GetRuntimeDir ()
317- if err != nil {
318- return fmt .Errorf ("could not get runtime directory: %w" , err )
319- }
320- newXDGRuntimeDir := n .getPath (xdgRuntimeDir )
321- // 1. Mount the netns into the new run to keep them accessible.
322- // Otherwise cni setup will fail because it cannot access the netns files.
323- err = mountAndMkdirDest (xdgRuntimeDir , newXDGRuntimeDir , none , unix .MS_BIND | unix .MS_REC )
324- if err != nil {
325- return err
326- }
327-
328- // 2. Also keep /run/systemd if it exists.
310+ // 1. Also keep /run/systemd if it exists.
329311 // Many files are symlinked into this dir, for example /dev/log.
330312 runSystemd := "/run/systemd"
331313 err = fileutils .Exists (runSystemd )
@@ -337,7 +319,7 @@ func (n *Netns) setupMounts() error {
337319 }
338320 }
339321
340- // 3 . On some distros /etc/resolv.conf is symlinked to somewhere under /run.
322+ // 2 . On some distros /etc/resolv.conf is symlinked to somewhere under /run.
341323 // Because the kernel will follow the symlink before mounting, it is not
342324 // possible to mount a file at /etc/resolv.conf. We have to ensure that
343325 // the link target will be available in the mount ns.
@@ -435,14 +417,7 @@ func (n *Netns) setupMounts() error {
435417 return wrapError (fmt .Sprintf ("mount resolv.conf to %q" , resolvePath ), err )
436418 }
437419
438- // 4. CNI plugins need access to /var/lib/cni
439- if n .backend == CNI {
440- if err := n .mountCNIVarDir (); err != nil {
441- return err
442- }
443- }
444-
445- // 5. Mount the new prepared run dir to /run, it has to be recursive to keep the other bind mounts.
420+ // 3. Mount the new prepared run dir to /run, it has to be recursive to keep the other bind mounts.
446421 runDir := n .getPath ("run" )
447422 err = os .MkdirAll (runDir , 0o700 )
448423 if err != nil {
@@ -464,36 +439,6 @@ func (n *Netns) setupMounts() error {
464439 return nil
465440}
466441
467- func (n * Netns ) mountCNIVarDir () error {
468- varDir := ""
469- varTarget := persistentCNIDir
470- // we can only mount to a target dir which exists, check /var/lib/cni recursively
471- // while we could always use /var there are cases where a user might store the cni
472- // configs under /var/custom and this would break
473- for {
474- if err := fileutils .Exists (varTarget ); err == nil {
475- varDir = n .getPath (varTarget )
476- break
477- }
478- varTarget = filepath .Dir (varTarget )
479- if varTarget == "/" {
480- break
481- }
482- }
483- if varDir == "" {
484- return errors .New ("failed to stat /var directory" )
485- }
486- if err := os .MkdirAll (varDir , 0o700 ); err != nil {
487- return wrapError ("create var dir" , err )
488- }
489- // make sure to mount var first
490- err := unix .Mount (varDir , varTarget , none , unix .MS_BIND , "" )
491- if err != nil {
492- return wrapError (fmt .Sprintf ("mount %q to %q" , varDir , varTarget ), err )
493- }
494- return nil
495- }
496-
497442func (n * Netns ) runInner (toRun func () error , cleanup bool ) (err error ) {
498443 nsRef , newNs , err := n .getOrCreateNetns ()
499444 if err != nil {
0 commit comments