]> xenbits.xensource.com Git - people/vhanquez/xen.git/commitdiff
libxl: Set VNC password through QMP
authorAnthony PERARD <anthony.perard@citrix.com>
Mon, 20 Feb 2012 18:45:29 +0000 (18:45 +0000)
committerAnthony PERARD <anthony.perard@citrix.com>
Mon, 20 Feb 2012 18:45:29 +0000 (18:45 +0000)
This patch provide the code to set the VNC password to QEMU upstream through
VNC. The password is still stored in xenstore but will not be used by QEMU
upstream.

Signed-off-by: Anthony PERARD <anthony.perard@citrix.com>
Acked-by: Ian Campbell <ian.campbell.com>
Committed-by: Ian Jackson <ian.jackson.citrix.com>
tools/libxl/libxl_create.c
tools/libxl/libxl_dm.c
tools/libxl/libxl_internal.h
tools/libxl/libxl_qmp.c

index 9148b26e810beee213e298169a6a9d8f8e8d972d..deccf8827bdeb410a59c20ab7d26034ad2eea01d 100644 (file)
@@ -594,7 +594,7 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
     if (dm_starting) {
         if (d_config->b_info.device_model_version
             == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
-            libxl__qmp_initializations(gc, domid);
+            libxl__qmp_initializations(gc, domid, d_config);
         }
         ret = libxl__confirm_device_model_startup(gc, &state, dm_starting);
         if (ret < 0) {
index 9187a941cd29b6a05c04dbc65992cc9af8e32cda..922b20b50a573ef9927a47bd688a21ced606e1bc 100644 (file)
@@ -361,10 +361,8 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
     if (vnc) {
         int display = 0;
         const char *listen = "127.0.0.1";
+        char *vncarg = NULL;
 
-        if (vnc->passwd && vnc->passwd[0]) {
-            assert(!"missing code for supplying vnc password to qemu");
-        }
         flexarray_append(dm_args, "-vnc");
 
         if (vnc->display) {
@@ -377,13 +375,19 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
         }
 
         if (strchr(listen, ':') != NULL)
-            flexarray_append(dm_args,
-                    libxl__sprintf(gc, "%s%s", listen,
-                        vnc->findunused ? ",to=99" : ""));
+            vncarg = libxl__sprintf(gc, "%s", listen);
         else
-            flexarray_append(dm_args,
-                    libxl__sprintf(gc, "%s:%d%s", listen, display,
-                        vnc->findunused ? ",to=99" : ""));
+            vncarg = libxl__sprintf(gc, "%s:%d", listen, display);
+        if (vnc->passwd && vnc->passwd[0]) {
+            vncarg = libxl__sprintf(gc, "%s,password", vncarg);
+        }
+        if (vnc->findunused) {
+            /* This option asks to QEMU to try this number of port before to
+             * give up.  So QEMU will try ports between $display and $display +
+             * 99.  This option needs to be the last one of the vnc options. */
+            vncarg = libxl__sprintf(gc, "%s,to=99", vncarg);
+        }
+        flexarray_append(dm_args, vncarg);
     }
     if (sdl) {
         flexarray_append(dm_args, "-sdl");
@@ -965,6 +969,8 @@ int libxl__create_device_model(libxl__gc *gc,
     }
 
     if (vnc && vnc->passwd) {
+        /* This xenstore key will only be used by qemu-xen-traditionnal.
+         * The code to supply vncpasswd to qemu-xen is later. */
 retry_transaction:
         /* Find uuid and the write the vnc password to xenstore for qemu. */
         t = xs_transaction_start(ctx->xsh);
index 7514ae30f48b43f794f41bb2ba57d7f9839bf4dd..46e131abc71025cbfe11b02f01050211f7e2ffd7 100644 (file)
@@ -1013,7 +1013,8 @@ _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);
 _hidden void libxl__qmp_cleanup(libxl__gc *gc, uint32_t domid);
 
 /* this helper calls qmp_initialize, query_serial and qmp_close */
-_hidden int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid);
+_hidden int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
+                                       const libxl_domain_config *guest_config);
 
 /* from libxl_json */
 #include <yajl/yajl_gen.h>
index 69d4d0517bea9fc9a184ec24d3052866c307eaa4..43fd134d8b1f9caed8a34a1f8256130e0f9897f1 100644 (file)
@@ -880,8 +880,33 @@ out:
     return rc;
 }
 
-int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid)
+static int qmp_change(libxl__gc *gc, libxl__qmp_handler *qmp,
+                      char *device, char *target, char *arg)
 {
+    flexarray_t *parameters = NULL;
+    libxl_key_value_list args = NULL;
+    int rc = 0;
+
+    parameters = flexarray_make(6, 1);
+    flexarray_append_pair(parameters, "device", device);
+    flexarray_append_pair(parameters, "target", target);
+    if (arg)
+        flexarray_append_pair(parameters, "arg", arg);
+    args = libxl__xs_kvs_of_flexarray(gc, parameters, parameters->count);
+    if (!args)
+        return ERROR_NOMEM;
+
+    rc = qmp_synchronous_send(qmp, "change", &args,
+                              NULL, NULL, qmp->timeout);
+
+    flexarray_free(parameters);
+    return rc;
+}
+
+int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid,
+                               const libxl_domain_config *guest_config)
+{
+    const libxl_vnc_info *vnc = libxl__dm_vnc(guest_config);
     libxl__qmp_handler *qmp = NULL;
     int ret = 0;
 
@@ -889,6 +914,9 @@ int libxl__qmp_initializations(libxl__gc *gc, uint32_t domid)
     if (!qmp)
         return -1;
     ret = libxl__qmp_query_serial(qmp);
+    if (!ret && vnc && vnc->passwd) {
+        ret = qmp_change(gc, qmp, "vnc", "password", vnc->passwd);
+    }
     libxl__qmp_close(qmp);
     return ret;
 }