mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Parse storage-opt in GraphDriver init on Windows
This ensures the storage-opts applies to all operations by the graph drivers, replacing the merging of storage-opts into container storage config at container-creation time, and hence applying storage-opts to non-container operations like `COPY` and `ADD` in the builder. Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
This commit is contained in:
parent
56d378a88f
commit
db7b7f6df9
3 changed files with 27 additions and 26 deletions
|
@ -187,23 +187,6 @@ func (daemon *Daemon) create(opts createOpts) (retC *container.Container, retErr
|
|||
|
||||
ctr.HostConfig.StorageOpt = opts.params.HostConfig.StorageOpt
|
||||
|
||||
// Fixes: https://github.com/moby/moby/issues/34074 and
|
||||
// https://github.com/docker/for-win/issues/999.
|
||||
// Merge the daemon's storage options if they aren't already present. We only
|
||||
// do this on Windows as there's no effective sandbox size limit other than
|
||||
// physical on Linux.
|
||||
if isWindows {
|
||||
if ctr.HostConfig.StorageOpt == nil {
|
||||
ctr.HostConfig.StorageOpt = make(map[string]string)
|
||||
}
|
||||
for _, v := range daemon.configStore.GraphOptions {
|
||||
opt := strings.SplitN(v, "=", 2)
|
||||
if _, ok := ctr.HostConfig.StorageOpt[opt[0]]; !ok {
|
||||
ctr.HostConfig.StorageOpt[opt[0]] = opt[1]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Set RWLayer for container after mount labels have been set
|
||||
rwLayer, err := daemon.imageService.CreateLayer(ctr, setupInitLayer(daemon.idMapping))
|
||||
if err != nil {
|
||||
|
|
|
@ -124,6 +124,7 @@ type Driver struct {
|
|||
cachedScratchMutex sync.Mutex // Protects race conditions from multiple threads creating the cached scratch.
|
||||
options []string // Graphdriver options we are initialised with.
|
||||
globalMode bool // Indicates if running in an unsafe/global service VM mode.
|
||||
defaultSandboxSize uint64 // The default sandbox size to use if one is not specified
|
||||
|
||||
// NOTE: It is OK to use a cache here because Windows does not support
|
||||
// restoring containers when the daemon dies.
|
||||
|
@ -164,6 +165,7 @@ func InitDriver(dataRoot string, options []string, _, _ []idtools.IDMap) (graphd
|
|||
svms: make(map[string]*serviceVMMapItem),
|
||||
},
|
||||
globalMode: false,
|
||||
defaultSandboxSize: client.DefaultVhdxSizeGB,
|
||||
}
|
||||
|
||||
// Looks for relevant options
|
||||
|
@ -178,6 +180,16 @@ func InitDriver(dataRoot string, options []string, _, _ []idtools.IDMap) (graphd
|
|||
return nil, fmt.Errorf("%s failed to parse value for 'lcow.globalmode' - must be 'true' or 'false'", title)
|
||||
}
|
||||
break
|
||||
case "lcow.sandboxsize":
|
||||
var err error
|
||||
d.defaultSandboxSize, err = strconv.ParseUint(opt[1], 10, 32)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("%s failed to parse value '%s' for 'lcow.sandboxsize'", title, v)
|
||||
}
|
||||
if d.defaultSandboxSize < client.DefaultVhdxSizeGB {
|
||||
return nil, fmt.Errorf("%s 'lcow.sandboxsize' option cannot be less than %d", title, client.DefaultVhdxSizeGB)
|
||||
}
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -517,7 +529,7 @@ func (d *Driver) CreateReadWrite(id, parent string, opts *graphdriver.CreateOpts
|
|||
}
|
||||
|
||||
// Look for an explicit sandbox size option.
|
||||
sandboxSize := uint64(client.DefaultVhdxSizeGB)
|
||||
sandboxSize := d.defaultSandboxSize
|
||||
for k, v := range opts.StorageOpt {
|
||||
switch strings.ToLower(k) {
|
||||
case "lcow.sandboxsize":
|
||||
|
|
|
@ -112,9 +112,17 @@ func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap)
|
|||
return nil, fmt.Errorf("windowsfilter failed to create '%s': %v", home, err)
|
||||
}
|
||||
|
||||
size, err := units.RAMInBytes(defaultSandboxSize)
|
||||
storageOpt := make(map[string]string)
|
||||
storageOpt["size"] = defaultSandboxSize
|
||||
|
||||
for _, v := range options {
|
||||
opt := strings.SplitN(v, "=", 2)
|
||||
storageOpt[strings.ToLower(opt[0])] = opt[1]
|
||||
}
|
||||
|
||||
storageOptions, err := parseStorageOpt(storageOpt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("windowsfilter failed to parse default size '%s': %v", defaultSandboxSize, err)
|
||||
return nil, fmt.Errorf("windowsfilter failed to parse default storage options - %s", err)
|
||||
}
|
||||
|
||||
d := &Driver{
|
||||
|
@ -124,9 +132,7 @@ func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap)
|
|||
},
|
||||
cache: make(map[string]string),
|
||||
ctr: graphdriver.NewRefCounter(&checker{}),
|
||||
defaultStorageOpts: &storageOptions{
|
||||
size: uint64(size),
|
||||
},
|
||||
defaultStorageOpts: storageOptions,
|
||||
}
|
||||
return d, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue