From a8b87a47b648b39ebc7ff9b9ac598ed60441756e Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Tue, 4 Mar 2014 12:30:52 -0800 Subject: [PATCH] Remove loopback mount bind Docker-DCO-1.1-Signed-off-by: Guillaume J. Charmes (github: creack) --- libcontainer/nsinit/mount.go | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/libcontainer/nsinit/mount.go b/libcontainer/nsinit/mount.go index 9ae7ec4..7ce90fd 100644 --- a/libcontainer/nsinit/mount.go +++ b/libcontainer/nsinit/mount.go @@ -38,9 +38,8 @@ func setupNewMountNamespace(rootfs, console string, readonly bool) error { if err := copyDevNodes(rootfs); err != nil { return fmt.Errorf("copy dev nodes %s", err) } - if err := setupLoopbackDevices(rootfs); err != nil { - return fmt.Errorf("setup loopback devices %s", err) - } + // In non-privileged mode, this fails. Discard the error. + setupLoopbackDevices(rootfs) if err := setupDev(rootfs); err != nil { return err } @@ -102,29 +101,13 @@ func copyDevNodes(rootfs string) error { func setupLoopbackDevices(rootfs string) error { for i := 0; ; i++ { - var ( - device = fmt.Sprintf("loop%d", i) - source = filepath.Join("/dev", device) - dest = filepath.Join(rootfs, "dev", device) - ) - - if _, err := os.Stat(source); err != nil { + if err := copyDevNode(rootfs, fmt.Sprintf("loop%d", i)); err != nil { if !os.IsNotExist(err) { return err } - return nil - } - if _, err := os.Stat(dest); err == nil { - os.Remove(dest) - } - f, err := os.Create(dest) - if err != nil { - return err - } - f.Close() - if err := system.Mount(source, dest, "none", syscall.MS_BIND, ""); err != nil { - return err + break } + } return nil }