Files
kata-containers/virtcontainers/device/drivers/vhost_user_fs.go
Stefan Hajnoczi 9480978364 qemu: add vhost-user-fs-pci device instead of 9p
When enable_virtio_fs is true, add a vhost-user-fs-pci for the
kataShared volume instead of 9p.

Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
2019-05-05 11:32:34 -06:00

66 lines
1.4 KiB
Go

// Copyright (C) 2019 Red Hat, Inc.
//
// SPDX-License-Identifier: Apache-2.0
//
package drivers
import (
"encoding/hex"
"github.com/kata-containers/runtime/virtcontainers/device/api"
"github.com/kata-containers/runtime/virtcontainers/device/config"
"github.com/kata-containers/runtime/virtcontainers/utils"
)
// VhostUserFSDevice is a virtio-fs vhost-user device
type VhostUserFSDevice struct {
*GenericDevice
config.VhostUserDeviceAttrs
}
// Device interface
func (device *VhostUserFSDevice) Attach(devReceiver api.DeviceReceiver) (err error) {
skip, err := device.bumpAttachCount(true)
if err != nil {
return err
}
if skip {
return nil
}
defer func() {
if err != nil {
device.bumpAttachCount(false)
}
}()
// generate a unique ID to be used for hypervisor commandline fields
randBytes, err := utils.GenerateRandomBytes(8)
if err != nil {
return err
}
id := hex.EncodeToString(randBytes)
device.DevID = id
device.Type = device.DeviceType()
return devReceiver.AppendDevice(device)
}
func (device *VhostUserFSDevice) Detach(devReceiver api.DeviceReceiver) error {
_, err := device.bumpAttachCount(false)
return err
}
func (device *VhostUserFSDevice) DeviceType() config.DeviceType {
return config.VhostUserFS
}
// GetDeviceInfo returns device information that the device is created based on
func (device *VhostUserFSDevice) GetDeviceInfo() interface{} {
device.Type = device.DeviceType()
return &device.VhostUserDeviceAttrs
}