[libvirt] [PATCH] qemu: handle missing bind host/service on chardev hotplug

Ján Tomko posted 1 patch 6 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/9ac0be0b61ac1b50ee0cb8ae414de6266035e1b8.1495194201.git.jtomko@redhat.com
src/qemu/qemu_monitor_json.c | 13 ++++++++++---
tests/qemumonitorjsontest.c  | 11 +++++++++++
2 files changed, 21 insertions(+), 3 deletions(-)
[libvirt] [PATCH] qemu: handle missing bind host/service on chardev hotplug
Posted by Ján Tomko 6 years, 11 months ago
On domain startup, bind host or bind service can be omitted
and we will format a working command line.

Extend this to hotplug as well and specify the service to QEMU
even if the host is missing.

https://bugzilla.redhat.com/show_bug.cgi?id=1452441
---
 src/qemu/qemu_monitor_json.c | 13 ++++++++++---
 tests/qemumonitorjsontest.c  | 11 +++++++++++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 0837290..ca9bb14 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6429,6 +6429,8 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
     virJSONValuePtr data = NULL;
     virJSONValuePtr addr = NULL;
     const char *backend_type = NULL;
+    const char *host;
+    const char *port;
     char *tlsalias = NULL;
     bool telnet;
 
@@ -6492,9 +6494,14 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
             virJSONValueObjectAppend(data, "remote", addr) < 0)
             goto error;
 
-        if (chr->data.udp.bindHost) {
-            addr = qemuMonitorJSONBuildInetSocketAddress(chr->data.udp.bindHost,
-                                                         chr->data.udp.bindService);
+        host = chr->data.udp.bindHost;
+        port = chr->data.udp.bindService;
+        if (host || port) {
+            if (!host)
+                host = "";
+            if (!port)
+                port = "";
+            addr = qemuMonitorJSONBuildInetSocketAddress(host, port);
             if (!addr ||
                 virJSONValueObjectAppend(data, "local", addr) < 0)
                 goto error;
diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
index e9f9d47..3de901c 100644
--- a/tests/qemumonitorjsontest.c
+++ b/tests/qemumonitorjsontest.c
@@ -895,6 +895,17 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt)
                                        "'data':{'host':'localhost',"
                                                "'port':'4321'}}}}}");
 
+    chr.data.udp.bindHost = NULL;
+    chr.data.udp.bindService = (char *) "4321";
+    CHECK("udp", false,
+          "{'id':'alias',"
+           "'backend':{'type':'udp',"
+                      "'data':{'remote':{'type':'inet',"
+                                        "'data':{'host':'example.com',"
+                                                "'port':'1234'}},"
+                              "'local':{'type':'inet',"
+                                       "'data':{'host':'',"
+                                               "'port':'4321'}}}}}");
     memset(&chr, 0, sizeof(chr));
     chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
     chr.data.nix.path = (char *) "/path/to/socket";
-- 
2.10.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: handle missing bind host/service on chardev hotplug
Posted by John Ferlan 6 years, 10 months ago

On 05/19/2017 07:43 AM, Ján Tomko wrote:
> On domain startup, bind host or bind service can be omitted
> and we will format a working command line.
> 
> Extend this to hotplug as well and specify the service to QEMU
> even if the host is missing.
> 
> https://bugzilla.redhat.com/show_bug.cgi?id=1452441
> ---
>  src/qemu/qemu_monitor_json.c | 13 ++++++++++---
>  tests/qemumonitorjsontest.c  | 11 +++++++++++
>  2 files changed, 21 insertions(+), 3 deletions(-)
> 
> diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
> index 0837290..ca9bb14 100644
> --- a/src/qemu/qemu_monitor_json.c
> +++ b/src/qemu/qemu_monitor_json.c
> @@ -6429,6 +6429,8 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
>      virJSONValuePtr data = NULL;
>      virJSONValuePtr addr = NULL;
>      const char *backend_type = NULL;
> +    const char *host;
> +    const char *port;
>      char *tlsalias = NULL;
>      bool telnet;
>  
> @@ -6492,9 +6494,14 @@ qemuMonitorJSONAttachCharDevCommand(const char *chrID,
>              virJSONValueObjectAppend(data, "remote", addr) < 0)
>              goto error;
>  
> -        if (chr->data.udp.bindHost) {
> -            addr = qemuMonitorJSONBuildInetSocketAddress(chr->data.udp.bindHost,
> -                                                         chr->data.udp.bindService);
> +        host = chr->data.udp.bindHost;
> +        port = chr->data.udp.bindService;
> +        if (host || port) {
> +            if (!host)
> +                host = "";
> +            if (!port)
> +                port = "";

I believe port should be "0" instead of ""

Also, it seems connectHost could be NULL too, how does that affect the
qemuMonitorJSONBuildInetSocketAddress a few lines earlier?

FWIW: Questions are from reading the qemuBuildChrChardevStr /
qemuBuildChrArgStr code and the libxl_conf.c implementation...


ACK, if you fix or shall I say...

Reviewed-by: John Ferlan <jferlan@redhat.com>

and IDC if that's added to the committed code (it's my attempt to
conform to something new, AKA teach an old dog new tricks).


John

> +            addr = qemuMonitorJSONBuildInetSocketAddress(host, port);
>              if (!addr ||
>                  virJSONValueObjectAppend(data, "local", addr) < 0)
>                  goto error;
> diff --git a/tests/qemumonitorjsontest.c b/tests/qemumonitorjsontest.c
> index e9f9d47..3de901c 100644
> --- a/tests/qemumonitorjsontest.c
> +++ b/tests/qemumonitorjsontest.c
> @@ -895,6 +895,17 @@ qemuMonitorJSONTestAttachChardev(virDomainXMLOptionPtr xmlopt)
>                                         "'data':{'host':'localhost',"
>                                                 "'port':'4321'}}}}}");
>  
> +    chr.data.udp.bindHost = NULL;
> +    chr.data.udp.bindService = (char *) "4321";
> +    CHECK("udp", false,
> +          "{'id':'alias',"
> +           "'backend':{'type':'udp',"
> +                      "'data':{'remote':{'type':'inet',"
> +                                        "'data':{'host':'example.com',"
> +                                                "'port':'1234'}},"
> +                              "'local':{'type':'inet',"
> +                                       "'data':{'host':'',"
> +                                               "'port':'4321'}}}}}");
>      memset(&chr, 0, sizeof(chr));
>      chr.type = VIR_DOMAIN_CHR_TYPE_UNIX;
>      chr.data.nix.path = (char *) "/path/to/socket";
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH] qemu: handle missing bind host/service on chardev hotplug
Posted by Ján Tomko 6 years, 9 months ago
On Mon, Jun 12, 2017 at 07:08:50AM -0400, John Ferlan wrote:
>Also, it seems connectHost could be NULL too, how does that affect the
>qemuMonitorJSONBuildInetSocketAddress a few lines earlier?
>
>FWIW: Questions are from reading the qemuBuildChrChardevStr /
>qemuBuildChrArgStr code and the libxl_conf.c implementation...
>

Missing connectHost is not addressed by this patch.
It seems QEMU can automatically fill in "localhost", when the host
is missing, but currently this does not work on a fresh domain start
etiher:

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

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