mirror of
https://github.com/aljazceru/kata-containers.git
synced 2025-12-24 01:24:26 +01:00
This PR prepares for the s390x support. It introduces: - a generalization of ccw and pci devices. The variables for the pci devices have been renamed by removing the Pci suffix. They have been moved to the qemu_arch_base.go - the mapping isVirtioPCI has been move to qemu_arch_base.go because in this way a different mapping can be added for other architecture (e.g s390x) - the functions QemuNetdevParam and QemuDeviceParam have been moved to qemu_arch_base.go. In this way, they could be reimplemented for other architecture for the case VHOSTUSER - a function disableModern has been introduced to check if the device is a pci device and then returns the right parameters. In the case of ccw devices, they don't have the disable-modern flag - a function mqParameter has been introduced to return the right parameters for the mq case. The virtio-net-ccw device doesn't have the vectors flag - in qemu_arch_base_test.go contains the test and strings that can be overwritten for other architectures (e.g s390). The devices names and the flags for the devices can be overwritten. - the string for the romfile has been replaced by a variable romfile that could be left empty if the devices doesn't support a romfile as for the ccw devices for s390. - clean-up: the disable-modern=on/off options have been changed to disable-modern=true/false. In the code there was a mixture of on/true off/false Fixes: #61 Co-authored-by: Yash D Jain <ydjainopensource@gmail.com> Signed-off-by: Alice Frosi <afrosi@de.ibm.com>
100 lines
5.0 KiB
Go
100 lines
5.0 KiB
Go
// +build !s390x
|
|
|
|
/*
|
|
// Copyright (c) 2016 Intel Corporation
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
*/
|
|
|
|
package qemu
|
|
|
|
import "testing"
|
|
|
|
var (
|
|
deviceFSString = "-device virtio-9p-pci,disable-modern=true,fsdev=workload9p,mount_tag=rootfs,romfile=efi-virtio.rom -fsdev local,id=workload9p,path=/var/lib/docker/devicemapper/mnt/e31ebda2,security_model=none"
|
|
deviceNetworkString = "-netdev tap,id=tap0,vhost=on,ifname=ceth0,downscript=no,script=no -device driver=virtio-net-pci,netdev=tap0,mac=01:02:de:ad:be:ef,disable-modern=true,romfile=efi-virtio.rom"
|
|
deviceNetworkStringMq = "-netdev tap,id=tap0,vhost=on,fds=3:4 -device driver=virtio-net-pci,netdev=tap0,mac=01:02:de:ad:be:ef,disable-modern=true,mq=on,vectors=6,romfile=efi-virtio.rom"
|
|
deviceNetworkPCIString = "-netdev tap,id=tap0,vhost=on,ifname=ceth0,downscript=no,script=no -device driver=virtio-net-pci,netdev=tap0,mac=01:02:de:ad:be:ef,bus=/pci-bus/pcie.0,addr=ff,disable-modern=true,romfile=efi-virtio.rom"
|
|
deviceNetworkPCIStringMq = "-netdev tap,id=tap0,vhost=on,fds=3:4 -device driver=virtio-net-pci,netdev=tap0,mac=01:02:de:ad:be:ef,bus=/pci-bus/pcie.0,addr=ff,disable-modern=true,mq=on,vectors=6,romfile=efi-virtio.rom"
|
|
deviceSerialString = "-device virtio-serial-pci,disable-modern=true,id=serial0,romfile=efi-virtio.rom"
|
|
deviceVhostUserNetString = "-chardev socket,id=char1,path=/tmp/nonexistentsocket.socket -netdev type=vhost-user,id=net1,chardev=char1,vhostforce -device virtio-net-pci,netdev=net1,mac=00:11:22:33:44:55,romfile=efi-virtio.rom"
|
|
deviceVSOCKString = "-device vhost-vsock-pci,disable-modern=true,id=vhost-vsock-pci0,guest-cid=4,romfile=efi-virtio.rom"
|
|
deviceVFIOString = "-device vfio-pci,host=02:10.0,romfile=efi-virtio.rom"
|
|
deviceSCSIControllerStr = "-device virtio-scsi-pci,id=foo,disable-modern=false,romfile=efi-virtio.rom"
|
|
deviceSCSIControllerBusAddrStr = "-device virtio-scsi-pci,id=foo,bus=pci.0,addr=00:04.0,disable-modern=true,iothread=iothread1,romfile=efi-virtio.rom"
|
|
deviceVhostUserSCSIString = "-chardev socket,id=char1,path=/tmp/nonexistentsocket.socket -device vhost-user-scsi-pci,id=scsi1,chardev=char1,romfile=efi-virtio.rom"
|
|
deviceVhostUserBlkString = "-chardev socket,id=char2,path=/tmp/nonexistentsocket.socket -device vhost-user-blk-pci,logical_block_size=4096,size=512M,chardev=char2,romfile=efi-virtio.rom"
|
|
deviceBlockString = "-device virtio-blk,disable-modern=true,drive=hd0,scsi=off,config-wce=off,romfile=efi-virtio.rom -drive id=hd0,file=/var/lib/vm.img,aio=threads,format=qcow2,if=none"
|
|
devicePCIBridgeString = "-device pci-bridge,bus=/pci-bus/pcie.0,id=mybridge,chassis_nr=5,shpc=on,addr=ff,romfile=efi-virtio.rom"
|
|
devicePCIEBridgeString = "-device pcie-pci-bridge,bus=/pci-bus/pcie.0,id=mybridge,addr=ff,romfile=efi-virtio.rom"
|
|
romfile = "efi-virtio.rom"
|
|
)
|
|
|
|
func TestAppendDeviceVhostUser(t *testing.T) {
|
|
|
|
vhostuserBlkDevice := VhostUserDevice{
|
|
SocketPath: "/tmp/nonexistentsocket.socket",
|
|
CharDevID: "char2",
|
|
TypeDevID: "",
|
|
Address: "",
|
|
VhostUserType: VhostUserBlk,
|
|
ROMFile: romfile,
|
|
}
|
|
testAppend(vhostuserBlkDevice, deviceVhostUserBlkString, t)
|
|
|
|
vhostuserSCSIDevice := VhostUserDevice{
|
|
SocketPath: "/tmp/nonexistentsocket.socket",
|
|
CharDevID: "char1",
|
|
TypeDevID: "scsi1",
|
|
Address: "",
|
|
VhostUserType: VhostUserSCSI,
|
|
ROMFile: romfile,
|
|
}
|
|
testAppend(vhostuserSCSIDevice, deviceVhostUserSCSIString, t)
|
|
|
|
vhostuserNetDevice := VhostUserDevice{
|
|
SocketPath: "/tmp/nonexistentsocket.socket",
|
|
CharDevID: "char1",
|
|
TypeDevID: "net1",
|
|
Address: "00:11:22:33:44:55",
|
|
VhostUserType: VhostUserNet,
|
|
ROMFile: romfile,
|
|
}
|
|
testAppend(vhostuserNetDevice, deviceVhostUserNetString, t)
|
|
}
|
|
|
|
func TestAppendVirtioBalloon(t *testing.T) {
|
|
balloonDevice := BalloonDevice{
|
|
ID: "balloon",
|
|
ROMFile: romfile,
|
|
}
|
|
|
|
var deviceString = "-device " + string(VirtioBalloon)
|
|
deviceString += ",id=" + balloonDevice.ID + ",romfile=" + balloonDevice.ROMFile
|
|
|
|
var OnDeflateOnOMM = ",deflate-on-oom=on"
|
|
var OffDeflateOnOMM = ",deflate-on-oom=off"
|
|
|
|
var OnDisableModern = ",disable-modern=true"
|
|
var OffDisableModern = ",disable-modern=false"
|
|
|
|
testAppend(balloonDevice, deviceString+OffDeflateOnOMM+OffDisableModern, t)
|
|
|
|
balloonDevice.DeflateOnOOM = true
|
|
testAppend(balloonDevice, deviceString+OnDeflateOnOMM+OffDisableModern, t)
|
|
|
|
balloonDevice.DisableModern = true
|
|
testAppend(balloonDevice, deviceString+OnDeflateOnOMM+OnDisableModern, t)
|
|
|
|
}
|