From patchwork Wed Sep 16 17:32:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Rose X-Patchwork-Id: 1365677 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=oeS3/zOU; dkim-atps=neutral Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BsJ966B0QzB41Y for ; Thu, 17 Sep 2020 10:43:06 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 881862E25F; Wed, 16 Sep 2020 17:35:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id nvNgq7n6Oyd4; Wed, 16 Sep 2020 17:34:52 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id A341B2E11D; Wed, 16 Sep 2020 17:33:36 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 770B9C0888; Wed, 16 Sep 2020 17:33:36 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id 64B47C0051 for ; Wed, 16 Sep 2020 17:33:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 06D118742B for ; Wed, 16 Sep 2020 17:33:33 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id HcaBjjgcxyRd for ; Wed, 16 Sep 2020 17:33:30 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f65.google.com (mail-pj1-f65.google.com [209.85.216.65]) by hemlock.osuosl.org (Postfix) with ESMTPS id DD9BE87470 for ; Wed, 16 Sep 2020 17:33:29 +0000 (UTC) Received: by mail-pj1-f65.google.com with SMTP id s14so1721503pju.1 for ; Wed, 16 Sep 2020 10:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=LTKHm8G4EMhtV5eJWe3HvCRXDi8yL8UsgtHuFKHyUcE=; b=oeS3/zOUzlntZtyZaga/UQSx4d1thRJvh84TcZl2LPSwnewltn7b5maZXeCdVinS7W JNsTYbbkAPIP7isHJmxXUvc0q2fMQO1xDIY3HYOoT6gq+fXfvue9AEencZ58mDYw0stP MH89tEKJo9ZGTOrHo6mvc/KFbnY3jR6ofTYNM3eP0R9+E1Lh393CBzw+kyC/dw9cv0Pn PBlNxGsbH94/gIgfdhUvzYHDoWMAdsYaXzzDUryMRa21l/749oLy7VqVo5TFIxNnVSC7 0E/4+hiZjXdLimNpDL1ZjhiDzebR2ZEWoRsRq+IL2Fw7VjeByjKQcbpahnxawccec52i fSeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=LTKHm8G4EMhtV5eJWe3HvCRXDi8yL8UsgtHuFKHyUcE=; b=CQDObC9uwtepRlvXATkTvmJteQQ2hT5/LfKh8M44yXHXwya07Na0XILLAJmfqWN4GS Eyth5qDvvRV2/lbh8LlPGCBmS0Dd3xZFRLg3gvh1xYI6CkEfPrj1e+1qxfd85HnVXgsw g1nlL6VZ89Rb703qedl+Rqk17cXuL3no4JKcZeRDekqDyyuTn1BgZ+5hY55SuRcP7+ac egBT/rUOaVBwfVZ+lgGTB4lzaLUvh1PiGE6n2JFhajO/6K+vaXzj4TxA4CKVCc/PgN1W 6qXb4hhLCuOB4jMeeXrclpeBDncYx0CPOx6q4gUaJNaOLYqAZgnkv/ceCappIrImWtdm lPJw== X-Gm-Message-State: AOAM532mMdbqr/yPm58kcSL3RasjQQk3EImY8PN4WPa7xCB5Bn0nQXI8 VbgUHkb/uu5k8s4ly50D3Y1sb2RaYyIT1g== X-Google-Smtp-Source: ABdhPJw7l8rwuGN4pAErOGYg9YvP5o8VarHAE9KK6vRBNQncVf6u4t99A5mWS1UJ6P+vXHsTHjzX/w== X-Received: by 2002:a17:902:b409:b029:d1:cbf4:bcda with SMTP id x9-20020a170902b409b02900d1cbf4bcdamr13287562plr.36.1600277608743; Wed, 16 Sep 2020 10:33:28 -0700 (PDT) Received: from VMware-box.domain ([97.115.183.169]) by smtp.googlemail.com with ESMTPSA id o20sm16248519pgh.63.2020.09.16.10.33.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Sep 2020 10:33:28 -0700 (PDT) From: Greg Rose To: dev@openvswitch.org Date: Wed, 16 Sep 2020 10:32:59 -0700 Message-Id: <20200916173311.30956-13-gvrose8192@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200916173311.30956-1-gvrose8192@gmail.com> References: <20200916173311.30956-1-gvrose8192@gmail.com> Subject: [ovs-dev] [PATCH V3 12/24] datapath: simplify the ovs_dp_cmd_new X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tonghao Zhang Upstream commit: commit eec62eadd1d757b0743ccbde55973814f3ad396e Author: Tonghao Zhang Date: Fri Nov 1 22:23:54 2019 +0800 net: openvswitch: simplify the ovs_dp_cmd_new use the specified functions to init resource. Signed-off-by: Tonghao Zhang Tested-by: Greg Rose Acked-by: Pravin B Shelar Signed-off-by: David S. Miller Cc: Tonghao Zhang Reviewed-by: Tonghao Zhang Signed-off-by: Greg Rose Acked-by: Yi-Hung Wei --- datapath/datapath.c | 60 ++++++++++++++++++++++++++++----------------- 1 file changed, 38 insertions(+), 22 deletions(-) diff --git a/datapath/datapath.c b/datapath/datapath.c index c222ef88e..f04ce210c 100644 --- a/datapath/datapath.c +++ b/datapath/datapath.c @@ -1665,6 +1665,31 @@ static int ovs_dp_change(struct datapath *dp, struct nlattr *a[]) return 0; } +static int ovs_dp_stats_init(struct datapath *dp) +{ + dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu); + if (!dp->stats_percpu) + return -ENOMEM; + + return 0; +} + +static int ovs_dp_vport_init(struct datapath *dp) +{ + int i; + + dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS, + sizeof(struct hlist_head), + GFP_KERNEL); + if (!dp->ports) + return -ENOMEM; + + for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) + INIT_HLIST_HEAD(&dp->ports[i]); + + return 0; +} + static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) { struct nlattr **a = info->attrs; @@ -1673,7 +1698,7 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) struct datapath *dp; struct vport *vport; struct ovs_net *ovs_net; - int err, i; + int err; err = -EINVAL; if (!a[OVS_DP_ATTR_NAME] || !a[OVS_DP_ATTR_UPCALL_PID]) @@ -1686,35 +1711,26 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) err = -ENOMEM; dp = kzalloc(sizeof(*dp), GFP_KERNEL); if (dp == NULL) - goto err_free_reply; + goto err_destroy_reply; ovs_dp_set_net(dp, sock_net(skb->sk)); /* Allocate table. */ err = ovs_flow_tbl_init(&dp->table); if (err) - goto err_free_dp; + goto err_destroy_dp; - dp->stats_percpu = netdev_alloc_pcpu_stats(struct dp_stats_percpu); - if (!dp->stats_percpu) { - err = -ENOMEM; + err = ovs_dp_stats_init(dp); + if (err) goto err_destroy_table; - } - dp->ports = kmalloc_array(DP_VPORT_HASH_BUCKETS, - sizeof(struct hlist_head), - GFP_KERNEL); - if (!dp->ports) { - err = -ENOMEM; - goto err_destroy_percpu; - } - - for (i = 0; i < DP_VPORT_HASH_BUCKETS; i++) - INIT_HLIST_HEAD(&dp->ports[i]); + err = ovs_dp_vport_init(dp); + if (err) + goto err_destroy_stats; err = ovs_meters_init(dp); if (err) - goto err_destroy_ports_array; + goto err_destroy_ports; /* Set up our datapath device. */ parms.name = nla_data(a[OVS_DP_ATTR_NAME]); @@ -1764,15 +1780,15 @@ static int ovs_dp_cmd_new(struct sk_buff *skb, struct genl_info *info) err_destroy_meters: ovs_meters_exit(dp); -err_destroy_ports_array: +err_destroy_ports: kfree(dp->ports); -err_destroy_percpu: +err_destroy_stats: free_percpu(dp->stats_percpu); err_destroy_table: ovs_flow_tbl_destroy(&dp->table); -err_free_dp: +err_destroy_dp: kfree(dp); -err_free_reply: +err_destroy_reply: kfree_skb(reply); err: return err;