Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions drivers/aufs/aufs.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func Init(home string, options graphdriver.Options) (graphdriver.Driver, error)

fsMagic, err := graphdriver.GetFSMagic(home)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "aufs: failed to getfsmagic %s", home)
}
if fsName, ok := graphdriver.FsNames[fsMagic]; ok {
backingFs = fsName
Expand All @@ -109,7 +109,7 @@ func Init(home string, options graphdriver.Options) (graphdriver.Driver, error)
for _, option := range options.DriverOptions {
key, val, err := parsers.ParseKeyValueOpt(option)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "aufs: ParseKeyValueOpt %s", option)
}
key = strings.ToLower(key)
switch key {
Expand Down Expand Up @@ -137,7 +137,7 @@ func Init(home string, options graphdriver.Options) (graphdriver.Driver, error)

rootUID, rootGID, err := idtools.GetRootUIDGID(options.UIDMaps, options.GIDMaps)
if err != nil {
return nil, err
return nil, errors.Wrapf(err, "aufs: failed to GetRootUIDGID")
}
// Create the root aufs driver dir and return
// if it already exists
Expand All @@ -146,17 +146,17 @@ func Init(home string, options graphdriver.Options) (graphdriver.Driver, error)
if os.IsExist(err) {
return a, nil
}
return nil, err
return nil, errors.Wrapf(err, "aufs: failed to mkdirallas: %s", home)
}

if err := mountpk.MakePrivate(home); err != nil {
return nil, err
return nil, errors.Wrapf(err, "aufs: failed to MakePrivate: %s", home)
}

