From 8e3432225357128fc135c8c3cf0318bd944c0c3b Mon Sep 17 00:00:00 2001 From: John Starks Date: Fri, 24 Jun 2016 15:24:06 -0700 Subject: [PATCH] Windows: Disable VM cloning for TP5 image The Windows TP5 image is not compatible with the Hyper-V isolated container clone feature. Detect old images and pass a flag specifying that clone should not be enabled. Signed-off-by: John Starks --- libcontainerd/client_windows.go | 7 +++++++ libcontainerd/process_windows.go | 9 +-------- libcontainerd/utils_windows.go | 18 +++++++++++++++++- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/libcontainerd/client_windows.go b/libcontainerd/client_windows.go index 484f465228..04ed4d85d1 100644 --- a/libcontainerd/client_windows.go +++ b/libcontainerd/client_windows.go @@ -85,6 +85,13 @@ func (clnt *client) Create(containerID string, spec Spec, options ...CreateOptio configuration.HvRuntime = &hcsshim.HvRuntime{ ImagePath: spec.Windows.HvRuntime.ImagePath, } + + // Images with build verison < 14350 don't support running with clone, but + // Windows cannot automatically detect this. Explicitly block cloning in this + // case. + if build := buildFromVersion(spec.Platform.OSVersion); build > 0 && build < 14350 { + configuration.HvRuntime.SkipTemplate = true + } } if configuration.HvPartition { diff --git a/libcontainerd/process_windows.go b/libcontainerd/process_windows.go index ad6143e1de..01427246f3 100644 --- a/libcontainerd/process_windows.go +++ b/libcontainerd/process_windows.go @@ -2,8 +2,6 @@ package libcontainerd import ( "io" - "strconv" - "strings" "github.com/Microsoft/hcsshim" ) @@ -38,12 +36,7 @@ func fixStdinBackspaceBehavior(w io.WriteCloser, osversion string, tty bool) io. if !tty { return w } - v := strings.Split(osversion, ".") - if len(v) < 3 { - return w - } - - if build, err := strconv.Atoi(v[2]); err != nil || build >= 14350 { + if build := buildFromVersion(osversion); build == 0 || build >= 14350 { return w } diff --git a/libcontainerd/utils_windows.go b/libcontainerd/utils_windows.go index 76ad61819d..1839dc19a1 100644 --- a/libcontainerd/utils_windows.go +++ b/libcontainerd/utils_windows.go @@ -1,6 +1,9 @@ package libcontainerd -import "strings" +import ( + "strconv" + "strings" +) // setupEnvironmentVariables convert a string array of environment variables // into a map as required by the HCS. Source array is in format [v1=k1] [v2=k2] etc. @@ -19,3 +22,16 @@ func setupEnvironmentVariables(a []string) map[string]string { func (s *ServicingOption) Apply(interface{}) error { return nil } + +// buildFromVersion takes an image version string and returns the Windows build +// number. It returns 0 if the build number is not present. +func buildFromVersion(osver string) int { + v := strings.Split(osver, ".") + if len(v) < 3 { + return 0 + } + if build, err := strconv.Atoi(v[2]); err == nil { + return build + } + return 0 +}