Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp553632pxk; Wed, 2 Sep 2020 08:36:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxR8PAD56T2G+RqH23s3/oImwL/c28USfCDvapTlTadnQcHkHVb85/AchFSKcYowj7YqASq X-Received: by 2002:a17:906:1ed4:: with SMTP id m20mr601330ejj.460.1599061015307; Wed, 02 Sep 2020 08:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599061015; cv=none; d=google.com; s=arc-20160816; b=JzveZjvtCiZsv5SlU42NJA8P0tgI16/cnCCHeMXhFuVzz0pJ9vPVg2ISBvBhN0eOwV Gz4Y3g0lcoiJEaF0BMIjF6XuQnDypwn2JN4+QEhx/qjEHfKCApFAXYoFhWv/ky2wBwrv KKKaNW9FmN0hQhRmF/Q7vdTdiM8/8OBfwmeyHDEI69sRSp6ItNA47zWcsj2Ge3QehyDh ckTX5E9XYRPt0CpW/+LPVdzaJu0jSGNETVn6eXOpxdFerL4h6COZQrz3pfYYRF44OTE6 3HvrQqaB43Ni+p8IajlYkxVuArfbwqIhWNW/8xoOdswY29mu0WXxBMKNZpfIYMAdsjgS l0Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=1kKbS82hTJ+9ykkSjSFnatKeT5amEg/7UUfmMRw5Teo=; b=A4ryaFXhNwULV8ONDSKkh6FkH2PodAGmqokaAIGUc5Dk3ojCJBTwlKtEeH/j3Qc4lH 2EzIANy1Gg4ZtZcnw9Id/rCx5hSPJ/K2ie0orsG8TOsLh+L9Rt3nESZmbYKdPMUiNn2I OKxY/YRLQ7x1onnRr6uioQUoHUXUEwvlABzpgQcqdhp8R0wfjgP1AVqzpmGUxKcnV+Z4 nsDvn9Pp30ah71r9C/V0FN9f40DYoazlCMBd7+OQ9Cd/Gjh1TKMcMDn6u0/McXP2/sl/ bus+jO7WWyL+3DkCBpPEhHI/iDXEyM6qQ3T6agOdFV8YCu/jYBtlkAfFxrL6RmLPKmNx BTOQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c7si2799901ejz.677.2020.09.02.08.36.32; Wed, 02 Sep 2020 08:36:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mellanox.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728430AbgIBPdW (ORCPT + 99 others); Wed, 2 Sep 2020 11:33:22 -0400 Received: from mail-il-dmz.mellanox.com ([193.47.165.129]:52305 "EHLO mellanox.co.il" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728382AbgIBPcg (ORCPT ); Wed, 2 Sep 2020 11:32:36 -0400 Received: from Internal Mail-Server by MTLPINE1 (envelope-from ayal@mellanox.com) with SMTP; 2 Sep 2020 18:32:29 +0300 Received: from dev-l-vrt-210.mtl.labs.mlnx (dev-l-vrt-210.mtl.labs.mlnx [10.234.210.1]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 082FWTDB014704; Wed, 2 Sep 2020 18:32:29 +0300 Received: from dev-l-vrt-210.mtl.labs.mlnx (localhost [127.0.0.1]) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Debian-8ubuntu1) with ESMTP id 082FWTUU026693; Wed, 2 Sep 2020 18:32:29 +0300 Received: (from ayal@localhost) by dev-l-vrt-210.mtl.labs.mlnx (8.15.2/8.15.2/Submit) id 082FWTiR026692; Wed, 2 Sep 2020 18:32:29 +0300 From: Aya Levin To: "David S. Miller" , Jakub Kicinski , Jiri Pirko , netdev@vger.kernel.org Cc: Moshe Shemesh , Eran Ben Elisha , Ido Schimmel , linux-kernel@vger.kernel.org, Aya Levin Subject: [PATCH net-next RFC v1 3/4] devlink: Add hierarchy between traps in device level and port level Date: Wed, 2 Sep 2020 18:32:13 +0300 Message-Id: <1599060734-26617-4-git-send-email-ayal@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1599060734-26617-1-git-send-email-ayal@mellanox.com> References: <1599060734-26617-1-git-send-email-ayal@mellanox.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Managing large scale port's traps may be complicated. This patch introduces a shortcut: when setting a trap on a device and this trap is not registered on this device, the action will take place on all related ports that did register this trap. Signed-off-by: Aya Levin --- net/core/devlink.c | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/net/core/devlink.c b/net/core/devlink.c index b13e1b40bf1c..dea5482b2517 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -6501,23 +6501,46 @@ static int devlink_nl_cmd_trap_set_doit(struct sk_buff *skb, struct devlink *devlink = info->user_ptr[0]; struct devlink_trap_mngr *trap_mngr; struct devlink_trap_item *trap_item; + struct devlink_port *devlink_port; int err; - trap_mngr = devlink_trap_get_trap_mngr_from_info(devlink, info); - if (list_empty(&trap_mngr->trap_list)) - return -EOPNOTSUPP; + devlink_port = devlink_port_get_from_attrs(devlink, info->attrs); + if (IS_ERR(devlink_port)) { + trap_mngr = &devlink->trap_mngr; + if (list_empty(&trap_mngr->trap_list)) + goto loop_over_ports; - trap_item = devlink_trap_item_get_from_info(trap_mngr, info); - if (!trap_item) { - NL_SET_ERR_MSG_MOD(extack, "Device did not register this trap"); - return -ENOENT; + trap_item = devlink_trap_item_get_from_info(trap_mngr, info); + if (!trap_item) + goto loop_over_ports; + } else { + trap_mngr = &devlink_port->trap_mngr; + if (list_empty(&trap_mngr->trap_list)) + return -EOPNOTSUPP; + + trap_item = devlink_trap_item_get_from_info(trap_mngr, info); + if (!trap_item) { + NL_SET_ERR_MSG_MOD(extack, "Port did not register this trap"); + return -ENOENT; + } } return devlink_trap_action_set(devlink, trap_mngr, trap_item, info); - err = devlink_trap_action_set(devlink, trap_mngr, trap_item, info); - if (err) - return err; +loop_over_ports: + if (list_empty(&devlink->port_list)) + return -EOPNOTSUPP; + list_for_each_entry(devlink_port, &devlink->port_list, list) { + trap_mngr = &devlink_port->trap_mngr; + if (list_empty(&trap_mngr->trap_list)) + continue; + trap_item = devlink_trap_item_get_from_info(trap_mngr, info); + if (!trap_item) + continue; + err = devlink_trap_action_set(devlink, trap_mngr, trap_item, info); + if (err) + return err; + } return 0; } -- 2.14.1