mirror of
https://github.com/aljazceru/kata-containers.git
synced 2026-01-25 09:14:29 +01:00
runtime: Re-vendor GoVMM
for vhost-user-fs-ccw devno support shortlog:f0e9a35Merge pull request #171 from Jakob-Naucke/fix-virtiofs-s390xabd3c7eqemu: VhostUserDevice CCW device numbers3eaeda7qemu: Refactor vhostuserDev.QemuParams7183b12Merge pull request #166 from kata-containers/egernst-patch-1092293fMerge pull request #169 from QiuMike/master511cf58Fix qemu commandline issue with empty romfile8ba62b0Merge pull request #164 from devimc/2021-03-30/tdxSupportb3eac95qmp: remove frequent, chatty log3141894qemu: add support for tdx-guest object Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
This commit is contained in:
232
src/runtime/vendor/github.com/kata-containers/govmm/qemu/qemu.go
generated
vendored
232
src/runtime/vendor/github.com/kata-containers/govmm/qemu/qemu.go
generated
vendored
@@ -227,6 +227,9 @@ type ObjectType string
|
||||
const (
|
||||
// MemoryBackendFile represents a guest memory mapped file.
|
||||
MemoryBackendFile ObjectType = "memory-backend-file"
|
||||
|
||||
// TDXGuest represents a TDX object
|
||||
TDXGuest ObjectType = "tdx-guest"
|
||||
)
|
||||
|
||||
// Object is a qemu object representation.
|
||||
@@ -249,6 +252,12 @@ type Object struct {
|
||||
|
||||
// Size is the object size in bytes
|
||||
Size uint64
|
||||
|
||||
// Debug this is a debug object
|
||||
Debug bool
|
||||
|
||||
// File is the device file
|
||||
File string
|
||||
}
|
||||
|
||||
// Valid returns true if the Object structure is valid and complete.
|
||||
@@ -259,6 +268,11 @@ func (object Object) Valid() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
case TDXGuest:
|
||||
if object.ID == "" || object.File == "" || object.DeviceID == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
default:
|
||||
return false
|
||||
}
|
||||
@@ -283,6 +297,13 @@ func (object Object) QemuParams(config *Config) []string {
|
||||
objectParams = append(objectParams, fmt.Sprintf(",size=%d", object.Size))
|
||||
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",memdev=%s", object.ID))
|
||||
case TDXGuest:
|
||||
objectParams = append(objectParams, string(object.Type))
|
||||
objectParams = append(objectParams, fmt.Sprintf(",id=%s", object.ID))
|
||||
if object.Debug {
|
||||
objectParams = append(objectParams, ",debug=on")
|
||||
}
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",file=%s", object.File))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
@@ -408,7 +429,7 @@ func (fsdev FSDevice) QemuParams(config *Config) []string {
|
||||
}
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",fsdev=%s", fsdev.ID))
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",mount_tag=%s", fsdev.MountTag))
|
||||
if fsdev.Transport.isVirtioPCI(config) {
|
||||
if fsdev.Transport.isVirtioPCI(config) && fsdev.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", fsdev.ROMFile))
|
||||
}
|
||||
if fsdev.Transport.isVirtioCCW(config) {
|
||||
@@ -541,7 +562,7 @@ func (cdev CharDevice) QemuParams(config *Config) []string {
|
||||
if cdev.Name != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",name=%s", cdev.Name))
|
||||
}
|
||||
if cdev.Driver == VirtioSerial && cdev.Transport.isVirtioPCI(config) {
|
||||
if cdev.Driver == VirtioSerial && cdev.Transport.isVirtioPCI(config) && cdev.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", cdev.ROMFile))
|
||||
}
|
||||
|
||||
@@ -811,7 +832,7 @@ func (netdev NetDevice) QemuDeviceParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, netdev.mqParameter(config))
|
||||
}
|
||||
|
||||
if netdev.Transport.isVirtioPCI(config) {
|
||||
if netdev.Transport.isVirtioPCI(config) && netdev.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", netdev.ROMFile))
|
||||
}
|
||||
|
||||
@@ -944,7 +965,7 @@ func (dev SerialDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",%s", s))
|
||||
}
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",id=%s", dev.ID))
|
||||
if dev.Transport.isVirtioPCI(config) {
|
||||
if dev.Transport.isVirtioPCI(config) && dev.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", dev.ROMFile))
|
||||
if dev.Driver == VirtioSerial && dev.MaxPorts != 0 {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",max_ports=%d", dev.MaxPorts))
|
||||
@@ -1075,7 +1096,7 @@ func (blkdev BlockDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, ",config-wce=off")
|
||||
}
|
||||
|
||||
if blkdev.Transport.isVirtioPCI(config) {
|
||||
if blkdev.Transport.isVirtioPCI(config) && blkdev.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", blkdev.ROMFile))
|
||||
}
|
||||
|
||||
@@ -1190,6 +1211,9 @@ type VhostUserDevice struct {
|
||||
// ROMFile specifies the ROM file being used for this device.
|
||||
ROMFile string
|
||||
|
||||
// DevNo identifies the CCW device for s390x.
|
||||
DevNo string
|
||||
|
||||
// Transport is the virtio transport for this device.
|
||||
Transport VirtioTransport
|
||||
}
|
||||
@@ -1254,88 +1278,150 @@ func (vhostuserDev VhostUserDevice) Valid() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// QemuNetParams builds QEMU netdev and device parameters for a VhostUserNet device
|
||||
func (vhostuserDev VhostUserDevice) QemuNetParams(config *Config) []string {
|
||||
var qemuParams []string
|
||||
var netParams []string
|
||||
var devParams []string
|
||||
|
||||
driver := vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
netParams = append(netParams, "type=vhost-user")
|
||||
netParams = append(netParams, fmt.Sprintf("id=%s", vhostuserDev.TypeDevID))
|
||||
netParams = append(netParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
netParams = append(netParams, "vhostforce")
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, fmt.Sprintf("netdev=%s", vhostuserDev.TypeDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("mac=%s", vhostuserDev.Address))
|
||||
|
||||
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
|
||||
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-netdev")
|
||||
qemuParams = append(qemuParams, strings.Join(netParams, ","))
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(devParams, ","))
|
||||
|
||||
return qemuParams
|
||||
}
|
||||
|
||||
// QemuSCSIParams builds QEMU device parameters for a VhostUserSCSI device
|
||||
func (vhostuserDev VhostUserDevice) QemuSCSIParams(config *Config) []string {
|
||||
var qemuParams []string
|
||||
var devParams []string
|
||||
|
||||
driver := vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, fmt.Sprintf("id=%s", vhostuserDev.TypeDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
|
||||
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
|
||||
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(devParams, ","))
|
||||
|
||||
return qemuParams
|
||||
}
|
||||
|
||||
// QemuBlkParams builds QEMU device parameters for a VhostUserBlk device
|
||||
func (vhostuserDev VhostUserDevice) QemuBlkParams(config *Config) []string {
|
||||
var qemuParams []string
|
||||
var devParams []string
|
||||
|
||||
driver := vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, "logical_block_size=4096")
|
||||
devParams = append(devParams, "size=512M")
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
|
||||
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
|
||||
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(devParams, ","))
|
||||
|
||||
return qemuParams
|
||||
}
|
||||
|
||||
// QemuFSParams builds QEMU device parameters for a VhostUserFS device
|
||||
func (vhostuserDev VhostUserDevice) QemuFSParams(config *Config) []string {
|
||||
var qemuParams []string
|
||||
var devParams []string
|
||||
|
||||
driver := vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("tag=%s", vhostuserDev.Tag))
|
||||
if vhostuserDev.CacheSize != 0 {
|
||||
devParams = append(devParams, fmt.Sprintf("cache-size=%dM", vhostuserDev.CacheSize))
|
||||
}
|
||||
if vhostuserDev.SharedVersions {
|
||||
devParams = append(devParams, "versiontable=/dev/shm/fuse_shared_versions")
|
||||
}
|
||||
if vhostuserDev.Transport.isVirtioCCW(config) {
|
||||
devParams = append(devParams, fmt.Sprintf("devno=%s", vhostuserDev.DevNo))
|
||||
}
|
||||
if vhostuserDev.Transport.isVirtioPCI(config) && vhostuserDev.ROMFile != "" {
|
||||
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(devParams, ","))
|
||||
|
||||
return qemuParams
|
||||
}
|
||||
|
||||
// QemuParams returns the qemu parameters built out of this vhostuser device.
|
||||
func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
|
||||
var qemuParams []string
|
||||
var charParams []string
|
||||
var netParams []string
|
||||
var devParams []string
|
||||
var driver string
|
||||
|
||||
charParams = append(charParams, "socket")
|
||||
charParams = append(charParams, fmt.Sprintf("id=%s", vhostuserDev.CharDevID))
|
||||
charParams = append(charParams, fmt.Sprintf("path=%s", vhostuserDev.SocketPath))
|
||||
|
||||
qemuParams = append(qemuParams, "-chardev")
|
||||
qemuParams = append(qemuParams, strings.Join(charParams, ","))
|
||||
|
||||
switch vhostuserDev.VhostUserType {
|
||||
// if network based vhost device:
|
||||
case VhostUserNet:
|
||||
driver = vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
netParams = append(netParams, "type=vhost-user")
|
||||
netParams = append(netParams, fmt.Sprintf("id=%s", vhostuserDev.TypeDevID))
|
||||
netParams = append(netParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
netParams = append(netParams, "vhostforce")
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, fmt.Sprintf("netdev=%s", vhostuserDev.TypeDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("mac=%s", vhostuserDev.Address))
|
||||
devParams = vhostuserDev.QemuNetParams(config)
|
||||
case VhostUserSCSI:
|
||||
driver = vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, fmt.Sprintf("id=%s", vhostuserDev.TypeDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
devParams = vhostuserDev.QemuSCSIParams(config)
|
||||
case VhostUserBlk:
|
||||
driver = vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, "logical_block_size=4096")
|
||||
devParams = append(devParams, "size=512M")
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
devParams = vhostuserDev.QemuBlkParams(config)
|
||||
case VhostUserFS:
|
||||
driver = vhostuserDev.deviceName(config)
|
||||
if driver == "" {
|
||||
return nil
|
||||
}
|
||||
|
||||
devParams = append(devParams, driver)
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("tag=%s", vhostuserDev.Tag))
|
||||
if vhostuserDev.CacheSize != 0 {
|
||||
devParams = append(devParams, fmt.Sprintf("cache-size=%dM", vhostuserDev.CacheSize))
|
||||
}
|
||||
if vhostuserDev.SharedVersions {
|
||||
devParams = append(devParams, "versiontable=/dev/shm/fuse_shared_versions")
|
||||
}
|
||||
devParams = vhostuserDev.QemuFSParams(config)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
if vhostuserDev.Transport.isVirtioPCI(config) {
|
||||
devParams = append(devParams, fmt.Sprintf("romfile=%s", vhostuserDev.ROMFile))
|
||||
if devParams != nil {
|
||||
return append(qemuParams, devParams...)
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-chardev")
|
||||
qemuParams = append(qemuParams, strings.Join(charParams, ","))
|
||||
|
||||
// if network based vhost device:
|
||||
if vhostuserDev.VhostUserType == VhostUserNet {
|
||||
qemuParams = append(qemuParams, "-netdev")
|
||||
qemuParams = append(qemuParams, strings.Join(netParams, ","))
|
||||
}
|
||||
qemuParams = append(qemuParams, "-device")
|
||||
qemuParams = append(qemuParams, strings.Join(devParams, ","))
|
||||
|
||||
return qemuParams
|
||||
return nil
|
||||
}
|
||||
|
||||
// deviceName returns the QEMU device name for the current combination of
|
||||
@@ -1510,7 +1596,9 @@ func (vfioDev VFIODevice) QemuParams(config *Config) []string {
|
||||
if vfioDev.DeviceID != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",x-pci-device-id=%s", vfioDev.DeviceID))
|
||||
}
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", vfioDev.ROMFile))
|
||||
if vfioDev.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", vfioDev.ROMFile))
|
||||
}
|
||||
}
|
||||
|
||||
if vfioDev.Bus != "" {
|
||||
@@ -1595,7 +1683,7 @@ func (scsiCon SCSIController) QemuParams(config *Config) []string {
|
||||
if scsiCon.IOThread != "" {
|
||||
devParams = append(devParams, fmt.Sprintf("iothread=%s", scsiCon.IOThread))
|
||||
}
|
||||
if scsiCon.Transport.isVirtioPCI(config) {
|
||||
if scsiCon.Transport.isVirtioPCI(config) && scsiCon.ROMFile != "" {
|
||||
devParams = append(devParams, fmt.Sprintf("romfile=%s", scsiCon.ROMFile))
|
||||
}
|
||||
|
||||
@@ -1701,7 +1789,7 @@ func (bridgeDev BridgeDevice) QemuParams(config *Config) []string {
|
||||
}
|
||||
|
||||
var transport VirtioTransport
|
||||
if transport.isVirtioPCI(config) {
|
||||
if transport.isVirtioPCI(config) && bridgeDev.ROMFile != "" {
|
||||
deviceParam = append(deviceParam, fmt.Sprintf(",romfile=%s", bridgeDev.ROMFile))
|
||||
}
|
||||
|
||||
@@ -1780,7 +1868,7 @@ func (vsock VSOCKDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",id=%s", vsock.ID))
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",%s=%d", VSOCKGuestCID, vsock.ContextID))
|
||||
|
||||
if vsock.Transport.isVirtioPCI(config) {
|
||||
if vsock.Transport.isVirtioPCI(config) && vsock.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf(",romfile=%s", vsock.ROMFile))
|
||||
}
|
||||
|
||||
@@ -1853,7 +1941,7 @@ func (v RngDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, v.deviceName(config))
|
||||
deviceParams = append(deviceParams, "rng="+v.ID)
|
||||
|
||||
if v.Transport.isVirtioPCI(config) {
|
||||
if v.Transport.isVirtioPCI(config) && v.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf("romfile=%s", v.ROMFile))
|
||||
}
|
||||
|
||||
@@ -1930,7 +2018,7 @@ func (b BalloonDevice) QemuParams(config *Config) []string {
|
||||
deviceParams = append(deviceParams, "id="+b.ID)
|
||||
}
|
||||
|
||||
if b.Transport.isVirtioPCI(config) {
|
||||
if b.Transport.isVirtioPCI(config) && b.ROMFile != "" {
|
||||
deviceParams = append(deviceParams, fmt.Sprintf("romfile=%s", b.ROMFile))
|
||||
}
|
||||
|
||||
|
||||
5
src/runtime/vendor/github.com/kata-containers/govmm/qemu/qmp.go
generated
vendored
5
src/runtime/vendor/github.com/kata-containers/govmm/qemu/qmp.go
generated
vendored
@@ -267,10 +267,6 @@ func (q *QMP) readLoop(fromVMCh chan<- []byte) {
|
||||
|
||||
for scanner.Scan() {
|
||||
line := scanner.Bytes()
|
||||
if q.cfg.Logger.V(1) {
|
||||
q.cfg.Logger.Infof("read from QMP: %s", string(line))
|
||||
}
|
||||
|
||||
// Since []byte channel type transfer slice info(include slice underlying array pointer, len, cap)
|
||||
// between channel sender and receiver. scanner.Bytes() returned slice's underlying array
|
||||
// may point to data that will be overwritten by a subsequent call to Scan(reference from:
|
||||
@@ -442,7 +438,6 @@ func (q *QMP) writeNextQMPCommand(cmdQueue *list.List) {
|
||||
}
|
||||
cmdQueue.Remove(cmdEl)
|
||||
}
|
||||
q.cfg.Logger.Infof("%s", string(encodedCmd))
|
||||
encodedCmd = append(encodedCmd, '\n')
|
||||
if unixConn, ok := q.conn.(*net.UnixConn); ok && len(cmd.oob) > 0 {
|
||||
_, _, err = unixConn.WriteMsgUnix(encodedCmd, cmd.oob, nil)
|
||||
|
||||
Reference in New Issue
Block a user