From e2989c4d487c8706a7e0ba82e9f22fa21e5207bc Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Thu, 23 May 2019 11:56:59 -0700 Subject: [PATCH] aufs: remove mntL Commit 5cd62852fa199f27 added a lock around call to unix.Mount() to avoid the race in aufs kernel code related to xino file creation and removal. While this is going to be fixed in the kernel, we still need to support the current aufs, so some kind of fix is required. A think a better fix (rather than a lock) is to add a random suffix to the file name (note it is and was a separate file per mount, never mind the same file name -- the file is created/opened and removed instantly, so each mount deals with its own file). With the suffix added, the possibility to hit the race is extremely low, and we don't have to do any locking. Note we don't add any more characters, instead we're replacing `xino` with four random characters in the 0-9a-z range. See also: https://sourceforge.net/p/aufs/mailman/message/36674769/ Signed-off-by: Kir Kolyshkin --- daemon/graphdriver/aufs/aufs.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/daemon/graphdriver/aufs/aufs.go b/daemon/graphdriver/aufs/aufs.go index bbd19a82b0..bc0e668c9a 100644 --- a/daemon/graphdriver/aufs/aufs.go +++ b/daemon/graphdriver/aufs/aufs.go @@ -28,10 +28,12 @@ import ( "fmt" "io" "io/ioutil" + "math/rand" "os" "os/exec" "path" "path/filepath" + "strconv" "strings" "sync" "time" @@ -80,7 +82,6 @@ type Driver struct { pathCache map[string]string naiveDiff graphdriver.DiffDriver locker *locker.Locker - mntL sync.Mutex } // Init returns a new AUFS driver. @@ -618,14 +619,14 @@ func (a *Driver) aufsMount(ro []string, rw, target, mountLabel string) (err erro bp += copy(b[bp:], layer) } - opts := "dio,xino=/dev/shm/aufs.xino" + // random 4 characters in the 0-9a-z range (e.g. "g6dz") + rnd := strconv.FormatInt(int64(1e9+rand.Uint32()%1e9), 36)[1:5] + opts := "dio,xino=/dev/shm/aufs." + rnd if useDirperm() { opts += ",dirperm1" } data := label.FormatMountLabel(fmt.Sprintf("%s,%s", string(b[:bp]), opts), mountLabel) - a.mntL.Lock() err = unix.Mount("none", target, "aufs", 0, data) - a.mntL.Unlock() if err != nil { err = errors.Wrap(err, "mount target="+target+" data="+data) return @@ -641,9 +642,7 @@ func (a *Driver) aufsMount(ro []string, rw, target, mountLabel string) (err erro bp += copy(b[bp:], layer) } data := label.FormatMountLabel(string(b[:bp]), mountLabel) - a.mntL.Lock() err = unix.Mount("none", target, "aufs", unix.MS_REMOUNT, data) - a.mntL.Unlock() if err != nil { err = errors.Wrap(err, "mount target="+target+" flags=MS_REMOUNT data="+data) return