Skip to content
Open
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
4 changes: 4 additions & 0 deletions pkg/unikontainers/hypervisors/qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
type Qemu struct {
binaryPath string
binary string
vhost bool
}

func (q *Qemu) Stop(pid int) error {
Expand Down Expand Up @@ -95,6 +96,9 @@ func (q *Qemu) Execve(args types.ExecArgs, ukernel types.Unikernel) error {
netcli += args.Net.MAC
netcli += " -net tap,script=no,downscript=no,ifname="
netcli += args.Net.TapDev
if q.vhost {
netcli += ",vhost=on"
}
}
cmdString += netcli
} else {
Expand Down
28 changes: 18 additions & 10 deletions pkg/unikontainers/hypervisors/vmm.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,33 @@ var vmmLog = logrus.WithField("subsystem", "monitors")

type VMMFactory struct {
binary string
createFunc func(binary, binaryPath string) types.VMM
createFunc func(binary, binaryPath string, config types.MonitorConfig) types.VMM
}

var vmmFactories = map[VmmType]VMMFactory{
SptVmm: {
binary: SptBinary,
createFunc: func(binary, binaryPath string) types.VMM { return &SPT{binary: binary, binaryPath: binaryPath} },
binary: SptBinary,
createFunc: func(binary, binaryPath string, _ types.MonitorConfig) types.VMM {
return &SPT{binary: binary, binaryPath: binaryPath}
},
},
HvtVmm: {
binary: HvtBinary,
createFunc: func(binary, binaryPath string) types.VMM { return &HVT{binary: binary, binaryPath: binaryPath} },
binary: HvtBinary,
createFunc: func(binary, binaryPath string, _ types.MonitorConfig) types.VMM {
return &HVT{binary: binary, binaryPath: binaryPath}
},
},
QemuVmm: {
binary: QemuBinary,
createFunc: func(binary, binaryPath string) types.VMM { return &Qemu{binary: binary, binaryPath: binaryPath} },
binary: QemuBinary,
createFunc: func(binary, binaryPath string, config types.MonitorConfig) types.VMM {
return &Qemu{binary: binary, binaryPath: binaryPath, vhost: config.Vhost}
},
},
FirecrackerVmm: {
binary: FirecrackerBinary,
createFunc: func(binary, binaryPath string) types.VMM { return &Firecracker{binary: binary, binaryPath: binaryPath} },
binary: FirecrackerBinary,
createFunc: func(binary, binaryPath string, _ types.MonitorConfig) types.VMM {
return &Firecracker{binary: binary, binaryPath: binaryPath}
},
},
}

Expand Down Expand Up @@ -80,7 +88,7 @@ func NewVMM(vmmType VmmType, monitors map[string]types.MonitorConfig) (vmm types
return nil, err
}

return factory.createFunc(factory.binary, vmmPath), nil
return factory.createFunc(factory.binary, vmmPath, monitors[string(vmmType)]), nil
}

func getVMMPath(vmmType VmmType, binary string, monitors map[string]types.MonitorConfig) (string, error) {
Expand Down
1 change: 1 addition & 0 deletions pkg/unikontainers/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,5 @@ type MonitorConfig struct {
DefaultVCPUs uint `toml:"default_vcpus"`
BinaryPath string `toml:"path,omitempty"` // Optional path to the hypervisor binary
DataPath string `toml:"data_path,omitempty"` // Optional path to the hypervisor data files (e.g. qemu bios stuff)
Vhost bool `toml:"vhost,omitempty"` // Optional: enable vhost for network performance optimization
}
5 changes: 5 additions & 0 deletions pkg/unikontainers/urunc_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ func (p *UruncConfig) Map() map[string]string {
cfgMap[prefix+"default_vcpus"] = strconv.FormatUint(uint64(hvCfg.DefaultVCPUs), 10)
cfgMap[prefix+"binary_path"] = hvCfg.BinaryPath
cfgMap[prefix+"data_path"] = hvCfg.DataPath
cfgMap[prefix+"vhost"] = strconv.FormatBool(hvCfg.Vhost)
}
for eb, ebCfg := range p.ExtraBins {
prefix := "urunc_config.extra_binaries." + eb + "."
Expand Down Expand Up @@ -171,6 +172,10 @@ func UruncConfigFromMap(cfgMap map[string]string) *UruncConfig {
hvCfg.BinaryPath = val
case "data_path":
hvCfg.DataPath = val
case "vhost":
if boolVal, err := strconv.ParseBool(val); err == nil {
hvCfg.Vhost = boolVal
}
}
cfg.Monitors[hv] = hvCfg
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/unikontainers/urunc_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
testQemuVCPUsKey = "urunc_config.monitors.qemu.default_vcpus"
testQemuBinaryKey = "urunc_config.monitors.qemu.binary_path"
testQemuDataKey = "urunc_config.monitors.qemu.data_path"
testQemuVhostKey = "urunc_config.monitors.qemu.vhost"
testHvtMemoryKey = "urunc_config.monitors.hvt.default_memory_mb"
testVirtiofsdPathKey = "urunc_config.extra_binaries.virtiofsd.path"
testVirtiofsdOptsKey = "urunc_config.extra_binaries.virtiofsd.options"
Expand Down Expand Up @@ -56,6 +57,7 @@ func TestUruncConfigFromMap(t *testing.T) {
testQemuVCPUsKey: "2",
testQemuBinaryKey: testQemuBinaryPath,
testQemuDataKey: testQemuDataPath,
testQemuVhostKey: "true",
}

config := UruncConfigFromMap(cfgMap)
Expand All @@ -67,6 +69,7 @@ func TestUruncConfigFromMap(t *testing.T) {
assert.Equal(t, uint(2), qemuConfig.DefaultVCPUs)
assert.Equal(t, testQemuBinaryPath, qemuConfig.BinaryPath)
assert.Equal(t, testQemuDataPath, qemuConfig.DataPath)
assert.True(t, qemuConfig.Vhost)
})

t.Run("multiple monitors", func(t *testing.T) {
Expand Down