From 7643e8909675fb7b1d52a8c7566fb674db340a39 Mon Sep 17 00:00:00 2001 From: John Howard Date: Thu, 6 Jul 2017 14:29:43 -0700 Subject: [PATCH] Revendor jhowardmsft/opengcs v0.0.9 Signed-off-by: John Howard --- vendor.conf | 2 +- .../opengcs/gogcs/client/config.go | 2 - .../opengcs/gogcs/client/createsandbox.go | 19 ++------ .../opengcs/gogcs/client/hotaddvhd.go | 2 - .../opengcs/gogcs/client/hotremovevhd.go | 2 - .../opengcs/gogcs/client/layervhddetails.go | 2 - .../opengcs/gogcs/client/process.go | 43 ++++++++++++++++++- .../opengcs/gogcs/client/tartovhd.go | 6 +-- .../opengcs/gogcs/client/unsupported.go | 2 - .../opengcs/gogcs/client/utilities.go | 12 +++--- .../opengcs/gogcs/client/vhdtotar.go | 2 - 11 files changed, 54 insertions(+), 40 deletions(-) diff --git a/vendor.conf b/vendor.conf index 20460d5cc9..ece20e6462 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.7 +github.com/jhowardmsft/opengcs v0.0.9 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 49f3e0b1c5..fedb563abe 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "encoding/json" "fmt" diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go index 4fd9cc907a..65971601a1 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go @@ -2,19 +2,15 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" "os" - "sync" "github.com/Sirupsen/logrus" ) -var sandboxCacheLock sync.Mutex - -// CreateSandbox does what it says on the tin. This is done by copying a prebuilt-sandbox from the ServiceVM +// CreateSandbox does what it says on the tin. This is done by copying a prebuilt-sandbox from the ServiceVM. +// It is the responsibility of the caller to synchronise simultaneous attempts to create the cache file. // TODO: @jhowardmsft maxSizeInMB isn't hooked up in GCS. Needs a platform change which is in flight. func (config *Config) CreateSandbox(destFile string, maxSizeInMB uint32, cacheFile string) error { // Smallest we can accept is the default sandbox size as we can't size down, only expand. @@ -26,17 +22,13 @@ func (config *Config) CreateSandbox(destFile string, maxSizeInMB uint32, cacheFi // Retrieve from cache if the default size and already on disk if cacheFile != "" && maxSizeInMB == DefaultSandboxSizeMB { - sandboxCacheLock.Lock() if _, err := os.Stat(cacheFile); err == nil { - if err := copyFile(cacheFile, destFile); err != nil { - sandboxCacheLock.Unlock() + if err := CopyFile(cacheFile, destFile, false); err != nil { return fmt.Errorf("opengcs: CreateSandbox: Failed to copy cached sandbox '%s' to '%s': %s", cacheFile, destFile, err) } - sandboxCacheLock.Unlock() logrus.Debugf("opengcs: CreateSandbox: %s fulfilled from cache", destFile) return nil } - sandboxCacheLock.Unlock() } if config.Uvm == nil { @@ -62,15 +54,12 @@ func (config *Config) CreateSandbox(destFile string, maxSizeInMB uint32, cacheFi // Populate the cache 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) { - if err := copyFile(destFile, cacheFile); err != nil { - sandboxCacheLock.Unlock() + if err := CopyFile(destFile, cacheFile, false); err != nil { return fmt.Errorf("opengcs: CreateSandbox: Failed to seed sandbox cache '%s' from '%s': %s", destFile, cacheFile, err) } } - sandboxCacheLock.Unlock() } logrus.Debugf("opengcs: CreateSandbox: %s created (non-cache)", destFile) diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotaddvhd.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotaddvhd.go index 62de79016a..c0545925f7 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotaddvhd.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotaddvhd.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotremovevhd.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotremovevhd.go index 71167d00ee..1f3d21aa81 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotremovevhd.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotremovevhd.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/layervhddetails.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/layervhddetails.go index 6ce29cdc56..010780069a 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/layervhddetails.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/layervhddetails.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" "os" diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/process.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/process.go index 6592ab6a03..02655227a9 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/process.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/process.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" "io" @@ -59,3 +57,44 @@ func (config *Config) createUtilsProcess(commandLine string) (process, error) { logrus.Debugf("opengcs: createUtilsProcess success: pid %d", proc.Process.Pid()) return proc, nil } + +// RunProcess runs the given command line program in the utilityVM. It takes in +// an input to the reader to feed into stdin and returns stdout to output. +func (config *Config) RunProcess(commandLine string, input io.Reader, output io.Writer) error { + logrus.Debugf("opengcs: RunProcess: %s", commandLine) + process, err := config.createUtilsProcess(commandLine) + if err != nil { + return err + } + defer process.Process.Close() + + // Send the data into the process's stdin + if input != nil { + if _, err = copyWithTimeout(process.Stdin, + input, + 0, + config.UvmTimeoutSeconds, + fmt.Sprintf("send to stdin of %s", commandLine)); err != nil { + return err + } + + // Don't need stdin now we've sent everything. This signals GCS that we are finished sending data. + if err := process.Process.CloseStdin(); err != nil { + return err + } + } + + if output != nil { + // Copy the data over to the writer. + if _, err := copyWithTimeout(output, + process.Stdout, + 0, + config.UvmTimeoutSeconds, + fmt.Sprintf("RunProcess: copy back from %s", commandLine)); err != nil { + return err + } + } + + logrus.Debugf("opengcs: runProcess success: %s", commandLine) + return nil +} diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go index f6ce79ecb6..3560245b49 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" "io" @@ -26,7 +24,7 @@ func (config *Config) TarToVhd(targetVHDFile string, reader io.Reader) (int64, e defer process.Process.Close() // Send the tarstream into the `tar2vhd`s stdin - if _, err = copyWithTimeout(process.Stdin, reader, 0, config.UvmTimeoutSeconds, fmt.Sprintf("send %s, to stdin of tar2vhd", targetVHDFile)); err != nil { + if _, err = copyWithTimeout(process.Stdin, reader, 0, config.UvmTimeoutSeconds, fmt.Sprintf("stdin of tar2vhd for generating %s", targetVHDFile)); err != nil { return 0, fmt.Errorf("opengcs: TarToVhd: %s: failed to send to tar2vhd in uvm: %s", targetVHDFile, err) } @@ -36,7 +34,7 @@ func (config *Config) TarToVhd(targetVHDFile string, reader io.Reader) (int64, e } // 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)) + payloadSize, err := writeFileFromReader(targetVHDFile, process.Stdout, config.UvmTimeoutSeconds, fmt.Sprintf("stdout of tar2vhd to %s", targetVHDFile)) if err != nil { return 0, fmt.Errorf("opengcs: TarToVhd: %s: failed writing VHD file: %s", targetVHDFile, err) } diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/unsupported.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/unsupported.go index 4a7abab3b0..63b7067dce 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/unsupported.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/unsupported.go @@ -1,5 +1,3 @@ // +build !windows package client - -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go index 4ebd9bb156..8976dc0af9 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" "io" @@ -72,10 +70,13 @@ func copyWithTimeout(dst io.Writer, src io.Reader, size int64, timeoutSeconds in return result.bytes, nil } -// copyFile is a utility for copying a file - used for the sandbox cache. +// CopyFile is a utility for copying a file - used for the sandbox cache. // Uses CopyFileW win32 API for performance -func copyFile(srcFile, destFile string) error { +func CopyFile(srcFile, destFile string, overwrite bool) error { var bFailIfExists uint32 = 1 + if overwrite { + bFailIfExists = 0 + } lpExistingFileName, err := syscall.UTF16PtrFromString(srcFile) if err != nil { @@ -92,8 +93,7 @@ func copyFile(srcFile, destFile string) error { uintptr(unsafe.Pointer(lpNewFileName)), uintptr(bFailIfExists)) if r1 == 0 { - return fmt.Errorf("failed CopyFileW Win32 call from '%s' to %s: %s", srcFile, destFile, err) + return fmt.Errorf("failed CopyFileW Win32 call from '%s' to '%s': %s", srcFile, destFile, err) } return nil - } diff --git a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/vhdtotar.go b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/vhdtotar.go index 9504fb7c84..bdbd381929 100644 --- a/vendor/github.com/jhowardmsft/opengcs/gogcs/client/vhdtotar.go +++ b/vendor/github.com/jhowardmsft/opengcs/gogcs/client/vhdtotar.go @@ -2,8 +2,6 @@ package client -// TODO @jhowardmsft - This will move to Microsoft/opengcs soon - import ( "fmt" "io"