Skip to content

Commit

Permalink
Merge pull request #633 from rgooch/master
Browse files Browse the repository at this point in the history
Support disabling virtio for VMs.
  • Loading branch information
rgooch committed Aug 4, 2019
2 parents d8a2919 + b3efe7d commit 8e159f9
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmd/vm-control/createVm.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func createVmInfoFromFlags() hyper_proto.VmInfo {
return hyper_proto.VmInfo{
ConsoleType: consoleType,
DestroyProtection: *destroyProtection,
DisableVirtIO: *disableVirtIO,
Hostname: *vmHostname,
MemoryInMiB: uint64(memory >> 20),
MilliCPUs: *milliCPUs,
Expand Down
11 changes: 6 additions & 5 deletions cmd/vm-control/importVirshVm.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,12 @@ func importVirshVm(macAddr, domainName string, sAddrs []proto.Address,
tags["Name"] = domainName
}
request := proto.ImportLocalVmRequest{VmInfo: proto.VmInfo{
ConsoleType: consoleType,
Hostname: domainName,
OwnerGroups: ownerGroups,
OwnerUsers: ownerUsers,
Tags: tags,
ConsoleType: consoleType,
DisableVirtIO: *disableVirtIO,
Hostname: domainName,
OwnerGroups: ownerGroups,
OwnerUsers: ownerUsers,
Tags: tags,
}}
verificationCookie, err := readRootCookie(logger)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions cmd/vm-control/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ var (
consoleType hyper_proto.ConsoleType
destroyProtection = flag.Bool("destroyProtection", false,
"If true, do not destroy running VM")
disableVirtIO = flag.Bool("disableVirtIO", false,
"If true, disable virtio drivers, reducing I/O performance")
dhcpTimeout = flag.Duration("dhcpTimeout", time.Minute,
"Time to wait before timing out on DHCP request from VM")
fleetManagerHostname = flag.String("fleetManagerHostname", "",
Expand Down
15 changes: 12 additions & 3 deletions hypervisor/manager/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ func (m *Manager) allocateVm(req proto.CreateVmRequest,
Address: address,
ConsoleType: req.ConsoleType,
DestroyProtection: req.DestroyProtection,
DisableVirtIO: req.DisableVirtIO,
Hostname: req.Hostname,
ImageName: req.ImageName,
ImageURL: req.ImageURL,
Expand Down Expand Up @@ -2782,6 +2783,10 @@ func (vm *vmInfoType) getBridgesAndOptions(haveManagerLock bool) (
subnetIDs = append(subnetIDs, subnetId)
}
var bridges, options []string
deviceDriver := "virtio-net-pci"
if vm.DisableVirtIO {
deviceDriver = "e1000"
}
for index, address := range addresses {
subnet, ok := vm.manager.subnets[subnetIDs[index]]
if !ok {
Expand All @@ -2802,8 +2807,8 @@ func (vm *vmInfoType) getBridgesAndOptions(haveManagerLock bool) (
options = append(options,
"-netdev", fmt.Sprintf("tap,id=net%d,fd=%d%s",
index, index+3, vlanOption),
"-device", fmt.Sprintf("virtio-net-pci,netdev=net%d,mac=%s",
index, address.MacAddress))
"-device", fmt.Sprintf("%s,netdev=net%d,mac=%s",
deviceDriver, index, address.MacAddress))
}
return bridges, options, nil
}
Expand Down Expand Up @@ -2873,14 +2878,18 @@ func (vm *vmInfoType) startVm(haveManagerLock bool) error {
"-vga", "std")
}
}
var interfaceDriver string
if !vm.DisableVirtIO {
interfaceDriver = ",if=virtio"
}
for index, volume := range vm.VolumeLocations {
var volumeFormat proto.VolumeFormat
if index < len(vm.Volumes) {
volumeFormat = vm.Volumes[index].Format
}
cmd.Args = append(cmd.Args,
"-drive", "file="+volume.Filename+",format="+volumeFormat.String()+
",if=virtio")
interfaceDriver)
}
os.Remove(filepath.Join(vm.dirname, "bootlog"))
cmd.ExtraFiles = tapFiles // Start at fd=3 for QEMU.
Expand Down
1 change: 1 addition & 0 deletions proto/hypervisor/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ type VmInfo struct {
Address Address
ConsoleType ConsoleType `json:",omitempty"`
DestroyProtection bool `json:",omitempty"`
DisableVirtIO bool `json:",omitempty"`
Hostname string `json:",omitempty"`
ImageName string `json:",omitempty"`
ImageURL string `json:",omitempty"`
Expand Down
3 changes: 3 additions & 0 deletions proto/hypervisor/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ func (left *VmInfo) Equal(right *VmInfo) bool {
if left.DestroyProtection != right.DestroyProtection {
return false
}
if left.DisableVirtIO != right.DisableVirtIO {
return false
}
if left.Hostname != right.Hostname {
return false
}
Expand Down

0 comments on commit 8e159f9

Please sign in to comment.