[libvirt] [PATCH v2] tools: virsh: Adding unix socket support to 'domdisplay' command.

Julio Faracco posted 1 patch 6 years, 8 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/1501278575-22627-1-git-send-email-jcfaracco@gmail.com
tools/virsh-domain.c | 52 +++++++++++++++++++++++++++++++++++++++++-----------
1 file changed, 41 insertions(+), 11 deletions(-)
[libvirt] [PATCH v2] tools: virsh: Adding unix socket support to 'domdisplay' command.
Posted by Julio Faracco 6 years, 8 months ago
This commit adds the unix socket URL support to 'domdisplay' command.
Before, even if an user was using unix socket to define a spice graphics,
the command 'domdisplay' showed that the settings were not supported. Now,
the command shows the proper URL: spice+unix://foo/bar.sock.

Settings:
<graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
  <listen type='address' address='127.0.0.1'/>
</graphics>
<graphics type='spice'>
  <listen type='socket' socket='/tmp/spice.sock'/>
</graphics>

Before:
virsh # domdisplay --all Windows7
vnc://127.0.0.1:0

After:
virsh # domdisplay --all Windows7
vnc://127.0.0.1:0
spice+unix:///tmp/spice.sock

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1336720

Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
---
 tools/virsh-domain.c | 52 +++++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 41 insertions(+), 11 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 0684979..935ef8a 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -10948,6 +10948,8 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
     char *xpath = NULL;
     char *listen_addr = NULL;
     int port, tls_port = 0;
+    char *type_conn = NULL;
+    char *socket = NULL;
     char *passwd = NULL;
     char *output = NULL;
     const char *scheme[] = { "vnc", "spice", "rdp", NULL };
@@ -11008,9 +11010,6 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         if (tmp)
             tls_port = 0;
 
-        if (!port && !tls_port)
-            continue;
-
         /* Create our XPATH lookup for the current display's address */
         if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "@listen") < 0)
             goto cleanup;
@@ -11021,6 +11020,29 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         listen_addr = virXPathString(xpath, ctxt);
         VIR_FREE(xpath);
 
