virtcontainers: Enable virtio-fs on s390x

Allow and configure vhost-user-fs devices (virtio-fs) on s390x. As a
consequence, appendVhostUserDevice now takes a context, which affects
its signature for other architectures.

Fixes: #1753

Signed-off-by: Jakob Naucke <jakob.naucke@ibm.com>
This commit is contained in:
Jakob Naucke 2021-04-26 18:06:54 +02:00
parent 8385ff9554
commit 3ee61776d6
No known key found for this signature in database
GPG Key ID: 45FA1C7D310C0EBE
5 changed files with 75 additions and 16 deletions

View File

@ -1924,7 +1924,7 @@ func (q *qemu) addDevice(ctx context.Context, devInfo interface{}, devType devic
vhostDev.SocketPath = sockPath
vhostDev.DevID = id
q.qemuConfig.Devices, err = q.arch.appendVhostUserDevice(q.qemuConfig.Devices, vhostDev)
q.qemuConfig.Devices, err = q.arch.appendVhostUserDevice(ctx, q.qemuConfig.Devices, vhostDev)
} else {
q.Logger().WithField("volume-type", "virtio-9p").Info("adding volume")
q.qemuConfig.Devices, err = q.arch.append9PVolume(ctx, q.qemuConfig.Devices, v)
@ -1939,7 +1939,7 @@ func (q *qemu) addDevice(ctx context.Context, devInfo interface{}, devType devic
case config.BlockDrive:
q.qemuConfig.Devices, err = q.arch.appendBlockDevice(ctx, q.qemuConfig.Devices, v)
case config.VhostUserDeviceAttrs:
q.qemuConfig.Devices, err = q.arch.appendVhostUserDevice(q.qemuConfig.Devices, v)
q.qemuConfig.Devices, err = q.arch.appendVhostUserDevice(ctx, q.qemuConfig.Devices, v)
case config.VFIODev:
q.qemuConfig.Devices = q.arch.appendVFIODevice(q.qemuConfig.Devices, v)
default:

View File

@ -96,7 +96,7 @@ type qemuArch interface {
appendBlockDevice(ctx context.Context, devices []govmmQemu.Device, drive config.BlockDrive) ([]govmmQemu.Device, error)
// appendVhostUserDevice appends a vhost user device to devices
appendVhostUserDevice(devices []govmmQemu.Device, drive config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error)
appendVhostUserDevice(ctx context.Context, devices []govmmQemu.Device, drive config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error)
// appendVFIODevice appends a VFIO device to devices
appendVFIODevice(devices []govmmQemu.Device, vfioDevice config.VFIODev) []govmmQemu.Device
@ -633,7 +633,7 @@ func (q *qemuArchBase) appendBlockDevice(_ context.Context, devices []govmmQemu.
return devices, nil
}
func (q *qemuArchBase) appendVhostUserDevice(devices []govmmQemu.Device, attr config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error) {
func (q *qemuArchBase) appendVhostUserDevice(ctx context.Context, devices []govmmQemu.Device, attr config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error) {
qemuVhostUserDevice := govmmQemu.VhostUserDevice{}
switch attr.Type {

View File

@ -224,7 +224,7 @@ func testQemuArchBaseAppend(t *testing.T, structure interface{}, expected []govm
case config.VFIODev:
devices = qemuArchBase.appendVFIODevice(devices, s)
case config.VhostUserDeviceAttrs:
devices, err = qemuArchBase.appendVhostUserDevice(devices, s)
devices, err = qemuArchBase.appendVhostUserDevice(context.Background(), devices, s)
}
assert.NoError(err)

View File

@ -13,6 +13,7 @@ import (
govmmQemu "github.com/kata-containers/govmm/qemu"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/types"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/utils"
)
type qemuS390x struct {
@ -152,10 +153,33 @@ func (q *qemuS390x) appendCCWBlockDevice(ctx context.Context, devices []govmmQem
return devices, nil
}
// 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) {
return nil, fmt.Errorf("No vhost-user devices supported on s390x")
func (q *qemuS390x) appendVhostUserDevice(ctx context.Context, devices []govmmQemu.Device, attr config.VhostUserDeviceAttrs) ([]govmmQemu.Device, error) {
if attr.Type != config.VhostUserFS {
return devices, fmt.Errorf("vhost-user device of type %s not supported on s390x, only vhost-user-fs-ccw is supported", attr.Type)
}
addr, b, err := q.addDeviceToBridge(ctx, attr.DevID, types.CCW)
if err != nil {
return devices, fmt.Errorf("Failed to append vhost user device: %s", err)
}
var devno string
devno, err = b.AddressFormatCCW(addr)
if err != nil {
return devices, fmt.Errorf("Failed to append vhost user device: %s", err)
}
qemuVhostUserDevice := govmmQemu.VhostUserDevice{
SocketPath: attr.SocketPath,
CharDevID: utils.MakeNameID("char", attr.DevID, maxDevIDSize),
TypeDevID: utils.MakeNameID("fs", attr.DevID, maxDevIDSize),
Tag: attr.Tag,
CacheSize: attr.CacheSize,
VhostUserType: govmmQemu.VhostUserFS,
DevNo: devno,
}
devices = append(devices, qemuVhostUserDevice)
return devices, nil
}
// supportGuestMemoryHotplug return false for s390x architecture. The pc-dimm backend device for s390x

View File

@ -6,11 +6,14 @@
package virtcontainers
import (
"context"
"fmt"
"testing"
govmmQemu "github.com/kata-containers/govmm/qemu"
"github.com/stretchr/testify/assert"
"github.com/kata-containers/kata-containers/src/runtime/virtcontainers/device/config"
)
func newTestQemu(assert *assert.Assertions, machineType string) qemuArch {
@ -54,15 +57,47 @@ func TestQemuS390xMemoryTopology(t *testing.T) {
}
func TestQemuS390xAppendVhostUserDevice(t *testing.T) {
macAddress := "00:11:22:33:44:55:66"
qemu := qemuS390x{}
assert := assert.New(t)
qemu := newTestQemu(assert, QemuCCWVirtio)
vhostUserDevice := config.VhostUserDeviceAttrs{
Type: config.VhostUserNet,
MacAddress: macAddress,
// test devices that should not work
for _, deviceType := range []config.DeviceType{config.VhostUserSCSI, config.VhostUserNet, config.VhostUserBlk} {
vhostUserDevice := config.VhostUserDeviceAttrs{
Type: deviceType,
}
_, err := qemu.appendVhostUserDevice(context.Background(), nil, vhostUserDevice)
assert.Error(err)
}
_, err := qemu.appendVhostUserDevice(nil, vhostUserDevice)
assert.Error(err)
// test vhost user fs (virtio-fs)
socketPath := "nonexistentpath.sock"
id := "deadbeef"
tag := "shared"
var cacheSize uint32 = 0
expected := []govmmQemu.Device{
govmmQemu.VhostUserDevice{
SocketPath: socketPath,
CharDevID: fmt.Sprintf("char-%s", id),
TypeDevID: fmt.Sprintf("fs-%s", id),
Tag: tag,
CacheSize: cacheSize,
VhostUserType: govmmQemu.VhostUserFS,
DevNo: "fe.0.0001",
},
}
vhostUserDevice := config.VhostUserDeviceAttrs{
DevID: id,
SocketPath: socketPath,
Type: config.VhostUserFS,
Tag: tag,
CacheSize: cacheSize,
}
var devices []govmmQemu.Device
devices, err := qemu.appendVhostUserDevice(context.Background(), devices, vhostUserDevice)
assert.NoError(err)
assert.Equal(devices, expected)
}