From patchwork Fri Jan 8 21:47:14 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 42539 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 6C856B7C14 for ; Sat, 9 Jan 2010 08:56:39 +1100 (EST) Received: from localhost ([127.0.0.1]:37245 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NTMou-0006OB-Nx for incoming@patchwork.ozlabs.org; Fri, 08 Jan 2010 16:56:36 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1NTMgM-0002vM-3m for qemu-devel@nongnu.org; Fri, 08 Jan 2010 16:47:46 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1NTMgG-0002rd-KP for qemu-devel@nongnu.org; Fri, 08 Jan 2010 16:47:45 -0500 Received: from [199.232.76.173] (port=58799 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NTMgG-0002rV-F5 for qemu-devel@nongnu.org; Fri, 08 Jan 2010 16:47:40 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49900) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1NTMgF-0007gg-Tz for qemu-devel@nongnu.org; Fri, 08 Jan 2010 16:47:40 -0500 Received: from int-mx08.intmail.prod.int.phx2.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id o08LlcPa032676 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 8 Jan 2010 16:47:38 -0500 Received: from localhost (vpn-11-153.rdu.redhat.com [10.11.11.153]) by int-mx08.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id o08LlblD008119; Fri, 8 Jan 2010 16:47:38 -0500 From: Luiz Capitulino To: qemu-devel@nongnu.org Date: Fri, 8 Jan 2010 19:47:14 -0200 Message-Id: <1262987236-2943-6-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1262987236-2943-1-git-send-email-lcapitulino@redhat.com> References: <1262987236-2943-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.21 X-detected-operating-system: by monty-python.gnu.org: Genre and OS details not recognized. Cc: aliguori@us.ibm.com Subject: [Qemu-devel] [PATCH 5/7] VNC: Cache client info at connection time X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org When a disconnection happens the client's socket on QEMU side may become invalid, this way it won't be possible to query it to get client information, which is going to be needed by the future VNC disconnect QMP event. To always have this information available we query the socket at connection time and cache the client info in struct VncState. Note that the caching occurs in protocol_client_init(), meaning that client information is only available _after_ the client has successfully authenticated if an authentication method is being used. This is also true for 'query-vnc' or 'info vnc'. If any kind of authentication is enabled and the client is connected but didn't authenticate yet, its info won't be available. Signed-off-by: Luiz Capitulino --- vnc.c | 19 ++++++++++++------- vnc.h | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/vnc.c b/vnc.c index a6e54f3..f340d08 100644 --- a/vnc.c +++ b/vnc.c @@ -230,14 +230,14 @@ static int vnc_server_info_put(QDict *qdict) return 0; } -static QDict *do_info_vnc_client(Monitor *mon, VncState *client) +static void vnc_client_cache_info(VncState *client) { QDict *qdict; qdict = qdict_new(); if (vnc_qdict_remote_addr(qdict, client->csock) < 0) { QDECREF(qdict); - return NULL; + return; } #ifdef CONFIG_VNC_TLS @@ -254,7 +254,7 @@ static QDict *do_info_vnc_client(Monitor *mon, VncState *client) } #endif - return qdict; + client->info = QOBJECT(qdict); } static void info_vnc_iter(QObject *obj, void *opaque) @@ -337,16 +337,17 @@ void do_info_vnc(Monitor *mon, QObject **ret_data) if (vnc_display == NULL || vnc_display->display == NULL) { *ret_data = qobject_from_jsonf("{ 'enabled': false }"); } else { - QDict *qdict; QList *clist; clist = qlist_new(); if (vnc_display->clients) { VncState *client = vnc_display->clients; while (client) { - qdict = do_info_vnc_client(mon, client); - if (qdict) - qlist_append(clist, qdict); + if (client->info) { + /* incref so that it's not freed by upper layers */ + qobject_incref(client->info); + qlist_append_obj(clist, client->info); + } client = client->next; } } @@ -1099,6 +1100,8 @@ static void vnc_disconnect_finish(VncState *vs) if (!vs->vd->clients) dcl->idle = 1; + qobject_decref(vs->info); + vnc_remove_timer(vs->vd); qemu_free(vs); } @@ -2053,6 +2056,8 @@ static int protocol_client_init(VncState *vs, uint8_t *data, size_t len) char buf[1024]; int size; + vnc_client_cache_info(vs); + vnc_write_u16(vs, ds_get_width(vs->ds)); vnc_write_u16(vs, ds_get_height(vs->ds)); diff --git a/vnc.h b/vnc.h index fcc6824..1210824 100644 --- a/vnc.h +++ b/vnc.h @@ -144,6 +144,8 @@ struct VncState VncStateSASL sasl; #endif + QObject *info; + Buffer output; Buffer input; /* current output mode information */