Skip to content
This repository was archived by the owner on Feb 8, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions hypervisor/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const (
COMMAND_STOP_POD
COMMAND_SHUTDOWN
COMMAND_RELEASE
COMMAND_NEWCONTAINER
COMMAND_ONLINECPUMEM
COMMAND_ATTACH
COMMAND_DETACH
Expand Down Expand Up @@ -116,8 +115,6 @@ func EventString(ev int) string {
return "COMMAND_SHUTDOWN"
case COMMAND_RELEASE:
return "COMMAND_RELEASE"
case COMMAND_NEWCONTAINER:
return "COMMAND_NEWCONTAINER"
case COMMAND_ATTACH:
return "COMMAND_ATTACH"
case COMMAND_DETACH:
Expand Down
6 changes: 0 additions & 6 deletions hypervisor/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ type RunPodCommand struct {

type ReplacePodCommand RunPodCommand

type NewContainerCommand struct {
container *pod.UserContainer
info *ContainerInfo
}

type OnlineCpuMemCommand struct{}

type ShutdownCommand struct {
Expand Down Expand Up @@ -211,7 +206,6 @@ func (qe *NetDevRemovedEvent) Event() int { return EVENT_INTERFACE_EJECTED }
func (qe *RunPodCommand) Event() int { return COMMAND_RUN_POD }
func (qe *GetPodStatsCommand) Event() int { return COMMAND_GET_POD_STATS }
func (qe *ReplacePodCommand) Event() int { return COMMAND_REPLACE_POD }
func (qe *NewContainerCommand) Event() int { return COMMAND_NEWCONTAINER }
func (qe *OnlineCpuMemCommand) Event() int { return COMMAND_ONLINECPUMEM }
func (qe *AttachCommand) Event() int { return COMMAND_ATTACH }
func (qe *WindowSizeCommand) Event() int { return COMMAND_WINDOWSIZE }
Expand Down
18 changes: 14 additions & 4 deletions hypervisor/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -567,12 +567,22 @@ func (vm *Vm) AddProcess(container, execId string, terminal bool, args []string,
}

func (vm *Vm) NewContainer(c *pod.UserContainer, info *ContainerInfo) error {
newContainerCommand := &NewContainerCommand{
container: c,
info: info,
err := vm.GenericOperation("NewContainer", func(ctx *VmContext, result chan<- error) {
ctx.newContainer(c, info, result)
}, StateInit, StateRunning)

if err != nil {
return fmt.Errorf("Create new container failed: %v", err)
}

vm.Hub <- newContainerCommand
vm.GenericOperation("StartNewContainerStdin", func(ctx *VmContext, result chan<- error) {
// start stdin. TODO: find the correct idx if parallel multi INIT_NEWCONTAINER
idx := len(ctx.vmSpec.Containers) - 1
c := ctx.vmSpec.Containers[idx]
ctx.ptys.startStdin(c.Process.Stdio, c.Process.Terminal)
result <- nil
}, StateInit, StateRunning)

return nil
}

Expand Down
43 changes: 9 additions & 34 deletions hypervisor/vm_states.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,24 +85,24 @@ func (ctx *VmContext) prepareDevice(cmd *RunPodCommand) bool {
return true
}

func (ctx *VmContext) prepareContainer(cmd *NewContainerCommand) *hyperstartapi.Container {
func (ctx *VmContext) prepareContainer(spec *pod.UserContainer, info *ContainerInfo) *hyperstartapi.Container {
ctx.lock.Lock()

idx := len(ctx.vmSpec.Containers)
vmContainer := &hyperstartapi.Container{}

ctx.initContainerInfo(idx, vmContainer, cmd.container)
ctx.setContainerInfo(idx, vmContainer, cmd.info)
ctx.initContainerInfo(idx, vmContainer, spec)
ctx.setContainerInfo(idx, vmContainer, info)

vmContainer.Sysctl = cmd.container.Sysctl
vmContainer.Sysctl = spec.Sysctl
vmContainer.Process.Stdio = ctx.ptys.attachId
ctx.ptys.attachId++
if !cmd.container.Tty {
if !spec.Tty {
vmContainer.Process.Stderr = ctx.ptys.attachId
ctx.ptys.attachId++
}

ctx.userSpec.Containers = append(ctx.userSpec.Containers, *cmd.container)
ctx.userSpec.Containers = append(ctx.userSpec.Containers, *spec)
ctx.vmSpec.Containers = append(ctx.vmSpec.Containers, *vmContainer)

ctx.lock.Unlock()
Expand All @@ -122,12 +122,13 @@ func (ctx *VmContext) prepareContainer(cmd *NewContainerCommand) *hyperstartapi.
return vmContainer
}

func (ctx *VmContext) newContainer(cmd *NewContainerCommand) {
c := ctx.prepareContainer(cmd)
func (ctx *VmContext) newContainer(spec *pod.UserContainer, info *ContainerInfo, result chan<- error) {
c := ctx.prepareContainer(spec, info)
glog.Infof("start sending INIT_NEWCONTAINER")
ctx.vm <- &hyperstartCmd{
Code: hyperstartapi.INIT_NEWCONTAINER,
Message: c,
result: result,
}
glog.Infof("sent INIT_NEWCONTAINER")
}
Expand Down Expand Up @@ -428,8 +429,6 @@ func stateInit(ctx *VmContext, ev VmEvent) {
ctx.shutdownVM(false, "")
ctx.Become(stateDestroying, StateDestroying)
ctx.reportVmShutdown()
case COMMAND_NEWCONTAINER:
ctx.newContainer(ev.(*NewContainerCommand))
case COMMAND_ONLINECPUMEM:
ctx.onlineCpuMem(ev.(*OnlineCpuMemCommand))
case COMMAND_WINDOWSIZE:
Expand All @@ -441,17 +440,6 @@ func stateInit(ctx *VmContext, ev VmEvent) {
ctx.setTimeout(60)
ctx.Become(stateStarting, StateStarting)
}
case COMMAND_ACK:
ack := ev.(*CommandAck)
glog.V(1).Infof("[init] got init ack to %d", ack.reply)
if ack.reply.Code == hyperstartapi.INIT_NEWCONTAINER {
glog.Infof("Get ack for new container")

// start stdin. TODO: find the correct idx if parallel multi INIT_NEWCONTAINER
idx := len(ctx.vmSpec.Containers) - 1
c := ctx.vmSpec.Containers[idx]
ctx.ptys.startStdin(c.Process.Stdio, c.Process.Terminal)
}
default:
unexpectedEventHandler(ctx, ev, "pod initiating")
}
Expand Down Expand Up @@ -547,26 +535,13 @@ func stateRunning(ctx *VmContext, ev VmEvent) {
glog.Info("pod is running, got release command, let VM fly")
ctx.Become(nil, StateNone)
ctx.reportSuccess("", nil)
case COMMAND_NEWCONTAINER:
ctx.newContainer(ev.(*NewContainerCommand))
case COMMAND_WINDOWSIZE:
cmd := ev.(*WindowSizeCommand)
ctx.setWindowSize(cmd.ContainerId, cmd.ExecId, cmd.Size)
case EVENT_POD_FINISH:
result := ev.(*PodFinished)
ctx.reportPodFinished(result)
ctx.exitVM(false, "", true, false)
case COMMAND_ACK:
ack := ev.(*CommandAck)
glog.V(1).Infof("[running] got init ack to %d", ack.reply)

if ack.reply.Code == hyperstartapi.INIT_NEWCONTAINER {
glog.Infof("Get ack for new container")
// start stdin. TODO: find the correct idx if parallel multi INIT_NEWCONTAINER
idx := len(ctx.vmSpec.Containers) - 1
c := ctx.vmSpec.Containers[idx]
ctx.ptys.startStdin(c.Process.Stdio, c.Process.Terminal)
}
case COMMAND_GET_POD_STATS:
ctx.reportPodStats(ev)
case EVENT_INTERFACE_EJECTED:
Expand Down