From 820e74b62ba4b59c63e74eb2aec1082a043f1cd6 Mon Sep 17 00:00:00 2001 From: Damien Lespiau Date: Thu, 19 Jan 2017 16:01:38 +0000 Subject: [PATCH] vendor: Revendor virtcontainers to 0.2.3 to fix a potential panic Let's vendor virtcontainers 0.2.3, it's a good version if we want to minimize the changes while grabbing a fix for a panic that happens if the shim disappears underneath us. It's debatable if we should jump straight away to 0.3.0. That version would also need us to re-vender the runv package. It will have to happen, eventually, but we can control when. An benefit of going slowly on the updates is that we can revert a later vendoring to 0.3.0 if we find out it introduces regressions. Fixes: https://github.com/01org/cc-oci-runtime/issues/463 Signed-off-by: Damien Lespiau --- packages.json | 2 +- .../containers/virtcontainers/README.md | 8 +- .../virtcontainers/hyperstart/hyperstart.go | 116 +++++++++++------- .../hyperstart/mock/hyperstart.go | 77 ++++++------ 4 files changed, 109 insertions(+), 94 deletions(-) diff --git a/packages.json b/packages.json index 38b5bbf9..95afb152 100644 --- a/packages.json +++ b/packages.json @@ -21,7 +21,7 @@ }, "github.com/containers/virtcontainers": { "url": "https://github.com/containers/virtcontainers.git", - "version": "v0.2.1", + "version": "v0.2.3", "license": "Apache 2.0" }, "github.com/stretchr/testify": { diff --git a/vendor/github.com/containers/virtcontainers/README.md b/vendor/github.com/containers/virtcontainers/README.md index 4ab7b152..43af8280 100644 --- a/vendor/github.com/containers/virtcontainers/README.md +++ b/vendor/github.com/containers/virtcontainers/README.md @@ -1,7 +1,7 @@ -[![Build Status](https://travis-ci.org/sameo/virtcontainers.svg?branch=master)](https://travis-ci.org/sameo/virtcontainers) -[![Go Report Card](https://goreportcard.com/badge/github.com/sameo/virtcontainers)](https://goreportcard.com/report/github.com/sameo/virtcontainers) -[![Coverage Status](https://coveralls.io/repos/github/sameo/virtcontainers/badge.svg?branch=sameo%2Ftopic%2Funit)](https://coveralls.io/github/sameo/virtcontainers) -[![GoDoc](https://godoc.org/github.com/sameo/virtcontainers?status.svg)](https://godoc.org/github.com/sameo/virtcontainers) +[![Build Status](https://travis-ci.org/containers/virtcontainers.svg?branch=master)](https://travis-ci.org/containers/virtcontainers) +[![Go Report Card](https://goreportcard.com/badge/github.com/containers/virtcontainers)](https://goreportcard.com/report/github.com/containers/virtcontainers) +[![Coverage Status](https://coveralls.io/repos/github/sameo/virtcontainers/badge.svg?branch=master)](https://coveralls.io/github/sameo/virtcontainers?branch=master) +[![GoDoc](https://godoc.org/github.com/containers/virtcontainers?status.svg)](https://godoc.org/github.com/containers/virtcontainers) # virtcontainers diff --git a/vendor/github.com/containers/virtcontainers/hyperstart/hyperstart.go b/vendor/github.com/containers/virtcontainers/hyperstart/hyperstart.go index 8d0c5180..5933c972 100644 --- a/vendor/github.com/containers/virtcontainers/hyperstart/hyperstart.go +++ b/vendor/github.com/containers/virtcontainers/hyperstart/hyperstart.go @@ -31,51 +31,44 @@ import ( // Control command IDs // Need to be in sync with hyperstart/src/api.h const ( - Version = "version" - StartPod = "startpod" - GetPod = "getpod" - DestroyPod = "destroypod" - RestartContainer = "restartcontainer" - ExecCmd = "execcmd" - FinishCmd = "finishcmd" - Ready = "ready" - Ack = "ack" - Error = "error" - WinSize = "winsize" - Ping = "ping" - FinishPod = "finishpod" - Next = "next" - WriteFile = "writefile" - ReadFile = "readfile" - NewContainer = "newcontainer" - KillContainer = "killcontainer" - OnlineCPUMem = "onlinecpumem" - SetupInterface = "setupinterface" - SetupRoute = "setuproute" + Version = "version" + StartPod = "startpod" + DestroyPod = "destroypod" + ExecCmd = "execcmd" + Ready = "ready" + Ack = "ack" + Error = "error" + WinSize = "winsize" + Ping = "ping" + FinishPod = "finishpod" + Next = "next" + WriteFile = "writefile" + ReadFile = "readfile" + NewContainer = "newcontainer" + KillContainer = "killcontainer" + OnlineCPUMem = "onlinecpumem" + SetupInterface = "setupinterface" + SetupRoute = "setuproute" ) var codeList = map[string]uint32{ - Version: hyper.INIT_VERSION, - StartPod: hyper.INIT_STARTPOD, - GetPod: hyper.INIT_GETPOD, - DestroyPod: hyper.INIT_DESTROYPOD, - RestartContainer: hyper.INIT_RESTARTCONTAINER, - ExecCmd: hyper.INIT_EXECCMD, - FinishCmd: hyper.INIT_FINISHCMD, - Ready: hyper.INIT_READY, - Ack: hyper.INIT_ACK, - Error: hyper.INIT_ERROR, - WinSize: hyper.INIT_WINSIZE, - Ping: hyper.INIT_PING, - FinishPod: hyper.INIT_FINISHPOD, - Next: hyper.INIT_NEXT, - WriteFile: hyper.INIT_WRITEFILE, - ReadFile: hyper.INIT_READFILE, - NewContainer: hyper.INIT_NEWCONTAINER, - KillContainer: hyper.INIT_KILLCONTAINER, - OnlineCPUMem: hyper.INIT_ONLINECPUMEM, - SetupInterface: hyper.INIT_SETUPINTERFACE, - SetupRoute: hyper.INIT_SETUPROUTE, + Version: hyper.INIT_VERSION, + StartPod: hyper.INIT_STARTPOD, + DestroyPod: hyper.INIT_DESTROYPOD, + ExecCmd: hyper.INIT_EXECCMD, + Ready: hyper.INIT_READY, + Ack: hyper.INIT_ACK, + Error: hyper.INIT_ERROR, + WinSize: hyper.INIT_WINSIZE, + Ping: hyper.INIT_PING, + Next: hyper.INIT_NEXT, + WriteFile: hyper.INIT_WRITEFILE, + ReadFile: hyper.INIT_READFILE, + NewContainer: hyper.INIT_NEWCONTAINER, + KillContainer: hyper.INIT_KILLCONTAINER, + OnlineCPUMem: hyper.INIT_ONLINECPUMEM, + SetupInterface: hyper.INIT_SETUPINTERFACE, + SetupRoute: hyper.INIT_SETUPROUTE, } // Values related to the communication on control channel. @@ -90,11 +83,38 @@ const ( ttyHdrLenOffset = 8 ) +type connState struct { + sync.Mutex + opened bool +} + +func (c *connState) close() { + c.Lock() + defer c.Unlock() + + c.opened = false +} + +func (c *connState) open() { + c.Lock() + defer c.Unlock() + + c.opened = true +} + +func (c *connState) closed() bool { + c.Lock() + defer c.Unlock() + + return !c.opened +} + // Hyperstart is the base structure for hyperstart. type Hyperstart struct { ctlSerial, ioSerial string sockType string ctl, io net.Conn + ctlState, ioState connState // ctl access is arbitrated by ctlMutex. We can only allow a single // "transaction" (write command + read answer) at a time @@ -118,34 +138,36 @@ func (h *Hyperstart) OpenSockets() error { if err != nil { return err } + h.ctlState.open() h.io, err = net.Dial(h.sockType, h.ioSerial) if err != nil { h.ctl.Close() return err } + h.ioState.open() return nil } // CloseSockets closes both CTL and IO sockets. func (h *Hyperstart) CloseSockets() error { - if h.ctl != nil { + if !h.ctlState.closed() { err := h.ctl.Close() if err != nil { return err } - h.ctl = nil + h.ctlState.close() } - if h.io != nil { + if !h.ioState.closed() { err := h.io.Close() if err != nil { return err } - h.io = nil + h.ioState.close() } return nil @@ -166,7 +188,7 @@ func (h *Hyperstart) IsStarted() bool { ret := false timeoutDuration := 1 * time.Second - if h.ctl == nil { + if h.ctlState.closed() { return ret } diff --git a/vendor/github.com/containers/virtcontainers/hyperstart/mock/hyperstart.go b/vendor/github.com/containers/virtcontainers/hyperstart/mock/hyperstart.go index f2f0c7a2..e6dbeaa0 100644 --- a/vendor/github.com/containers/virtcontainers/hyperstart/mock/hyperstart.go +++ b/vendor/github.com/containers/virtcontainers/hyperstart/mock/hyperstart.go @@ -30,51 +30,44 @@ import ( // Control command string IDs const ( - Version = "version" - StartPod = "startpod" - GetPod = "getpod" - DestroyPod = "destroypod" - RestartContainer = "restartcontainer" - ExecCmd = "execcmd" - FinishCmd = "finishcmd" - Ready = "ready" - Ack = "ack" - Error = "error" - WinSize = "winsize" - Ping = "ping" - FinishPod = "finishpod" - Next = "next" - WriteFile = "writefile" - ReadFile = "readfile" - NewContainer = "newcontainer" - KillContainer = "killcontainer" - OnlineCPUMem = "onlinecpumem" - SetupInterface = "setupinterface" - SetupRoute = "setuproute" + Version = "version" + StartPod = "startpod" + DestroyPod = "destroypod" + ExecCmd = "execcmd" + Ready = "ready" + Ack = "ack" + Error = "error" + WinSize = "winsize" + Ping = "ping" + FinishPod = "finishpod" + Next = "next" + WriteFile = "writefile" + ReadFile = "readfile" + NewContainer = "newcontainer" + KillContainer = "killcontainer" + OnlineCPUMem = "onlinecpumem" + SetupInterface = "setupinterface" + SetupRoute = "setuproute" ) var codeList = map[int]string{ - hyper.INIT_VERSION: Version, - hyper.INIT_STARTPOD: StartPod, - hyper.INIT_GETPOD: GetPod, - hyper.INIT_DESTROYPOD: DestroyPod, - hyper.INIT_RESTARTCONTAINER: RestartContainer, - hyper.INIT_EXECCMD: ExecCmd, - hyper.INIT_FINISHCMD: FinishCmd, - hyper.INIT_READY: Ready, - hyper.INIT_ACK: Ack, - hyper.INIT_ERROR: Error, - hyper.INIT_WINSIZE: WinSize, - hyper.INIT_PING: Ping, - hyper.INIT_FINISHPOD: FinishPod, - hyper.INIT_NEXT: Next, - hyper.INIT_WRITEFILE: WriteFile, - hyper.INIT_READFILE: ReadFile, - hyper.INIT_NEWCONTAINER: NewContainer, - hyper.INIT_KILLCONTAINER: KillContainer, - hyper.INIT_ONLINECPUMEM: OnlineCPUMem, - hyper.INIT_SETUPINTERFACE: SetupInterface, - hyper.INIT_SETUPROUTE: SetupRoute, + hyper.INIT_VERSION: Version, + hyper.INIT_STARTPOD: StartPod, + hyper.INIT_DESTROYPOD: DestroyPod, + hyper.INIT_EXECCMD: ExecCmd, + hyper.INIT_READY: Ready, + hyper.INIT_ACK: Ack, + hyper.INIT_ERROR: Error, + hyper.INIT_WINSIZE: WinSize, + hyper.INIT_PING: Ping, + hyper.INIT_NEXT: Next, + hyper.INIT_WRITEFILE: WriteFile, + hyper.INIT_READFILE: ReadFile, + hyper.INIT_NEWCONTAINER: NewContainer, + hyper.INIT_KILLCONTAINER: KillContainer, + hyper.INIT_ONLINECPUMEM: OnlineCPUMem, + hyper.INIT_SETUPINTERFACE: SetupInterface, + hyper.INIT_SETUPROUTE: SetupRoute, } // Hyperstart is an object mocking the hyperstart agent.