diff mbox series

[v4,2/3] qapi/ui: display-update: add possibility to change listen address

Message ID 20220210141457.539582-3-vsementsov@virtuozzo.com
State New
Headers show
Series qapi/ui: change vnc addresses | expand

Commit Message

Vladimir Sementsov-Ogievskiy Feb. 10, 2022, 2:14 p.m. UTC
Add possibility to change addresses where VNC server listens for new
connections. Prior to 6.0 this functionality was available through
'change' qmp command which was deleted.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 docs/about/removed-features.rst |  3 +-
 qapi/ui.json                    | 65 +++++++++++++++++++++++++++++++++
 include/ui/console.h            |  1 +
 monitor/qmp-cmds.c              | 15 ++++++++
 ui/vnc.c                        | 23 ++++++++++++
 5 files changed, 106 insertions(+), 1 deletion(-)

Comments

Daniel P. Berrangé Feb. 10, 2022, 2:32 p.m. UTC | #1
For $SUBJECT - i'd reword slightly

     qapi/ui: add 'display-update' command for changing listen address

On Thu, Feb 10, 2022 at 03:14:56PM +0100, Vladimir Sementsov-Ogievskiy wrote:
> Add possibility to change addresses where VNC server listens for new
> connections. Prior to 6.0 this functionality was available through
> 'change' qmp command which was deleted.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  docs/about/removed-features.rst |  3 +-
>  qapi/ui.json                    | 65 +++++++++++++++++++++++++++++++++
>  include/ui/console.h            |  1 +
>  monitor/qmp-cmds.c              | 15 ++++++++
>  ui/vnc.c                        | 23 ++++++++++++
>  5 files changed, 106 insertions(+), 1 deletion(-)
> 
> diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst
> index 4c4da20d0f..63aba60873 100644
> --- a/docs/about/removed-features.rst
> +++ b/docs/about/removed-features.rst
> @@ -355,7 +355,8 @@ documentation of ``query-hotpluggable-cpus`` for additional details.
>  ``change`` (removed in 6.0)
>  '''''''''''''''''''''''''''
>  
> -Use ``blockdev-change-medium`` or ``change-vnc-password`` instead.
> +Use ``blockdev-change-medium`` or ``change-vnc-password`` or
> +``display-update`` instead.
>  
>  ``query-events`` (removed in 6.0)
>  '''''''''''''''''''''''''''''''''
> diff --git a/qapi/ui.json b/qapi/ui.json
> index 9354f4c467..a0851eeefa 100644
> --- a/qapi/ui.json
> +++ b/qapi/ui.json
> @@ -1334,3 +1334,68 @@
>  { 'command': 'display-reload',
>    'data': 'DisplayReloadOptions',
>    'boxed' : true }
> +
> +##
> +# @DisplayUpdateType:
> +#
> +# Available DisplayUpdate types.
> +#
> +# @vnc: VNC display
> +#
> +# Since: 7.0
> +#
> +##
> +{ 'enum': 'DisplayUpdateType',
> +  'data': ['vnc'] }
> +
> +##
> +# @DisplayUpdateOptionsVNC:
> +#
> +# Specify the VNC reload options.
> +#
> +# @addresses: If specified, change set of addresses
> +#             to listen for connections. Addresses configured
> +#             for websockets are not touched.
> +#
> +# Since: 7.0
> +#
> +##
> +{ 'struct': 'DisplayUpdateOptionsVNC',
> +  'data': { '*addresses': ['SocketAddress'] } }
> +
> +##
> +# @DisplayUpdateOptions:
> +#
> +# Options of the display configuration reload.
> +#
> +# @type: Specify the display type.
> +#
> +# Since: 7.0
> +#
> +##
> +{ 'union': 'DisplayUpdateOptions',
> +  'base': {'type': 'DisplayUpdateType'},
> +  'discriminator': 'type',
> +  'data': { 'vnc': 'DisplayUpdateOptionsVNC' } }
> +
> +##
> +# @display-update:
> +#
> +# Update display configuration.
> +#
> +# Returns: Nothing on success.
> +#
> +# Since: 7.0
> +#
> +# Example:
> +#
> +# -> { "execute": "display-reload",

typo   s/reload/update/


With the minor tweaks

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


Regards,
Daniel
diff mbox series

Patch

diff --git a/docs/about/removed-features.rst b/docs/about/removed-features.rst
index 4c4da20d0f..63aba60873 100644
--- a/docs/about/removed-features.rst
+++ b/docs/about/removed-features.rst
@@ -355,7 +355,8 @@  documentation of ``query-hotpluggable-cpus`` for additional details.
 ``change`` (removed in 6.0)
 '''''''''''''''''''''''''''
 
-Use ``blockdev-change-medium`` or ``change-vnc-password`` instead.
+Use ``blockdev-change-medium`` or ``change-vnc-password`` or
+``display-update`` instead.
 
 ``query-events`` (removed in 6.0)
 '''''''''''''''''''''''''''''''''
