]> xenbits.xensource.com Git - libvirt.git/commitdiff
virsh: report the D-Bus bus URI for domdisplay
authorMarc-André Lureau <marcandre.lureau@redhat.com>
Fri, 13 May 2022 18:38:14 +0000 (20:38 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Thu, 19 May 2022 10:36:24 +0000 (12:36 +0200)
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@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
tools/virsh-domain.c

index ba492e807ef6fdc7312733e48611a08240176b07..bac4cc0fb63c8d7fdbf9d368dba4fbbb38280e13 100644 (file)
@@ -11675,7 +11675,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,
@@ -11684,6 +11684,23 @@ static const vshCmdOptDef opts_domdisplay[] = {
     {.name = NULL}
 };
 
+static char *
+virshGetDBusDisplay(vshControl *ctl, xmlXPathContext *ctxt)
+{
+    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=")) {
+        return g_strdup_printf("dbus+unix://%s", addr + 10);
+    }
+
+    vshError(ctl, _("'%s' D-Bus address is not handled"), addr);
+    return NULL;
+}
 
 static char *
 virshGetOneDisplay(vshControl *ctl,
@@ -11704,6 +11721,9 @@ virshGetOneDisplay(vshControl *ctl,
     g_autofree char *sockpath = NULL;
     g_autofree char *passwd = NULL;
 
+    if (STREQ(scheme, "dbus"))
+        return virshGetDBusDisplay(ctl, ctxt);
+
     /* Attempt to get the port number for the current graphics scheme */
     xpathPort = g_strdup_printf(xpath_fmt, scheme, "@port");
 
@@ -11830,7 +11850,7 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autoptr(virshDomain) dom = 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;