WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [PATCH] xen-upstream-qemu: get vncpassword through xenst

To: Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH] xen-upstream-qemu: get vncpassword through xenstore, enable VNC_AUTH_VNC
From: ZhouPeng <zpengxen@xxxxxxxxx>
Date: Thu, 21 Apr 2011 12:16:35 +0800
Cc: "Xen-Devel \(E-mail\)" <xen-devel@xxxxxxxxxxxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>, qemu-devel@xxxxxxxxxx
Delivery-date: Wed, 20 Apr 2011 21:17:34 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=K1fLigLbERH7nVvPKn/HI9sPY472nuSuOh+NPWj1yhY=; b=wNee/gR/cl0FrFYC7DsHyU2kuwMBiQrgVAVlZaWywCa00W6/TDi4wwm9lMYKIiPFF8 LqaVeWLXgQTkU8R2LMkoXrerJnzfGKldlHt/tfReznP0B/xR72KLLt4r0qCfdCCmzk2Z E6oW8hxeR3lujqnOweVeNkpARS2uDg4ybUJoE=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=wlDJevR5KuHc9lcm/Z5aXLC5eEWFuFa3ndjkbUPHLBJ521K29kDbS6HEyasXyKDhJA DlvE5c2JtGrmUFrN0etIiTkqh6orCCfnWMd95OIFglThNhuxBZ1M2HFaVgB0L0A6mIHO jgEKm/Nt/EcEHqzl65KOSRkEx0optsJPzREtc=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <alpine.DEB.2.00.1104201313530.10886@kaball-desktop>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
References: <BANLkTinEmMNVu5UMTz=h5R-pCrBMyi=0oQ@xxxxxxxxxxxxxx> <alpine.DEB.2.00.1104201313530.10886@kaball-desktop>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thank you for your review.

Does this means the xen-upsteam-qemu will give up xenstore?

Many features of xen except for vncpasswd
may need that xl send||receive msg to||from xen-qemu.
I think some other part of xen may need to read xenstore which may be
updated by qemu.
xenstore's sharing characteristic give much convenience for many-way
msg communication,
but the RPC may only give single-way.

So I am somewhat in doubt xen-upstream-qemu will give up xenstore.

IMO, I don't think qemu may accept xenstore's code only used by xen,

except
qemu need to add a new general shared many-way msg exchange mechanism,
like xenstore database.

Thank you Stefano Stabellini.

send the patch again to CC to qemu-devel@xxxxxxxxxx
=================================================================
This pacth allows you to use vncpasswd for xen-upstream-qemu

Signed-off-by: Zhou Peng <zhoupeng@xxxxxxxxxxxxxxx>

xen-upstream-qemu: get vncpassword through xenstore, enable VNC_AUTH_VNC

diff --git a/Makefile.objs b/Makefile.objs
index f8cf199..2a012bf 100644
--- a/Makefile.objs
+++ b/Makefile.objs
@@ -157,6 +157,8 @@ common-obj-$(CONFIG_SLIRP) += $(addprefix slirp/,
$(slirp-obj-y))
 common-obj-$(CONFIG_XEN) += xen_backend.o xen_devconfig.o
 common-obj-$(CONFIG_XEN) += xen_console.o xenfb.o xen_disk.o xen_nic.o

+common-obj-$(CONFIG_XEN) += xenstore.o
+
 ######################################################################
 # libuser

diff --git a/vl.c b/vl.c
index 60ec6de..b519690 100644
--- a/vl.c
+++ b/vl.c
@@ -163,6 +163,8 @@ int main(int argc, char **argv)

 #include "ui/qemu-spice.h"

+#include "xenstore.h"
+
 //#define DEBUG_NET
 //#define DEBUG_SLIRP

