Skip to content

Commit

Permalink
virtcontainers: add devno
Browse files Browse the repository at this point in the history
The devno number is use to identify the device on IBM Z arch.

Fixes: kata-containers#1153

Signed-off-by: Alice Frosi <afrosi@de.ibm.com>
Reviewed-by: Jan Schintag <jan.schintag@de.ibm.com>
  • Loading branch information
Alice Frosi authored and jschintag committed Aug 28, 2019
1 parent bc06de1 commit ccde04d
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 6 deletions.
3 changes: 3 additions & 0 deletions virtcontainers/persist/api/device.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ type BlockDrive struct {

// VirtPath at which the device appears inside the VM, outside of the container mount namespace
VirtPath string

// DevNo
DevNo string
}

// VFIODev represents a VFIO drive used for hotplugging
Expand Down
139 changes: 133 additions & 6 deletions virtcontainers/qemu_s390x.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,28 @@ func (q *qemuS390x) bridges(number uint32) {
q.Bridges = genericBridges(number, q.machineType)
}

// appendBridges appends to devices the given bridges
func (q *qemuS390x) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
return genericAppendBridges(devices, q.Bridges, q.machineType)
}

// appendConsole appends a console to devices.
// The function has been overwriten to correctly set the driver to the CCW device
func (q *qemuS390x) appendConsole(devices []govmmQemu.Device, path string) []govmmQemu.Device {
id := "serial0"
addr, b, err := q.addDeviceToBridge(id, types.CCW)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append console")
return devices
}

var devno string
devno, err = b.AddressFormatCCW(addr)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append console")
return devices
}

serial := govmmQemu.SerialDevice{
Driver: virtioSerialCCW,
ID: "serial0",
ID: id,
DisableModern: q.nestedRun,
DevNo: devno,
}

devices = append(devices, serial)
Expand All @@ -119,6 +129,36 @@ func (q *qemuS390x) appendConsole(devices []govmmQemu.Device, path string) []gov
return devices
}

func (q *qemuS390x) appendImage(devices []govmmQemu.Device, path string) ([]govmmQemu.Device, error) {
drive, err := genericImage(path)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append image")
return nil, err
}

return q.appendBlockDevice(devices, drive), nil
}

func (q *qemuS390x) appendBlockDevice(devices []govmmQemu.Device, drive config.BlockDrive) []govmmQemu.Device {
d, err := genericBlockDevice(drive, false)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append blk-dev")
return devices
}
addr, b, err := q.addDeviceToBridge(drive.ID, types.CCW)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append blk-dev")
return devices
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append blk-dev")
return devices
}
devices = append(devices, d)
return devices
}

// appendVhostUserDevice throws an error if vhost devices are tried to be used.
// See issue https://github.com/kata-containers/runtime/issues/659
func (q *qemuS390x) appendVhostUserDevice(devices []govmmQemu.Device, attr config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error) {
Expand All @@ -130,3 +170,90 @@ func (q *qemuS390x) appendVhostUserDevice(devices []govmmQemu.Device, attr confi
func (q *qemuS390x) supportGuestMemoryHotplug() bool {
return false
}

func (q *qemuS390x) appendNetwork(devices []govmmQemu.Device, endpoint Endpoint) []govmmQemu.Device {
d, err := genericNetwork(endpoint, false, false, q.networkIndex)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append network")
return devices
}
q.networkIndex++
addr, b, err := q.addDeviceToBridge(d.ID, types.CCW)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append network")
return devices
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append network")
return devices
}

devices = append(devices, d)
return devices
}

func (q *qemuS390x) appendRNGDevice(devices []govmmQemu.Device, rngDev config.RNGDev) []govmmQemu.Device {
addr, b, err := q.addDeviceToBridge(rngDev.ID, types.CCW)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append RNG-Device")
return devices
}
var devno string
devno, err = b.AddressFormatCCW(addr)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append RNG-Device")
return devices
}

devices = append(devices,
govmmQemu.RngDevice{
ID: rngDev.ID,
Filename: rngDev.Filename,
DevNo: devno,
},
)

return devices
}

func (q *qemuS390x) append9PVolume(devices []govmmQemu.Device, volume types.Volume) []govmmQemu.Device {
if volume.MountTag == "" || volume.HostPath == "" {
return devices
}
d := generic9PVolume(volume, false)
addr, b, err := q.addDeviceToBridge(d.ID, types.CCW)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append 9p-Volume")
return devices
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append 9p-Volume")
return devices
}
devices = append(devices, d)
return devices
}

// appendBridges appends to devices the given bridges
func (q *qemuS390x) appendBridges(devices []govmmQemu.Device) []govmmQemu.Device {
return genericAppendBridges(devices, q.Bridges, q.machineType)
}

func (q *qemuS390x) appendSCSIController(devices []govmmQemu.Device, enableIOThreads bool) ([]govmmQemu.Device, *govmmQemu.IOThread) {
d, t := genericSCSIController(enableIOThreads, q.nestedRun)
addr, b, err := q.addDeviceToBridge(d.ID, types.CCW)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append scsi-controller")
return devices, nil
}
d.DevNo, err = b.AddressFormatCCW(addr)
if err != nil {
virtLog.WithField("subsystem", "qemus390x").WithError(err).Error("Failed to append scsi-controller")
return devices, nil
}

devices = append(devices, d)
return devices, t
}

0 comments on commit ccde04d

Please sign in to comment.