From 3f14e25a7f67e0236dfdcde792ac571ca7874c47 Mon Sep 17 00:00:00 2001 From: John Howard Date: Mon, 26 Jun 2017 21:22:50 -0700 Subject: [PATCH 1/2] Vendor github.com/jhowardmsft/opengcs v0.0.7 Signed-off-by: John Howard --- vendor.conf | 2 +- .../opengcs/gogcs/client/config.go | 42 ++++++++++++------- .../opengcs/gogcs/client/createsandbox.go | 4 +- .../opengcs/gogcs/client/tartovhd.go | 4 +- .../opengcs/gogcs/client/utilities.go | 15 +------ 5 files changed, 34 insertions(+), 33 deletions(-) diff --git a/vendor.conf b/vendor.conf index 387df4aad2..bad511c4d4 100644 --- a/vendor.conf +++ b/vendor.conf @@ -8,7 +8,7 @@ github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git github.com/gorilla/context v1.1 github.com/gorilla/mux v1.1 -github.com/jhowardmsft/opengcs v0.0.4 +github.com/jhowardmsft/opengcs v0.0.7 github.com/kr/pty 5cf931ef8f github.com/mattn/go-shellwords v1.0.3 github.com/tchap/go-patricia v2.2.6 diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go index 830d37bef0..49f3e0b1c5 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go @@ -52,19 +52,20 @@ const ( // // VHD is the priority. type Config struct { - KirdPath string // Path to where kernel/initrd are found (defaults to c:\program files\lcow) - KernelFile string // Kernel for Utility VM (embedded in a UEFI bootloader) - does NOT include full path, just filename - InitrdFile string // Initrd image for Utility VM - does NOT include full path, just filename - Vhdx string // VHD for booting the utility VM - is a full path - Name string // Name of the utility VM - RequestedMode Mode // What mode is preferred when validating - ActualMode Mode // What mode was obtained during validation - UvmTimeoutSeconds int // How long to wait for the utility VM to respond in seconds - Uvm hcsshim.Container // The actual container + KirdPath string // Path to where kernel/initrd are found (defaults to c:\program files\Linux Containers) + KernelFile string // Kernel for Utility VM (embedded in a UEFI bootloader) - does NOT include full path, just filename + InitrdFile string // Initrd image for Utility VM - does NOT include full path, just filename + Vhdx string // VHD for booting the utility VM - is a full path + Name string // Name of the utility VM + RequestedMode Mode // What mode is preferred when validating + ActualMode Mode // What mode was obtained during validation + UvmTimeoutSeconds int // How long to wait for the utility VM to respond in seconds + Uvm hcsshim.Container // The actual container + MappedVirtualDisks []hcsshim.MappedVirtualDisk // Data-disks to be attached } // GenerateDefault generates a default config from a set of options -// If baseDir is not supplied, defaults to $env:ProgramFiles\lcow +// If baseDir is not supplied, defaults to $env:ProgramFiles\Linux Containers func (config *Config) GenerateDefault(options []string) error { if config.UvmTimeoutSeconds < 0 { return fmt.Errorf("opengcs: cannot generate a config when supplied a negative utility VM timeout") @@ -111,7 +112,7 @@ func (config *Config) GenerateDefault(options []string) error { } if config.KirdPath == "" { - config.KirdPath = filepath.Join(os.Getenv("ProgramFiles"), "lcow") + config.KirdPath = filepath.Join(os.Getenv("ProgramFiles"), "Linux Containers") } if config.Vhdx == "" { @@ -138,6 +139,8 @@ func (config *Config) GenerateDefault(options []string) error { } } + config.MappedVirtualDisks = nil + return nil } @@ -172,11 +175,6 @@ func (config *Config) validate() error { return fmt.Errorf("opengcs: configuration is invalid") } - // Move to validation - //if _, err := os.Stat(baseDir); os.IsNotExist(err) { - // return fmt.Errorf("opengcs: cannot create default utility VM configuration as directory '%s' was not found", baseDir) - //} - if _, err := os.Stat(filepath.Join(config.KirdPath, config.KernelFile)); os.IsNotExist(err) { return fmt.Errorf("opengcs: kernel '%s' was not found", filepath.Join(config.KirdPath, config.KernelFile)) } @@ -185,6 +183,17 @@ func (config *Config) validate() error { } config.ActualMode = ModeActualKernelInitrd + + // Ensure all the MappedVirtualDisks exist on the host + for _, mvd := range config.MappedVirtualDisks { + if _, err := os.Stat(mvd.HostPath); err != nil { + return fmt.Errorf("opengcs: MappedVirtualDisk '%s' was not found", mvd.HostPath) + } + if mvd.ContainerPath == "" { + return fmt.Errorf("opengcs: MappedVirtualDisk '%s' has no container path", mvd.HostPath) + } + } + return nil } @@ -202,6 +211,7 @@ func (config *Config) Create() error { SystemType: "container", ContainerType: "linux", TerminateOnLastHandleClosed: true, + MappedVirtualDisks: config.MappedVirtualDisks, } if config.ActualMode == ModeActualVhdx { diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go index 66ab703735..4fd9cc907a 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go @@ -25,7 +25,7 @@ func (config *Config) CreateSandbox(destFile string, maxSizeInMB uint32, cacheFi logrus.Debugf("opengcs: CreateSandbox: %s size:%dMB cache:%s", destFile, maxSizeInMB, cacheFile) // Retrieve from cache if the default size and already on disk - if maxSizeInMB == DefaultSandboxSizeMB { + if cacheFile != "" && maxSizeInMB == DefaultSandboxSizeMB { sandboxCacheLock.Lock() if _, err := os.Stat(cacheFile); err == nil { if err := copyFile(cacheFile, destFile); err != nil { @@ -61,7 +61,7 @@ func (config *Config) CreateSandbox(destFile string, maxSizeInMB uint32, cacheFi } // Populate the cache - if maxSizeInMB == DefaultSandboxSizeMB { + if cacheFile != "" && maxSizeInMB == DefaultSandboxSizeMB { sandboxCacheLock.Lock() // It may already exist due to being created on another thread, in which case no copy back needed. if _, err := os.Stat(cacheFile); os.IsNotExist(err) { diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go index 8832e096e6..f6ce79ecb6 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go @@ -31,7 +31,9 @@ func (config *Config) TarToVhd(targetVHDFile string, reader io.Reader) (int64, e } // Don't need stdin now we've sent everything. This signals GCS that we are finished sending data. - process.Process.CloseStdin() + if err := process.Process.CloseStdin(); err != nil { + return 0, fmt.Errorf("opengcs: TarToVhd: %s: failed closing stdin handle: %s", targetVHDFile, err) + } // Write stdout contents of `tar2vhd` to the VHD file payloadSize, err := writeFileFromReader(targetVHDFile, process.Stdout, config.UvmTimeoutSeconds, fmt.Sprintf("output of tar2vhd to %s", targetVHDFile)) diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go index 427cde7795..4ebd9bb156 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go @@ -41,20 +41,9 @@ func copyWithTimeout(dst io.Writer, src io.Reader, size int64, timeoutSeconds in done := make(chan resultType, 1) go func() { - // TODO @jhowardmsft. Needs platform fix. Improve reliability by - // chunking the data. Ultimately can just use io.Copy instead with no loop result := resultType{} - var copied int64 - for { - copied, result.err = io.CopyN(dst, src, 1024) - result.bytes += copied - if copied == 0 { - done <- result - break - } - // TODO @jhowardmsft - next line is debugging only. Remove - //logrus.Debugf("%s: copied so far %d\n", context, result.bytes) - } + result.bytes, result.err = io.Copy(dst, src) + done <- result }() var result resultType From 2c43cbe0d5132618c74de4631c89c541bbafb8c2 Mon Sep 17 00:00:00 2001 From: John Howard Date: Mon, 26 Jun 2017 21:26:18 -0700 Subject: [PATCH 2/2] LCOW: Change to c:\Program Files\Linux Containers Signed-off-by: John Howard --- libcontainerd/client_windows.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libcontainerd/client_windows.go b/libcontainerd/client_windows.go index d7f312e6e4..ee310f6865 100644 --- a/libcontainerd/client_windows.go +++ b/libcontainerd/client_windows.go @@ -299,7 +299,7 @@ func (clnt *client) createLinux(containerID string, checkpoint string, checkpoin Owner: defaultOwner, TerminateOnLastHandleClosed: true, HvRuntime: &hcsshim.HvRuntime{ - ImagePath: `c:\program files\lcow`, + ImagePath: `c:\Program Files\Linux Containers`, LinuxKernelFile: `bootx64.efi`, LinuxInitrdFile: `initrd.img`, },