From f565536673142f746e6edb1ba4fdc8038ffc268c Mon Sep 17 00:00:00 2001 From: Eric Ernst Date: Tue, 12 Dec 2017 09:13:04 -0800 Subject: [PATCH] vhost-user: add blk device support Introduce basic vhost-user-blk-pci support. In adding this, cleaned up the QemuParams function to use a more appropriate switch statement. Similarly, cleanup up the Valid() logic. We still need to look into parameterization of the block parameter fields as well as introducing multiqueue support for the vhost-user devices. Signed-off-by: Eric Ernst --- qemu/qemu.go | 33 ++++++++++++++++++++++++++++----- qemu/qemu_test.go | 11 +++++++++++ 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/qemu/qemu.go b/qemu/qemu.go index de935bcc7d..959f193871 100644 --- a/qemu/qemu.go +++ b/qemu/qemu.go @@ -712,6 +712,8 @@ 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 device meant to be passed @@ -726,9 +728,22 @@ type VhostUserDevice struct { // 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.Address == "") { + + 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)) @@ -756,10 +772,17 @@ 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.Address)) - } else { + 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") diff --git a/qemu/qemu_test.go b/qemu/qemu_test.go index 4610734675..35d7e84e59 100644 --- a/qemu/qemu_test.go +++ b/qemu/qemu_test.go @@ -267,8 +267,19 @@ 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",