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
14 changes: 14 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion containerd/containerd.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ var ContainerdCommand = cli.Command{
driver := context.GlobalString("driver")
kernel := context.GlobalString("kernel")
initrd := context.GlobalString("initrd")
vsock := context.GlobalBool("vsock")
template := context.GlobalString("template")
stateDir := context.String("state-dir")
containerdDir := context.String("containerd-dir")
Expand Down Expand Up @@ -111,7 +112,7 @@ var ContainerdCommand = cli.Command{
if template != "" {
f = singlefactory.New(templatefactory.NewFromExisted(tconfig))
} else {
f = factory.NewFromConfigs(kernel, initrd, nil)
f = factory.NewFromConfigs(kernel, initrd, vsock, nil)
}
sv, err := supervisor.New(stateDir, containerdDir, f,
context.GlobalInt("default_cpus"), context.GlobalInt("default_memory"))
Expand Down
8 changes: 7 additions & 1 deletion driverloader/driverloader_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ import (
"github.com/hyperhq/runv/hypervisor/libvirt"
"github.com/hyperhq/runv/hypervisor/qemu"
"github.com/hyperhq/runv/hypervisor/xen"
"github.com/hyperhq/runv/lib/vsock"
)

func Probe(driver string) (hypervisor.HypervisorDriver, error) {
func Probe(driver string) (hd hypervisor.HypervisorDriver, err error) {
defer func() {
if hd != nil && hypervisor.VsockCidManager == nil {
hypervisor.VsockCidManager = vsock.NewDefaultVsockCidAllocator()
}
}()
switch strings.ToLower(driver) {
case "libvirt":
ld := libvirt.InitDriver()
Expand Down
3 changes: 2 additions & 1 deletion factory/direct/direct.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ type directFactory struct {
config hypervisor.BootConfig
}

func New(cpu, mem int, kernel, initrd string) base.Factory {
func New(cpu, mem int, kernel, initrd string, vsock bool) base.Factory {
b := hypervisor.BootConfig{
CPU: cpu,
Memory: mem,
HotAddCpuMem: true,
EnableVsock: vsock,
Kernel: kernel,
Initrd: initrd,
}
Expand Down
13 changes: 7 additions & 6 deletions factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package factory

import (
"encoding/json"

"github.com/golang/glog"
"github.com/hyperhq/runv/factory/base"
"github.com/hyperhq/runv/factory/cache"
Expand All @@ -28,21 +29,21 @@ type FactoryConfig struct {
Memory int `json:"memory"`
}

func NewFromConfigs(kernel, initrd string, configs []FactoryConfig) Factory {
func NewFromConfigs(kernel, initrd string, vsock bool, configs []FactoryConfig) Factory {
bases := make([]base.Factory, len(configs))
for i, c := range configs {
var b base.Factory
if c.Template {
b = template.New(hypervisor.BaseDir+"/template", c.Cpu, c.Memory, kernel, initrd)
b = template.New(hypervisor.BaseDir+"/template", c.Cpu, c.Memory, kernel, initrd, vsock)
} else {
b = direct.New(c.Cpu, c.Memory, kernel, initrd)
b = direct.New(c.Cpu, c.Memory, kernel, initrd, vsock)
}
bases[i] = cache.New(c.Cache, b)
}

if len(bases) == 0 {
// skip GetVm from the base factory
return single.New(direct.New(1000000, 1000000, kernel, initrd))
return single.New(direct.New(1000000, 1000000, kernel, initrd, vsock))
} else if len(bases) == 1 {
return single.New(bases[0])
} else {
Expand All @@ -52,12 +53,12 @@ func NewFromConfigs(kernel, initrd string, configs []FactoryConfig) Factory {

// vmFactoryPolicy = [FactoryConfig,]*FactoryConfig
// FactoryConfig = {["cache":NUMBER,]["template":true|false,]"cpu":NUMBER,"memory":NUMBER}
func NewFromPolicy(kernel, initrd string, policy string) Factory {
func NewFromPolicy(kernel, initrd string, vsock bool, policy string) Factory {
var configs []FactoryConfig
jsonString := "[" + policy + "]"
err := json.Unmarshal([]byte(jsonString), &configs)
if err != nil && policy != "none" {
glog.Errorf("Incorrect policy: %s", policy)
}
return NewFromConfigs(kernel, initrd, configs)
return NewFromConfigs(kernel, initrd, vsock, configs)
}
9 changes: 5 additions & 4 deletions factory/single/single.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ func (f Factory) GetVm(cpu, mem int) (*hypervisor.Vm, error) {
if config.CPU > cpu || config.Memory > mem {
// also strip unrelated option from @config
boot := &hypervisor.BootConfig{
CPU: cpu,
Memory: mem,
Kernel: config.Kernel,
Initrd: config.Initrd,
CPU: cpu,
Memory: mem,
Kernel: config.Kernel,
Initrd: config.Initrd,
EnableVsock: config.EnableVsock,
}
return hypervisor.GetVm("", boot, false)
}
Expand Down
6 changes: 3 additions & 3 deletions factory/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type templateFactory struct {
s *template.TemplateVmConfig
}

func New(templateRoot string, cpu, mem int, kernel, initrd string) base.Factory {
func New(templateRoot string, cpu, mem int, kernel, initrd string, vsock bool) base.Factory {
var vmName string

for {
Expand All @@ -25,11 +25,11 @@ func New(templateRoot string, cpu, mem int, kernel, initrd string) base.Factory
break
}
}
s, err := template.CreateTemplateVM(templateRoot+"/"+vmName, vmName, cpu, mem, kernel, initrd)
s, err := template.CreateTemplateVM(templateRoot+"/"+vmName, vmName, cpu, mem, kernel, initrd, vsock)
if err != nil {
glog.Infof("failed to create template factory: %v", err)
glog.Infof("use direct factory instead")
return direct.New(cpu, mem, kernel, initrd)
return direct.New(cpu, mem, kernel, initrd, vsock)
}
return &templateFactory{s: s}
}
Expand Down
3 changes: 3 additions & 0 deletions hyperstart/api/json/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ const (

// "hyperstart" is the special container ID for adding processes.
const HYPERSTART_EXEC_CONTAINER = "hyperstart"

const HYPER_VSOCK_CTL_PORT = 2718
const HYPER_VSOCK_MSG_PORT = 2719
Loading