1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Vendor github.com/jhowardmsft/opengcs v0.0.7

Signed-off-by: John Howard <jhoward@microsoft.com>
This commit is contained in:
John Howard 2017-06-26 21:22:50 -07:00
parent 8f3c526e78
commit 3f14e25a7f
5 changed files with 34 additions and 33 deletions

View file

@ -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.4 github.com/jhowardmsft/opengcs v0.0.7
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

View file

@ -52,19 +52,20 @@ const (
// //
// VHD is the priority. // VHD is the priority.
type Config struct { type Config struct {
KirdPath string // Path to where kernel/initrd are found (defaults to c:\program files\lcow) 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 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 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 Vhdx string // VHD for booting the utility VM - is a full path
Name string // Name of the utility VM Name string // Name of the utility VM
RequestedMode Mode // What mode is preferred when validating RequestedMode Mode // What mode is preferred when validating
ActualMode Mode // What mode was obtained during validation ActualMode Mode // What mode was obtained during validation
UvmTimeoutSeconds int // How long to wait for the utility VM to respond in seconds UvmTimeoutSeconds int // How long to wait for the utility VM to respond in seconds
Uvm hcsshim.Container // The actual container Uvm hcsshim.Container // The actual container
MappedVirtualDisks []hcsshim.MappedVirtualDisk // Data-disks to be attached
} }
// GenerateDefault generates a default config from a set of options // 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 { func (config *Config) GenerateDefault(options []string) error {
if config.UvmTimeoutSeconds < 0 { if config.UvmTimeoutSeconds < 0 {
return fmt.Errorf("opengcs: cannot generate a config when supplied a negative utility VM timeout") 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 == "" { if config.KirdPath == "" {
config.KirdPath = filepath.Join(os.Getenv("ProgramFiles"), "lcow") config.KirdPath = filepath.Join(os.Getenv("ProgramFiles"), "Linux Containers")
} }
if config.Vhdx == "" { if config.Vhdx == "" {
@ -138,6 +139,8 @@ func (config *Config) GenerateDefault(options []string) error {
} }
} }
config.MappedVirtualDisks = nil
return nil return nil
} }
@ -172,11 +175,6 @@ func (config *Config) validate() error {
return fmt.Errorf("opengcs: configuration is invalid") 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) { 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)) 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 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 return nil
} }
@ -202,6 +211,7 @@ func (config *Config) Create() error {
SystemType: "container", SystemType: "container",
ContainerType: "linux", ContainerType: "linux",
TerminateOnLastHandleClosed: true, TerminateOnLastHandleClosed: true,
MappedVirtualDisks: config.MappedVirtualDisks,
} }
if config.ActualMode == ModeActualVhdx { if config.ActualMode == ModeActualVhdx {

View file

@ -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) logrus.Debugf("opengcs: CreateSandbox: %s size:%dMB cache:%s", destFile, maxSizeInMB, cacheFile)
// Retrieve from cache if the default size and already on disk // Retrieve from cache if the default size and already on disk
if maxSizeInMB == DefaultSandboxSizeMB { if cacheFile != "" && maxSizeInMB == DefaultSandboxSizeMB {
sandboxCacheLock.Lock() 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); err != nil {
@ -61,7 +61,7 @@ func (config *Config) CreateSandbox(destFile string, maxSizeInMB uint32, cacheFi
} }
// Populate the cache // Populate the cache
if maxSizeInMB == DefaultSandboxSizeMB { if cacheFile != "" && maxSizeInMB == DefaultSandboxSizeMB {
sandboxCacheLock.Lock() 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) {

View file

@ -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. // 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 // 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("output of tar2vhd to %s", targetVHDFile))

View file

@ -41,20 +41,9 @@ func copyWithTimeout(dst io.Writer, src io.Reader, size int64, timeoutSeconds in
done := make(chan resultType, 1) done := make(chan resultType, 1)
go func() { 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{} result := resultType{}
var copied int64 result.bytes, result.err = io.Copy(dst, src)
for { done <- result
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)
}
}() }()
var result resultType var result resultType