Browse code

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)

Alexander Larsson authored on 2014/06/05 17:34:20
Showing 13 changed files
... ...
@@ -780,7 +780,7 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D
780 780
 	graphdriver.DefaultDriver = config.GraphDriver
781 781
 
782 782
 	// Load storage driver
783
-	driver, err := graphdriver.New(config.Root)
783
+	driver, err := graphdriver.New(config.Root, config.GraphOptions)
784 784
 	if err != nil {
785 785
 		return nil, err
786 786
 	}
... ...
@@ -809,7 +809,7 @@ func NewDaemonFromDirectory(config *daemonconfig.Config, eng *engine.Engine) (*D
809 809
 
810 810
 	// We don't want to use a complex driver like aufs or devmapper
811 811
 	// for volumes, just a plain filesystem
812
-	volumesDriver, err := graphdriver.GetDriver("vfs", config.Root)
812
+	volumesDriver, err := graphdriver.GetDriver("vfs", config.Root, config.GraphOptions)
813 813
 	if err != nil {
814 814
 		return nil, err
815 815
 	}
... ...
@@ -57,7 +57,7 @@ type Driver struct {
57 57
 
58 58
 // New returns a new AUFS driver.
59 59
 // An error is returned if AUFS is not supported.
60
-func Init(root string) (graphdriver.Driver, error) {
60
+func Init(root string, options []string) (graphdriver.Driver, error) {
61 61
 	// Try to load the aufs kernel module
62 62
 	if err := supportsAufs(); err != nil {
63 63
 		return nil, graphdriver.ErrNotSupported
... ...
@@ -17,7 +17,7 @@ var (
17 17
 )
18 18
 
19 19
 func testInit(dir string, t *testing.T) graphdriver.Driver {
20
-	d, err := Init(dir)
20
+	d, err := Init(dir, nil)
21 21
 	if err != nil {
22 22
 		if err == graphdriver.ErrNotSupported {
23 23
 			t.Skip(err)
... ...
@@ -22,7 +22,7 @@ func init() {
22 22
 	graphdriver.Register("btrfs", Init)
23 23
 }
24 24
 
25
-func Init(home string) (graphdriver.Driver, error) {
25
+func Init(home string, options []string) (graphdriver.Driver, error) {
26 26
 	rootdir := path.Dir(home)
27 27
 
28 28
 	var buf syscall.Statfs_t
... ...
@@ -26,7 +26,7 @@ type Driver struct {
26 26
 	home string
27 27
 }
28 28
 
29
-func Init(home string) (graphdriver.Driver, error) {
29
+func Init(home string, options []string) (graphdriver.Driver, error) {
30 30
 	deviceSet, err := NewDeviceSet(home, true)
31 31
 	if err != nil {
32 32
 		return nil, err
... ...
@@ -15,7 +15,7 @@ const (
15 15
 	FsMagicAufs  = FsMagic(0x61756673)
16 16
 )
17 17
 
18
-type InitFunc func(root string) (Driver, error)
18
+type InitFunc func(root string, options []string) (Driver, error)
19 19
 
20 20
 type Driver interface {
21 21
 	String() string
... ...
@@ -69,23 +69,23 @@ func Register(name string, initFunc InitFunc) error {
69 69
 	return nil
70 70
 }
71 71
 
72
-func GetDriver(name, home string) (Driver, error) {
72
+func GetDriver(name, home string, options []string) (Driver, error) {
73 73
 	if initFunc, exists := drivers[name]; exists {
74
-		return initFunc(path.Join(home, name))
74
+		return initFunc(path.Join(home, name), options)
75 75
 	}
76 76
 	return nil, ErrNotSupported
77 77
 }
78 78
 
79
-func New(root string) (driver Driver, err error) {
79
+func New(root string, options []string) (driver Driver, err error) {
80 80
 	for _, name := range []string{os.Getenv("DOCKER_DRIVER"), DefaultDriver} {
81 81
 		if name != "" {
82
-			return GetDriver(name, root)
82
+			return GetDriver(name, root, options)
83 83
 		}
84 84
 	}
85 85
 
86 86
 	// Check for priority drivers first
87 87
 	for _, name := range priority {
88
-		driver, err = GetDriver(name, root)
88
+		driver, err = GetDriver(name, root, options)
89 89
 		if err != nil {
90 90
 			if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
91 91
 				continue
... ...
@@ -97,7 +97,7 @@ func New(root string) (driver Driver, err error) {
97 97
 
98 98
 	// Check all registered drivers if no priority driver is found
99 99
 	for _, initFunc := range drivers {
100
-		if driver, err = initFunc(root); err != nil {
100
+		if driver, err = initFunc(root, options); err != nil {
101 101
 			if err == ErrNotSupported || err == ErrPrerequisites || err == ErrIncompatibleFS {
102 102
 				continue
103 103
 			}
... ...
@@ -29,7 +29,7 @@ func newDriver(t *testing.T, name string) *Driver {
29 29
 		t.Fatal(err)
30 30
 	}
31 31
 
32
-	d, err := graphdriver.GetDriver(name, root)
32
+	d, err := graphdriver.GetDriver(name, root, nil)
33 33
 	if err != nil {
34 34
 		if err == graphdriver.ErrNotSupported || err == graphdriver.ErrPrerequisites {
35 35
 			t.Skip("Driver %s not supported", name)
... ...
@@ -12,7 +12,7 @@ func init() {
12 12
 	graphdriver.Register("vfs", Init)
13 13
 }
14 14
 
15
-func Init(home string) (graphdriver.Driver, error) {
15
+func Init(home string, options []string) (graphdriver.Driver, error) {
16 16
 	d := &Driver{
17 17
 		home: home,
18 18
 	}
... ...
@@ -25,6 +25,7 @@ type Config struct {
25 25
 	BridgeIP                    string
26 26
 	InterContainerCommunication bool
27 27
 	GraphDriver                 string
28
+	GraphOptions                []string
28 29
 	ExecDriver                  string
29 30
 	Mtu                         int
30 31
 	DisableNetwork              bool
... ...
@@ -49,6 +50,10 @@ func ConfigFromJob(job *engine.Job) *Config {
49 49
 		ExecDriver:                  job.Getenv("ExecDriver"),
50 50
 		EnableSelinuxSupport:        job.GetenvBool("EnableSelinuxSupport"),
51 51
 	}
52
+	if graphOpts := job.GetenvList("GraphOptions"); graphOpts != nil {
53
+		config.GraphOptions = graphOpts
54
+	}
55
+
52 56
 	if dns := job.GetenvList("Dns"); dns != nil {
53 57
 		config.Dns = dns
54 58
 	}
... ...
@@ -41,6 +41,7 @@ func main() {
41 41
 	var (
42 42
 		flVersion            = flag.Bool([]string{"v", "-version"}, false, "Print version information and quit")
43 43
 		flDaemon             = flag.Bool([]string{"d", "-daemon"}, false, "Enable daemon mode")
44
+		flGraphOpts          opts.ListOpts
44 45
 		flDebug              = flag.Bool([]string{"D", "-debug"}, false, "Enable debug mode")
45 46
 		flAutoRestart        = flag.Bool([]string{"r", "-restart"}, true, "Restart previously running containers")
46 47
 		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() {
69 69
 	flag.Var(&flDns, []string{"#dns", "-dns"}, "Force docker to use specific DNS servers")
70 70
 	flag.Var(&flDnsSearch, []string{"-dns-search"}, "Force Docker to use specific DNS search domains")
71 71
 	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.")
72
+	flag.Var(&flGraphOpts, []string{"-storage-opt"}, "Set storage driver options")
72 73
 
73 74
 	flag.Parse()
74 75
 
... ...
@@ -156,6 +158,7 @@ func main() {
156 156
 			job.Setenv("DefaultIp", *flDefaultIp)
157 157
 			job.SetenvBool("InterContainerCommunication", *flInterContainerComm)
158 158
 			job.Setenv("GraphDriver", *flGraphDriver)
159
+			job.SetenvList("GraphOptions", flGraphOpts.GetAll())
159 160
 			job.Setenv("ExecDriver", *flExecDriver)
160 161
 			job.SetenvInt("Mtu", *flMtu)
161 162
 			job.SetenvBool("EnableSelinuxSupport", *flSelinuxEnabled)
... ...
@@ -73,6 +73,7 @@ expect an integer, and they can only be specified once.
73 73
       -p, --pidfile="/var/run/docker.pid"        Path to use for daemon PID file
74 74
       -r, --restart=true                         Restart previously running containers
75 75
       -s, --storage-driver=""                    Force the docker runtime to use a specific storage driver
76
+      --storage-opt=[]                           Set storage driver options
76 77
       --selinux-enabled=false                    Enable selinux support
77 78
       --tls=false                                Use TLS; implied by tls-verify flags
78 79
       --tlscacert="/home/sven/.docker/ca.pem"    Trust only remotes providing a certificate signed by the CA given here
... ...
@@ -36,7 +36,7 @@ func fakeTar() (io.Reader, error) {
36 36
 }
37 37
 
38 38
 func mkTestTagStore(root string, t *testing.T) *TagStore {
39
-	driver, err := graphdriver.New(root)
39
+	driver, err := graphdriver.New(root, nil)
40 40
 	if err != nil {
41 41
 		t.Fatal(err)
42 42
 	}
... ...
@@ -293,7 +293,7 @@ func tempGraph(t *testing.T) (*graph.Graph, graphdriver.Driver) {
293 293
 	if err != nil {
294 294
 		t.Fatal(err)
295 295
 	}
296
-	driver, err := graphdriver.New(tmp)
296
+	driver, err := graphdriver.New(tmp, nil)
297 297
 	if err != nil {
298 298
 		t.Fatal(err)
299 299
 	}