block aufs on incompatible file systems

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
This commit is contained in:
unclejack 2014-05-29 22:55:59 +03:00
parent 189c600b3b
commit e8a87120d4
2 changed files with 27 additions and 9 deletions

View file

@ -23,20 +23,23 @@ package aufs
import (
"bufio"
"fmt"
"github.com/dotcloud/docker/archive"
"github.com/dotcloud/docker/daemon/graphdriver"
"github.com/dotcloud/docker/pkg/label"
mountpk "github.com/dotcloud/docker/pkg/mount"
"github.com/dotcloud/docker/utils"
"os"
"os/exec"
"path"
"strings"
"sync"
"syscall"
"github.com/dotcloud/docker/archive"
"github.com/dotcloud/docker/daemon/graphdriver"
"github.com/dotcloud/docker/pkg/label"
mountpk "github.com/dotcloud/docker/pkg/mount"
"github.com/dotcloud/docker/utils"
)
var (
ErrAufsNotSupported = fmt.Errorf("AUFS was not found in /proc/filesystems")
IncompatibleFSMagic = []int64{0x9123683E /*btrfs*/, 0x61756673 /*AUFS*/}
)
func init() {
@ -56,6 +59,20 @@ func Init(root string) (graphdriver.Driver, error) {
if err := supportsAufs(); err != nil {
return nil, graphdriver.ErrNotSupported
}
rootdir := path.Dir(root)
var buf syscall.Statfs_t
if err := syscall.Statfs(rootdir, &buf); err != nil {
return nil, fmt.Errorf("Couldn't stat the root directory: %s", err)
}
for _, magic := range IncompatibleFSMagic {
if int64(buf.Type) == magic {
return nil, graphdriver.ErrIncompatibleFS
}
}
paths := []string{
"mnt",
"diff",

View file

@ -44,8 +44,9 @@ var (
"vfs",
}
ErrNotSupported = errors.New("driver not supported")
ErrPrerequisites = errors.New("Prerequisites for driver not satisfied (wrong filesystem?)")
ErrNotSupported = errors.New("driver not supported")
ErrPrerequisites = errors.New("prerequisites for driver not satisfied (wrong filesystem?)")
ErrIncompatibleFS = fmt.Errorf("backing file system is unsupported for this graph driver")
)
func init() {
@ -79,7 +80,7 @@ func New(root string) (driver Driver, err error) {
for _, name := range priority {
driver, err = GetDriver(name, root)
if err != nil {
if err == ErrNotSupported || err == ErrPrerequisites {
if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
continue
}
return nil, err
@ -90,7 +91,7 @@ func New(root string) (driver Driver, err error) {
// Check all registered drivers if no priority driver is found
for _, initFunc := range drivers {
if driver, err = initFunc(root); err != nil {
if err == ErrNotSupported || err == ErrPrerequisites {
if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
continue
}
return nil, err