[libvirt PATCH v3 08/16] virsh: report the D-Bus bus URI for domdisplay

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Wed Dec 22 19:43:37 UTC 2021


From: Marc-André Lureau <marcandre.lureau at redhat.com>

This implementation reports only Unix bus address using the URI format
proposed in https://gitlab.freedesktop.org/dbus/dbus/-/issues/348.

We prefer a URI form over the D-Bus address form, since all other
display protocols use a URI, allowing to distinguish between protocols
and making client implementation simpler.

Other transports (for example TCP) are not yet handled.

The client is assumed to know what to lookup on the bus (the bus name,
path & interface of the VM, eventually matching its UUID)

P2P mode doesn't report any available URI.

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 tools/virsh-domain.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 002cfc4be6af..00ed07a02cb4 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -11497,7 +11497,7 @@ static const vshCmdOptDef opts_domdisplay[] = {
     {.name = "type",
      .type = VSH_OT_STRING,
      .help = N_("select particular graphical display "
-                "(e.g. \"vnc\", \"spice\", \"rdp\")")
+                "(e.g. \"vnc\", \"spice\", \"rdp\", \"dbus\")")
     },
     {.name = "all",
      .type = VSH_OT_BOOL,
@@ -11506,6 +11506,26 @@ static const vshCmdOptDef opts_domdisplay[] = {
     {.name = NULL}
 };
 
+static bool
+cmdDomDisplayDBus(vshControl *ctl, xmlXPathContext *ctxt, virBuffer *buf)
+{
+    g_autofree char *addr = NULL;
+    const char *xpath = "string(/domain/devices/graphics[@type='dbus']/@address)";
+
+    addr = virXPathString(xpath, ctxt);
+    if (!addr)
+        return false;
+
+    if (STRPREFIX(addr, "unix:path=")) {
+        virBufferAsprintf(buf, "dbus+unix://%s", addr + 10);
+    } else {
+        vshError(ctl, _("'%s' D-Bus address is not handled"), addr);
+        return false;
+    }
+
+    return true;
+}
+
 static bool
 cmdDomDisplayScheme(vshControl *ctl, const char *scheme,
                     xmlXPathContext *ctxt, virBuffer *buf)
@@ -11521,6 +11541,9 @@ cmdDomDisplayScheme(vshControl *ctl, const char *scheme,
     bool params = false;
     int tmp;
 
+    if (STREQ(scheme, "dbus"))
+        return cmdDomDisplayDBus(ctl, ctxt, buf);
+
     /* Create our XPATH lookup for the current display's port */
     xpath = g_strdup_printf(xpath_fmt, scheme, "@port");
 
@@ -11681,7 +11704,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     g_autofree char *output = NULL;
     bool ret = false;
-    const char *scheme[] = { "vnc", "spice", "rdp", NULL };
+    const char *scheme[] = { "vnc", "spice", "rdp", "dbus", NULL };
     const char *type = NULL;
     int iter = 0;
     int flags = 0;
-- 
2.34.1.8.g35151cf07204




More information about the libvir-list mailing list