mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Perform fsmagic detection on driver's home-dir if it exists
The fsmagic check was always performed on "data-root" (`/var/lib/docker`), not on the storage-driver's home directory (e.g. `/var/lib/docker/<somedriver>`). This caused detection to be done on the wrong filesystem in situations where `/var/lib/docker/<somedriver>` was a mount, and a different filesystem than `/var/lib/docker` itself. This patch checks if the storage-driver's home directory exists, and only falls back to `/var/lib/docker` if it doesn't exist. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
parent
20a42b1f56
commit
f9c8fa305e
5 changed files with 42 additions and 7 deletions
|
@ -89,7 +89,16 @@ func Init(root string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
|||
return nil, graphdriver.ErrNotSupported
|
||||
}
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(root)
|
||||
// Perform feature detection on /var/lib/docker/aufs if it's an existing directory.
|
||||
// This covers situations where /var/lib/docker/aufs is a mount, and on a different
|
||||
// filesystem than /var/lib/docker.
|
||||
// If the path does not exist, fall back to using /var/lib/docker for feature detection.
|
||||
testdir := root
|
||||
if _, err := os.Stat(testdir); os.IsNotExist(err) {
|
||||
testdir = filepath.Dir(testdir)
|
||||
}
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(testdir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -51,7 +51,16 @@ type btrfsOptions struct {
|
|||
// An error is returned if BTRFS is not supported.
|
||||
func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (graphdriver.Driver, error) {
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(home)
|
||||
// Perform feature detection on /var/lib/docker/btrfs if it's an existing directory.
|
||||
// This covers situations where /var/lib/docker/btrfs is a mount, and on a different
|
||||
// filesystem than /var/lib/docker.
|
||||
// If the path does not exist, fall back to using /var/lib/docker for feature detection.
|
||||
testdir := home
|
||||
if _, err := os.Stat(testdir); os.IsNotExist(err) {
|
||||
testdir = filepath.Dir(testdir)
|
||||
}
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(testdir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -3,8 +3,6 @@
|
|||
package graphdriver
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"golang.org/x/sys/unix"
|
||||
)
|
||||
|
@ -82,7 +80,7 @@ var (
|
|||
// GetFSMagic returns the filesystem id given the path.
|
||||
func GetFSMagic(rootpath string) (FsMagic, error) {
|
||||
var buf unix.Statfs_t
|
||||
if err := unix.Statfs(filepath.Dir(rootpath), &buf); err != nil {
|
||||
if err := unix.Statfs(rootpath, &buf); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return FsMagic(buf.Type), nil
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"os"
|
||||
"os/exec"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
|
||||
"github.com/docker/docker/daemon/graphdriver"
|
||||
|
@ -119,7 +120,16 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
|||
return nil, graphdriver.ErrNotSupported
|
||||
}
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(home)
|
||||
// Perform feature detection on /var/lib/docker/overlay if it's an existing directory.
|
||||
// This covers situations where /var/lib/docker/overlay is a mount, and on a different
|
||||
// filesystem than /var/lib/docker.
|
||||
// If the path does not exist, fall back to using /var/lib/docker for feature detection.
|
||||
testdir := home
|
||||
if _, err := os.Stat(testdir); os.IsNotExist(err) {
|
||||
testdir = filepath.Dir(testdir)
|
||||
}
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(testdir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -136,7 +136,16 @@ func Init(home string, options []string, uidMaps, gidMaps []idtools.IDMap) (grap
|
|||
return nil, err
|
||||
}
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(home)
|
||||
// Perform feature detection on /var/lib/docker/overlay2 if it's an existing directory.
|
||||
// This covers situations where /var/lib/docker/overlay2 is a mount, and on a different
|
||||
// filesystem than /var/lib/docker.
|
||||
// If the path does not exist, fall back to using /var/lib/docker for feature detection.
|
||||
testdir := home
|
||||
if _, err := os.Stat(testdir); os.IsNotExist(err) {
|
||||
testdir = filepath.Dir(testdir)
|
||||
}
|
||||
|
||||
fsMagic, err := graphdriver.GetFSMagic(testdir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue