Skip to contentSkip to conversation

Help with QEMU DBUS display

DISCUSSION Elijah R 2 participants 2 messages Aug 28, 2023

lore
Share & tools
lore

Elijah R

author
#0 lore raw

Hi!

I'm currently attempting to use qemu's DBUS display from within a go application, using the godbus <https://pkg.go.dev/github.com/godbus/dbus/v5> library. However, I'm hitting some roadblocks, and this is probably because I'm a bit confused about how qemu's peer-to-peer dbus connection works, and it's not explained in the documentation.

I invoke QEMU with the following argument

-display dbus,p2p=yes

and then connect to QMP through a separate UNIX socket. From my understanding, I need to listen on the socket separately in the program, and then pass qemu the file descriptor over QMP and run add_client.

In the same program I listen to the socket, and start waiting for a connection. Then, on another thread, get a file descriptor for the socket by first dialing it. Here's my code for that

sock, err := net.Dial("unix", "/tmp/qemudbus.sock") if err != nil {
return err
}
uc, ok := sock.(*net.UnixConn)
if !ok {
return fmt.Errorf("Could not cast
Conn to UnixConn")
}
file, err := uc.File()

I then pass this file descriptor to QEMU using QMP (I'm using DigitalOcean's qmp library)

res, err := mon.RunWithFile([]byte({"execute": "getfd", "arguments": {"fdname": "dbusmon"}}), file)

And add the dbus client:

res, err = mon.Run([]byte({"execute": "add_client", "arguments": {"protocol": "@dbus-display", "fdname": "dbusmon"}}))

This seems to work fine, as I'm then (apparently) able to make a DBUS connection with that socket without any error.

However, when I then try to do anything with that connection (In this case I'm attempting to introspect /org/qemu/Display1/VM), the call hangs and never returns.

node, err := introspect.Call(session.Object("org.qemu.Display1.VM", "/org/qemu/Display1/VM"))

I'm not sure what's going wrong here, but I suspect I'm obtaining the file descriptor wrong (am I supposed to dial the socket?) or I'm doing things in the wrong order.

Thanks in advance for any help.

Regards,

Elijah R

#1 lore raw

Hi

Quoted 32 lines · Elijah R

Hi!

I'm currently attempting to use qemu's DBUS display from within a go application, using the godbus library. However, I'm hitting some roadblocks, and this is probably because I'm a bit confused about how qemu's peer-to-peer dbus connection works, and it's not explained in the documentation.

I invoke QEMU with the following argument

-display dbus,p2p=yes

and then connect to QMP through a separate UNIX socket. From my understanding, I need to listen on the socket separately in the program, and then pass qemu the file descriptor over QMP and run add_client.

In the same program I listen to the socket, and start waiting for a connection. Then, on another thread, get a file descriptor for the socket by first dialing it. Here's my code for that

sock, err := net.Dial("unix", "/tmp/qemudbus.sock") if err != nil {
return err
}
uc, ok := sock.(*net.UnixConn)
if !ok {
return fmt.Errorf("Could not cast Conn to UnixConn") }
file, err := uc.File()

I then pass this file descriptor to QEMU using QMP (I'm using DigitalOcean's qmp library)

res, err := mon.RunWithFile([]byte({"execute": "getfd", "arguments": {"fdname": "dbusmon"}}), file)

And add the dbus client:

res, err = mon.Run([]byte({"execute": "add_client", "arguments": {"protocol": "@dbus-display", "fdname": "dbusmon"}}))

Quoted 8 lines

This seems to work fine, as I'm then (apparently) able to make a DBUS connection with that so cket without any error.

However, when I then try to do anything with that connection (In this case I'm attempting to introspect /org/qemu/Display1/VM), the call hangs and never returns.

node, err := introspect.Call(session.Object("org.qemu.Display1.VM", "/org/qemu/Display1/VM"))

I'm not sure what's going wrong here, but I suspect I'm obtaining the file descriptor wrong (am I supposed to dial the socket?) or I'm doing things in the wrong order.

You seem to be doing everything correctly. Before doing the call, make sure D-Bus authentication took place. I am not very familiar with go, but could you share the code?