Received: from eggs.gnu.org ([2001:4830:134:3::10]:48924) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoYBF-0001hV-AR for qemu-devel@nongnu.org; Tue, 20 Oct 2015 10:46:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoYBA-0007mj-IU for qemu-devel@nongnu.org; Tue, 20 Oct 2015 10:46:25 -0400 Received: from mx1.redhat.com ([209.132.183.28]:46117) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoYBA-0007mM-BK for qemu-devel@nongnu.org; Tue, 20 Oct 2015 10:46:20 -0400 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id CD91A91E86 for ; Tue, 20 Oct 2015 14:46:19 +0000 (UTC) From: Markus Armbruster References: <1444968943-11254-1-git-send-email-eblake@redhat.com> <1444968943-11254-5-git-send-email-eblake@redhat.com> <87h9lmat1b.fsf@blackfin.pond.sub.org> <1445331261.13733.65.camel@redhat.com> Date: Tue, 20 Oct 2015 16:46:16 +0200 In-Reply-To: <1445331261.13733.65.camel@redhat.com> (Gerd Hoffmann's message of "Tue, 20 Oct 2015 10:54:21 +0200") Message-ID: <87io614myv.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH v9 04/17] vnc: hoist allocation of VncBasicInfo to callers List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Gerd Hoffmann Cc: qemu-devel@nongnu.org Gerd Hoffmann writes: > Hi, > >> > -static VncBasicInfo *vnc_basic_info_get(struct sockaddr_storage *sa, >> > - socklen_t salen) >> > +static void vnc_basic_info_get(struct sockaddr_storage *sa, >> > + socklen_t salen, >> > + VncBasicInfo *info, >> > + Error **errp) > >> The function no longer "gets info", it merely initializes it. Rename it >> accordingly? Gerd? > > vnc_fill_basic_info maybe? Fine with me. Could also call it _init_ instead of _fill_. >> Outside this patch's scope, but since I'm looking at the code already... >> >> Here's the only caller of vnc_server_info_get(): >> >> static void vnc_qmp_event(VncState *vs, QAPIEvent event) >> { >> VncServerInfo *si; >> >> if (!vs->info) { >> return; >> } >> g_assert(vs->info->base); >> >> si = vnc_server_info_get(vs->vd); >> if (!si) { >> ---> return; >> } >> >> switch (event) { >> case QAPI_EVENT_VNC_CONNECTED: >> qapi_event_send_vnc_connected(si, vs->info->base, &error_abort); >> break; >> case QAPI_EVENT_VNC_INITIALIZED: >> qapi_event_send_vnc_initialized(si, vs->info, &error_abort); >> break; >> case QAPI_EVENT_VNC_DISCONNECTED: >> qapi_event_send_vnc_disconnected(si, vs->info, &error_abort); >> break; >> default: >> break; >> } >> >> qapi_free_VncServerInfo(si); >> } >> >> When vnc_server_info_get() fails, the event is dropped. Why is that >> okay? Failure seems unlikely, though. > > Suggestions what else to do? I don't wanna crash qemu by calling > qapi_event_send_vnc_* with a NULL pointer. And, yes, it should be > highly unlikely so trying some more sophisticated error handling would > probably be dead code ... These events signal a state change. Dropping them make me feel uneasy, because if a client uses them to track state, it gets out of sync. What's the state machine here? If I understand things correctly, we have a number of VNC servers, tracked in vnc_displays, which is a list of VncDisplay. Each of them goes through the following states: * Unconnected On connect, emit VNC_CONNECTED and go to Pre-auth * Pre-auth On authentication, emit VNC_INITIALIZED, and go to Active On disconnect, emit VNC_DISCONNECTED, and go to Unconnected * Active On disconnect, emit VNC_DISCONNECTED, and go to Unconnected Correct? The events need to identify the server to be of any use for state tracking. Currently, this is members host, service, family of data member server. We could avoid failures in vnc_qmp_event() as follows: 1. When we create a server, we obtain its info with getsockname() and getnameinfo(). If they fail, we fail server creation. Else, we store the info for vnc_qmp_event(). 2. When a client connects, we obtain its info with getpeername() and getnameinfo(). If they fail, we refuse the connection. Else, we store the infor for vnc_qmp_event(). Alternatively, we can embrace the failures and send the events without the information we failed to get. Requires another way to identify the server. VncDisplay's id, perhaps? Might be nice to have anyway.