2013-11-03 20:54:51 -05:00
|
|
|
package graphdriver
|
2013-10-31 21:07:54 -04:00
|
|
|
|
2013-11-04 18:22:34 -05:00
|
|
|
import (
|
|
|
|
"fmt"
|
2013-11-04 23:51:12 -05:00
|
|
|
"github.com/dotcloud/docker/archive"
|
2013-11-07 22:02:15 -05:00
|
|
|
"github.com/dotcloud/docker/utils"
|
2013-11-19 06:13:22 -05:00
|
|
|
"os"
|
2013-11-08 14:36:58 -05:00
|
|
|
"path"
|
2013-11-04 18:22:34 -05:00
|
|
|
)
|
|
|
|
|
2013-11-07 19:35:26 -05:00
|
|
|
type InitFunc func(root string) (Driver, error)
|
2013-11-04 23:51:12 -05:00
|
|
|
|
|
|
|
type Driver interface {
|
2013-11-15 04:24:48 -05:00
|
|
|
String() string
|
|
|
|
|
2013-11-07 15:34:01 -05:00
|
|
|
Create(id, parent string) error
|
|
|
|
Remove(id string) error
|
2013-11-04 23:51:12 -05:00
|
|
|
|
2013-11-07 15:34:01 -05:00
|
|
|
Get(id string) (dir string, err error)
|
2013-12-05 16:18:02 -05:00
|
|
|
Put(id string)
|
2013-11-19 05:32:08 -05:00
|
|
|
Exists(id string) bool
|
2013-11-04 23:51:12 -05:00
|
|
|
|
2013-11-15 05:04:02 -05:00
|
|
|
Status() [][2]string
|
|
|
|
|
2013-11-11 20:17:38 -05:00
|
|
|
Cleanup() error
|
|
|
|
}
|
|
|
|
|
|
|
|
type Differ interface {
|
2013-11-11 15:09:26 -05:00
|
|
|
Diff(id string) (archive.Archive, error)
|
2013-11-08 17:54:20 -05:00
|
|
|
Changes(id string) ([]archive.Change, error)
|
2013-11-11 20:17:38 -05:00
|
|
|
ApplyDiff(id string, diff archive.Archive) error
|
2013-11-19 04:36:54 -05:00
|
|
|
DiffSize(id string) (bytes int64, err error)
|
2013-11-11 10:47:36 -05:00
|
|
|
}
|
|
|
|
|
2013-11-04 18:22:34 -05:00
|
|
|
var (
|
2013-11-20 14:39:15 -05:00
|
|
|
DefaultDriver string
|
2013-11-04 18:22:34 -05:00
|
|
|
// All registred drivers
|
|
|
|
drivers map[string]InitFunc
|
|
|
|
// Slice of drivers that should be used in an order
|
|
|
|
priority = []string{
|
|
|
|
"aufs",
|
|
|
|
"devicemapper",
|
2013-11-25 13:28:17 -05:00
|
|
|
"vfs",
|
2013-11-21 15:45:48 -05:00
|
|
|
// experimental, has to be enabled manually for now
|
|
|
|
"btrfs",
|
2013-11-04 18:22:34 -05:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
2013-11-07 15:31:50 -05:00
|
|
|
func init() {
|
|
|
|
drivers = make(map[string]InitFunc)
|
|
|
|
}
|
|
|
|
|
2013-11-04 18:22:34 -05:00
|
|
|
func Register(name string, initFunc InitFunc) error {
|
|
|
|
if _, exists := drivers[name]; exists {
|
|
|
|
return fmt.Errorf("Name already registered %s", name)
|
|
|
|
}
|
|
|
|
drivers[name] = initFunc
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2013-11-15 05:30:28 -05:00
|
|
|
func GetDriver(name, home string) (Driver, error) {
|
2013-11-07 21:49:32 -05:00
|
|
|
if initFunc, exists := drivers[name]; exists {
|
2013-11-08 14:36:58 -05:00
|
|
|
return initFunc(path.Join(home, name))
|
2013-11-07 21:49:32 -05:00
|
|
|
}
|
|
|
|
return nil, fmt.Errorf("No such driver: %s", name)
|
|
|
|
}
|
|
|
|
|
2013-11-20 14:39:15 -05:00
|
|
|
func New(root string) (driver Driver, err error) {
|
|
|
|
for _, name := range []string{os.Getenv("DOCKER_DRIVER"), DefaultDriver} {
|
2013-11-19 06:13:22 -05:00
|
|
|
if name != "" {
|
|
|
|
return GetDriver(name, root)
|
|
|
|
}
|
2013-11-07 21:49:32 -05:00
|
|
|
}
|
2013-11-19 06:13:22 -05:00
|
|
|
|
2013-11-04 18:22:34 -05:00
|
|
|
// Check for priority drivers first
|
|
|
|
for _, name := range priority {
|
2013-11-20 14:39:15 -05:00
|
|
|
if driver, err = GetDriver(name, root); err != nil {
|
|
|
|
utils.Debugf("Error loading driver %s: %s", name, err)
|
2013-11-07 21:49:32 -05:00
|
|
|
continue
|
2013-11-04 18:22:34 -05:00
|
|
|
}
|
2013-11-07 21:49:32 -05:00
|
|
|
return driver, nil
|
2013-11-04 18:22:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check all registered drivers if no priority driver is found
|
|
|
|
for _, initFunc := range drivers {
|
2013-11-20 14:39:15 -05:00
|
|
|
if driver, err = initFunc(root); err != nil {
|
2013-11-04 18:22:34 -05:00
|
|
|
continue
|
|
|
|
}
|
|
|
|
return driver, nil
|
|
|
|
}
|
2013-11-20 14:39:15 -05:00
|
|
|
return nil, err
|
2013-11-04 18:22:34 -05:00
|
|
|
}
|