From 7e5ee6d176357fb294d0ca7b9a93373f6cc84bc0 Mon Sep 17 00:00:00 2001 From: Darren Stahl Date: Wed, 8 Jun 2016 12:41:48 -0700 Subject: [PATCH] Windows: Added support for storage-opt size Signed-off-by: Darren Stahl --- daemon/graphdriver/windows/windows.go | 46 ++++++++++++++++++++++++--- daemon/oci_windows.go | 1 - docs/reference/commandline/create.md | 2 +- docs/reference/commandline/run.md | 2 +- libcontainerd/client_windows.go | 3 -- 5 files changed, 44 insertions(+), 10 deletions(-) diff --git a/daemon/graphdriver/windows/windows.go b/daemon/graphdriver/windows/windows.go index 65af035047..eaa9ff5a77 100644 --- a/daemon/graphdriver/windows/windows.go +++ b/daemon/graphdriver/windows/windows.go @@ -32,12 +32,19 @@ import ( "github.com/docker/docker/pkg/longpath" "github.com/docker/docker/pkg/reexec" "github.com/docker/docker/pkg/system" + "github.com/docker/go-units" "github.com/vbatts/tar-split/tar/storage" ) // filterDriver is an HCSShim driver type for the Windows Filter driver. const filterDriver = 1 +var ( + vmcomputedll = syscall.NewLazyDLL("vmcompute.dll") + hcsExpandSandboxSize = vmcomputedll.NewProc("ExpandSandboxSize") + hcsSandboxSizeSupported = hcsExpandSandboxSize.Find() == nil +) + // init registers the windows graph drivers to the register. func init() { graphdriver.Register("windowsfilter", InitFilter) @@ -118,10 +125,6 @@ func (d *Driver) Create(id, parent, mountLabel string, storageOpt map[string]str } func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt map[string]string) error { - if len(storageOpt) != 0 { - return fmt.Errorf("--storage-opt is not supported for windows") - } - rPId, err := d.resolveID(parent) if err != nil { return err @@ -184,6 +187,17 @@ func (d *Driver) create(id, parent, mountLabel string, readOnly bool, storageOpt if err := hcsshim.CreateSandboxLayer(d.info, id, parentPath, layerChain); err != nil { return err } + + storageOptions, err := parseStorageOpt(storageOpt) + if err != nil { + return fmt.Errorf("Failed to parse storage options - %s", err) + } + + if hcsSandboxSizeSupported { + if err := hcsshim.ExpandSandboxSize(d.info, id, storageOptions.size); err != nil { + return err + } + } } if _, err := os.Lstat(d.dir(parent)); err != nil { @@ -851,3 +865,27 @@ func (d *Driver) DiffGetter(id string) (graphdriver.FileGetCloser, error) { return &fileGetCloserWithBackupPrivileges{d.dir(id)}, nil } + +type storageOptions struct { + size uint64 +} + +func parseStorageOpt(storageOpt map[string]string) (*storageOptions, error) { + options := storageOptions{} + + // Read size to change the block device size per container. + for key, val := range storageOpt { + key := strings.ToLower(key) + switch key { + case "size": + size, err := units.RAMInBytes(val) + if err != nil { + return nil, err + } + options.size = uint64(size) + default: + return nil, fmt.Errorf("Unknown storage option: %s", key) + } + } + return &options, nil +} diff --git a/daemon/oci_windows.go b/daemon/oci_windows.go index 571f273917..f1e44adb86 100644 --- a/daemon/oci_windows.go +++ b/daemon/oci_windows.go @@ -185,7 +185,6 @@ func (daemon *Daemon) createSpec(c *container.Container) (*libcontainerd.Spec, e Storage: &windowsoci.Storage{ Bps: &c.HostConfig.IOMaximumBandwidth, Iops: &c.HostConfig.IOMaximumIOps, - //TODO SandboxSize: ..., }, } return (*libcontainerd.Spec)(&s), nil diff --git a/docs/reference/commandline/create.md b/docs/reference/commandline/create.md index fb84d38794..41504fe0e8 100644 --- a/docs/reference/commandline/create.md +++ b/docs/reference/commandline/create.md @@ -155,7 +155,7 @@ Set storage driver options per container. This (size) will allow to set the container rootfs size to 120G at creation time. User cannot pass a size less than the Default BaseFS Size. This option is only -available for the `devicemapper`, `btrfs`, and `zfs` graph drivers. +available for the `devicemapper`, `btrfs`, `windowsfilter`, and `zfs` graph drivers. ### Specify isolation technology for container (--isolation) diff --git a/docs/reference/commandline/run.md b/docs/reference/commandline/run.md index ad009aa872..69746279f2 100644 --- a/docs/reference/commandline/run.md +++ b/docs/reference/commandline/run.md @@ -187,7 +187,7 @@ The `-w` lets the command being executed inside directory given, here This (size) will allow to set the container rootfs size to 120G at creation time. User cannot pass a size less than the Default BaseFS Size. This option is only -available for the `devicemapper`, `btrfs`, and `zfs` graph drivers. +available for the `devicemapper`, `btrfs`, `windowsfilter`, and `zfs` graph drivers. ### Mount tmpfs (--tmpfs) diff --git a/libcontainerd/client_windows.go b/libcontainerd/client_windows.go index 78b3b992f1..b3ad28deae 100644 --- a/libcontainerd/client_windows.go +++ b/libcontainerd/client_windows.go @@ -74,9 +74,6 @@ func (clnt *client) Create(containerID string, spec Spec, options ...CreateOptio if spec.Windows.Resources.Storage.Iops != nil { configuration.StorageIOPSMaximum = *spec.Windows.Resources.Storage.Iops } - if spec.Windows.Resources.Storage.SandboxSize != nil { - configuration.StorageSandboxSize = *spec.Windows.Resources.Storage.SandboxSize - } } }