+        /* Create our XPATH lookup for the current spice type. */
+        if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@type") < 0)
+            goto cleanup;
+
+        /* Attempt to get the type of spice connection */
+        VIR_FREE(type_conn);
+        type_conn = virXPathString(xpath, ctxt);
+        VIR_FREE(xpath);
+
+        if (STREQ_NULLABLE(type_conn, "socket")) {
+            if (!socket) {
+                if (virAsprintf(&xpath, xpath_fmt, scheme[iter], "listen/@socket") < 0)
+                    goto cleanup;
+
+                socket = virXPathString(xpath, ctxt);
+
+                VIR_FREE(xpath);
+            }
+        }
+
+        if (!port && !tls_port && !socket)
+            continue;
+
         if (!listen_addr) {
             /* The subelement address - <listen address='xyz'/> -
              * *should* have been automatically backfilled into its
@@ -11035,11 +11057,9 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 
             listen_addr = virXPathString(xpath, ctxt);
             VIR_FREE(xpath);
-        }
-
-        /* If listen_addr is 0.0.0.0 or [::] we should try to parse URI and set
-         * listen_addr based on current URI. */
-        if (listen_addr) {
+        } else {
+            /* If listen_addr is 0.0.0.0 or [::] we should try to parse URI and set
+             * listen_addr based on current URI. */
             if (virSocketAddrParse(&addr, listen_addr, AF_UNSPEC) > 0 &&
                 virSocketAddrIsWildcard(&addr)) {
 
@@ -11078,20 +11098,28 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
         VIR_FREE(xpath);
 
         /* Build up the full URI, starting with the scheme */
-        virBufferAsprintf(&buf, "%s://", scheme[iter]);
+        if (socket)
+            virBufferAsprintf(&buf, "%s+unix://", scheme[iter]);
+        else
+            virBufferAsprintf(&buf, "%s://", scheme[iter]);
 
         /* There is no user, so just append password if there's any */
         if (STREQ(scheme[iter], "vnc") && passwd)
             virBufferAsprintf(&buf, ":%s@", passwd);
 
         /* Then host name or IP */
-        if (!listen_addr)
+        if (!listen_addr && !socket)
             virBufferAddLit(&buf, "localhost");
-        else if (strchr(listen_addr, ':'))
+        else if (!socket && strchr(listen_addr, ':'))
             virBufferAsprintf(&buf, "[%s]", listen_addr);
+        else if (socket)
+            virBufferAsprintf(&buf, "%s", socket);
         else
             virBufferAsprintf(&buf, "%s", listen_addr);
 
+        /* Free socket to prepare the pointer for the next iteration */
+        VIR_FREE(socket);
+
         /* Add the port */
         if (port) {
             if (STREQ(scheme[iter], "vnc")) {
@@ -11148,6 +11176,8 @@ cmdDomDisplay(vshControl *ctl, const vshCmd *cmd)
 
  cleanup:
     VIR_FREE(xpath);
+    VIR_FREE(type_conn);
+    VIR_FREE(socket);
     VIR_FREE(passwd);
     VIR_FREE(listen_addr);
     VIR_FREE(output);
-- 
2.7.4

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] tools: virsh: Adding unix socket support to 'domdisplay' command.
Posted by Michal Privoznik 6 years, 8 months ago
On 07/28/2017 11:49 PM, Julio Faracco wrote:
> This commit adds the unix socket URL support to 'domdisplay' command.
> Before, even if an user was using unix socket to define a spice graphics,
> the command 'domdisplay' showed that the settings were not supported. Now,
> the command shows the proper URL: spice+unix://foo/bar.sock.
> 
> Settings:
> <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
>   <listen type='address' address='127.0.0.1'/>
> </graphics>
> <graphics type='spice'>
>   <listen type='socket' socket='/tmp/spice.sock'/>
> </graphics>
> 
> Before:
> virsh # domdisplay --all Windows7
> vnc://127.0.0.1:0
> 
> After:
> virsh # domdisplay --all Windows7
> vnc://127.0.0.1:0
> spice+unix:///tmp/spice.sock
> 
> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1336720
> 
> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
> ---
>  tools/virsh-domain.c | 52 +++++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 41 insertions(+), 11 deletions(-)

Looks good. ACK. I'll push it after the release.

Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v2] tools: virsh: Adding unix socket support to 'domdisplay' command.
Posted by Julio Faracco 6 years, 8 months ago
Thanks, Michal!

2017-07-31 5:48 GMT-03:00 Michal Privoznik <mprivozn@redhat.com>:
> On 07/28/2017 11:49 PM, Julio Faracco wrote:
>> This commit adds the unix socket URL support to 'domdisplay' command.
>> Before, even if an user was using unix socket to define a spice graphics,
>> the command 'domdisplay' showed that the settings were not supported. Now,
>> the command shows the proper URL: spice+unix://foo/bar.sock.
>>
>> Settings:
>> <graphics type='vnc' port='-1' autoport='yes' listen='127.0.0.1'>
>>   <listen type='address' address='127.0.0.1'/>
>> </graphics>
>> <graphics type='spice'>
>>   <listen type='socket' socket='/tmp/spice.sock'/>
>> </graphics>
>>
>> Before:
>> virsh # domdisplay --all Windows7
>> vnc://127.0.0.1:0
>>
>> After:
>> virsh # domdisplay --all Windows7
>> vnc://127.0.0.1:0
>> spice+unix:///tmp/spice.sock
>>
>> Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1336720
>>
>> Signed-off-by: Julio Faracco <jcfaracco@gmail.com>
>> ---
>>  tools/virsh-domain.c | 52 +++++++++++++++++++++++++++++++++++++++++-----------
>>  1 file changed, 41 insertions(+), 11 deletions(-)
>
> Looks good. ACK. I'll push it after the release.
>
> Michal

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list