mirror of
https://github.com/kata-containers/kata-containers.git
synced 2025-06-24 06:27:39 +00:00
Merge pull request #4 from egernst/vhost-user-add-blk
Vhost-user: add block device support
This commit is contained in:
commit
064ffdb2b2
45
qemu/qemu.go
45
qemu/qemu.go
@ -704,7 +704,7 @@ func (blkdev BlockDevice) QemuParams(config *Config) []string {
|
||||
return qemuParams
|
||||
}
|
||||
|
||||
// VhostUserDeviceType is a qemu networking device type.
|
||||
// VhostUserDeviceType is a qemu vhost-user device type.
|
||||
type VhostUserDeviceType string
|
||||
|
||||
const (
|
||||
@ -712,23 +712,38 @@ const (
|
||||
VhostUserSCSI = "vhost-user-scsi-pci"
|
||||
//VhostUserNet represents a net vhostuser device type
|
||||
VhostUserNet = "virtio-net-pci"
|
||||
//VhostUserBlk represents a block vhostuser device type
|
||||
VhostUserBlk = "vhost-user-blk-pci"
|
||||
)
|
||||
|
||||
// VhostUserDevice represents a qemu vhost-user network device meant to be passed
|
||||
// VhostUserDevice represents a qemu vhost-user device meant to be passed
|
||||
// in to the guest
|
||||
type VhostUserDevice struct {
|
||||
SocketPath string //path to vhostuser socket on host
|
||||
CharDevID string
|
||||
TypeDevID string //id (SCSI) or netdev (net) device parameter
|
||||
MacAddress string //only valid if device type is VhostUserNet
|
||||
TypeDevID string //variable QEMU parameter based on value of VhostUserType
|
||||
Address string //used for MAC address in net case
|
||||
VhostUserType VhostUserDeviceType
|
||||
}
|
||||
|
||||
// Valid returns true if there is a valid socket path defined for VhostUserDevice
|
||||
// Valid returns true if there is a valid structure defined for VhostUserDevice
|
||||
func (vhostuserDev VhostUserDevice) Valid() bool {
|
||||
if vhostuserDev.SocketPath == "" || vhostuserDev.CharDevID == "" ||
|
||||
vhostuserDev.TypeDevID == "" ||
|
||||
(vhostuserDev.VhostUserType == VhostUserNet && vhostuserDev.MacAddress == "") {
|
||||
|
||||
if vhostuserDev.SocketPath == "" || vhostuserDev.CharDevID == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
switch vhostuserDev.VhostUserType {
|
||||
case VhostUserNet:
|
||||
if vhostuserDev.TypeDevID == "" || vhostuserDev.Address == "" {
|
||||
return false
|
||||
}
|
||||
case VhostUserSCSI:
|
||||
if vhostuserDev.TypeDevID == "" {
|
||||
return false
|
||||
}
|
||||
case VhostUserBlk:
|
||||
default:
|
||||
return false
|
||||
}
|
||||
|
||||
@ -746,8 +761,9 @@ func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
|
||||
charParams = append(charParams, fmt.Sprintf("id=%s", vhostuserDev.CharDevID))
|
||||
charParams = append(charParams, fmt.Sprintf("path=%s", vhostuserDev.SocketPath))
|
||||
|
||||
switch vhostuserDev.VhostUserType {
|
||||
// if network based vhost device:
|
||||
if vhostuserDev.VhostUserType == VhostUserNet {
|
||||
case VhostUserNet:
|
||||
netParams = append(netParams, "type=vhost-user")
|
||||
netParams = append(netParams, fmt.Sprintf("id=%s", vhostuserDev.TypeDevID))
|
||||
netParams = append(netParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
@ -755,11 +771,18 @@ func (vhostuserDev VhostUserDevice) QemuParams(config *Config) []string {
|
||||
|
||||
devParams = append(devParams, VhostUserNet)
|
||||
devParams = append(devParams, fmt.Sprintf("netdev=%s", vhostuserDev.TypeDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("mac=%s", vhostuserDev.MacAddress))
|
||||
} else {
|
||||
devParams = append(devParams, fmt.Sprintf("mac=%s", vhostuserDev.Address))
|
||||
case VhostUserSCSI:
|
||||
devParams = append(devParams, VhostUserSCSI)
|
||||
devParams = append(devParams, fmt.Sprintf("id=%s", vhostuserDev.TypeDevID))
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
case VhostUserBlk:
|
||||
devParams = append(devParams, VhostUserBlk)
|
||||
devParams = append(devParams, "logical_block_size=4096")
|
||||
devParams = append(devParams, "size=512M")
|
||||
devParams = append(devParams, fmt.Sprintf("chardev=%s", vhostuserDev.CharDevID))
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
|
||||
qemuParams = append(qemuParams, "-chardev")
|
||||
|
@ -269,13 +269,24 @@ func TestAppendDeviceBlock(t *testing.T) {
|
||||
|
||||
var 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"
|
||||
var deviceVhostUserSCSIString = "-chardev socket,id=char1,path=/tmp/nonexistentsocket.socket -device vhost-user-scsi-pci,id=scsi1,chardev=char1"
|
||||
var deviceVhostUserBlkString = "-chardev socket,id=char2,path=/tmp/nonexistentsocket.socket -device vhost-user-blk-pci,logical_block_size=4096,size=512M,chardev=char2"
|
||||
|
||||
func TestAppendDeviceVhostUser(t *testing.T) {
|
||||
|
||||
vhostuserBlkDevice := VhostUserDevice{
|
||||
SocketPath: "/tmp/nonexistentsocket.socket",
|
||||
CharDevID: "char2",
|
||||
TypeDevID: "",
|
||||
Address: "",
|
||||
VhostUserType: VhostUserBlk,
|
||||
}
|
||||
testAppend(vhostuserBlkDevice, deviceVhostUserBlkString, t)
|
||||
|
||||
vhostuserSCSIDevice := VhostUserDevice{
|
||||
SocketPath: "/tmp/nonexistentsocket.socket",
|
||||
CharDevID: "char1",
|
||||
TypeDevID: "scsi1",
|
||||
MacAddress: "",
|
||||
Address: "",
|
||||
VhostUserType: VhostUserSCSI,
|
||||
}
|
||||
testAppend(vhostuserSCSIDevice, deviceVhostUserSCSIString, t)
|
||||
@ -284,7 +295,7 @@ func TestAppendDeviceVhostUser(t *testing.T) {
|
||||
SocketPath: "/tmp/nonexistentsocket.socket",
|
||||
CharDevID: "char1",
|
||||
TypeDevID: "net1",
|
||||
MacAddress: "00:11:22:33:44:55",
|
||||
Address: "00:11:22:33:44:55",
|
||||
VhostUserType: VhostUserNet,
|
||||
}
|
||||
testAppend(vhostuserNetDevice, deviceVhostUserNetString, t)
|
||||
|
Loading…
Reference in New Issue
Block a user