qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* Help with QEMU DBUS display
@ 2023-08-28  3:57 Elijah R
  2023-08-28  6:28 ` Marc-André Lureau
  0 siblings, 1 reply; 2+ messages in thread
From: Elijah R @ 2023-08-28  3:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: marcandre.lureau


[-- Attachment #1.1.1: Type: text/plain, Size: 1965 bytes --]

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

[-- Attachment #1.1.2: Type: text/html, Size: 2696 bytes --]

[-- Attachment #1.2: Type: text/plain, Size: 0 bytes --]



[-- Attachment #1.3: publickey - elijah@elijahr.dev - a0a86704.asc --]
[-- Type: application/pgp-keys, Size: 697 bytes --]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 249 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Help with QEMU DBUS display
  2023-08-28  3:57 Help with QEMU DBUS display Elijah R
@ 2023-08-28  6:28 ` Marc-André Lureau
  0 siblings, 0 replies; 2+ messages in thread
From: Marc-André Lureau @ 2023-08-28  6:28 UTC (permalink / raw)
  To: Elijah R; +Cc: qemu-devel

Hi

On Mon, Aug 28, 2023 at 7:58 AM Elijah R <elijah@elijahr.dev> wrote:
>
> 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"}}`))
>
> 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?



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-08-28 12:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-08-28  3:57 Help with QEMU DBUS display Elijah R
2023-08-28  6:28 ` Marc-André Lureau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).