xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Anthony PERARD <anthony.perard@citrix.com>
To: Xen Devel <xen-devel@lists.xensource.com>
Cc: Anthony PERARD <anthony.perard@citrix.com>,
	Stefano Stabellini <stefano.stabellini@eu.citrix.com>
Subject: [PATCH] libxl: Set VNC password through QMP
Date: Wed, 8 Feb 2012 11:49:58 +0000	[thread overview]
Message-ID: <1328701798-30808-1-git-send-email-anthony.perard@citrix.com> (raw)

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>

---
 tools/libxl/libxl_create.c   |    3 +++
 tools/libxl/libxl_dm.c       |   21 ++++++++++++---------
 tools/libxl/libxl_internal.h |    1 +
 tools/libxl/libxl_qmp.c      |   37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 53 insertions(+), 9 deletions(-)

diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c
index ebf2ed7..ae0d668 100644
--- a/tools/libxl/libxl_create.c
+++ b/tools/libxl/libxl_create.c
@@ -619,6 +619,9 @@ static int do_domain_create(libxl__gc *gc, libxl_domain_config *d_config,
         if (dm_info->device_model_version
             == LIBXL_DEVICE_MODEL_VERSION_QEMU_XEN) {
             libxl__qmp_initializations(ctx, domid);
+            if (dm_info->vncpasswd) {
+                libxl__qmp_vnc_password(gc, domid, dm_info->vncpasswd);
+            }
         }
         ret = libxl__confirm_device_model_startup(gc, dm_info, dm_starting);
         if (ret < 0) {
diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c
index 97d91b4..6f7d0d5 100644
--- a/tools/libxl/libxl_dm.c
+++ b/tools/libxl/libxl_dm.c
@@ -271,10 +271,8 @@ static char ** libxl__build_device_model_args_new(libxl__gc *gc,
     if (info->vnc) {
         int display = 0;
         const char *listen = "127.0.0.1";
+        char *vncarg = NULL;
 
-        if (info->vncpasswd && info->vncpasswd[0]) {
-            assert(!"missing code for supplying vnc password to qemu");
-        }
         flexarray_append(dm_args, "-vnc");
 
         if (info->vncdisplay) {
@@ -287,13 +285,16 @@ 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,
-                        info->vncunused ? ",to=99" : ""));
+            vncarg = libxl__sprintf(gc, "%s", listen);
         else
-            flexarray_append(dm_args,
-                    libxl__sprintf(gc, "%s:%d%s", listen, display,
-                        info->vncunused ? ",to=99" : ""));
+            vncarg = libxl__sprintf(gc, "%s:%d", listen, display);
+        if (info->vncpasswd && info->vncpasswd[0]) {
+            vncarg = libxl__sprintf(gc, "%s,password", vncarg);
+        }
+        if (info->vncunused) {
+            vncarg = libxl__sprintf(gc, "%s,to=99", vncarg);
+        }
+        flexarray_append(dm_args, vncarg);
     }
     if (info->sdl) {
         flexarray_append(dm_args, "-sdl");
@@ -862,6 +863,8 @@ int libxl__create_device_model(libxl__gc *gc,
     }
 
     if (info->vncpasswd) {
+        /* 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);
diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h
index fa7fb16..b33be99 100644
--- a/tools/libxl/libxl_internal.h
+++ b/tools/libxl/libxl_internal.h
@@ -592,6 +592,7 @@ _hidden int libxl__qmp_pci_del(libxl__gc *gc, int domid,
                                libxl_device_pci *pcidev);
 /* Save current QEMU state into fd. */
 _hidden int libxl__qmp_migrate(libxl__gc *gc, int domid, int fd);
+_hidden int libxl__qmp_vnc_password(libxl__gc *gc, int domid, char *password);
 /* close and free the QMP handler */
 _hidden void libxl__qmp_close(libxl__qmp_handler *qmp);
 /* remove the socket file, if the file has already been removed,
diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c
index 1777e44..274db19 100644
--- a/tools/libxl/libxl_qmp.c
+++ b/tools/libxl/libxl_qmp.c
@@ -879,6 +879,43 @@ out:
     return rc;
 }
 
+static int qmp_change(libxl__gc *gc, int domid,
+                      char *device, char *target, char *arg)
+{
+    libxl__qmp_handler *qmp = NULL;
+    flexarray_t *parameters = NULL;
+    libxl_key_value_list args = NULL;
+    int rc = 0;
+
+    qmp = libxl__qmp_initialize(libxl__gc_owner(gc), domid);
+    if (!qmp)
+        return ERROR_FAIL;
+
+    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);
+    libxl__qmp_close(qmp);
+    return rc;
+}
+
+int libxl__qmp_vnc_password(libxl__gc *gc, int domid, char *password)
+{
+    if (!password)
+        return ERROR_FAIL;
+
+    return qmp_change(gc, domid, "vnc", "password", password);
+}
+
 int libxl__qmp_initializations(libxl_ctx *ctx, uint32_t domid)
 {
     libxl__qmp_handler *qmp = NULL;
-- 
tg: (6674c38..) qmp-vnc-password (depends on: master)

             reply	other threads:[~2012-02-08 11:49 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-08 11:49 Anthony PERARD [this message]
2012-02-08 16:47 ` [PATCH] libxl: Set VNC password through QMP Ian Campbell
2012-02-08 17:24   ` Anthony PERARD
2012-02-09  6:28     ` Ian Campbell
2012-02-09 10:58       ` Anthony PERARD
2012-02-09 11:17         ` Ian Campbell
2012-02-09 13:15           ` chris
2012-02-09 13:45             ` Anthony PERARD

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1328701798-30808-1-git-send-email-anthony.perard@citrix.com \
    --to=anthony.perard@citrix.com \
    --cc=stefano.stabellini@eu.citrix.com \
    --cc=xen-devel@lists.xensource.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).