Skip to content

Commit 17708e7

Browse files
committed
graphdriver: custom build-time priority list
Add a way to specify a custom graphdriver priority list during build. This can be done with something like go build -ldflags "-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,devicemapper" As ldflags are already used by the engine build process, and it seems that only one (last) `-ldflags` argument is taken into account by go, an envoronment variable `DOCKER_LDFLAGS` is introduced in order to be able to append some text to `-ldflags`. With this in place, using the feature becomes make DOCKER_LDFLAGS="-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,devicemapper" dynbinary The idea behind this is, the priority list might be different for different distros, so vendors are now able to change it without patching the source code. Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
1 parent 7c53e73 commit 17708e7

File tree

7 files changed

+21
-24
lines changed

7 files changed

+21
-24
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,13 @@ export DOCKER_GITCOMMIT
1616
# env vars passed through directly to Docker's build scripts
1717
# to allow things like `make KEEPBUNDLE=1 binary` easily
1818
# `project/PACKAGERS.md` have some limited documentation of some of these
19+
#
20+
# DOCKER_LDFLAGS can be used to pass additional parameters to -ldflags
21+
# option of "go build". For example, a built-in graphdriver priority list
22+
# can be changed during build time like this:
23+
#
24+
# make DOCKER_LDFLAGS="-X github.com/docker/docker/daemon/graphdriver.priority=overlay2,devicemapper" dynbinary
25+
#
1926
DOCKER_ENVS := \
2027
-e DOCKER_CROSSPLATFORMS \
2128
-e BUILD_APT_MIRROR \
@@ -31,6 +38,7 @@ DOCKER_ENVS := \
3138
-e DOCKER_GITCOMMIT \
3239
-e DOCKER_GRAPHDRIVER \
3340
-e DOCKER_INCREMENTAL_BINARY \
41+
-e DOCKER_LDFLAGS \
3442
-e DOCKER_PORT \
3543
-e DOCKER_REMAP_ROOT \
3644
-e DOCKER_STORAGE_OPTS \

daemon/graphdriver/driver.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ func New(name string, pg plugingetter.PluginGetter, config Options) (Driver, err
208208

209209
// Guess for prior driver
210210
driversMap := scanPriorDrivers(config.Root)
211-
for _, name := range priority {
211+
list := strings.Split(priority, ",")
212+
logrus.Debugf("[graphdriver] priority list: %v", list)
213+
for _, name := range list {
212214
if name == "vfs" {
213215
// don't use vfs even if there is state present.
214216
continue
@@ -243,7 +245,7 @@ func New(name string, pg plugingetter.PluginGetter, config Options) (Driver, err
243245
}
244246

245247
// Check for priority drivers first
246-
for _, name := range priority {
248+
for _, name := range list {
247249
driver, err := getBuiltinDriver(name, config.Root, config.DriverOptions, config.UIDMaps, config.GIDMaps)
248250
if err != nil {
249251
if isDriverNotSupported(err) {

daemon/graphdriver/driver_freebsd.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ import (
77
)
88

99
var (
10-
// Slice of drivers that should be used in an order
11-
priority = []string{
12-
"zfs",
13-
}
10+
// List of drivers that should be used in an order
11+
priority = "zfs"
1412
)
1513

1614
// Mounted checks if the given path is mounted as the fs type

daemon/graphdriver/driver_linux.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,8 @@ const (
5151
)
5252

5353
var (
54-
// Slice of drivers that should be used in an order
55-
priority = []string{
56-
"btrfs",
57-
"zfs",
58-
"overlay2",
59-
"aufs",
60-
"overlay",
61-
"devicemapper",
62-
"vfs",
63-
}
54+
// List of drivers that should be used in an order
55+
priority = "btrfs,zfs,overlay2,aufs,overlay,devicemapper,vfs"
6456

6557
// FsNames maps filesystem id to name of the filesystem.
6658
FsNames = map[FsMagic]string{

daemon/graphdriver/driver_unsupported.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
package graphdriver
44

55
var (
6-
// Slice of drivers that should be used in an order
7-
priority = []string{
8-
"unsupported",
9-
}
6+
// List of drivers that should be used in an order
7+
priority = "unsupported"
108
)
119

1210
// GetFSMagic returns the filesystem id given the path.

daemon/graphdriver/driver_windows.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package graphdriver
22

33
var (
4-
// Slice of drivers that should be used in order
5-
priority = []string{
6-
"windowsfilter",
7-
}
4+
// List of drivers that should be used in order
5+
priority = "windowsfilter"
86
)
97

108
// GetFSMagic returns the filesystem id given the path.

hack/make/.binary

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ go build \
5757
-ldflags "
5858
$LDFLAGS
5959
$LDFLAGS_STATIC_DOCKER
60+
$DOCKER_LDFLAGS
6061
" \
6162
$GO_PACKAGE
6263
)

0 commit comments

Comments
 (0)