@@ -3321,7 +3323,11 @@ int main(int argc, char **argv, char **envp)
 #ifdef CONFIG_VNC
     /* init remote displays */
     if (vnc_display) {
+        char password[20];
         vnc_display_init(ds);
+        xenstore_read_vncpasswd(xen_domid, password, sizeof(password));
+        vnc_display_password(ds, password);
+
         if (vnc_display_open(ds, vnc_display) < 0)
             exit(1);

diff --git a/xenstore.c b/xenstore.c
new file mode 100644
index 0000000..0bb2a55
--- /dev/null
+++ b/xenstore.c
@@ -0,0 +1,154 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ *
+ * Copyright (C) 2006 Christian Limpach
+ * Copyright (C) 2006 XenSource Ltd.
+ * Copyright (C) 2011 Zhou Peng <zhoupeng@xxxxxxxxxxxxxxx>.
+ *
+ */
+
+#include "xenstore.h"
+#include <xs.h>
+
+struct xs_handle *xsh = NULL;
+static FILE *logfile = NULL;
+extern uint32_t xen_domid;
+
+static int pasprintf(char **buf, const char *fmt, ...)
+{
+    va_list ap;
+    int ret = 0;
+
+    if (*buf)
+        free(*buf);
+    va_start(ap, fmt);
+    if (vasprintf(buf, fmt, ap) == -1) {
+        buf = NULL;
+        ret = -1;
+    }
+    va_end(ap);
+    return ret;
+}
+
+static const char *xenstore_get_guest_uuid(void)
+{
+    static char *already_computed = NULL;
+
+    char *domain_path = NULL, *vm_path = NULL, *vm_value = NULL, *p = NULL;
+    unsigned int len;
+
+    if (already_computed)
+        return already_computed;
+
+    if (xsh == NULL)
+        return NULL;
+
+    domain_path = xs_get_domain_path(xsh, xen_domid);
+    if (domain_path == NULL) {
+        fprintf(logfile, "xs_get_domain_path() error. xen_domid
%d.\n", xen_domid);
+        goto out;
+    }
+
+    if (pasprintf(&vm_path, "%s/vm", domain_path) == -1) {
+        fprintf(logfile, "xenstore_get_guest_uuid(): out of memory.\n");
+        goto out;
+    }
+    vm_value = xs_read(xsh, XBT_NULL, vm_path, &len);
+    if (vm_value == NULL) {
+        fprintf(logfile, "xs_read(): uuid get error. %s.\n", vm_path);
+        goto out;
+    }
+
+    if (strtok(vm_value, "/") == NULL) {
+        fprintf(logfile, "failed to parse guest uuid\n");
+        goto out;
+    }
+    p = strtok(NULL, "/");
+    if (p == NULL) {
+        fprintf(logfile, "failed to parse guest uuid\n");
+        goto out;
+    }
+
+    if (pasprintf(&already_computed, "%s", p) == -1) {
+        fprintf(logfile, "xenstore_get_guest_uuid(): out of memory.\n");
+        goto out;
+    }
+
+    fprintf(logfile, "Guest uuid = %s\n", already_computed);
+
+ out:
+    free(domain_path);
+    free(vm_path);
+    free(vm_value);
+
+    return already_computed;
+}
+
+void xenstore_read_vncpasswd(int domid, char *pwbuf, size_t pwbuflen)
+{
+    char *buf = NULL, *path, *uuid = NULL, *passwd = NULL;
+    unsigned int i, len;
+
+    pwbuf[0] = '\0';
+
+    if (xsh == NULL)
+        return;
+
+    path = xs_get_domain_path(xsh, domid);
+    if (path == NULL) {
+        fprintf(logfile, "xs_get_domain_path() error. domid %d.\n", domid);
+        return;
+    }
+
+    pasprintf(&buf, "%s/vm", path);
+    free(path);
+    uuid = xs_read(xsh, XBT_NULL, buf, &len);
+    if (uuid == NULL) {
+        fprintf(logfile, "xs_read(): uuid get error. %s.\n", buf);
+        free(buf);
+        return;
+    }
+
+    pasprintf(&buf, "%s/vncpasswd", uuid);
+    free(uuid);
+    passwd = xs_read(xsh, XBT_NULL, buf, &len);
+    if (passwd == NULL) {
+        fprintf(logfile, "xs_read(): vncpasswd get error. %s.\n", buf);
+        free(buf);
+        return;
+    }
+
+    if (len >= pwbuflen)
+    {
+        fprintf(logfile,
+                "xenstore_read_vncpasswd(): truncated password to
avoid buffer overflow\n");
+        len = pwbuflen - 1;
+    }
+
+    for (i=0; i<len; i++)
+        pwbuf[i] = passwd[i];
+    pwbuf[len] = '\0';
+    passwd[0] = '\0';
+    if (xs_write(xsh, XBT_NULL, buf, passwd, 1) == 0)
+        fprintf(logfile, "xs_write() vncpasswd failed.\n");
+
+    free(passwd);
+    free(buf);
+}
+
+static void xenstore_init(void)
+{
+    logfile = stderr;
+
+    xenstore_get_guest_uuid();
+
+    xsh = xs_daemon_open();
+    if (xsh == NULL) {
+        fprintf(logfile, "Could not contact xenstore for domain config\n");
+        return;
+    }
+}
+
+device_init(xenstore_init);
diff --git a/xenstore.h b/xenstore.h
new file mode 100644
index 0000000..5242f2c
--- /dev/null
+++ b/xenstore.h
@@ -0,0 +1,15 @@
+/*
+ * This file is subject to the terms and conditions of the GNU General
+ * Public License.  See the file "COPYING" in the main directory of
+ * this archive for more details.
+ *
+ */
+
+#ifndef XEN_STORE_H
+#define XEN_STORE_H
+
+#include "qemu-common.h"
+
+void xenstore_read_vncpasswd(int domid, char *pwbuf, size_t pwbuflen);
+
+#endif /* XEN_STORE_H */

2011/4/20 Stefano Stabellini <stefano.stabellini@xxxxxxxxxxxxx>:
> On Wed, 20 Apr 2011, ZhouPeng wrote:
>> This pacth allows you to use vncpasswd for xen-upstream-qemu
>>
>> Signed-off-by: Zhou Peng <zhoupeng@xxxxxxxxxxxxxxx>
>>
>> xen-upstream-qemu: get vncpassword through xenstore, enable VNC_AUTH_VNC
>>
>
> This patch is for upstream qemu, right?

Yes, it's for xen-qemu-0.14.50 from Anthony's tree, very close to the
upstream qemu.

> In that case you always need to CC qemu-devel@xxxxxxxxxxx
> Also when submitting patches for upstream qemu we need to try to reuse
> the existing infrastructure to do things.
> In this particular example, we cannot use xenstore to communicate the
> password to qemu, we have to use QMP that is the RPC mechanism exported
> by Qemu. Unfortunately libxl doesn't speak QMP yet, but adding QMP
> support to libxl is one of the next things that have to be done anyway.
>
>

-- 
Zhou Peng
Operating System Technology Group
Institute of Software, the Chinese Academy of Sciences (ISCAS)

Attachment: xen-upstream-qemu-vncpassword-by-xenstore.diff
Description: Text Data

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel