From patchwork Thu Oct 22 09:43:31 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Daniel_P=2E_Berrang=C3=A9?= X-Patchwork-Id: 534338 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 25F48141323 for ; Thu, 22 Oct 2015 20:43:57 +1100 (AEDT) Received: from localhost ([::1]:58146 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpCPb-0007HV-7D for incoming@patchwork.ozlabs.org; Thu, 22 Oct 2015 05:43:55 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:38236) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpCPL-00070v-1L for qemu-devel@nongnu.org; Thu, 22 Oct 2015 05:43:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZpCPI-0005ke-AN for qemu-devel@nongnu.org; Thu, 22 Oct 2015 05:43:38 -0400 Received: from mx1.redhat.com ([209.132.183.28]:34001) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZpCPI-0005ka-4I for qemu-devel@nongnu.org; Thu, 22 Oct 2015 05:43:36 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id 6ACCB341AC9; Thu, 22 Oct 2015 09:43:35 +0000 (UTC) Received: from redhat.com (vpn1-7-197.ams2.redhat.com [10.36.7.197]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id t9M9hVrA009651 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Thu, 22 Oct 2015 05:43:34 -0400 Date: Thu, 22 Oct 2015 10:43:31 +0100 From: "Daniel P. Berrange" To: Knut Omang Message-ID: <20151022094330.GD9079@redhat.com> References: <1444648509-29179-1-git-send-email-berrange@redhat.com> <1444648509-29179-4-git-send-email-berrange@redhat.com> <1445449978.7681.367.camel@ifi.uio.no> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1445449978.7681.367.camel@ifi.uio.no> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Paolo Bonzini , qemu-devel@nongnu.org, "Dr. David Alan Gilbert" Subject: Re: [Qemu-devel] [PATCH v2 03/16] sockets: allow port to be NULL when listening on IP address X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org On Wed, Oct 21, 2015 at 07:52:58PM +0200, Knut Omang wrote: > On Mon, 2015-10-12 at 12:14 +0100, Daniel P. Berrange wrote: > > If the port in the SocketAddress struct is NULL, it can allow > > the kernel to automatically select a free port. This is useful > > in particular in unit tests to avoid a race trying to find a > > free port to run a test case on. > > This patch seems to do a bit more than it claims ;-) > > I just noticed that after a rebase a few minutes ago, all options I > have that uses this type of port syntax: > > -serial telnet:ip:port > -serial tcp:ip:port > -qmp ip:port > > started to ignore the port argument and instead provide a dynamic port. > Rebasing without this patch fixes the issue, It is the change to qapi-schema.json that causes this. When 'port' is marked as optional in the schema for InetSocketAddress, then even if the 'port' field is set to a non-NULL string, the qapi_copy_SocketAddress function will not copy that field, so the valid port setting gets discarded. For reasons I don't understand, it appears that even string fields which are marked as optional get a 'has_XXX' flag, to distinguish betweeen a NULL string and an unset string. I struggle to imagine why we need this. It makes sense for integer/boolean types, but I would have thought just checking for NULL was sufficient for string types. Auditing the code to add in 'has_port = true' everywhere that we set 'port = ' is a bit of work, so simplest is probably to revert the change which marks port as optional in qapi-schema.json by doing Regards, Daniel diff --git a/qapi-schema.json b/qapi-schema.json index f60be29..c613dfd 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2615,8 +2615,6 @@ # @host: host part of the address # # @port: port part of the address, or lowest port if @to is present. -# Kernel selects a free port if omitted for listener addresses. -# #optional # # @to: highest port to try # @@ -2631,7 +2629,7 @@ { 'struct': 'InetSocketAddress', 'data': { 'host': 'str', - '*port': 'str', + 'port': 'str', '*to': 'uint16', '*ipv4': 'bool', '*ipv6': 'bool' } }