Skip to content

[WIP] feature: initial spice streaming agent support. #18569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions pkg/hostman/guestman/desc/desc.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ type SGuestHardwareDesc struct {
// vnc or spice
Vdi string
VdiDevice *SGuestVdi `json:",omitempty"`
// vdi options
VdiOptions map[string]string

VirtioScsi *SGuestVirtioScsi `json:",omitempty"`
PvScsi *SGuestPvScsi `json:",omitempty"`
Expand Down Expand Up @@ -245,6 +247,11 @@ type SSpiceDesc struct {
Vdagent *CharDev
VdagentSerialPort *VirtSerialPort

// https://gitlab.freedesktop.org/spice/spice-streaming-agent
// Spice Streaming Agent
StreamingAgent *CharDev
StreamingAgentPort *VirtSerialPort

// usb redirect
UsbRedirct *UsbRedirctDesc

Expand Down
45 changes: 31 additions & 14 deletions pkg/hostman/guestman/pci.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"yunion.io/x/log"
"yunion.io/x/pkg/errors"

compute_api "yunion.io/x/onecloud/pkg/apis/compute"
"yunion.io/x/onecloud/pkg/hostman/guestman/desc"
"yunion.io/x/onecloud/pkg/hostman/guestman/qemu"
"yunion.io/x/onecloud/pkg/hostman/monitor"
Expand Down Expand Up @@ -78,7 +79,7 @@ func (s *SKVMGuestInstance) initGuestDevicesDesc(pciRoot, pciBridge *desc.PCICon
// vdi device for spice
s.Desc.VdiDevice = new(desc.SGuestVdi)
if s.IsVdiSpice() {
s.initSpiceDevices(pciRoot)
s.initSpiceDevices(pciRoot, s.isEnableSpiceStreaming())
}

s.initVirtioSerial(pciRoot)
Expand Down Expand Up @@ -494,7 +495,7 @@ func (s *SKVMGuestInstance) initGuestVga(pciRoot *desc.PCIController) {
}
}

func (s *SKVMGuestInstance) initSpiceDevices(pciRoot *desc.PCIController) {
func (s *SKVMGuestInstance) initSpiceDevices(pciRoot *desc.PCIController, enableStreaming bool) {
spice := new(desc.SSpiceDesc)
spice.IntelHDA = &desc.SoundCard{
PCIDevice: desc.NewPCIDevice(pciRoot.CType, "intel-hda", "sound0"),
Expand Down Expand Up @@ -535,6 +536,22 @@ func (s *SKVMGuestInstance) initSpiceDevices(pciRoot *desc.PCIController) {
"nr": "1",
},
}

if enableStreaming {
// -chardev spiceport,name=org.spice-space.stream.0,id=charchannel1
streamingAgentCharDevId := "charchannel1"
streamingAgentCharDevName := "org.spice-space.stream.0"
spice.StreamingAgent = desc.NewCharDev("spiceport", streamingAgentCharDevId, streamingAgentCharDevName)
// -device virtserialport,bus=virtio-serial0.0,nr=1,chardev=charchannel1,id=channel1,name=org.spice-space.stream.0
spice.StreamingAgentPort = &desc.VirtSerialPort{
Chardev: streamingAgentCharDevId,
Name: streamingAgentCharDevName,
Options: map[string]string{
"nr": "2",
},
}
}

spice.Options = map[string]string{
"disable-ticketing": "off",
"seamless-migration": "on",
Expand Down Expand Up @@ -869,8 +886,8 @@ func (s *SKVMGuestInstance) initGuestDescFromExistingGuest(
}
case "sound0":
if s.Desc.VdiDevice.Spice == nil {
s.Desc.Vdi = "spice"
s.initSpiceDevices(pciRoot)
s.Desc.Vdi = compute_api.VM_VDI_PROTOCOL_SPICE
s.initSpiceDevices(pciRoot, false)
}
s.Desc.VdiDevice.Spice.IntelHDA.PCIAddr = pciAddr
err = s.ensureDevicePciAddress(s.Desc.VdiDevice.Spice.IntelHDA.PCIDevice, -1, nil)
Expand All @@ -879,8 +896,8 @@ func (s *SKVMGuestInstance) initGuestDescFromExistingGuest(
}
case "vdagent-serial0":
if s.Desc.VdiDevice.Spice == nil {
s.Desc.Vdi = "spice"
s.initSpiceDevices(pciRoot)
s.Desc.Vdi = compute_api.VM_VDI_PROTOCOL_SPICE
s.initSpiceDevices(pciRoot, false)
}
s.Desc.VdiDevice.Spice.VdagentSerial.PCIAddr = pciAddr
err = s.ensureDevicePciAddress(s.Desc.VdiDevice.Spice.VdagentSerial.PCIDevice, -1, nil)
Expand All @@ -899,8 +916,8 @@ func (s *SKVMGuestInstance) initGuestDescFromExistingGuest(
}
case "usbspice":
if s.Desc.VdiDevice.Spice == nil {
s.Desc.Vdi = "spice"
s.initSpiceDevices(pciRoot)
s.Desc.Vdi = compute_api.VM_VDI_PROTOCOL_SPICE
s.initSpiceDevices(pciRoot, false)
}
s.Desc.VdiDevice.Spice.UsbRedirct.EHCI1.PCIAddr = pciAddr
multiFunc := true
Expand All @@ -910,8 +927,8 @@ func (s *SKVMGuestInstance) initGuestDescFromExistingGuest(
}
case "uhci1":
if s.Desc.VdiDevice.Spice == nil {
s.Desc.Vdi = "spice"
s.initSpiceDevices(pciRoot)
s.Desc.Vdi = compute_api.VM_VDI_PROTOCOL_SPICE
s.initSpiceDevices(pciRoot, false)
}
multiFunc := true
s.Desc.VdiDevice.Spice.UsbRedirct.UHCI1.PCIAddr = pciAddr
Expand All @@ -921,8 +938,8 @@ func (s *SKVMGuestInstance) initGuestDescFromExistingGuest(
}
case "uhci2":
if s.Desc.VdiDevice.Spice == nil {
s.Desc.Vdi = "spice"
s.initSpiceDevices(pciRoot)
s.Desc.Vdi = compute_api.VM_VDI_PROTOCOL_SPICE
s.initSpiceDevices(pciRoot, false)
}
multiFunc := true
s.Desc.VdiDevice.Spice.UsbRedirct.UHCI2.PCIAddr = pciAddr
Expand All @@ -932,8 +949,8 @@ func (s *SKVMGuestInstance) initGuestDescFromExistingGuest(
}
case "uhci3":
if s.Desc.VdiDevice.Spice == nil {
s.Desc.Vdi = "spice"
s.initSpiceDevices(pciRoot)
s.Desc.Vdi = compute_api.VM_VDI_PROTOCOL_SPICE
s.initSpiceDevices(pciRoot, false)
}
multiFunc := true
s.Desc.VdiDevice.Spice.UsbRedirct.UHCI3.PCIAddr = pciAddr
Expand Down
2 changes: 1 addition & 1 deletion pkg/hostman/guestman/pci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestSKVMGuestInstance_initGuestDesc(t *testing.T) {
// vdi device for spice
s.Desc.VdiDevice = new(desc.SGuestVdi)
if s.IsVdiSpice() {
s.initSpiceDevices(pciRoot)
s.initSpiceDevices(pciRoot, s.isEnableSpiceStreaming())
}

s.initVirtioSerial(pciRoot)
Expand Down
7 changes: 7 additions & 0 deletions pkg/hostman/guestman/qemu-kvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3275,3 +3275,10 @@ func (s *SKVMGuestInstance) getTftpEndpoint(baremetalManagerUri string) (string,

return endpoint, nil
}

func (s *SKVMGuestInstance) isEnableSpiceStreaming() bool {
if s.Desc.Vdi == api.VM_VDI_PROTOCOL_SPICE && s.Desc.VdiOptions != nil && s.Desc.VdiOptions["streaming"] == "true" {
return true
}
return false
}
4 changes: 2 additions & 2 deletions pkg/hostman/guestman/qemu-kvmhelper.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func (s *SKVMGuestInstance) CpuMax() (uint, error) {
}

func (s *SKVMGuestInstance) IsVdiSpice() bool {
return s.Desc.Vdi == "spice"
return s.Desc.Vdi == api.VM_VDI_PROTOCOL_SPICE
}

func (s *SKVMGuestInstance) GetOsName() string {
Expand Down Expand Up @@ -254,7 +254,7 @@ func (s *SKVMGuestInstance) isPcie() bool {
func (s *SKVMGuestInstance) GetVdiProtocol() string {
vdi := s.Desc.Vdi
if vdi == "" {
vdi = "vnc"
vdi = api.VM_VDI_PROTOCOL_VNC
}
return vdi
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/hostman/guestman/qemu/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func generateSpiceOptions(port uint, spice *desc.SSpiceDesc) []string {
opts = append(opts, chardevOption(spice.Vdagent))
opts = append(opts, virtSerialPortOption(spice.VdagentSerialPort, spice.VdagentSerial.Id))

if spice.StreamingAgent != nil {
// streaming port
opts = append(opts, chardevOption(spice.StreamingAgent))
opts = append(opts, virtSerialPortOption(spice.StreamingAgentPort, spice.VdagentSerial.Id))
}

// usb redirct
opts = append(opts, usbRedirOptions(spice.UsbRedirct)...)
return opts
Expand Down