mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Revendor jhowardmsft/opengcs v0.0.9
Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
parent
0fcd082d88
commit
7643e89096
11 changed files with 54 additions and 40 deletions
|
@ -8,7 +8,7 @@ github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a
|
||||||
github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
|
github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git
|
||||||
github.com/gorilla/context v1.1
|
github.com/gorilla/context v1.1
|
||||||
github.com/gorilla/mux 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/kr/pty 5cf931ef8f
|
||||||
github.com/mattn/go-shellwords v1.0.3
|
github.com/mattn/go-shellwords v1.0.3
|
||||||
github.com/tchap/go-patricia v2.2.6
|
github.com/tchap/go-patricia v2.2.6
|
||||||
|
|
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go
generated
vendored
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/config.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
19
vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go
generated
vendored
19
vendor/github.com/jhowardmsft/opengcs/gogcs/client/createsandbox.go
generated
vendored
|
@ -2,19 +2,15 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
|
||||||
|
|
||||||
"github.com/Sirupsen/logrus"
|
"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.
|
||||||
|
// It is the responsibility of the caller to synchronise simultaneous attempts to create the cache file.
|
||||||
// CreateSandbox does what it says on the tin. This is done by copying a prebuilt-sandbox from the ServiceVM
|
|
||||||
// TODO: @jhowardmsft maxSizeInMB isn't hooked up in GCS. Needs a platform change which is in flight.
|
// 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 {
|
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.
|
// 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
|
// Retrieve from cache if the default size and already on disk
|
||||||
if cacheFile != "" && maxSizeInMB == DefaultSandboxSizeMB {
|
if cacheFile != "" && maxSizeInMB == DefaultSandboxSizeMB {
|
||||||
sandboxCacheLock.Lock()
|
|
||||||
if _, err := os.Stat(cacheFile); err == nil {
|
if _, err := os.Stat(cacheFile); err == nil {
|
||||||
if err := copyFile(cacheFile, destFile); err != nil {
|
if err := CopyFile(cacheFile, destFile, false); err != nil {
|
||||||
sandboxCacheLock.Unlock()
|
|
||||||
return fmt.Errorf("opengcs: CreateSandbox: Failed to copy cached sandbox '%s' to '%s': %s", cacheFile, destFile, err)
|
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)
|
logrus.Debugf("opengcs: CreateSandbox: %s fulfilled from cache", destFile)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
sandboxCacheLock.Unlock()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Uvm == nil {
|
if config.Uvm == nil {
|
||||||
|
@ -62,15 +54,12 @@ func (config *Config) CreateSandbox(destFile string, maxSizeInMB uint32, cacheFi
|
||||||
|
|
||||||
// Populate the cache
|
// Populate the cache
|
||||||
if cacheFile != "" && 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.
|
// 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 := os.Stat(cacheFile); os.IsNotExist(err) {
|
||||||
if err := copyFile(destFile, cacheFile); err != nil {
|
if err := CopyFile(destFile, cacheFile, false); err != nil {
|
||||||
sandboxCacheLock.Unlock()
|
|
||||||
return fmt.Errorf("opengcs: CreateSandbox: Failed to seed sandbox cache '%s' from '%s': %s", destFile, cacheFile, err)
|
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)
|
logrus.Debugf("opengcs: CreateSandbox: %s created (non-cache)", destFile)
|
||||||
|
|
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotaddvhd.go
generated
vendored
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotaddvhd.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
|
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotremovevhd.go
generated
vendored
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/hotremovevhd.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
|
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/layervhddetails.go
generated
vendored
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/layervhddetails.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
43
vendor/github.com/jhowardmsft/opengcs/gogcs/client/process.go
generated
vendored
43
vendor/github.com/jhowardmsft/opengcs/gogcs/client/process.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -59,3 +57,44 @@ func (config *Config) createUtilsProcess(commandLine string) (process, error) {
|
||||||
logrus.Debugf("opengcs: createUtilsProcess success: pid %d", proc.Process.Pid())
|
logrus.Debugf("opengcs: createUtilsProcess success: pid %d", proc.Process.Pid())
|
||||||
return proc, nil
|
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
|
||||||
|
}
|
||||||
|
|
6
vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go
generated
vendored
6
vendor/github.com/jhowardmsft/opengcs/gogcs/client/tartovhd.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -26,7 +24,7 @@ func (config *Config) TarToVhd(targetVHDFile string, reader io.Reader) (int64, e
|
||||||
defer process.Process.Close()
|
defer process.Process.Close()
|
||||||
|
|
||||||
// Send the tarstream into the `tar2vhd`s stdin
|
// 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)
|
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
|
// 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 {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("opengcs: TarToVhd: %s: failed writing VHD file: %s", targetVHDFile, err)
|
return 0, fmt.Errorf("opengcs: TarToVhd: %s: failed writing VHD file: %s", targetVHDFile, err)
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/unsupported.go
generated
vendored
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/unsupported.go
generated
vendored
|
@ -1,5 +1,3 @@
|
||||||
// +build !windows
|
// +build !windows
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
12
vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go
generated
vendored
12
vendor/github.com/jhowardmsft/opengcs/gogcs/client/utilities.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -72,10 +70,13 @@ func copyWithTimeout(dst io.Writer, src io.Reader, size int64, timeoutSeconds in
|
||||||
return result.bytes, nil
|
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
|
// Uses CopyFileW win32 API for performance
|
||||||
func copyFile(srcFile, destFile string) error {
|
func CopyFile(srcFile, destFile string, overwrite bool) error {
|
||||||
var bFailIfExists uint32 = 1
|
var bFailIfExists uint32 = 1
|
||||||
|
if overwrite {
|
||||||
|
bFailIfExists = 0
|
||||||
|
}
|
||||||
|
|
||||||
lpExistingFileName, err := syscall.UTF16PtrFromString(srcFile)
|
lpExistingFileName, err := syscall.UTF16PtrFromString(srcFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -92,8 +93,7 @@ func copyFile(srcFile, destFile string) error {
|
||||||
uintptr(unsafe.Pointer(lpNewFileName)),
|
uintptr(unsafe.Pointer(lpNewFileName)),
|
||||||
uintptr(bFailIfExists))
|
uintptr(bFailIfExists))
|
||||||
if r1 == 0 {
|
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
|
return nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/vhdtotar.go
generated
vendored
2
vendor/github.com/jhowardmsft/opengcs/gogcs/client/vhdtotar.go
generated
vendored
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package client
|
package client
|
||||||
|
|
||||||
// TODO @jhowardmsft - This will move to Microsoft/opengcs soon
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
|
Loading…
Add table
Reference in a new issue