From d011c4127f07f7cb621719e073ca824784d94c9c Mon Sep 17 00:00:00 2001 From: John Howard Date: Fri, 8 Sep 2017 13:35:01 -0700 Subject: [PATCH] LCOW: Add GCS debugging Signed-off-by: John Howard Upstream-commit: 5a0e2beac330d49c2b7436bf29e87d52dab4f557 Component: engine --- .../engine/libcontainerd/client_windows.go | 5 +++++ .../engine/libcontainerd/container_windows.go | 5 +++++ .../engine/libcontainerd/utils_windows.go | 19 ++++++++++++++++++- 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/components/engine/libcontainerd/client_windows.go b/components/engine/libcontainerd/client_windows.go index 67ebb5998d..a721b4a8cc 100644 --- a/components/engine/libcontainerd/client_windows.go +++ b/components/engine/libcontainerd/client_windows.go @@ -439,6 +439,11 @@ func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendly if err != nil { return -1, err } + + defer func() { + container.debugGCS() + }() + // Note we always tell HCS to // create stdout as it's required regardless of '-i' or '-t' options, so that // docker can always grab the output through logs. We also tell HCS to always diff --git a/components/engine/libcontainerd/container_windows.go b/components/engine/libcontainerd/container_windows.go index 06f9c82209..5eeb4736f6 100644 --- a/components/engine/libcontainerd/container_windows.go +++ b/components/engine/libcontainerd/container_windows.go @@ -50,6 +50,7 @@ func (ctr *container) start(attachStdio StdioCallback) error { logrus.Debugln("libcontainerd: starting container ", ctr.containerID) if err = ctr.hcsContainer.Start(); err != nil { logrus.Errorf("libcontainerd: failed to start container: %s", err) + ctr.debugGCS() // Before terminating! if err := ctr.terminate(); err != nil { logrus.Errorf("libcontainerd: failed to cleanup after a failed Start. %s", err) } else { @@ -58,6 +59,10 @@ func (ctr *container) start(attachStdio StdioCallback) error { return err } + defer func() { + ctr.debugGCS() + }() + // Note we always tell HCS to // create stdout as it's required regardless of '-i' or '-t' options, so that // docker can always grab the output through logs. We also tell HCS to always diff --git a/components/engine/libcontainerd/utils_windows.go b/components/engine/libcontainerd/utils_windows.go index aa2fe422a6..fc2869b6b4 100644 --- a/components/engine/libcontainerd/utils_windows.go +++ b/components/engine/libcontainerd/utils_windows.go @@ -1,6 +1,10 @@ package libcontainerd -import "strings" +import ( + "strings" + + opengcs "github.com/Microsoft/opengcs/client" +) // setupEnvironmentVariables converts 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 +23,16 @@ func setupEnvironmentVariables(a []string) map[string]string { func (s *LCOWOption) Apply(interface{}) error { return nil } + +// DebugGCS is a dirty hack for debugging for Linux Utility VMs. It simply +// runs a bunch of commands inside the UVM, but seriously aides in advanced debugging. +func (c *container) debugGCS() { + if c == nil || c.isWindows || c.hcsContainer == nil { + return + } + cfg := opengcs.Config{ + Uvm: c.hcsContainer, + UvmTimeoutSeconds: 600, + } + cfg.DebugGCS() +}