// Populate the dir structure
for _, p := range paths {
if err := idtools.MkdirAllAs(path.Join(home, p), 0700, rootUID, rootGID); err != nil {
return nil, err
return nil, errors.Wrapf(err, "aufs: failed to MakePrivate: %s", path.Join(home, p))
}
}
logger := logrus.WithFields(logrus.Fields{
Expand Down Expand Up @@ -326,7 +326,7 @@ func (a *Driver) createDirsFor(id, parent string) error {
rootPair.GID = int(st.GID())
}
if err := idtools.MkdirAllAndChownNew(path.Join(a.rootPath(), p, id), os.FileMode(0755), rootPair); err != nil {
return err
return errors.Wrapf(err, "aufs: failed to makedir %s", path.Join(a.rootPath(), p))
}
}
return nil
Expand Down
69 changes: 45 additions & 24 deletions drivers/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"os"
"path/filepath"
"strings"
"sync"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand All @@ -24,6 +25,9 @@ const (
)

var (
once sync.Once
defaultDriverName string
defaultDriverNameErr error
// All registered drivers
drivers map[string]InitFunc

Expand Down Expand Up @@ -209,6 +213,46 @@ func Register(name string, initFunc InitFunc) error {
return nil
}

// GetDefaultDriverName returns the driver name
func GetDefaultDriverName(config Options) (string, error) {
once.Do(func() {
driver, err := getDefaultDriver(config)
if err != nil {
defaultDriverNameErr = err
} else {
defaultDriverName = driver.String()
}
})
return defaultDriverName, defaultDriverNameErr
}

// GetDefaultDriver initializes and returns the registered driver
func getDefaultDriver(config Options) (Driver, error) {
// Check for priority drivers first
for _, name := range priority {
driver, err := getBuiltinDriver(name, config.Root, config)
if err != nil {
if isDriverNotSupported(err) {
continue
}
return nil, err
}
return driver, nil
}
// Check all registered drivers if no priority driver is found
for name, initFunc := range drivers {
driver, err := initFunc(filepath.Join(config.Root, name), config)
if err != nil {
if isDriverNotSupported(err) {
continue
}
return nil, err
}
return driver, nil
}
return nil, fmt.Errorf("No supported storage backend found")
}

// GetDriver initializes and returns the registered driver
func GetDriver(name string, config Options) (Driver, error) {
if initFunc, exists := drivers[name]; exists {
Expand Down Expand Up @@ -281,30 +325,7 @@ func New(name string, config Options) (Driver, error) {
}
}

// Check for priority drivers first
for _, name := range priority {
driver, err := getBuiltinDriver(name, config.Root, config)
if err != nil {
if isDriverNotSupported(err) {
continue
}
return nil, err
}
return driver, nil
}

// Check all registered drivers if no priority driver is found
for name, initFunc := range drivers {
driver, err := initFunc(filepath.Join(config.Root, name), config)
if err != nil {
if isDriverNotSupported(err) {
continue
}
return nil, err
}
return driver, nil
}
return nil, fmt.Errorf("No supported storage backend found")
return getDefaultDriver(config)
}

// isDriverNotSupported returns true if the error initializing
Expand Down
24 changes: 19 additions & 5 deletions store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3278,15 +3278,15 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
data, err := ioutil.ReadFile(configFile)
if err != nil {
if !os.IsNotExist(err) {
fmt.Printf("Failed to read %s %v\n", configFile, err.Error())
fmt.Fprintf(os.Stderr, "Failed to read %s %v\n", configFile, err.Error())
return
}
}

config := new(tomlConfig)

if _, err := toml.Decode(string(data), config); err != nil {
fmt.Printf("Failed to parse %s %v\n", configFile, err.Error())
fmt.Fprintf(os.Stderr, "Failed to parse %s %v\n", configFile, err.Error())
return
}
if config.Storage.Driver != "" {
Expand Down Expand Up @@ -3322,7 +3322,7 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {
if config.Storage.Options.RemapUser != "" && config.Storage.Options.RemapGroup != "" {
mappings, err := idtools.NewIDMappings(config.Storage.Options.RemapUser, config.Storage.Options.RemapGroup)
if err != nil {
fmt.Printf("Error initializing ID mappings for %s:%s %v\n", config.Storage.Options.RemapUser, config.Storage.Options.RemapGroup, err)
fmt.Fprintf(os.Stderr, "Error initializing ID mappings for %s:%s %v\n", config.Storage.Options.RemapUser, config.Storage.Options.RemapGroup, err)
return
}
storeOptions.UIDMap = mappings.UIDs()
Expand All @@ -3331,20 +3331,34 @@ func ReloadConfigurationFile(configFile string, storeOptions *StoreOptions) {

uidmap, err := idtools.ParseIDMap([]string{config.Storage.Options.RemapUIDs}, "remap-uids")
if err != nil {
fmt.Print(err)
fmt.Fprint(os.Stderr, err)
} else {
storeOptions.UIDMap = append(storeOptions.UIDMap, uidmap...)
}
gidmap, err := idtools.ParseIDMap([]string{config.Storage.Options.RemapGIDs}, "remap-gids")
if err != nil {
fmt.Print(err)
fmt.Fprint(os.Stderr, err)
} else {
storeOptions.GIDMap = append(storeOptions.GIDMap, gidmap...)
}
if os.Getenv("STORAGE_DRIVER") != "" {
storeOptions.GraphDriverName = os.Getenv("STORAGE_DRIVER")
}

if storeOptions.GraphDriverName == "" {
options := drivers.Options{
Root: storeOptions.GraphRoot,
RunRoot: storeOptions.RunRoot,
UIDMaps: storeOptions.UIDMap,
GIDMaps: storeOptions.GIDMap,
}
name, err := drivers.GetDefaultDriverName(options)
if err != nil {
fmt.Fprintf(os.Stderr, "Error getting default driver name: %v\n", err)
} else {
storeOptions.GraphDriverName = name
}
}
storeOptions.GraphDriverOptions = cfg.GetGraphDriverOptions(storeOptions.GraphDriverName, config.Storage.Options)

if os.Getenv("STORAGE_OPTS") != "" {
Expand Down
5 changes: 5 additions & 0 deletions tests/helpers.bash
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ populate() {
lowerlayer="$output"
# Mount the layer.
run storage --debug=false mount $lowerlayer
echo $output
[ "$status" -eq 0 ]
[ "$output" != "" ]
local lowermount="$output"
Expand Down Expand Up @@ -81,11 +82,13 @@ populate() {

# Create a second layer based on the first.
run storage --debug=false create-layer "$lowerlayer"
echo $output
[ "$status" -eq 0 ]
[ "$output" != "" ]
midlayer="$output"
# Mount the second layer.
run storage --debug=false mount $midlayer
echo $output
[ "$status" -eq 0 ]
[ "$output" != "" ]
local midmount="$output"
Expand Down Expand Up @@ -133,11 +136,13 @@ populate() {

# Create a third layer based on the second.
run storage --debug=false create-layer "$midlayer"
echo $output
[ "$status" -eq 0 ]
[ "$output" != "" ]
upperlayer="$output"
# Mount the third layer.
run storage --debug=false mount $upperlayer
echo $output
[ "$status" -eq 0 ]
[ "$output" != "" ]
local uppermount="$output"
Expand Down