From 60d92830c6c31d0ba286b0ff1e8a377e84b061ca Mon Sep 17 00:00:00 2001 From: Anthony PERARD Date: Mon, 20 Feb 2012 18:45:29 +0000 Subject: [PATCH] libxl: Set VNC password through QMP 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 Acked-by: Ian Campbell Committed-by: Ian Jackson --- tools/libxl/libxl_create.c | 2 +- tools/libxl/libxl_dm.c | 24 +++++++++++++++--------- tools/libxl/libxl_internal.h | 3 ++- tools/libxl/libxl_qmp.c | 30 +++++++++++++++++++++++++++++- 4 files changed, 47 insertions(+), 12 deletions(-) diff --git a/tools/libxl/libxl_create.c b/tools/libxl/libxl_create.c index 9148b26e81..deccf8827b 100644 --- a/tools/libxl/libxl_create.c +++ b/tools/libxl/libxl_create.c @@ -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) { diff --git a/tools/libxl/libxl_dm.c b/tools/libxl/libxl_dm.c index 9187a941cd..922b20b50a 100644 --- a/tools/libxl/libxl_dm.c +++ b/tools/libxl/libxl_dm.c @@ -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); diff --git a/tools/libxl/libxl_internal.h b/tools/libxl/libxl_internal.h index 7514ae30f4..46e131abc7 100644 --- a/tools/libxl/libxl_internal.h +++ b/tools/libxl/libxl_internal.h @@ -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 diff --git a/tools/libxl/libxl_qmp.c b/tools/libxl/libxl_qmp.c index 69d4d0517b..43fd134d8b 100644 --- a/tools/libxl/libxl_qmp.c +++ b/tools/libxl/libxl_qmp.c @@ -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; } -- 2.39.5