From patchwork Fri Jul 3 13:45:48 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?UTF-8?B?Wm9sdMOhbiBLxZF2w6Fnw7M=?= X-Patchwork-Id: 491088 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 2DE4614076B for ; Fri, 3 Jul 2015 23:48:20 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=KZy6Ymro; dkim-atps=neutral Received: from localhost ([::1]:41329 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZB1KE-0002Im-Az for incoming@patchwork.ozlabs.org; Fri, 03 Jul 2015 09:48:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:42532) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZB1Hl-0006C5-LM for qemu-devel@nongnu.org; Fri, 03 Jul 2015 09:45:46 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZB1Hj-0007Ku-L0 for qemu-devel@nongnu.org; Fri, 03 Jul 2015 09:45:45 -0400 Received: from mail-wi0-x229.google.com ([2a00:1450:400c:c05::229]:35090) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZB1Hi-0007KH-9t for qemu-devel@nongnu.org; Fri, 03 Jul 2015 09:45:42 -0400 Received: by wiga1 with SMTP id a1so178527350wig.0 for ; Fri, 03 Jul 2015 06:45:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type:content-transfer-encoding; bh=lIEvRDYE71nKPUP/l/76TxCvN1EJOlVOmJOy458KdOU=; b=KZy6YmroXQdvlQJtwkT9+tW8priJVxkR3KA5GHssqNnIFULteD5yyKBn1Dq3IQSLYS TGk4yUm98uo+hbvhqHHV+4nMlP1KhvEQ1qF/chrA4TKkZx+RWqh+Zo7CqOQprMphKT9m 9NF6wrwEWZTro42TcEQfvkoQwWte2ZF7qan/fn2888VcbEGByOhjcIqrOk/Bg1WL2F0+ 2ylNChEle2rZjFzXpyXHXO0WmpWi/nt8BzKzputxYLdgfa7/dKBCrZE1gpfeEwqD/TMw O691tg6IXvYmAFY1dkyOi3cdSO318JczThw3SNQ2ta4tEOe7CwzYLCPagL1i2ydHourr 8oIg== X-Received: by 10.180.20.198 with SMTP id p6mr27498388wie.38.1435931141672; Fri, 03 Jul 2015 06:45:41 -0700 (PDT) Received: from nullptr.home.dirty-ice.org (94-21-30-178.pool.digikabel.hu. [94.21.30.178]) by mx.google.com with ESMTPSA id ej5sm13451036wjd.22.2015.07.03.06.45.40 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 03 Jul 2015 06:45:40 -0700 (PDT) From: "=?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?=" X-Google-Original-From: =?UTF-8?q?K=C5=91v=C3=A1g=C3=B3=2C=20Zolt=C3=A1n?= To: qemu-devel@nongnu.org Date: Fri, 3 Jul 2015 15:45:48 +0200 Message-Id: <6768de730e4c4751a6501b1b0fd0742331fb06b8.1435930020.git.DirtY.iCE.hu@gmail.com> X-Mailer: git-send-email 2.4.5 In-Reply-To: References: MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::229 Cc: Jason Wang , Gerd Hoffmann , Stefan Hajnoczi , Markus Armbruster Subject: [Qemu-devel] [PATCH v2 3/6] net: remove NetLegacy struct X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list 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 NetLegacy is just Netdev with some extra fields (name, vlan) and an optional id. This patch merges the two structs, and net_client_init1 got some extra checks to make sure only accept valid -netdev command lines. This is some extra work, but allows us to uniformly manage both legacy -net and non-legacy -netdev in code. Signed-off-by: Kővágó, Zoltán --- net/net.c | 42 +++++++++++++++++++++--------------------- qapi-schema.json | 30 +++++++++--------------------- 2 files changed, 30 insertions(+), 42 deletions(-) diff --git a/net/net.c b/net/net.c index 6ff7fec..10e7672 100644 --- a/net/net.c +++ b/net/net.c @@ -911,17 +911,29 @@ static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND_MAX])( }; -static int net_client_init1(const void *object, int is_netdev, Error **errp) +static int net_client_init1(const Netdev *netdev, int is_netdev, Error **errp) { - const NetClientOptions *opts; + const NetClientOptions *opts = netdev->opts; const char *name; NetClientState *peer = NULL; if (is_netdev) { - const Netdev *netdev = object; - opts = netdev->opts; name = netdev->id; + /* validate -netdev option: has id, no vlan or name */ + if (!netdev->has_id) { + error_setg(errp, QERR_MISSING_PARAMETER, "id"); + return -1; + } + if (netdev->has_name) { + error_setg(errp, QERR_INVALID_PARAMETER, "name"); + return -1; + } + if (netdev->has_vlan) { + error_setg(errp, QERR_INVALID_PARAMETER, "vlan"); + return -1; + } + if (opts->kind == NET_CLIENT_OPTIONS_KIND_DUMP || opts->kind == NET_CLIENT_OPTIONS_KIND_NIC || !net_client_init_fun[opts->kind]) { @@ -930,10 +942,8 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) return -1; } } else { - const NetLegacy *net = object; - opts = net->opts; /* missing optional values have been initialized to "all bits zero" */ - name = net->has_id ? net->id : net->name; + name = netdev->has_id ? netdev->id : netdev->name; if (opts->kind == NET_CLIENT_OPTIONS_KIND_NONE) { return 0; /* nothing to do */ @@ -954,7 +964,7 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) /* Do not add to a vlan if it's a nic with a netdev= parameter. */ if (opts->kind != NET_CLIENT_OPTIONS_KIND_NIC || !opts->nic->has_netdev) { - peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL); + peer = net_hub_add_port(netdev->has_vlan ? netdev->vlan : 0, NULL); } } @@ -970,26 +980,16 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp) } -static void net_visit(Visitor *v, int is_netdev, void **object, Error **errp) -{ - if (is_netdev) { - visit_type_Netdev(v, (Netdev **)object, NULL, errp); - } else { - visit_type_NetLegacy(v, (NetLegacy **)object, NULL, errp); - } -} - - int net_client_init(QemuOpts *opts, int is_netdev, Error **errp) { - void *object = NULL; + Netdev *object = NULL; Error *err = NULL; int ret = -1; { OptsVisitor *ov = opts_visitor_new(opts); - net_visit(opts_get_visitor(ov), is_netdev, &object, &err); + visit_type_Netdev(opts_get_visitor(ov), &object, NULL, &err); opts_visitor_cleanup(ov); } @@ -1000,7 +1000,7 @@ int net_client_init(QemuOpts *opts, int is_netdev, Error **errp) if (object) { QapiDeallocVisitor *dv = qapi_dealloc_visitor_new(); - net_visit(qapi_dealloc_get_visitor(dv), is_netdev, &object, NULL); + visit_type_Netdev(qapi_dealloc_get_visitor(dv), &object, NULL, NULL); qapi_dealloc_visitor_cleanup(dv); } diff --git a/qapi-schema.json b/qapi-schema.json index 7ebf99e..08e376b 100644 --- a/qapi-schema.json +++ b/qapi-schema.json @@ -2500,21 +2500,25 @@ 'vhost-user': 'NetdevVhostUserOptions' } } ## -# @NetLegacy +# @Netdev # -# Captures the configuration of a network device; legacy. +# Captures the configuration of a network device. # -# @vlan: #optional vlan number +# @vlan: #optional vlan number (legacy, forbidden with -netdev) # -# @id: #optional identifier for monitor commands +# @id: #optional identifier for monitor commands (required with -netdev) # # @name: #optional identifier for monitor commands, ignored if @id is present +# (legacy, forbidden with -netdev) # # @opts: device type specific properties (legacy) # # Since 1.2 +# +# @id #optional - since 2.4 +# @vlan, @name - since 2.4 ## -{ 'struct': 'NetLegacy', +{ 'struct': 'Netdev', 'data': { '*vlan': 'int32', '*id': 'str', @@ -2522,22 +2526,6 @@ 'opts': 'NetClientOptions' } } ## -# @Netdev -# -# Captures the configuration of a network device. -# -# @id: identifier for monitor commands. -# -# @opts: device type specific properties -# -# Since 1.2 -## -{ 'struct': 'Netdev', - 'data': { - 'id': 'str', - 'opts': 'NetClientOptions' } } - -## # @InetSocketAddress # # Captures a socket address or address range in the Internet namespace.