Explorar o código

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>
Paul "TBBle" Hampson %!s(int64=4) %!d(string=hai) anos
pai
achega
db7b7f6df9
Modificáronse 3 ficheiros con 27 adicións e 26 borrados
  1. 0 17
      daemon/create.go
  2. 14 2
      daemon/graphdriver/lcow/lcow.go
  3. 13 7
      daemon/graphdriver/windows/windows.go

+ 0 - 17
daemon/create.go

@@ -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 {

+ 14 - 2
daemon/graphdriver/lcow/lcow.go

@@ -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.
@@ -163,7 +164,8 @@ func InitDriver(dataRoot string, options []string, _, _ []idtools.IDMap) (graphd
 		serviceVms: &serviceVMMap{
 			svms: make(map[string]*serviceVMMapItem),
 		},
-		globalMode: false,
+		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":

+ 13 - 7
daemon/graphdriver/windows/windows.go

@@ -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{
@@ -122,11 +130,9 @@ func InitFilter(home string, options []string, uidMaps, gidMaps []idtools.IDMap)
 			HomeDir: home,
 			Flavour: filterDriver,
 		},
-		cache: make(map[string]string),
-		ctr:   graphdriver.NewRefCounter(&checker{}),
-		defaultStorageOpts: &storageOptions{
-			size: uint64(size),
-		},
+		cache:              make(map[string]string),
+		ctr:                graphdriver.NewRefCounter(&checker{}),
+		defaultStorageOpts: storageOptions,
 	}
 	return d, nil
 }