Signed-off-by: John Howard <jhoward@microsoft.com>
| ... | ... |
@@ -440,9 +440,7 @@ func (clnt *client) AddProcess(ctx context.Context, containerID, processFriendly |
| 440 | 440 |
return -1, err |
| 441 | 441 |
} |
| 442 | 442 |
|
| 443 |
- defer func() {
|
|
| 444 |
- container.debugGCS() |
|
| 445 |
- }() |
|
| 443 |
+ defer container.debugGCS() |
|
| 446 | 444 |
|
| 447 | 445 |
// Note we always tell HCS to |
| 448 | 446 |
// create stdout as it's required regardless of '-i' or '-t' options, so that |
| ... | ... |
@@ -59,9 +59,7 @@ func (ctr *container) start(attachStdio StdioCallback) error {
|
| 59 | 59 |
return err |
| 60 | 60 |
} |
| 61 | 61 |
|
| 62 |
- defer func() {
|
|
| 63 |
- ctr.debugGCS() |
|
| 64 |
- }() |
|
| 62 |
+ defer ctr.debugGCS() |
|
| 65 | 63 |
|
| 66 | 64 |
// Note we always tell HCS to |
| 67 | 65 |
// create stdout as it's required regardless of '-i' or '-t' options, so that |
| ... | ... |
@@ -24,7 +24,7 @@ func (s *LCOWOption) Apply(interface{}) error {
|
| 24 | 24 |
return nil |
| 25 | 25 |
} |
| 26 | 26 |
|
| 27 |
-// DebugGCS is a dirty hack for debugging for Linux Utility VMs. It simply |
|
| 27 |
+// debugGCS is a dirty hack for debugging for Linux Utility VMs. It simply |
|
| 28 | 28 |
// runs a bunch of commands inside the UVM, but seriously aides in advanced debugging. |
| 29 | 29 |
func (c *container) debugGCS() {
|
| 30 | 30 |
if c == nil || c.isWindows || c.hcsContainer == nil {
|
| ... | ... |
@@ -8,7 +8,7 @@ github.com/docker/libtrust 9cbd2a1374f46905c68a4eb3694a130610adc62a |
| 8 | 8 |
github.com/go-check/check 4ed411733c5785b40214c70bce814c3a3a689609 https://github.com/cpuguy83/check.git |
| 9 | 9 |
github.com/gorilla/context v1.1 |
| 10 | 10 |
github.com/gorilla/mux v1.1 |
| 11 |
-github.com/Microsoft/opengcs v0.3.3 |
|
| 11 |
+github.com/Microsoft/opengcs v0.3.4 |
|
| 12 | 12 |
github.com/kr/pty 5cf931ef8f |
| 13 | 13 |
github.com/mattn/go-shellwords v1.0.3 |
| 14 | 14 |
github.com/sirupsen/logrus v1.0.1 |
| ... | ... |
@@ -57,6 +57,8 @@ func (config *Config) CreateExt4Vhdx(destFile string, sizeGB uint32, cacheFile s |
| 57 | 57 |
return fmt.Errorf("failed to create VHDx %s: %s", destFile, err)
|
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 |
+ defer config.DebugGCS() |
|
| 61 |
+ |
|
| 60 | 62 |
// Attach it to the utility VM, but don't mount it (as there's no filesystem on it) |
| 61 | 63 |
if err := config.HotAddVhd(destFile, "", false, false); err != nil {
|
| 62 | 64 |
return fmt.Errorf("opengcs: CreateExt4Vhdx: failed to hot-add %s to utility VM: %s", cacheFile, err)
|
| ... | ... |
@@ -20,6 +20,8 @@ func (config *Config) HotAddVhd(hostPath string, containerPath string, readOnly |
| 20 | 20 |
return fmt.Errorf("cannot hot-add VHD as no utility VM is in configuration")
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 |
+ defer config.DebugGCS() |
|
| 24 |
+ |
|
| 23 | 25 |
modification := &hcsshim.ResourceModificationRequestResponse{
|
| 24 | 26 |
Resource: "MappedVirtualDisk", |
| 25 | 27 |
Data: hcsshim.MappedVirtualDisk{
|
| ... | ... |
@@ -18,6 +18,8 @@ func (config *Config) HotRemoveVhd(hostPath string) error {
|
| 18 | 18 |
return fmt.Errorf("cannot hot-add VHD as no utility VM is in configuration")
|
| 19 | 19 |
} |
| 20 | 20 |
|
| 21 |
+ defer config.DebugGCS() |
|
| 22 |
+ |
|
| 21 | 23 |
modification := &hcsshim.ResourceModificationRequestResponse{
|
| 22 | 24 |
Resource: "MappedVirtualDisk", |
| 23 | 25 |
Data: hcsshim.MappedVirtualDisk{
|
| ... | ... |
@@ -3,8 +3,12 @@ |
| 3 | 3 |
package client |
| 4 | 4 |
|
| 5 | 5 |
import ( |
| 6 |
+ "bytes" |
|
| 6 | 7 |
"fmt" |
| 7 | 8 |
"io" |
| 9 |
+ "os" |
|
| 10 |
+ "strings" |
|
| 11 |
+ "time" |
|
| 8 | 12 |
|
| 9 | 13 |
"github.com/Microsoft/hcsshim" |
| 10 | 14 |
"github.com/sirupsen/logrus" |
| ... | ... |
@@ -110,3 +114,44 @@ func (config *Config) RunProcess(commandLine string, stdin io.Reader, stdout io. |
| 110 | 110 |
logrus.Debugf("opengcs: runProcess success: %s", commandLine)
|
| 111 | 111 |
return process.Process, nil |
| 112 | 112 |
} |
| 113 |
+ |
|
| 114 |
+func debugCommand(s string) string {
|
|
| 115 |
+ return fmt.Sprintf(`echo -e 'DEBUG COMMAND: %s\\n--------------\\n';%s;echo -e '\\n\\n';`, s, s) |
|
| 116 |
+} |
|
| 117 |
+ |
|
| 118 |
+// DebugGCS extracts logs from the GCS. It's a useful hack for debugging, |
|
| 119 |
+// but not necessarily optimal, but all that is available to us in RS3. |
|
| 120 |
+func (config *Config) DebugGCS() {
|
|
| 121 |
+ if logrus.GetLevel() < logrus.DebugLevel || len(os.Getenv("OPENGCS_DEBUG_ENABLE")) == 0 {
|
|
| 122 |
+ return |
|
| 123 |
+ } |
|
| 124 |
+ |
|
| 125 |
+ var out bytes.Buffer |
|
| 126 |
+ cmd := os.Getenv("OPENGCS_DEBUG_COMMAND")
|
|
| 127 |
+ if cmd == "" {
|
|
| 128 |
+ cmd = `sh -c "` |
|
| 129 |
+ cmd += debugCommand("ls -l /tmp")
|
|
| 130 |
+ cmd += debugCommand("cat /tmp/gcs.log")
|
|
| 131 |
+ cmd += debugCommand("ls -l /tmp/gcs")
|
|
| 132 |
+ cmd += debugCommand("ls -l /tmp/gcs/*")
|
|
| 133 |
+ cmd += debugCommand("cat /tmp/gcs/*/config.json")
|
|
| 134 |
+ cmd += debugCommand("ls -lR /var/run/gcsrunc")
|
|
| 135 |
+ cmd += debugCommand("cat /var/run/gcsrunc/log.log")
|
|
| 136 |
+ cmd += debugCommand("ps -ef")
|
|
| 137 |
+ cmd += `"` |
|
| 138 |
+ } |
|
| 139 |
+ proc, err := config.RunProcess(cmd, nil, &out, nil) |
|
| 140 |
+ defer func() {
|
|
| 141 |
+ if proc != nil {
|
|
| 142 |
+ proc.Kill() |
|
| 143 |
+ proc.Close() |
|
| 144 |
+ } |
|
| 145 |
+ }() |
|
| 146 |
+ if err != nil {
|
|
| 147 |
+ logrus.Debugln("benign failure getting gcs logs: ", err)
|
|
| 148 |
+ } |
|
| 149 |
+ if proc != nil {
|
|
| 150 |
+ proc.WaitTimeout(time.Duration(int(time.Second) * 30)) |
|
| 151 |
+ } |
|
| 152 |
+ logrus.Debugf("GCS Debugging:\n%s\n\nEnd GCS Debugging\n", strings.TrimSpace(out.String()))
|
|
| 153 |
+} |
| ... | ... |
@@ -17,6 +17,8 @@ func (config *Config) TarToVhd(targetVHDFile string, reader io.Reader) (int64, e |
| 17 | 17 |
return 0, fmt.Errorf("cannot Tar2Vhd as no utility VM is in configuration")
|
| 18 | 18 |
} |
| 19 | 19 |
|
| 20 |
+ defer config.DebugGCS() |
|
| 21 |
+ |
|
| 20 | 22 |
process, err := config.createUtilsProcess("tar2vhd")
|
| 21 | 23 |
if err != nil {
|
| 22 | 24 |
return 0, fmt.Errorf("failed to start tar2vhd for %s: %s", targetVHDFile, err)
|
| ... | ... |
@@ -20,6 +20,8 @@ func (config *Config) VhdToTar(vhdFile string, uvmMountPath string, isSandbox bo |
| 20 | 20 |
return nil, fmt.Errorf("cannot VhdToTar as no utility VM is in configuration")
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 |
+ defer config.DebugGCS() |
|
| 24 |
+ |
|
| 23 | 25 |
vhdHandle, err := os.Open(vhdFile) |
| 24 | 26 |
if err != nil {
|
| 25 | 27 |
return nil, fmt.Errorf("opengcs: VhdToTar: failed to open %s: %s", vhdFile, err)
|