Skip to contentSkip to conversation

ui: add support for remote power control to VNC server

PATCH In review Daniel P. Berrangé 2 participants 3 messages Dec 11, 2020 – Dec 15, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ui: add support for remote power control to VNC server

The "XVP" (Xen VNC Proxy) extension defines a mechanism for a VNC client to issue power control requests to trigger graceful shutdown, reboot, or hard reset.

This option is not enabled by default, since we cannot assume that users with VNC access implicitly have administrator access to the guest OS.

Thus is it enabled with a boolean "power-control" option e.g.

-vnc :1,power-control=on

While, QEMU can easily support shutdown and reset, there's no easy way to wire up reboot support at this time. In theory it could be done by issuing a shutdown, followed by a reset, but there's no convenient wiring for such a pairing in QEMU. It also isn't possible to have the VNC server directly talk to QEMU guest agent, since the agent chardev is typically owned by an external mgmt app.

---
 qemu-options.hx |  4 ++++
 ui/vnc.c        | 58 +++++++++++++++++++++++++++++++++++++++++++++++++
 ui/vnc.h        | 13 +++++++++++
 3 files changed, 75 insertions(+)
qemu-options.hx +4 -0
index 104632ea34..c009c4466e 100644
@@ -2215,6 +2215,10 @@ SRST
         transmission. When not using an -audiodev argument, this option
         must be omitted, otherwise is must be present and specify a
         valid audiodev.
+
+    ``power-control``
+        Permit the remote client to issue shutdown, reboot or reset power
+        control requests.
 ERST
 
 ARCHHEADING(, QEMU_ARCH_I386)
ui/vnc.c +58 -0

94 lines not on this page · raw message

ui/vnc.h +13 -0
index 4e2637ce6c..177380cb5e 100644
@@ -176,6 +176,7 @@ struct VncDisplay
     int ws_subauth; /* Used by websockets */
     bool lossy;
     bool non_adaptive;
+    bool power_control;
     QCryptoTLSCreds *tlscreds;
     QAuthZ *tlsauthz;
     char *tlsauthzid;
@@ -411,6 +412,7 @@ enum {
 #define VNC_ENCODING_AUDIO                0XFFFFFEFD /* -259 */
 #define VNC_ENCODING_TIGHT_PNG            0xFFFFFEFC /* -260 */
 #define VNC_ENCODING_LED_STATE            0XFFFFFEFB /* -261 */
+#define VNC_ENCODING_XVP                  0XFFFFFECB /* -309 */
 #define VNC_ENCODING_WMVi                 0x574D5669
 
 /*****************************************************************************
@@ -450,6 +452,7 @@ enum {
 #define VNC_FEATURE_ZRLE                     9
 #define VNC_FEATURE_ZYWRLE                  10
 #define VNC_FEATURE_LED_STATE               11
+#define VNC_FEATURE_XVP                     12
 
 #define VNC_FEATURE_RESIZE_MASK              (1 << VNC_FEATURE_RESIZE)
 #define VNC_FEATURE_HEXTILE_MASK             (1 << VNC_FEATURE_HEXTILE)
@@ -463,6 +466,7 @@ enum {
 #define VNC_FEATURE_ZRLE_MASK                (1 << VNC_FEATURE_ZRLE)
 #define VNC_FEATURE_ZYWRLE_MASK              (1 << VNC_FEATURE_ZYWRLE)
 #define VNC_FEATURE_LED_STATE_MASK           (1 << VNC_FEATURE_LED_STATE)
+#define VNC_FEATURE_XVP_MASK                 (1 << VNC_FEATURE_XVP)
 
 
 /* Client -> Server message IDs */
@@ -515,6 +519,15 @@ enum {
 #define VNC_MSG_SERVER_QEMU_AUDIO_BEGIN           1
 #define VNC_MSG_SERVER_QEMU_AUDIO_DATA            2
 
+/* XVP server -> client status code */
+#define VNC_XVP_CODE_FAIL 0
+#define VNC_XVP_CODE_INIT 1
+
+/* XVP client -> server action request  */
+#define VNC_XVP_ACTION_SHUTDOWN 2
+#define VNC_XVP_ACTION_REBOOT 3
+#define VNC_XVP_ACTION_RESET 4
+
 
 /*****************************************************************************
  *
Signature · 1 line
2.29.2
#1 lore raw
Quoted 3 lines · Daniel P. Berrangé

The "XVP" (Xen VNC Proxy) extension defines a mechanism for a VNC client to issue power control requests to trigger graceful shutdown, reboot, or hard reset.

Looks good. Any other clients are supporting this?

ui/vnc.c static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) · line 2401

Quoted 7 lines
ui/vnc.c +6 -0
+            case VNC_XVP_ACTION_REBOOT:
+                send_xvp_message(vs, VNC_XVP_CODE_FAIL);
+                break;
 
+            default:
+                send_xvp_message(vs, VNC_XVP_CODE_FAIL);
+                break;

Minor nit:

These two are identical, so you can drop the first.

take care,
Gerd

#2 lore raw
Quoted 6 lines · Gerd Hoffmann
Quoted 3 lines · Daniel P. Berrangé

The "XVP" (Xen VNC Proxy) extension defines a mechanism for a VNC client to issue power control requests to trigger graceful shutdown, reboot, or hard reset.

Looks good. Any other clients are supporting this?

AFAIK, it has only been implmeneted in the Xen VNC Proxy's own Java client. The extension is documented in rfbproto.rst and is trivial though, so I've now implemented the corresponding client side in GTK-VNC too.

Quoted 9 lines

ui/vnc.c static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len) · line 2401

Quoted 8 lines
ui/vnc.c +6 -0
+            case VNC_XVP_ACTION_REBOOT:
+                send_xvp_message(vs, VNC_XVP_CODE_FAIL);
+                break;
 
+            default:
+                send_xvp_message(vs, VNC_XVP_CODE_FAIL);
+                break;
Quoted 7 lines

Minor nit:

These two are identical, so you can drop the first.

take care,
Gerd

Regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|