diff --git a/qapi/ui.json b/qapi/ui.json
index 9354f4c467..a0851eeefa 100644
--- a/qapi/ui.json
+++ b/qapi/ui.json
@@ -1334,3 +1334,68 @@ 
 { 'command': 'display-reload',
   'data': 'DisplayReloadOptions',
   'boxed' : true }
+
+##
+# @DisplayUpdateType:
+#
+# Available DisplayUpdate types.
+#
+# @vnc: VNC display
+#
+# Since: 7.0
+#
+##
+{ 'enum': 'DisplayUpdateType',
+  'data': ['vnc'] }
+
+##
+# @DisplayUpdateOptionsVNC:
+#
+# Specify the VNC reload options.
+#
+# @addresses: If specified, change set of addresses
+#             to listen for connections. Addresses configured
+#             for websockets are not touched.
+#
+# Since: 7.0
+#
+##
+{ 'struct': 'DisplayUpdateOptionsVNC',
+  'data': { '*addresses': ['SocketAddress'] } }
+
+##
+# @DisplayUpdateOptions:
+#
+# Options of the display configuration reload.
+#
+# @type: Specify the display type.
+#
+# Since: 7.0
+#
+##
+{ 'union': 'DisplayUpdateOptions',
+  'base': {'type': 'DisplayUpdateType'},
+  'discriminator': 'type',
+  'data': { 'vnc': 'DisplayUpdateOptionsVNC' } }
+
+##
+# @display-update:
+#
+# Update display configuration.
+#
+# Returns: Nothing on success.
+#
+# Since: 7.0
+#
+# Example:
+#
+# -> { "execute": "display-reload",
+#      "arguments": { "type": "vnc", "addresses":
+#                     [ { "type": "inet", "host": "0.0.0.0",
+#                         "port": "5901" } ] } }
+# <- { "return": {} }
+#
+##
+{ 'command': 'display-update',
+  'data': 'DisplayUpdateOptions',
+  'boxed' : true }
diff --git a/include/ui/console.h b/include/ui/console.h
index f590819880..45f2ed4e2c 100644
--- a/include/ui/console.h
+++ b/include/ui/console.h
@@ -513,6 +513,7 @@  int vnc_display_pw_expire(const char *id, time_t expires);
 void vnc_parse(const char *str);
 int vnc_init_func(void *opaque, QemuOpts *opts, Error **errp);
 bool vnc_display_reload_certs(const char *id,  Error **errp);
+bool vnc_display_update(DisplayUpdateOptionsVNC *arg, Error **errp);
 
 /* input.c */
 int index_from_key(const char *key, size_t key_length);
diff --git a/monitor/qmp-cmds.c b/monitor/qmp-cmds.c
index db4d186448..246c8c1202 100644
--- a/monitor/qmp-cmds.c
+++ b/monitor/qmp-cmds.c
@@ -368,6 +368,21 @@  void qmp_display_reload(DisplayReloadOptions *arg, Error **errp)
     }
 }
 
+void qmp_display_update(DisplayUpdateOptions *arg, Error **errp)
+{
+    switch (arg->type) {
+    case DISPLAY_UPDATE_TYPE_VNC:
+#ifdef CONFIG_VNC
+        vnc_display_update(&arg->u.vnc, errp);
+#else
+        error_setg(errp, "vnc is invalid, missing 'CONFIG_VNC'");
+#endif
+        break;
+    default:
+        abort();
+    }
+}
+
 static int qmp_x_query_rdma_foreach(Object *obj, void *opaque)
 {
     RdmaProvider *rdma;
diff --git a/ui/vnc.c b/ui/vnc.c
index fa0fb736d3..c57146d9f8 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -3973,6 +3973,29 @@  static int vnc_display_listen(VncDisplay *vd,
     return 0;
 }
 
+bool vnc_display_update(DisplayUpdateOptionsVNC *arg, Error **errp)
+{
+    VncDisplay *vd = vnc_display_find(NULL);
+
+    if (!vd) {
+        error_setg(errp, "Can not find vnc display");
+        return false;
+    }
+
+    if (arg->has_addresses) {
+        if (vd->listener) {
+            qio_net_listener_disconnect(vd->listener);
+            object_unref(OBJECT(vd->listener));
+            vd->listener = NULL;
+        }
+
+        if (vnc_display_listen(vd, arg->addresses, NULL, errp) < 0) {
+            return false;
+        }
+    }
+
+    return true;
+}
 
 void vnc_display_open(const char *id, Error **errp)
 {