Add --storage-opt graph driver option and pass through to driver

This lets you add storage specific options for the daemon.

Docker-DCO-1.1-Signed-off-by: Alexander Larsson <alexl@redhat.com> (github: alexlarsson)
This commit is contained in:
Alexander Larsson 2014-06-05 10:34:20 +02:00
parent 948e54ac45
commit 822ea97ffc
13 changed files with 26 additions and 17 deletions

View File

@ -780,7 +780,7 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D
graphdriver.DefaultDriver = config.GraphDriver
// Load storage driver
driver, err := graphdriver.New(config.Root)
driver, err := graphdriver.New(config.Root, config.GraphOptions)
if err != nil {
return nil, err
}
@ -809,7 +809,7 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D
// We don't want to use a complex driver like aufs or devmapper
// for volumes, just a plain filesystem
volumesDriver, err := graphdriver.GetDriver("vfs", config.Root)
volumesDriver, err := graphdriver.GetDriver("vfs", config.Root, config.GraphOptions)
if err != nil {
return nil, err
}

View File

@ -57,7 +57,7 @@ type Driver struct {
// New returns a new AUFS driver.
// An error is returned if AUFS is not supported.
func Init(root string) (graphdriver.Driver, error) {
func Init(root string, options []string) (graphdriver.Driver, error) {
// Try to load the aufs kernel module
if err := supportsAufs(); err != nil {
return nil, graphdriver.ErrNotSupported

View File

@ -17,7 +17,7 @@ var (
)
func testInit(dir string, t *testing.T) graphdriver.Driver {
d, err := Init(dir)
d, err := Init(dir, nil)
if err != nil {
if err == graphdriver.ErrNotSupported {
t.Skip(err)

View File

@ -22,7 +22,7 @@ func init() {
graphdriver.Register("btrfs", Init)
}
func Init(home string) (graphdriver.Driver, error) {
func Init(home string, options []string) (graphdriver.Driver, error) {
rootdir := path.Dir(home)
var buf syscall.Statfs_t

View File

@ -26,7 +26,7 @@ type Driver struct {
home string
}
func Init(home string) (graphdriver.Driver, error) {
func Init(home string, options []string) (graphdriver.Driver, error) {
deviceSet, err := NewDeviceSet(home, true)
if err != nil {
return nil, err

View File

@ -15,7 +15,7 @@ const (
FsMagicAufs = FsMagic(0x61756673)
)
type InitFunc func(root string) (Driver, error)
type InitFunc func(root string, options []string) (Driver, error)
type Driver interface {
String() string
@ -69,23 +69,23 @@ func Register(name string, initFunc InitFunc) error {
return nil
}
func GetDriver(name, home string) (Driver, error) {
func GetDriver(name, home string, options []string) (Driver, error) {
if initFunc, exists := drivers[name]; exists {
return initFunc(path.Join(home, name))
return initFunc(path.Join(home, name), options)
}
return nil, ErrNotSupported
}
func New(root string) (driver Driver, err error) {
func New(root string, options []string) (driver Driver, err error) {
for _, name := range []string{os.Getenv("DOCKER_DRIVER"), DefaultDriver} {
if name != "" {
return GetDriver(name, root)
return GetDriver(name, root, options)
}
}
// Check for priority drivers first
for _, name := range priority {
driver, err = GetDriver(name, root)
driver, err = GetDriver(name, root, options)
if err != nil {
if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
continue
@ -97,7 +97,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 driver, err = initFunc(root, options); err != nil {
if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
continue
}

View File

@ -29,7 +29,7 @@ func newDriver(t *testing.T, name string) *Driver {
t.Fatal(err)
}
d, err := graphdriver.GetDriver(name, root)
d, err := graphdriver.GetDriver(name, root, nil)
if err != nil {
if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites {
t.Skip("Driver %s not supported", name)

View File

@ -12,7 +12,7 @@ func init() {
graphdriver.Register("vfs", Init)
}
func Init(home string) (graphdriver.Driver, error) {
func Init(home string, options []string) (graphdriver.Driver, error) {
d := &Driver{
home: home,
}

View File

@ -25,6 +25,7 @@ type Config struct {
BridgeIP string
InterContainerCommunication bool
GraphDriver string
GraphOptions []string
ExecDriver string
Mtu int
DisableNetwork bool
@ -49,6 +50,10 @@ func ConfigFromJob(job *engine.Job) *Config {
ExecDriver: job.Getenv("ExecDriver"),
EnableSelinuxSupport: job.GetenvBool("EnableSelinuxSupport"),
}
if graphOpts := job.GetenvList("GraphOptions"); graphOpts != nil {
config.GraphOptions = graphOpts
}
if dns := job.GetenvList("Dns"); dns != nil {
config.Dns = dns
}

View File

@ -41,6 +41,7 @@ func main() {
var (
flVersion = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
flDaemon = flag.Bool([]string{"d", "-daemon"}, false, "Enable daemon mode")
flGraphOpts opts.ListOpts
flDebug = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode")
flAutoRestart = flag.Bool([]string{"r", "-restart"}, true, "Restart previously running containers")
bridgeName = flag.String([]string{"b", "-bridge"}, "", "Attach containers to a pre-existing network bridge\nuse 'none' to disable container networking")
@ -69,6 +70,7 @@ func main() {
flag.Var(&flDns, []string{"#dns", "-dns"}, "Force docker to use specific DNS servers")
flag.Var(&flDnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
flag.Var(&flHosts, []string{"H", "-host"}, "The socket(s) to bind to in daemon mode\nspecified using one or more tcp://host:port, unix:///path/to/socket, fd://* or fd://socketfd.")
flag.Var(&flGraphOpts, []string{"-storage-opt"}, "Set storage driver options")
flag.Parse()
@ -156,6 +158,7 @@ func main() {
job.Setenv("DefaultIp", *flDefaultIp)
job.SetenvBool("InterContainerCommunication", *flInterContainerComm)
job.Setenv("GraphDriver", *flGraphDriver)
job.SetenvList("GraphOptions", flGraphOpts.GetAll())
job.Setenv("ExecDriver", *flExecDriver)
job.SetenvInt("Mtu", *flMtu)
job.SetenvBool("EnableSelinuxSupport", *flSelinuxEnabled)

View File

@ -73,6 +73,7 @@ expect an integer, and they can only be specified once.
-p, --pidfile="/var/run/docker.pid" Path to use for daemon PID file
-r, --restart=true Restart previously running containers
-s, --storage-driver="" Force the docker runtime to use a specific storage driver
--storage-opt=[] Set storage driver options
--selinux-enabled=false Enable selinux support
--tls=false Use TLS; implied by tls-verify flags
--tlscacert="/home/sven/.docker/ca.pem" Trust only remotes providing a certificate signed by the CA given here

View File

@ -36,7 +36,7 @@ func fakeTar() (io.Reader, error) {
}
func mkTestTagStore(root string, t *testing.T) *TagStore {
driver, err := graphdriver.New(root)
driver, err := graphdriver.New(root, nil)
if err != nil {
t.Fatal(err)
}

View File

@ -293,7 +293,7 @@ func tempGraph(t *testing.T) (*graph.Graph, graphdriver.Driver) {
if err != nil {
t.Fatal(err)
}
driver, err := graphdriver.New(tmp)
driver, err := graphdriver.New(tmp, nil)
if err != nil {
t.Fatal(err)
}