From patchwork Thu Jul 20 12:18:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320426 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0173A18013 for ; Thu, 20 Jul 2023 12:18:35 +0000 (UTC) Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D5842115 for ; Thu, 20 Jul 2023 05:18:34 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-3fbef8ad9bbso6222125e9.0 for ; Thu, 20 Jul 2023 05:18:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855513; x=1690460313; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=/kSaJ38xyljlMmEibkqyMZA7beyTOEb9WwKeGXy20WQ=; b=BZj1w451fg0D7cDc3MXIrh6zUaRjq2WNzIW+VezbgTcKhTFroU5lDvDib4nsL1LkWf uM+RY9iBeZk+TJUh/hr+NdDj8HiSlZY4L6HC0PgR2wwTiDkgCxl5Wu6eajMQ88ZlHSYM wvEa3Ouh92q/lwCbYU4QlX33Rcm1ZWcWsjLU5uLj+5zXE96O10SnFQWXQ6Y0hhB0y64e o9nRScbjynoq8lRzZ5AK+ALNmsBX595c1Me2dR50FmXzG9pyrnfWbL5a4IXKlCazMmo6 WAO/GG8hTET4jYLZbh+RjNSh0s3zHEhGnmgkB9fxCrBEMNe0VOLKM71POnnQddIYYmhv neCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855513; x=1690460313; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/kSaJ38xyljlMmEibkqyMZA7beyTOEb9WwKeGXy20WQ=; b=V+gS7bOB4JCe/6IIZJQZud1XRHROc8u8poNhttwYaPGoHADN2OlrWMvgKQoVFb4ZAI QCIC6EFZaKmOLRsDIc77kM13j8wGRiqBcurYxY6jDXEDThHcvSG9O5jpxm0fnuK9nu23 jk3uL8faEPdPXINsRctKbVhGp9DNZL0BmRdxynn6gMUMAhoo8pI4ysV4SiFDp0QLApa3 KGUWtJspvP63adU7SjLHA/kGBfbcJN5b+AjVOsG+U/D8F70iHARdm+sKcgwVAD+4Hx4N Qn7gW9cBQpBlgtcRW6RnHct6UxeriSykATpIxDekTipFbwqBKu2MDt6xt1I3Lgz+sPLK VKaw== X-Gm-Message-State: ABy/qLZkbgiCbDrjC/GliiFpMtRLnJeufuwUGZ0vc9yX0rp4TWYeWe70 SLSI7DO49aYUEmSWzwDQU13ILOEan62A7swvgrQ= X-Google-Smtp-Source: APBJJlHOSygQmnwwMtYo17bqtx+2J6XgsPIeC5IHsZl8thIbciUJY8rkFjV4qbGUX4Br+TyW3GI7OQ== X-Received: by 2002:a1c:ed14:0:b0:3fb:b67b:7f15 with SMTP id l20-20020a1ced14000000b003fbb67b7f15mr4239815wmh.21.1689855512699; Thu, 20 Jul 2023 05:18:32 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id o1-20020a056000010100b003144bfbd0b3sm1186142wrx.37.2023.07.20.05.18.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:32 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 01/11] devlink: parse linecard attr in doit() callbacks Date: Thu, 20 Jul 2023 14:18:19 +0200 Message-ID: <20230720121829.566974-2-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko No need to give the linecards any special treatment in netlink attribute parsing, as unlike for ports, there is only a couple of commands benefiting from that. Remove DEVLINK_NL_FLAG_NEED_LINECARD, make pre_doit() callback simpler by moving the linecard attribute parsing to linecard_[gs]et_doit() ops. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 7 ------- net/devlink/leftover.c | 19 +++++++++++++------ net/devlink/netlink.c | 8 -------- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 62921b2eb0d3..44b3a69c448e 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -92,7 +92,6 @@ static inline bool devl_is_registered(struct devlink *devlink) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) #define DEVLINK_NL_FLAG_NEED_RATE BIT(2) #define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3) -#define DEVLINK_NL_FLAG_NEED_LINECARD BIT(4) enum devlink_multicast_groups { DEVLINK_MCGRP_CONFIG, @@ -199,12 +198,6 @@ int devlink_resources_validate(struct devlink *devlink, struct devlink_resource *resource, struct genl_info *info); -/* Line cards */ -struct devlink_linecard; - -struct devlink_linecard * -devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info); - /* Rates */ int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, struct netlink_ext_ack *extack); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 5128b9c7eea8..dba58830ed28 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -285,7 +285,7 @@ devlink_linecard_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) return ERR_PTR(-EINVAL); } -struct devlink_linecard * +static struct devlink_linecard * devlink_linecard_get_from_info(struct devlink *devlink, struct genl_info *info) { return devlink_linecard_get_from_attrs(devlink, info->attrs); @@ -1814,11 +1814,15 @@ static void devlink_linecard_notify(struct devlink_linecard *linecard, static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, struct genl_info *info) { - struct devlink_linecard *linecard = info->user_ptr[1]; - struct devlink *devlink = linecard->devlink; + struct devlink *devlink = info->user_ptr[0]; + struct devlink_linecard *linecard; struct sk_buff *msg; int err; + linecard = devlink_linecard_get_from_info(devlink, info); + if (IS_ERR(linecard)) + return PTR_ERR(linecard); + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return -ENOMEM; @@ -2008,10 +2012,15 @@ static int devlink_linecard_type_unset(struct devlink_linecard *linecard, static int devlink_nl_cmd_linecard_set_doit(struct sk_buff *skb, struct genl_info *info) { - struct devlink_linecard *linecard = info->user_ptr[1]; struct netlink_ext_ack *extack = info->extack; + struct devlink *devlink = info->user_ptr[0]; + struct devlink_linecard *linecard; int err; + linecard = devlink_linecard_get_from_info(devlink, info); + if (IS_ERR(linecard)) + return PTR_ERR(linecard); + if (info->attrs[DEVLINK_ATTR_LINECARD_TYPE]) { const char *type; @@ -6354,14 +6363,12 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_LINECARD_GET, .doit = devlink_nl_cmd_linecard_get_doit, .dumpit = devlink_nl_instance_iter_dumpit, - .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, /* can be retrieved by unprivileged users */ }, { .cmd = DEVLINK_CMD_LINECARD_SET, .doit = devlink_nl_cmd_linecard_set_doit, .flags = GENL_ADMIN_PERM, - .internal_flags = DEVLINK_NL_FLAG_NEED_LINECARD, }, { .cmd = DEVLINK_CMD_SB_GET, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 7a332eb70f70..cd2754698478 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -112,7 +112,6 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs) static int devlink_nl_pre_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { - struct devlink_linecard *linecard; struct devlink_port *devlink_port; struct devlink *devlink; int err; @@ -151,13 +150,6 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops, goto unlock; } info->user_ptr[1] = rate_node; - } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_LINECARD) { - linecard = devlink_linecard_get_from_info(devlink, info); - if (IS_ERR(linecard)) { - err = PTR_ERR(linecard); - goto unlock; - } - info->user_ptr[1] = linecard; } return 0; From patchwork Thu Jul 20 12:18:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320427 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 13C63182AA for ; Thu, 20 Jul 2023 12:18:37 +0000 (UTC) Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 832192118 for ; Thu, 20 Jul 2023 05:18:35 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3fbab0d0b88so11932315e9.0 for ; Thu, 20 Jul 2023 05:18:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855514; x=1690460314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+x9FZDhdqblB+z/ExbJxjIHAvQZBsO/rmW9NK1t2hdg=; b=uXC8Y6DjL0uaP1H7Oc1B0OSISmt1/nOcbzTY7LKqTmvC6MFVG2fJpgA0ysNZvXcbP4 G/zkVXZGRYDzQFRYsuOJh3RqkvFnveeawar5SuRigJm5V94NYzXvBasyKYizw3r+OM6k o8I+yDhKO/2Axev9X/iJoWccxynlW3GXPbCawGSnSsuQP2rCkd3ZpRpBGq2ukvYYjgTS mqWpAT54k4nphbErbeNnF+71fI7ZJYbWaKWRcFjARPwrMw1m2rOdHuXyNVTanvOQPndo CfwFg5jarZ4h7dqqhDq2OW8UhoKUV4rIfDattIb+kgFUVIfiQjhP7x59mjfqw04VeKBZ T00Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855514; x=1690460314; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+x9FZDhdqblB+z/ExbJxjIHAvQZBsO/rmW9NK1t2hdg=; b=GFNVMR0SvShspxIvrY4BdsiRRGHeFRpmeSYZX0hux9p6Ss60IUjmdLo+tf5Sy0rwtH Uue2PkfoRonwXgvtLDna6fBL+ENdgocuf7IPnrkG6d2cuCjs54HZguGY6tTwiYlwr6ld GWnS0Jy9UpXvNjNAo3USDUdt5Dhc0OvC9g7/jF4+thRMiB7zp3kNQXMszrAAo53SbPlt qLHs1vGmtThZ4yhu3C9yYSWeJ26g0s88g6hK/gf7CKQG4jq+dr3XinAAb4+6HmYO+qsn hV0XbEKst4cKqozHEAGgOklYsGBNuMmv68Z8FWf7/MYySPfOomY/e/USWSImqCRcqHIv dtag== X-Gm-Message-State: ABy/qLZONqPbtY2Jt6PYwlhl9fZAdYFtQ8fpn8mYmblTpcEBu5CCe4Vx vd/PIEcoDEK01DjoObPSKaZ/paHj7MJmLX+wdHk= X-Google-Smtp-Source: APBJJlGrBPv62yTag8+NVdZHmWQ4m7yz8yDaMlUXb0IdyiyCctvm1KHdewat4jQtJzAfbadJvH02fQ== X-Received: by 2002:a05:600c:1d8e:b0:3fb:ebe2:6f5f with SMTP id p14-20020a05600c1d8e00b003fbebe26f5fmr4465130wms.13.1689855514128; Thu, 20 Jul 2023 05:18:34 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id u5-20020a5d5145000000b00314145e6d61sm1212356wrt.6.2023.07.20.05.18.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:33 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 02/11] devlink: parse rate attrs in doit() callbacks Date: Thu, 20 Jul 2023 14:18:20 +0200 Message-ID: <20230720121829.566974-3-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko No need to give the rate any special treatment in netlink attributes parsing, as unlike for ports, there is only a couple of commands benefiting from that. Remove DEVLINK_NL_FLAG_NEED_RATE*, make pre_doit() callback simpler by moving the rate attributes parsing to rate_*_doit() ops. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 8 +------- net/devlink/leftover.c | 37 ++++++++++++++++++++++++------------- net/devlink/netlink.c | 18 ------------------ 3 files changed, 25 insertions(+), 38 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 44b3a69c448e..f6e466be2310 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -90,8 +90,6 @@ static inline bool devl_is_registered(struct devlink *devlink) /* Netlink */ #define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) -#define DEVLINK_NL_FLAG_NEED_RATE BIT(2) -#define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3) enum devlink_multicast_groups { DEVLINK_MCGRP_CONFIG, @@ -201,11 +199,7 @@ int devlink_resources_validate(struct devlink *devlink, /* Rates */ int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, struct netlink_ext_ack *extack); -struct devlink_rate * -devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info); -struct devlink_rate * -devlink_rate_node_get_from_info(struct devlink *devlink, - struct genl_info *info); + /* Devlink nl cmds */ int devlink_nl_cmd_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_reload(struct sk_buff *skb, struct genl_info *info); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index dba58830ed28..2f7130c60333 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -232,13 +232,13 @@ devlink_rate_node_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) return devlink_rate_node_get_by_name(devlink, rate_node_name); } -struct devlink_rate * +static struct devlink_rate * devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info) { return devlink_rate_node_get_from_attrs(devlink, info->attrs); } -struct devlink_rate * +static struct devlink_rate * devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info) { struct nlattr **attrs = info->attrs; @@ -1041,10 +1041,15 @@ const struct devlink_cmd devl_cmd_rate_get = { static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, struct genl_info *info) { - struct devlink_rate *devlink_rate = info->user_ptr[1]; + struct devlink *devlink = info->user_ptr[0]; + struct devlink_rate *devlink_rate; struct sk_buff *msg; int err; + devlink_rate = devlink_rate_get_from_info(devlink, info); + if (IS_ERR(devlink_rate)) + return PTR_ERR(devlink_rate); + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); if (!msg) return -ENOMEM; @@ -1629,11 +1634,16 @@ static bool devlink_rate_set_ops_supported(const struct devlink_ops *ops, static int devlink_nl_cmd_rate_set_doit(struct sk_buff *skb, struct genl_info *info) { - struct devlink_rate *devlink_rate = info->user_ptr[1]; - struct devlink *devlink = devlink_rate->devlink; - const struct devlink_ops *ops = devlink->ops; + struct devlink *devlink = info->user_ptr[0]; + struct devlink_rate *devlink_rate; + const struct devlink_ops *ops; int err; + devlink_rate = devlink_rate_get_from_info(devlink, info); + if (IS_ERR(devlink_rate)) + return PTR_ERR(devlink_rate); + + ops = devlink->ops; if (!ops || !devlink_rate_set_ops_supported(ops, info, devlink_rate->type)) return -EOPNOTSUPP; @@ -1704,18 +1714,22 @@ static int devlink_nl_cmd_rate_new_doit(struct sk_buff *skb, static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb, struct genl_info *info) { - struct devlink_rate *rate_node = info->user_ptr[1]; - struct devlink *devlink = rate_node->devlink; - const struct devlink_ops *ops = devlink->ops; + struct devlink *devlink = info->user_ptr[0]; + struct devlink_rate *rate_node; int err; + rate_node = devlink_rate_node_get_from_info(devlink, info); + if (IS_ERR(rate_node)) + return PTR_ERR(rate_node); + if (refcount_read(&rate_node->refcnt) > 1) { NL_SET_ERR_MSG(info->extack, "Node has children. Cannot delete node."); return -EBUSY; } devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL); - err = ops->rate_node_del(rate_node, rate_node->priv, info->extack); + err = devlink->ops->rate_node_del(rate_node, rate_node->priv, + info->extack); if (rate_node->parent) refcount_dec(&rate_node->parent->refcnt); list_del(&rate_node->list); @@ -6314,14 +6328,12 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_RATE_GET, .doit = devlink_nl_cmd_rate_get_doit, .dumpit = devlink_nl_instance_iter_dumpit, - .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, /* can be retrieved by unprivileged users */ }, { .cmd = DEVLINK_CMD_RATE_SET, .doit = devlink_nl_cmd_rate_set_doit, .flags = GENL_ADMIN_PERM, - .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, }, { .cmd = DEVLINK_CMD_RATE_NEW, @@ -6332,7 +6344,6 @@ const struct genl_small_ops devlink_nl_ops[56] = { .cmd = DEVLINK_CMD_RATE_DEL, .doit = devlink_nl_cmd_rate_del_doit, .flags = GENL_ADMIN_PERM, - .internal_flags = DEVLINK_NL_FLAG_NEED_RATE_NODE, }, { .cmd = DEVLINK_CMD_PORT_SPLIT, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index cd2754698478..336f375f9ff6 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -132,24 +132,6 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops, devlink_port = devlink_port_get_from_info(devlink, info); if (!IS_ERR(devlink_port)) info->user_ptr[1] = devlink_port; - } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_RATE) { - struct devlink_rate *devlink_rate; - - devlink_rate = devlink_rate_get_from_info(devlink, info); - if (IS_ERR(devlink_rate)) { - err = PTR_ERR(devlink_rate); - goto unlock; - } - info->user_ptr[1] = devlink_rate; - } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_RATE_NODE) { - struct devlink_rate *rate_node; - - rate_node = devlink_rate_node_get_from_info(devlink, info); - if (IS_ERR(rate_node)) { - err = PTR_ERR(rate_node); - goto unlock; - } - info->user_ptr[1] = rate_node; } return 0; From patchwork Thu Jul 20 12:18:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320428 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BAF08182A9 for ; Thu, 20 Jul 2023 12:18:39 +0000 (UTC) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22E732106 for ; Thu, 20 Jul 2023 05:18:37 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3fba8e2aa52so6298225e9.1 for ; Thu, 20 Jul 2023 05:18:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855515; x=1690460315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=7d+tR6uSf/87DNnoqjV0r7jwvenZOCziKxtTsdd31WI=; b=cWs4Kj0qfETc/oA/OjsRni/E4S/1iVu/gSmcj/2qWSnXsW8Iah6aAVL8Q+AY1FCPlI CxP0wSx1/RuA1t+fVzmHIO2cS6d3onJv/ghBE4ADB4pmzekhZNAtENYvXzugG+RHsHai sTW6y5OcA67anyOYwkWJh2kbpXUhjT2NXCXlPH1HsAu9GORGz6xaSSAWghQTXH2Awh52 IkbT6yzqWeG10FIEVkjVxdwuI7DZr2ps3eKqWLoomw0hh8dnOK9GT3aUFjHfZP/ejW3E UgLjH6OXJznm9iBJ8Wl/goGIlSYe2Zhjck7LKLS6zscf6ctQdwNcapVGRjbn31g97qbF Ft/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855515; x=1690460315; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=7d+tR6uSf/87DNnoqjV0r7jwvenZOCziKxtTsdd31WI=; b=a9H4hH7ZVRxefiTemI0SG0Srl5ZtMYE+BSrNrIxuFwPytGtnQ1N7K94hOUt1fDho82 AA5/l0N+Un8Bbsz3WIOEJ5/ArWZdQAjZK/AIaDTY8Or7JtKLj9R3ZS2xZy26jvr2SYBu JRp18AmcgXSNcW9nQCIuoUtMYxMT/+f1ECvG2HsqUc/DpabUBe62L0A4QtPaggZRx3lg n95tW04OCXayokP/qKwEdMDz3LLNxe9hEeFrhjpoubkhAPQa7CEEtRFpNvMOxgmRHlSQ cdlY8028MYlaxMh9r8U5uiI7VfZ+v5XVykhNQ7N3KdjovIVveRaKjK7I14Ivk0EKKnuQ LBqQ== X-Gm-Message-State: ABy/qLYe8iSk1uyhzP7awJkhFmaDu8G9PHTGiHGAB4MtZg3fYl1s+Xl0 p4erhHfbodfgNLW8zpWCBTddjClON/9kqvf5YEY= X-Google-Smtp-Source: APBJJlHpZ3jJzuG1AR3+nkQkpbWM27kXGUCTQAs2gvocY6aQL23LsEecwJrdHD+Nbyu4u1yNLw/qQg== X-Received: by 2002:a7b:cd9a:0:b0:3fa:97b3:7ce0 with SMTP id y26-20020a7bcd9a000000b003fa97b37ce0mr1620545wmj.26.1689855515728; Thu, 20 Jul 2023 05:18:35 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id 3-20020a05600c234300b003fc04d13242sm3815347wmq.0.2023.07.20.05.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:35 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 03/11] devlink: introduce __devlink_nl_pre_doit() with internal flags as function arg Date: Thu, 20 Jul 2023 14:18:21 +0200 Message-ID: <20230720121829.566974-4-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko To be able define pre_doit() helpers what don't rely on internal_flags in the follow-up patches, have __devlink_nl_pre_doit() to accept the flags as a function arg and make devlink_nl_pre_doit() a wrapper helper function calling it. Signed-off-by: Jiri Pirko --- net/devlink/netlink.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 336f375f9ff6..f1a5ba0f6deb 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -109,8 +109,8 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs) return ERR_PTR(-ENODEV); } -static int devlink_nl_pre_doit(const struct genl_split_ops *ops, - struct sk_buff *skb, struct genl_info *info) +static int __devlink_nl_pre_doit(struct sk_buff *skb, struct genl_info *info, + u8 flags) { struct devlink_port *devlink_port; struct devlink *devlink; @@ -121,14 +121,14 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops, return PTR_ERR(devlink); info->user_ptr[0] = devlink; - if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_PORT) { + if (flags & DEVLINK_NL_FLAG_NEED_PORT) { devlink_port = devlink_port_get_from_info(devlink, info); if (IS_ERR(devlink_port)) { err = PTR_ERR(devlink_port); goto unlock; } info->user_ptr[1] = devlink_port; - } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT) { + } else if (flags & DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT) { devlink_port = devlink_port_get_from_info(devlink, info); if (!IS_ERR(devlink_port)) info->user_ptr[1] = devlink_port; @@ -141,6 +141,12 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops, return err; } +static int devlink_nl_pre_doit(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ + return __devlink_nl_pre_doit(skb, info, ops->internal_flags); +} + static void devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { From patchwork Thu Jul 20 12:18:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320429 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A8ACF182A9 for ; Thu, 20 Jul 2023 12:18:40 +0000 (UTC) Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2EDC211B for ; Thu, 20 Jul 2023 05:18:38 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-3fbc244d384so5968565e9.0 for ; Thu, 20 Jul 2023 05:18:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855517; x=1690460317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xB8dsxV8cWtAw51fDMZsKz1ROYUNPqZkPdJ43tnJILM=; b=xhhX+uga8+jdyb01Ot3w8XHj+9VuQOF51iF/NPJKN3+LmQyE+/WvMDNK1vAfLBsIri Zy3Rxrm905CitdbbhKWDYxyx9UUHnM5aCsoMsKLcq2+dN17gopvM+CopzaAnnsyrCF4f BSEQPEHPPJz9GSxFly4n1AS1OCdKat7zuzH/mSt+3FROAaxtXjKdLY+hKFDDWjRur/wg pKx7v0ngMlSu2alut5w7wWXjXAL9e7Q6T/scKxK4MnTHs/qKXmwkCWZWlgb6/+kQ6DUI 0gbin2HHl568YpNUP9yQLQtJ/AHK5+SrzmAMPBJRyWn68q+TGgPvv1uzETWhi9DdkTeL GP8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855517; x=1690460317; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xB8dsxV8cWtAw51fDMZsKz1ROYUNPqZkPdJ43tnJILM=; b=bqZKdENa6W7bbR5sJXOhkq/p0dEGwHG3rjtUju76RPCqJuYu5SDY7Sx8SrAn/wcvJa 1Q7kiEqhvpqlJjqfiI7Fos/lH5zd8tuiK0OeMttmvtjmZH/V2efUHUeOJz2T3AqsOg3e uIFbKSqYYbS3DR0o96rEtfSgxvHmzMbI/EitpefwjcKk3FE4FfCcGP/Txuweschcukty F1Tv1xrXKGPYTtMtOYFK8Oq1osTMRviSrxByibzMItO8e44v114voWb9OrraL9zdN73x hhCZrU769/HPl23ZtpWz2Z0Vq3hQeCBKwbKWZ4ZMXJgn2Vsn/FdC7Y9tcfz1Cp03INYO M+Cw== X-Gm-Message-State: ABy/qLYbQt0auSss7hJctryEFzK6AhBTGSlbB9Oq5vViK5xx4JmsYa4n WdQ9pHitBXfEz3SZlsOhE1LAeKKo/oHIfiuRuqY= X-Google-Smtp-Source: APBJJlG5ggDdLw9+44eYVNRM1zmH9bYyWwRSvN/hP6xiR2DsP0ojcG26ouBbwBobu07KMtQQ5wjddA== X-Received: by 2002:a05:600c:b57:b0:3fb:fa9f:5292 with SMTP id k23-20020a05600c0b5700b003fbfa9f5292mr6398267wmr.25.1689855517401; Thu, 20 Jul 2023 05:18:37 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id q21-20020a1ce915000000b003fba6709c68sm1037643wmc.47.2023.07.20.05.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:36 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 04/11] devlink: convert port get command to split ops Date: Thu, 20 Jul 2023 14:18:22 +0200 Message-ID: <20230720121829.566974-5-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Do the conversion of port get command to split ops. Introduce devlink_nl_pre_doit_port() helper to indicate port object attribute parsing and use it as pre_doit() callback. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 4 +++- net/devlink/leftover.c | 14 +++----------- net/devlink/netlink.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 12 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index f6e466be2310..2870be150ee3 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -116,7 +116,7 @@ struct devlink_cmd { struct netlink_callback *cb); }; -extern const struct genl_small_ops devlink_nl_ops[56]; +extern const struct genl_small_ops devlink_nl_ops[55]; struct devlink * devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs); @@ -209,6 +209,8 @@ int devlink_nl_cmd_info_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_flash_update(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, + struct genl_info *info); int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 2f7130c60333..33f71e8fe8ee 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -1077,8 +1077,8 @@ devlink_rate_is_parent_node(struct devlink_rate *devlink_rate, return false; } -static int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, + struct genl_info *info) { struct devlink_port *devlink_port = info->user_ptr[1]; struct sk_buff *msg; @@ -6301,7 +6301,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, return devlink_trap_policer_set(devlink, policer_item, info); } -const struct genl_small_ops devlink_nl_ops[56] = { +const struct genl_small_ops devlink_nl_ops[55] = { { .cmd = DEVLINK_CMD_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6309,14 +6309,6 @@ const struct genl_small_ops devlink_nl_ops[56] = { .dumpit = devlink_nl_instance_iter_dumpit, /* can be retrieved by unprivileged users */ }, - { - .cmd = DEVLINK_CMD_PORT_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_port_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_PORT_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index f1a5ba0f6deb..cd35fa637846 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -147,6 +147,12 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops, return __devlink_nl_pre_doit(skb, info, ops->internal_flags); } +static int devlink_nl_pre_doit_port(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ + return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_PORT); +} + static void devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { @@ -213,6 +219,27 @@ int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, return msg->len; } +static const struct genl_split_ops devlink_nl_split_ops[] = { + { + .cmd = DEVLINK_CMD_PORT_GET, + .pre_doit = devlink_nl_pre_doit_port, + .doit = devlink_nl_cmd_port_get_doit, + .post_doit = devlink_nl_post_doit, + .flags = GENL_CMD_CAP_DO, + .validate = GENL_DONT_VALIDATE_STRICT, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, + { + .cmd = DEVLINK_CMD_PORT_GET, + .dumpit = devlink_nl_instance_iter_dumpit, + .flags = GENL_CMD_CAP_DUMP, + .validate = GENL_DONT_VALIDATE_DUMP, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, +}; + struct genl_family devlink_nl_family __ro_after_init = { .name = DEVLINK_GENL_NAME, .version = DEVLINK_GENL_VERSION, @@ -225,6 +252,8 @@ struct genl_family devlink_nl_family __ro_after_init = { .module = THIS_MODULE, .small_ops = devlink_nl_ops, .n_small_ops = ARRAY_SIZE(devlink_nl_ops), + .split_ops = devlink_nl_split_ops, + .n_split_ops = ARRAY_SIZE(devlink_nl_split_ops), .resv_start_op = DEVLINK_CMD_SELFTESTS_RUN + 1, .mcgrps = devlink_nl_mcgrps, .n_mcgrps = ARRAY_SIZE(devlink_nl_mcgrps), From patchwork Thu Jul 20 12:18:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320430 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A13F6182A9 for ; Thu, 20 Jul 2023 12:18:41 +0000 (UTC) Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5785E2106 for ; Thu, 20 Jul 2023 05:18:40 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3158a5e64b6so606742f8f.0 for ; Thu, 20 Jul 2023 05:18:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855519; x=1690460319; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SmEdpWHeF8GWphuFHjL0WVrMSMYpJbqUJBQiBFOHlys=; b=GkzC0s2WM9fC4NsiKzbg2ieucKj5zd1Gsu76ADS39eyoXlShNs8vTODwcfb9HPkoUj 3yTqF/LUADmTK7dP4+5Ox/uXZYRvKBwb/31PcSkZjT6vMOM+DJtJ8ef9kHXdsabbXucu 0BhSXBMZlV763WZACbpag52OwI71ishF58jVZNy29JAfQaeJz/VsVlmXQKzgSSkkeghP xz6gFUVAyYyVg6q/pUPVdIFlzV4fSGMZN49ybsUlmDjKSSQLSEaakXgXG/Q6A0FOmrYP f1vDKtxGDb7m1VndIzdXJKNBOz2QOZqADlFWdRDMWVeYNQK/UdN6GNHsskmIhsmn0E1N G+ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855519; x=1690460319; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SmEdpWHeF8GWphuFHjL0WVrMSMYpJbqUJBQiBFOHlys=; b=f3TuFv2El5BbkFWWy4SOjLxy6HnSHzU9/0nCK1O47dRUw76PRi4wUOf3RBZt7HVixt 1kCkOp8ccfIj4+H9ZqOnjMzLhiwo2DvorCi8ODSkXYxPhLDAVzNd5cvL9/YX8Pe5ubST VshqPSnFUoBYf26JSGuTLLyT8BpNM97GHGDcsGkgdQEAqRYbNHsnQISWe24N8/JL6OOV Tezn5NBLKS6oWCululgPfBnFmtOsROkwXu6c/3c6INuvWNMTW53CVMO5kWc1iPAoxXJj rRCkuiQqGm9I/ZN/ZYXfzzTy+MM2PJyqA61CmPbmhhAUN1IJikKz8eAMvGHGMS3ZHtyI LqRg== X-Gm-Message-State: ABy/qLZzwXhMQ94iDUlqm1UykpTWDxjmFwemG09Bltpd+fqS5W1uqKU6 DWLebbAadPfUfpT5Zoxg5qFIQ8mLH7AhlK9YB0U= X-Google-Smtp-Source: APBJJlHWzE+atNm0Ejq71qj+fV2+OcvrxNE/7GqMPrSZgev5FTvINXCOFO7xkQWRCvMgwyl+aBPqeQ== X-Received: by 2002:adf:e8cf:0:b0:311:162a:ce2a with SMTP id k15-20020adfe8cf000000b00311162ace2amr1988981wrn.29.1689855518889; Thu, 20 Jul 2023 05:18:38 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id t7-20020a5d6a47000000b00313f7b077fesm1197112wrw.59.2023.07.20.05.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:38 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 05/11] devlink: convert health reporter get command to split ops Date: Thu, 20 Jul 2023 14:18:23 +0200 Message-ID: <20230720121829.566974-6-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Do the conversion of health reporter get command to split ops. Introduce devlink_nl_pre_doit_port_optional() helper to indicate optional port object attribute parsing and use it as pre_doit() callback. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 2 +- net/devlink/leftover.c | 10 +--------- net/devlink/netlink.c | 25 +++++++++++++++++++++++++ 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 2870be150ee3..948b112c1328 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -116,7 +116,7 @@ struct devlink_cmd { struct netlink_callback *cb); }; -extern const struct genl_small_ops devlink_nl_ops[55]; +extern const struct genl_small_ops devlink_nl_ops[54]; struct devlink * devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 33f71e8fe8ee..262f3e49e87b 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -6301,7 +6301,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, return devlink_trap_policer_set(devlink, policer_item, info); } -const struct genl_small_ops devlink_nl_ops[55] = { +const struct genl_small_ops devlink_nl_ops[54] = { { .cmd = DEVLINK_CMD_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6550,14 +6550,6 @@ const struct genl_small_ops devlink_nl_ops[55] = { .dumpit = devlink_nl_instance_iter_dumpit, /* can be retrieved by unprivileged users */ }, - { - .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_health_reporter_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - .internal_flags = DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_HEALTH_REPORTER_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index cd35fa637846..794370e4d04a 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -153,6 +153,13 @@ static int devlink_nl_pre_doit_port(const struct genl_split_ops *ops, return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_PORT); } +static int devlink_nl_pre_doit_port_optional(const struct genl_split_ops *ops, + struct sk_buff *skb, + struct genl_info *info) +{ + return __devlink_nl_pre_doit(skb, info, DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT); +} + static void devlink_nl_post_doit(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { @@ -238,6 +245,24 @@ static const struct genl_split_ops devlink_nl_split_ops[] = { .maxattr = DEVLINK_ATTR_MAX, .policy = devlink_nl_policy, }, + { + .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, + .pre_doit = devlink_nl_pre_doit_port_optional, + .doit = devlink_nl_cmd_health_reporter_get_doit, + .post_doit = devlink_nl_post_doit, + .flags = GENL_CMD_CAP_DO, + .validate = GENL_DONT_VALIDATE_STRICT, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, + { + .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, + .dumpit = devlink_nl_instance_iter_dumpit, + .flags = GENL_CMD_CAP_DUMP, + .validate = GENL_DONT_VALIDATE_DUMP, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, }; struct genl_family devlink_nl_family __ro_after_init = { From patchwork Thu Jul 20 12:18:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320431 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 99C2918AE6 for ; Thu, 20 Jul 2023 12:18:43 +0000 (UTC) Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 01A722106 for ; Thu, 20 Jul 2023 05:18:42 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-3fbc244d384so5968985e9.0 for ; Thu, 20 Jul 2023 05:18:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855520; x=1690460320; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=jfomzBd2PwRVNE5zLngiFCaGvBicotIQrBKITcrn62Q=; b=c2iF+WKBdmbseLYY3RfM1Ae2jHp8vbRU6goGfHE9vrVnhjLMYgsdAmwds5yimqi51w UvhoK0LfZeJThWia6mIOA+HMprLDVN+RI5AfMcOPk2bqqy/Kh2ynMGnL9f94lLPmf3uJ XMFHrUm3103xY+FzLXsaiQ9CjLknL/wLDLZFqw8DB3rxy9aQ7wiuAcx2HUWoJoC0vWL8 VPcT3N40S9ZdsrHOVN+0t3afjoHqC5h/l9LQ9ECcNXolagJTVu9cATnUnpafnQJcoESH ZSlm/FoM6R2GiCfH591EBCbWkArao50Cf2Yhl19nVZBwvcTJgFQdAt3RVYfcZbBfXN7i e1uw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855520; x=1690460320; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jfomzBd2PwRVNE5zLngiFCaGvBicotIQrBKITcrn62Q=; b=FqTvA1QxpZ/SH1jlb3tBnKsrbNq/IZn0pIfJ8UVkntHC0QbamIY1BYShmqJKMQrCkO HE+JzQu9TjXM/aCrgF5SduKSCz+Zoq7UeKCLTiTeohnzwlaa+8Yg3CIXPasEcEZHJHqA IPCfr9n+x11Ol0onHQ54MHGzQ6fKAjykH+oIgwJYX11zJjF2cHywvdG/gUt1Gl0C4OQ6 6hZV6CWOoeqyvaVa5D09P6a7T7R08YOlTH9n5TqPXMB8VqKPd/ChOdtFYNcirlQG64tA StuhGDTy4oVNw5GKnIavZA1QFZr4VW4IHs2uv+CZ4Le+KeOsdkTAP53EX2IJxe0rxh8C Rdmg== X-Gm-Message-State: ABy/qLbimCfnCT4rTCwBYn8Ij9rHk7toZKVbH9OUsXant+5c8wLD0Y5Z rCgHLBcyntH+9hNOSsm+zXJ2FcPxqwLRTYAAlqk= X-Google-Smtp-Source: APBJJlHtLhc0qTZoJD3wnXQpAZG5EyKx9lYdlL6uPcZoE3Hp23DNOeUP1q0R8SpiLGulue05eD0sww== X-Received: by 2002:a05:600c:218:b0:3fb:b008:1ff6 with SMTP id 24-20020a05600c021800b003fbb0081ff6mr6231664wmi.0.1689855520484; Thu, 20 Jul 2023 05:18:40 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id z10-20020a05600c220a00b003fc07e1908csm1029404wml.43.2023.07.20.05.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:40 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 06/11] devlink: convert param get command to split ops Date: Thu, 20 Jul 2023 14:18:24 +0200 Message-ID: <20230720121829.566974-7-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Do the conversion of param get command to split ops. Introduce devlink_nl_pre_doit_simple() helper to indicate just devlink handle attributes parsing and use it as pre_doit() callback. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 4 +++- net/devlink/leftover.c | 13 +++---------- net/devlink/netlink.c | 24 ++++++++++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 948b112c1328..5ba3f066b3b2 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -116,7 +116,7 @@ struct devlink_cmd { struct netlink_callback *cb); }; -extern const struct genl_small_ops devlink_nl_ops[54]; +extern const struct genl_small_ops devlink_nl_ops[53]; struct devlink * devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs); @@ -211,6 +211,8 @@ int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb, struct genl_info *inf int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_param_get_doit(struct sk_buff *skb, + struct genl_info *info); int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 262f3e49e87b..8729dd740171 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -4295,8 +4295,8 @@ devlink_param_get_from_info(struct xarray *params, struct genl_info *info) return devlink_param_find_by_name(params, param_name); } -static int devlink_nl_cmd_param_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_param_get_doit(struct sk_buff *skb, + struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; struct devlink_param_item *param_item; @@ -6301,7 +6301,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, return devlink_trap_policer_set(devlink, policer_item, info); } -const struct genl_small_ops devlink_nl_ops[54] = { +const struct genl_small_ops devlink_nl_ops[53] = { { .cmd = DEVLINK_CMD_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6489,13 +6489,6 @@ const struct genl_small_ops devlink_nl_ops[54] = { .doit = devlink_nl_cmd_reload, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_PARAM_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_param_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_PARAM_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 794370e4d04a..bd128584e8c8 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -147,6 +147,12 @@ static int devlink_nl_pre_doit(const struct genl_split_ops *ops, return __devlink_nl_pre_doit(skb, info, ops->internal_flags); } +static int devlink_nl_pre_doit_simple(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ + return __devlink_nl_pre_doit(skb, info, 0); +} + static int devlink_nl_pre_doit_port(const struct genl_split_ops *ops, struct sk_buff *skb, struct genl_info *info) { @@ -245,6 +251,24 @@ static const struct genl_split_ops devlink_nl_split_ops[] = { .maxattr = DEVLINK_ATTR_MAX, .policy = devlink_nl_policy, }, + { + .cmd = DEVLINK_CMD_PARAM_GET, + .pre_doit = devlink_nl_pre_doit_simple, + .doit = devlink_nl_cmd_param_get_doit, + .post_doit = devlink_nl_post_doit, + .flags = GENL_CMD_CAP_DO, + .validate = GENL_DONT_VALIDATE_STRICT, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, + { + .cmd = DEVLINK_CMD_PARAM_GET, + .dumpit = devlink_nl_instance_iter_dumpit, + .flags = GENL_CMD_CAP_DUMP, + .validate = GENL_DONT_VALIDATE_DUMP, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, { .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, .pre_doit = devlink_nl_pre_doit_port_optional, From patchwork Thu Jul 20 12:18:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320432 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3122C18AE6 for ; Thu, 20 Jul 2023 12:18:44 +0000 (UTC) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 768062115 for ; Thu, 20 Jul 2023 05:18:43 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3fc04692e20so6216315e9.0 for ; Thu, 20 Jul 2023 05:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855522; x=1690460322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nNI4AIvtc24qZC/JImoWZi403YlvbJrU2GRSCx32kA0=; b=nSUea9AGjelwvRcQKCLz8iopr0Qi15cY2XWRoXu39BxFpRISle7eU+lGx0yfH4HySM TMNtwST4IVYKn855xB7wPHdlC5v3vy4ciCbUUPavcY1pLIQ9pg6d5i20gqitoQv9zsYU 2eVKCw1wr4ukuIfgqBFpCx+Sb241h7Qxjbmipo08eYyVYGLUGRe0TdRFs8PwatTEcjlK H3zFOQkzKFzafFZUj7CDHot0FY+qNc3aGrIc7o8Qv1j7b0T/v+p5zUL4H3BOuMbqmJPS 3BsDR92f1wLRx3bAw/fEgfWiyV81eSuiQAXIYjJCK0su2yIKJl7yD53yCP2obO/flTRq t9iA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855522; x=1690460322; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nNI4AIvtc24qZC/JImoWZi403YlvbJrU2GRSCx32kA0=; b=S7LZRdfwLVTYdjNhs51VRoFTmI4raBnBcaukhG7ZtmHRGPQdqijS1958RccLwJ25v1 o77fpdQ27WAmHwJQVO677KFBUP6cWZvxhgNzhBxZAg1jyZKPINPRRVXr6sezKBR+bS7E EGlHzsJZ+sjdXaaw1se46bBKr8uFav9+x9WZhRSa5AADx+fXohqfnQg0yvuW2PHZozfz Y9nIZFCIXN9atjJJGZYCVXxryPs0jRZE/r7J+Ds1UIb+15usOPfnJ0RD+wD3786I6XRK ApjP7sRPdi3J+G7Wvgj1Oi0iKpS+5Gx0W5FLv9y4KatIsnxz0OJm6MV0wroLOq+0M/7i pmjg== X-Gm-Message-State: ABy/qLbl+TK1ujt37rLrkn+xFISlpOdehtEHdoTpCVSkGDr2R0nTqnAZ FyL5ODGWk7FtJVXc1/zRbRSLyiFBzV8RUmluGnQ= X-Google-Smtp-Source: APBJJlGcLgsQJsIa6W8tuxgKe4CqnGLcmOZ9FyFdm5OCiWqPqP80yEnOmnka7YCEuSUE5IayUIzZpg== X-Received: by 2002:a05:600c:204b:b0:3fa:9561:3016 with SMTP id p11-20020a05600c204b00b003fa95613016mr6531587wmg.30.1689855522042; Thu, 20 Jul 2023 05:18:42 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id z20-20020a1c4c14000000b003fc6179e20asm3674604wmf.1.2023.07.20.05.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:41 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 07/11] devlink: convert trap get command to split ops Date: Thu, 20 Jul 2023 14:18:25 +0200 Message-ID: <20230720121829.566974-8-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Do the conversion of trap get command to split ops. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 3 ++- net/devlink/leftover.c | 11 ++--------- net/devlink/netlink.c | 16 ++++++++++++++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 5ba3f066b3b2..dc655d5797a8 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -116,7 +116,7 @@ struct devlink_cmd { struct netlink_callback *cb); }; -extern const struct genl_small_ops devlink_nl_ops[53]; +extern const struct genl_small_ops devlink_nl_ops[52]; struct devlink * devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs); @@ -227,3 +227,4 @@ int devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_trap_get_doit(struct sk_buff *skb, struct genl_info *info); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 8729dd740171..3dbba1906ee6 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -5655,8 +5655,7 @@ static int devlink_nl_trap_fill(struct sk_buff *msg, struct devlink *devlink, return -EMSGSIZE; } -static int devlink_nl_cmd_trap_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_trap_get_doit(struct sk_buff *skb, struct genl_info *info) { struct netlink_ext_ack *extack = info->extack; struct devlink *devlink = info->user_ptr[0]; @@ -6301,7 +6300,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, return devlink_trap_policer_set(devlink, policer_item, info); } -const struct genl_small_ops devlink_nl_ops[53] = { +const struct genl_small_ops devlink_nl_ops[52] = { { .cmd = DEVLINK_CMD_GET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6591,12 +6590,6 @@ const struct genl_small_ops devlink_nl_ops[53] = { .doit = devlink_nl_cmd_flash_update, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_TRAP_GET, - .doit = devlink_nl_cmd_trap_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_TRAP_SET, .doit = devlink_nl_cmd_trap_set_doit, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index bd128584e8c8..cabebff6e7a7 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -287,6 +287,22 @@ static const struct genl_split_ops devlink_nl_split_ops[] = { .maxattr = DEVLINK_ATTR_MAX, .policy = devlink_nl_policy, }, + { + .cmd = DEVLINK_CMD_TRAP_GET, + .pre_doit = devlink_nl_pre_doit_simple, + .doit = devlink_nl_cmd_trap_get_doit, + .post_doit = devlink_nl_post_doit, + .flags = GENL_CMD_CAP_DO, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, + { + .cmd = DEVLINK_CMD_TRAP_GET, + .dumpit = devlink_nl_instance_iter_dumpit, + .flags = GENL_CMD_CAP_DUMP, + .maxattr = DEVLINK_ATTR_MAX, + .policy = devlink_nl_policy, + }, }; struct genl_family devlink_nl_family __ro_after_init = { From patchwork Thu Jul 20 12:18:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320433 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ACB0318AE6 for ; Thu, 20 Jul 2023 12:18:46 +0000 (UTC) Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DB392106 for ; Thu, 20 Jul 2023 05:18:45 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-3fbc244d307so6133415e9.1 for ; Thu, 20 Jul 2023 05:18:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855523; x=1690460323; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ii8JB/y8HnFzFLg5jRSqjsd1dxooNhCffkYW/XJ2yHk=; b=XTgqp70aVW5kQPNF+nbUH014Vb+x52MsdQc4nlsSl76ME4D8nbfnCVR16UBRqrUqYR FmHYs2FKCVkXzvpnf+hLVwR8S8Yv5UjMLY0zR6KazYx5eYsxluTds++ZxTPZcPkvNDaw B4LuynPimy8RPWrAgLcsH2e9Ex+cXUYehz7HaaVswsyPrIYQcbYP+PDbNbgZG2dGqR/l zTtkQUq/Pt1uN0hIevL4grye0dRWNj/ozEclNYSORjYaJi7CDNB8LlX1mssHUcnrcRor YkRPFvf9Niau5DEOprEPMjLQdaXmeKsPgoj7nbLz+2B7cVfx/QKknuB26KeQrynrUFr6 dxVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855523; x=1690460323; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ii8JB/y8HnFzFLg5jRSqjsd1dxooNhCffkYW/XJ2yHk=; b=Z6W2NNJ0vLg+iJluMNt9JgnHv4Tjc6FPM9xqkOTvlfIOmwQLCCCoWTir8bz5YYTfnv BtCv348YV0cow52rBZHUoPZXNd9/K46dJxJGYD8GFJXkCPR6Q98cv+ATBs+OJceusoLh sg1sVgssLGFomQzVW+feKA0f29mTWAWZKxT87fvRRdigpPGOe2j0ojaMrsrDAsZSuuw6 1AZqThWzdK8UUJMBD2HWQCiOA7ib2g5CFr1r6PEH2lXmJT7UILp0N7otIv/2itU5oJVt sdi0E151Be2IHZRbfWbFfOPmZbQk6phdUPp3Aydf1YHN/PtBEQeeOW/zw3+SEuK/1xz1 PtsA== X-Gm-Message-State: ABy/qLZjmakEXIr5Heexbug6Ej4t9pei50VZT9s6bj18XBNJ+cwZZmye iHJ/ReIOf9oA/GsnhY53F+5KDsV7C2EoQYpc2rQ= X-Google-Smtp-Source: APBJJlG8UEpEyNAB3B/JeI3EA8UiE90J6o986qXvT3xbygseLG67RQEMC633oxEzk/36TzG/sei0LA== X-Received: by 2002:a05:600c:3658:b0:3fb:b008:2003 with SMTP id y24-20020a05600c365800b003fbb0082003mr6888098wmq.38.1689855523603; Thu, 20 Jul 2023 05:18:43 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id x2-20020adff642000000b0031444673643sm1180135wrp.57.2023.07.20.05.18.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:43 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 08/11] devlink: introduce set of macros and use it for split ops definitions Date: Thu, 20 Jul 2023 14:18:26 +0200 Message-ID: <20230720121829.566974-9-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko The split ops structures for all commands look pretty much the same. The are all using the same/similar callbacks. Introduce a set of macros to make the code shorter and also avoid possible future copy&paste mistakes and inconsistencies. Use this macros for already converted commands. Signed-off-by: Jiri Pirko --- net/devlink/netlink.c | 136 ++++++++++++++++++++---------------------- 1 file changed, 66 insertions(+), 70 deletions(-) diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index cabebff6e7a7..3dae9303cfa7 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -232,77 +232,73 @@ int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, return msg->len; } +#define __DEVL_NL_OP_DO(cmd_subname, doit_subname, pre_doit_suffix, _validate, \ + _maxattr, _policy) \ + { \ + .cmd = DEVLINK_CMD_##cmd_subname, \ + .pre_doit = devlink_nl_pre_doit_##pre_doit_suffix, \ + .doit = devlink_nl_cmd_##doit_subname##_doit, \ + .post_doit = devlink_nl_post_doit, \ + .flags = GENL_CMD_CAP_DO, \ + .validate = _validate, \ + .maxattr = _maxattr, \ + .policy = _policy, \ + } + +#define __DEVL_NL_OP_DUMP(cmd_subname, _validate, _maxattr, _policy) \ + { \ + .cmd = DEVLINK_CMD_##cmd_subname, \ + .dumpit = devlink_nl_instance_iter_dumpit, \ + .flags = GENL_CMD_CAP_DUMP, \ + .validate = _validate, \ + .maxattr = _maxattr, \ + .policy = _policy, \ + } + +#define __DEVL_NL_OP_LEGACY_DO(cmd_subname, doit_subname, pre_doit_suffix, \ + validate) \ + __DEVL_NL_OP_DO(cmd_subname, doit_subname, pre_doit_suffix, validate, \ + DEVLINK_ATTR_MAX, devlink_nl_policy) + +#define __DEVL_NL_OP_LEGACY_DUMP(cmd_subname, validate) \ + __DEVL_NL_OP_DUMP(cmd_subname, validate, \ + DEVLINK_ATTR_MAX, devlink_nl_policy) + +#define DEVL_NL_OP_LEGACY_DO(cmd_subname, doit_subname, pre_doit_suffix) \ + __DEVL_NL_OP_LEGACY_DO(cmd_subname, doit_subname, pre_doit_suffix, \ + GENL_DONT_VALIDATE_STRICT) + +#define DEVL_NL_OP_LEGACY_DUMP(cmd_subname) \ + __DEVL_NL_OP_LEGACY_DUMP(cmd_subname, GENL_DONT_VALIDATE_DUMP_STRICT) + +#define DEVL_NL_OP_LEGACY_STRICT_DO(cmd_subname, doit_subname, pre_doit_suffix) \ + __DEVL_NL_OP_LEGACY_DO(cmd_subname, doit_subname, pre_doit_suffix, 0) + +#define DEVL_NL_OP_LEGACY_STRICT_DUMP(cmd_subname) \ + __DEVL_NL_OP_LEGACY_DUMP(cmd_subname, 0) + +#define DEVL_NL_OP_DO(cmd_subname, doit_subname, pre_doit_suffix, \ + maxattr, policy) \ + __DEVL_NL_OP_DO(cmd_subname, doit_subname, pre_doit_suffix, 0, \ + maxattr, policy) + +#define DEVL_NL_OP_DUMP(cmd_subname, maxattr, policy) \ + __DEVL_NL_OP_DUMP(cmd_subname, 0, maxattr, policy) + static const struct genl_split_ops devlink_nl_split_ops[] = { - { - .cmd = DEVLINK_CMD_PORT_GET, - .pre_doit = devlink_nl_pre_doit_port, - .doit = devlink_nl_cmd_port_get_doit, - .post_doit = devlink_nl_post_doit, - .flags = GENL_CMD_CAP_DO, - .validate = GENL_DONT_VALIDATE_STRICT, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, - { - .cmd = DEVLINK_CMD_PORT_GET, - .dumpit = devlink_nl_instance_iter_dumpit, - .flags = GENL_CMD_CAP_DUMP, - .validate = GENL_DONT_VALIDATE_DUMP, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, - { - .cmd = DEVLINK_CMD_PARAM_GET, - .pre_doit = devlink_nl_pre_doit_simple, - .doit = devlink_nl_cmd_param_get_doit, - .post_doit = devlink_nl_post_doit, - .flags = GENL_CMD_CAP_DO, - .validate = GENL_DONT_VALIDATE_STRICT, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, - { - .cmd = DEVLINK_CMD_PARAM_GET, - .dumpit = devlink_nl_instance_iter_dumpit, - .flags = GENL_CMD_CAP_DUMP, - .validate = GENL_DONT_VALIDATE_DUMP, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, - { - .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, - .pre_doit = devlink_nl_pre_doit_port_optional, - .doit = devlink_nl_cmd_health_reporter_get_doit, - .post_doit = devlink_nl_post_doit, - .flags = GENL_CMD_CAP_DO, - .validate = GENL_DONT_VALIDATE_STRICT, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, - { - .cmd = DEVLINK_CMD_HEALTH_REPORTER_GET, - .dumpit = devlink_nl_instance_iter_dumpit, - .flags = GENL_CMD_CAP_DUMP, - .validate = GENL_DONT_VALIDATE_DUMP, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, - { - .cmd = DEVLINK_CMD_TRAP_GET, - .pre_doit = devlink_nl_pre_doit_simple, - .doit = devlink_nl_cmd_trap_get_doit, - .post_doit = devlink_nl_post_doit, - .flags = GENL_CMD_CAP_DO, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, - { - .cmd = DEVLINK_CMD_TRAP_GET, - .dumpit = devlink_nl_instance_iter_dumpit, - .flags = GENL_CMD_CAP_DUMP, - .maxattr = DEVLINK_ATTR_MAX, - .policy = devlink_nl_policy, - }, + DEVL_NL_OP_LEGACY_DO(PORT_GET, port_get, port), + DEVL_NL_OP_LEGACY_DUMP(PORT_GET), + DEVL_NL_OP_LEGACY_DO(PARAM_GET, param_get, simple), + DEVL_NL_OP_LEGACY_DUMP(PARAM_GET), + DEVL_NL_OP_LEGACY_DO(HEALTH_REPORTER_GET, health_reporter_get, + port_optional), + DEVL_NL_OP_LEGACY_DUMP(HEALTH_REPORTER_GET), + DEVL_NL_OP_LEGACY_STRICT_DO(TRAP_GET, trap_get, simple), + DEVL_NL_OP_LEGACY_STRICT_DUMP(TRAP_GET), + /* For every newly added command put above this line the set of macros + * DEVL_NL_OP_DO and DEVL_NL_OP_DUMP should be used. Note that + * there is an exception with non-iterator dump implementation. + */ }; struct genl_family devlink_nl_family __ro_after_init = { From patchwork Thu Jul 20 12:18:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320434 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D796218AE6 for ; Thu, 20 Jul 2023 12:18:48 +0000 (UTC) Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5F732115 for ; Thu, 20 Jul 2023 05:18:46 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-3158a5e64b6so606803f8f.0 for ; Thu, 20 Jul 2023 05:18:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855525; x=1690460325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=qhsdohNrpAKlDKxlWkClE3hMEC+PlU07lAyGbkdCoME=; b=4tTrogEMLpltBC+jb3/7oktR/7Snpx6rHPuPSX9vx4TvurEXn/dwjx0Gaqe/rWH+MM Tn2Cjz0IWmlXVwhJNg4d5199Ge63/xZN6g9B8bw9h8flSadWksbg/BZkRopV0zUXXypb Lnh4Sn3058VW2NhUB5RY/t8z4AEpM/vMyaa8o4abrH204TEMV9zgHtQa+UhY9U44eak5 miex4+cMKx2W64zeaTw+jQnoGsVaznWPY5U1I4Ccdc9cKwKcHRzSXHYoK9Z7OtI7R3Ng Smh6Plapnv/ZacMmi/5O+tDLEtEjjrItmm9zJuc4HN0xQDY1RY/xXVpDUr7oc49EZ0V8 QnVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855525; x=1690460325; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qhsdohNrpAKlDKxlWkClE3hMEC+PlU07lAyGbkdCoME=; b=U3HhJ1Og48NNKRXId1y/ja006ZR/cBGbs6mZ94DqYpOlTBx6mZ/f4eNTcrcNLKgrUh BC39uFqOl7M2EDvlH/ffEw0PqsnZHT+hxEV1yhTMsA2Y1M79Ttsv4gUy/3VQmrMYo48C pJSJSHJKhsbPY85NFBkExR63gV5C4/fsfG7WYON88JzcPeOYK8rqdrrH+taeOXkBv1ED utJa4dEXCDkkIn39koUgSLdvy+ypUzRhYOSZXrISo7gyoQkonNq/fj+LgZ4roGvbVs4z Wid3ZWJ5X4G9Z319M/xNcOJPG254/xdhToQXonju6ZS8I92A3LYyhXzQ7Nif/m+LqUm1 plRg== X-Gm-Message-State: ABy/qLbbcy4kcf2LIjfjrtGQcgr00M5WPc2s09jaJx4a4ZyB0zIjGMFl AhmjMgB7V6/Cn1qpO2ePT/b6G2z4rjSicaiQkTA= X-Google-Smtp-Source: APBJJlHb9dsBx1+DTfwF58IRCHVnaFRN06rjjomKV8in2mphxRfn9TVfcKl7857h5SuQn6nCyVHLxA== X-Received: by 2002:adf:ee8f:0:b0:314:2ba3:15dd with SMTP id b15-20020adfee8f000000b003142ba315ddmr1698362wro.16.1689855525220; Thu, 20 Jul 2023 05:18:45 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id f12-20020a7bcc0c000000b003fc0062f0f8sm1079569wmh.9.2023.07.20.05.18.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:44 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 09/11] devlink: convert rest of the iterator dumpit commands to split ops Date: Thu, 20 Jul 2023 14:18:27 +0200 Message-ID: <20230720121829.566974-10-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko In a similar fashion couple of example commands were converted previously, do the conversion of the rest of the commands that use devlink_nl_instance_iter_dumpit() callback. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 19 ++++-- net/devlink/leftover.c | 115 +++++------------------------------- net/devlink/netlink.c | 28 ++++++++- 3 files changed, 56 insertions(+), 106 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index dc655d5797a8..79614b45e8ac 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -116,7 +116,7 @@ struct devlink_cmd { struct netlink_callback *cb); }; -extern const struct genl_small_ops devlink_nl_ops[52]; +extern const struct genl_small_ops devlink_nl_ops[40]; struct devlink * devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs); @@ -124,9 +124,6 @@ devlink_get_from_attrs_lock(struct net *net, struct nlattr **attrs); void devlink_notify_unregister(struct devlink *devlink); void devlink_notify_register(struct devlink *devlink); -int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, - struct netlink_callback *cb); - static inline struct devlink_nl_dump_state * devlink_dump_state(struct netlink_callback *cb) { @@ -211,8 +208,15 @@ int devlink_nl_cmd_selftests_get_doit(struct sk_buff *skb, struct genl_info *inf int devlink_nl_cmd_selftests_run(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_port_get_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_sb_get_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_sb_pool_get_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb, + struct genl_info *info); +int devlink_nl_cmd_sb_tc_pool_bind_get_doit(struct sk_buff *skb, + struct genl_info *info); int devlink_nl_cmd_param_get_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_region_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_health_reporter_get_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, @@ -227,4 +231,11 @@ int devlink_nl_cmd_health_reporter_dump_clear_doit(struct sk_buff *skb, struct genl_info *info); int devlink_nl_cmd_health_reporter_test_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, + struct genl_info *info); int devlink_nl_cmd_trap_get_doit(struct sk_buff *skb, struct genl_info *info); +int devlink_nl_cmd_trap_group_get_doit(struct sk_buff *skb, + struct genl_info *info); +int devlink_nl_cmd_trap_policer_get_doit(struct sk_buff *skb, + struct genl_info *info); diff --git a/net/devlink/leftover.c b/net/devlink/leftover.c index 3dbba1906ee6..58ea1b9cc708 100644 --- a/net/devlink/leftover.c +++ b/net/devlink/leftover.c @@ -1038,8 +1038,7 @@ const struct devlink_cmd devl_cmd_rate_get = { .dump_one = devlink_nl_cmd_rate_get_dump_one, }; -static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; struct devlink_rate *devlink_rate; @@ -1825,8 +1824,8 @@ static void devlink_linecard_notify(struct devlink_linecard *linecard, msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); } -static int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_linecard_get_doit(struct sk_buff *skb, + struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; struct devlink_linecard *linecard; @@ -2091,8 +2090,7 @@ static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink, return -EMSGSIZE; } -static int devlink_nl_cmd_sb_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_sb_get_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; struct devlink_sb *devlink_sb; @@ -2194,8 +2192,7 @@ static int devlink_nl_sb_pool_fill(struct sk_buff *msg, struct devlink *devlink, return -EMSGSIZE; } -static int devlink_nl_cmd_sb_pool_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_sb_pool_get_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; struct devlink_sb *devlink_sb; @@ -2394,8 +2391,8 @@ static int devlink_nl_sb_port_pool_fill(struct sk_buff *msg, return err; } -static int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_sb_port_pool_get_doit(struct sk_buff *skb, + struct genl_info *info) { struct devlink_port *devlink_port = info->user_ptr[1]; struct devlink *devlink = devlink_port->devlink; @@ -2603,8 +2600,8 @@ devlink_nl_sb_tc_pool_bind_fill(struct sk_buff *msg, struct devlink *devlink, return -EMSGSIZE; } -static int devlink_nl_cmd_sb_tc_pool_bind_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_sb_tc_pool_bind_get_doit(struct sk_buff *skb, + struct genl_info *info) { struct devlink_port *devlink_port = info->user_ptr[1]; struct devlink *devlink = devlink_port->devlink; @@ -4793,8 +4790,7 @@ static void devlink_region_snapshot_del(struct devlink_region *region, kfree(snapshot); } -static int devlink_nl_cmd_region_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_region_get_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; struct devlink_port *port = NULL; @@ -5865,8 +5861,8 @@ devlink_nl_trap_group_fill(struct sk_buff *msg, struct devlink *devlink, return -EMSGSIZE; } -static int devlink_nl_cmd_trap_group_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_trap_group_get_doit(struct sk_buff *skb, + struct genl_info *info) { struct netlink_ext_ack *extack = info->extack; struct devlink *devlink = info->user_ptr[0]; @@ -6159,8 +6155,8 @@ devlink_nl_trap_policer_fill(struct sk_buff *msg, struct devlink *devlink, return -EMSGSIZE; } -static int devlink_nl_cmd_trap_policer_get_doit(struct sk_buff *skb, - struct genl_info *info) +int devlink_nl_cmd_trap_policer_get_doit(struct sk_buff *skb, + struct genl_info *info) { struct devlink_trap_policer_item *policer_item; struct netlink_ext_ack *extack = info->extack; @@ -6300,14 +6296,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, return devlink_trap_policer_set(devlink, policer_item, info); } -const struct genl_small_ops devlink_nl_ops[52] = { - { - .cmd = DEVLINK_CMD_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, +const struct genl_small_ops devlink_nl_ops[40] = { { .cmd = DEVLINK_CMD_PORT_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6315,12 +6304,6 @@ const struct genl_small_ops devlink_nl_ops[52] = { .flags = GENL_ADMIN_PERM, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, }, - { - .cmd = DEVLINK_CMD_RATE_GET, - .doit = devlink_nl_cmd_rate_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_RATE_SET, .doit = devlink_nl_cmd_rate_set_doit, @@ -6361,45 +6344,17 @@ const struct genl_small_ops devlink_nl_ops[52] = { .flags = GENL_ADMIN_PERM, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, }, - { - .cmd = DEVLINK_CMD_LINECARD_GET, - .doit = devlink_nl_cmd_linecard_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_LINECARD_SET, .doit = devlink_nl_cmd_linecard_set_doit, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_SB_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_sb_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, - { - .cmd = DEVLINK_CMD_SB_POOL_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_sb_pool_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_SB_POOL_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_sb_pool_set_doit, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_SB_PORT_POOL_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_sb_port_pool_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_SB_PORT_POOL_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6407,14 +6362,6 @@ const struct genl_small_ops devlink_nl_ops[52] = { .flags = GENL_ADMIN_PERM, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, }, - { - .cmd = DEVLINK_CMD_SB_TC_POOL_BIND_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_sb_tc_pool_bind_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_SB_TC_POOL_BIND_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6509,13 +6456,6 @@ const struct genl_small_ops devlink_nl_ops[52] = { .flags = GENL_ADMIN_PERM, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, }, - { - .cmd = DEVLINK_CMD_REGION_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_region_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - .flags = GENL_ADMIN_PERM, - }, { .cmd = DEVLINK_CMD_REGION_NEW, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6535,13 +6475,6 @@ const struct genl_small_ops devlink_nl_ops[52] = { .dumpit = devlink_nl_cmd_region_read_dumpit, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_INFO_GET, - .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, - .doit = devlink_nl_cmd_info_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_HEALTH_REPORTER_SET, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, @@ -6595,34 +6528,16 @@ const struct genl_small_ops devlink_nl_ops[52] = { .doit = devlink_nl_cmd_trap_set_doit, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_TRAP_GROUP_GET, - .doit = devlink_nl_cmd_trap_group_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_TRAP_GROUP_SET, .doit = devlink_nl_cmd_trap_group_set_doit, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_TRAP_POLICER_GET, - .doit = devlink_nl_cmd_trap_policer_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_TRAP_POLICER_SET, .doit = devlink_nl_cmd_trap_policer_set_doit, .flags = GENL_ADMIN_PERM, }, - { - .cmd = DEVLINK_CMD_SELFTESTS_GET, - .doit = devlink_nl_cmd_selftests_get_doit, - .dumpit = devlink_nl_instance_iter_dumpit, - /* can be retrieved by unprivileged users */ - }, { .cmd = DEVLINK_CMD_SELFTESTS_RUN, .doit = devlink_nl_cmd_selftests_run, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 3dae9303cfa7..90497d0e1a7b 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -195,8 +195,8 @@ static const struct devlink_cmd *devl_cmds[] = { [DEVLINK_CMD_SELFTESTS_GET] = &devl_cmd_selftests_get, }; -int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, - struct netlink_callback *cb) +static int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) { const struct genl_dumpit_info *info = genl_dumpit_info(cb); struct devlink_nl_dump_state *state = devlink_dump_state(cb); @@ -286,15 +286,39 @@ int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, __DEVL_NL_OP_DUMP(cmd_subname, 0, maxattr, policy) static const struct genl_split_ops devlink_nl_split_ops[] = { + DEVL_NL_OP_LEGACY_DO(GET, get, simple), + DEVL_NL_OP_LEGACY_DUMP(GET), DEVL_NL_OP_LEGACY_DO(PORT_GET, port_get, port), DEVL_NL_OP_LEGACY_DUMP(PORT_GET), + DEVL_NL_OP_LEGACY_DO(SB_GET, sb_get, simple), + DEVL_NL_OP_LEGACY_DUMP(SB_GET), + DEVL_NL_OP_LEGACY_DO(SB_POOL_GET, sb_pool_get, simple), + DEVL_NL_OP_LEGACY_DUMP(SB_POOL_GET), + DEVL_NL_OP_LEGACY_DO(SB_PORT_POOL_GET, sb_port_pool_get, simple), + DEVL_NL_OP_LEGACY_DUMP(SB_PORT_POOL_GET), + DEVL_NL_OP_LEGACY_DO(SB_TC_POOL_BIND_GET, sb_tc_pool_bind_get, simple), + DEVL_NL_OP_LEGACY_DUMP(SB_TC_POOL_BIND_GET), DEVL_NL_OP_LEGACY_DO(PARAM_GET, param_get, simple), DEVL_NL_OP_LEGACY_DUMP(PARAM_GET), + DEVL_NL_OP_LEGACY_DO(REGION_GET, region_get, simple), + DEVL_NL_OP_LEGACY_DUMP(REGION_GET), + DEVL_NL_OP_LEGACY_DO(INFO_GET, info_get, simple), + DEVL_NL_OP_LEGACY_DUMP(INFO_GET), DEVL_NL_OP_LEGACY_DO(HEALTH_REPORTER_GET, health_reporter_get, port_optional), DEVL_NL_OP_LEGACY_DUMP(HEALTH_REPORTER_GET), DEVL_NL_OP_LEGACY_STRICT_DO(TRAP_GET, trap_get, simple), DEVL_NL_OP_LEGACY_STRICT_DUMP(TRAP_GET), + DEVL_NL_OP_LEGACY_STRICT_DO(TRAP_GROUP_GET, trap_group_get, simple), + DEVL_NL_OP_LEGACY_STRICT_DUMP(TRAP_GROUP_GET), + DEVL_NL_OP_LEGACY_STRICT_DO(TRAP_POLICER_GET, trap_policer_get, simple), + DEVL_NL_OP_LEGACY_STRICT_DUMP(TRAP_POLICER_GET), + DEVL_NL_OP_LEGACY_DO(RATE_GET, rate_get, simple), + DEVL_NL_OP_LEGACY_DUMP(RATE_GET), + DEVL_NL_OP_LEGACY_DO(LINECARD_GET, linecard_get, simple), + DEVL_NL_OP_LEGACY_DUMP(LINECARD_GET), + DEVL_NL_OP_LEGACY_STRICT_DO(SELFTESTS_GET, selftests_get, simple), + DEVL_NL_OP_LEGACY_STRICT_DUMP(SELFTESTS_GET), /* For every newly added command put above this line the set of macros * DEVL_NL_OP_DO and DEVL_NL_OP_DUMP should be used. Note that * there is an exception with non-iterator dump implementation. From patchwork Thu Jul 20 12:18:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320435 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC0B318AE6 for ; Thu, 20 Jul 2023 12:18:49 +0000 (UTC) Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3801D2118 for ; Thu, 20 Jul 2023 05:18:48 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id 5b1f17b1804b1-3fbc244d307so6133955e9.1 for ; Thu, 20 Jul 2023 05:18:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855527; x=1690460327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=yPxToTyBRAptPJ35kaLzduS5meI3ZEBgPclW44Vycyk=; b=hGE3Cb6axyvxsCYd80XKyzxnymoezB9L3ebJSEfr7cwnTeK4O69aHFd/zsahlW0ldc yLLnsYNlatvpt4OIYazxzm+XdxHgHOAC3zlL8xgWBOrZ3EKVMYkRnQ58pc0wWD4Et8rs 3kcQQPj5jT6SNMfEFqbZAEdyPFxitCOZFRWkFYoP1pPxfOlTOVSJy9ISgGtjxpssFM+W M039ERxTMQlCyyvuXAm32pjqHJbftIj2gbgg23OwwlxDhytc5eZ3/Az8U19JlKSVz7hI muUfKShr9ekp6U7iSUSvZX2GDOv18Ivzj3wouR3s9720zaWdL46bBkFaO54zZbR7wlSh E1Wg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855527; x=1690460327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=yPxToTyBRAptPJ35kaLzduS5meI3ZEBgPclW44Vycyk=; b=l07ypgylegKyD2foTdPWgGbiAE5dPXygP6QgbdcAM++8IniS5ajB8kn3LgUcuSANXo qqllkYnaaOFyaIdFDH/9vX0nDS1gQRRdRgXIf1WCNkWEAFt7ZUXRlsY/A52/XP4cPFg2 1jPjnePCuTTXS4tRKXJKph8hE2KVlKNk6jaT6nmjo8lw6ngU8ZEUt04UI/3O2xQHRUq/ 6VTxXzWarJMpgVQuIXaTaBo3IV8qCGLlk0Mz6KbueciX8QKi7+5aguuSqdh9ZM5/5EZ9 QmqG5n9gbmdDw5MM8YpYgpw22/oqfEX8JGii7ls8GxSmLrJyCkRHppjc0rarhrjG/ThL LbQw== X-Gm-Message-State: ABy/qLaen4AJZvoVafVmpk7IP+G4Jz/WPO5v7e3GjsUOJJTaQO8a+B0a kT/nemEkbqYxYKV5Eu8LjUCNTKdYSwIPAe4e0oM= X-Google-Smtp-Source: APBJJlEKaMsIOXNYQdIIXdOsnw4w8ZmxIy38WTbEdVHcKgfpdGx85exAdP2+1RyvY6AxcupXrvkyWg== X-Received: by 2002:a05:600c:3658:b0:3fb:b008:2003 with SMTP id y24-20020a05600c365800b003fbb0082003mr6888217wmq.38.1689855526785; Thu, 20 Jul 2023 05:18:46 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id o1-20020a05600c378100b003fbd9e390e1sm3748391wmr.47.2023.07.20.05.18.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:46 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 10/11] devlink: introduce dump selector attr and use it for per-instance dumps Date: Thu, 20 Jul 2023 14:18:28 +0200 Message-ID: <20230720121829.566974-11-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko For SFs, one devlink instance per SF is created. There might be thousands of these on a single host. When a user needs to know port handle for specific SF, he needs to dump all devlink ports on the host which does not scale good. Allow user to pass devlink handle alongside the dump command and dump only objects which are under selected devlink instance. Introduce new attr DEVLINK_ATTR_DUMP_SELECTOR to nest the selection attributes. This way the userspace can use maxattr to tell if dump selector is supported by kernel or not. Assemble netlink policy for selector attribute. If user passes attr unknown to kernel, netlink validation errors out. Example: $ devlink port show auxiliary/mlx5_core.eth.0/65535: type eth netdev eth2 flavour physical port 0 splittable false auxiliary/mlx5_core.eth.1/131071: type eth netdev eth3 flavour physical port 1 splittable false $ devlink port show auxiliary/mlx5_core.eth.0 auxiliary/mlx5_core.eth.0/65535: type eth netdev eth2 flavour physical port 0 splittable false $ devlink port show auxiliary/mlx5_core.eth.1 auxiliary/mlx5_core.eth.1/131071: type eth netdev eth3 flavour physical port 1 splittable false Signed-off-by: Jiri Pirko --- v1->v2: - extended to patch that covers all dumpit commands - used start() and done() callback to parse the selector attr - changed the selector attr netlink policy to be created on fly - changed patch description accordingly --- include/uapi/linux/devlink.h | 2 + net/devlink/devl_internal.h | 1 + net/devlink/netlink.c | 99 +++++++++++++++++++++++++++++++++++- 3 files changed, 101 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 3782d4219ac9..8b74686512ae 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -612,6 +612,8 @@ enum devlink_attr { DEVLINK_ATTR_REGION_DIRECT, /* flag */ + DEVLINK_ATTR_DUMP_SELECTOR, /* nested */ + /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX, diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 79614b45e8ac..168d36dbc6f7 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -109,6 +109,7 @@ struct devlink_nl_dump_state { u64 dump_ts; }; }; + struct nlattr **selector; }; struct devlink_cmd { diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index 90497d0e1a7b..c2083398bd73 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -80,6 +80,7 @@ static const struct nla_policy devlink_nl_policy[DEVLINK_ATTR_MAX + 1] = { [DEVLINK_ATTR_RATE_TX_PRIORITY] = { .type = NLA_U32 }, [DEVLINK_ATTR_RATE_TX_WEIGHT] = { .type = NLA_U32 }, [DEVLINK_ATTR_REGION_DIRECT] = { .type = NLA_FLAG }, + [DEVLINK_ATTR_DUMP_SELECTOR] = { .type = NLA_NESTED }, }; struct devlink * @@ -195,6 +196,30 @@ static const struct devlink_cmd *devl_cmds[] = { [DEVLINK_CMD_SELFTESTS_GET] = &devl_cmd_selftests_get, }; +static int devlink_nl_instance_single_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) +{ + struct devlink_nl_dump_state *state = devlink_dump_state(cb); + const struct genl_dumpit_info *info = genl_dumpit_info(cb); + struct nlattr **selector = state->selector; + const struct devlink_cmd *cmd; + struct devlink *devlink; + int err; + + cmd = devl_cmds[info->op.cmd]; + + devlink = devlink_get_from_attrs_lock(sock_net(msg->sk), selector); + if (IS_ERR(devlink)) + return PTR_ERR(devlink); + err = cmd->dump_one(msg, devlink, cb); + devl_unlock(devlink); + devlink_put(devlink); + + if (err != -EMSGSIZE) + return err; + return msg->len; +} + static int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, struct netlink_callback *cb) { @@ -232,6 +257,76 @@ static int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, return msg->len; } +static void devlink_nl_policy_cpy(struct nla_policy *policy, unsigned int attr) +{ + memcpy(&policy[attr], &devlink_nl_policy[attr], sizeof(*policy)); +} + +static void devlink_nl_dump_selector_policy_init(const struct devlink_cmd *cmd, + struct nla_policy *policy) +{ + devlink_nl_policy_cpy(policy, DEVLINK_ATTR_BUS_NAME); + devlink_nl_policy_cpy(policy, DEVLINK_ATTR_DEV_NAME); +} + +static int devlink_nl_start(struct netlink_callback *cb) +{ + struct devlink_nl_dump_state *state = devlink_dump_state(cb); + const struct genl_dumpit_info *info = genl_dumpit_info(cb); + struct nlattr **attrs = info->attrs; + const struct devlink_cmd *cmd; + struct nla_policy *policy; + struct nlattr **selector; + int err; + + if (!attrs[DEVLINK_ATTR_DUMP_SELECTOR]) + return 0; + + selector = kzalloc(sizeof(*selector) * (DEVLINK_ATTR_MAX + 1), + GFP_KERNEL); + if (!selector) + return -ENOMEM; + policy = kzalloc(sizeof(*policy) * (DEVLINK_ATTR_MAX + 1), GFP_KERNEL); + if (!policy) { + kfree(selector); + return -ENOMEM; + } + + cmd = devl_cmds[info->op.cmd]; + devlink_nl_dump_selector_policy_init(cmd, policy); + err = nla_parse_nested(selector, DEVLINK_ATTR_MAX, + attrs[DEVLINK_ATTR_DUMP_SELECTOR], + policy, cb->extack); + kfree(policy); + if (err) { + kfree(selector); + return err; + } + + state->selector = selector; + return 0; +} + +static int devlink_nl_dumpit(struct sk_buff *msg, struct netlink_callback *cb) +{ + struct devlink_nl_dump_state *state = devlink_dump_state(cb); + struct nlattr **selector = state->selector; + + if (selector && selector[DEVLINK_ATTR_BUS_NAME] && + selector[DEVLINK_ATTR_DEV_NAME]) + return devlink_nl_instance_single_dumpit(msg, cb); + else + return devlink_nl_instance_iter_dumpit(msg, cb); +} + +static int devlink_nl_done(struct netlink_callback *cb) +{ + struct devlink_nl_dump_state *state = devlink_dump_state(cb); + + kfree(state->selector); + return 0; +} + #define __DEVL_NL_OP_DO(cmd_subname, doit_subname, pre_doit_suffix, _validate, \ _maxattr, _policy) \ { \ @@ -248,7 +343,9 @@ static int devlink_nl_instance_iter_dumpit(struct sk_buff *msg, #define __DEVL_NL_OP_DUMP(cmd_subname, _validate, _maxattr, _policy) \ { \ .cmd = DEVLINK_CMD_##cmd_subname, \ - .dumpit = devlink_nl_instance_iter_dumpit, \ + .start = devlink_nl_start, \ + .dumpit = devlink_nl_dumpit, \ + .done = devlink_nl_done, \ .flags = GENL_CMD_CAP_DUMP, \ .validate = _validate, \ .maxattr = _maxattr, \ From patchwork Thu Jul 20 12:18:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiri Pirko X-Patchwork-Id: 13320436 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3910818C0A for ; Thu, 20 Jul 2023 12:18:51 +0000 (UTC) Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFB5B2106 for ; Thu, 20 Jul 2023 05:18:49 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id 5b1f17b1804b1-3fbc1218262so6082815e9.3 for ; Thu, 20 Jul 2023 05:18:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=resnulli-us.20221208.gappssmtp.com; s=20221208; t=1689855528; x=1690460328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=kJPr/vMKbuV0TpgGx2ePkiFr9rU+ybeZG0PO9Ib0uNQ=; b=2imtr7cYCE4wD9c1hA4406ddXVwxaagoHZSbHsA1Ok4qdvUyR1K+tWNle7o94kPr9B 09TUqwckkPMRFDzn4v60QJ/Nq5XQDrKMAuKfYa1SYGtrEXaQlPCO0Vh3D3fhD0qpaRCz qgiYSUuGKmTMYwwX5ud755DZaMV5KWrhLfI2q901i9+CbNfCAX5aVP33VGnHD/otyP92 35jPXMNCoVqLvGozNLC9YfGRSdw6dAJAhzIH9ao40UBkOEK0mUHTix65G6CjZaM/QZGx TpDRDM98OHPSck8nAxMEbA17qJEK9hrdueChZBYPOz1nhBLTMZC3uurXcsvMx/Tp2aJd Vhyw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689855528; x=1690460328; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=kJPr/vMKbuV0TpgGx2ePkiFr9rU+ybeZG0PO9Ib0uNQ=; b=E4E2KVZ5dJ9xs30FPUkmf8OASwjDBwASDguygPfW1X+JbJqzZs1BNTx6LyhmMwXgDj Vike0PqlzTBlIwyOrcQogBQprjj7tYU9KFp6vdiARUZhEuBOAjGBblvTY4vTcNEcG+/D 1MrDNSe7GPNOnGQ/j/eZ1VlXM3Ja6YijVpLeDX0ihh+CVlLWelgLfqYYCCwp0ZKJSrGo SybYYCyo9GqF8/tnhUkpMrenyCdkNIAmOPcqdZ3ytZta0vJRQKK4dg8OzuWm6/1iu07K jQaWZMZToMFGQG7aw5l3RgWEQGqGP5owqm/jHdL58niMsWlaWcebz7kqn/Fwpnl2mxi/ mQpQ== X-Gm-Message-State: ABy/qLZ1tWhiZrmrHKtrhZAy9QztqsRBqC2Qg+ABzK+grFZxe+7A5JIm aHSYIGc4/nX0eVLAzmh2Zb+Iiv6nCvRJYBngdTs= X-Google-Smtp-Source: APBJJlG5oBk0biBCBZ1SHd6/H/OijoZfE+5TBpY4lVaQeXbxQ+GMCWAkAAXQ33A1J/D0BNX1J65LUA== X-Received: by 2002:a05:600c:3658:b0:3fb:b008:2003 with SMTP id y24-20020a05600c365800b003fbb0082003mr6888281wmq.38.1689855528366; Thu, 20 Jul 2023 05:18:48 -0700 (PDT) Received: from localhost (host-213-179-129-39.customer.m-online.net. [213.179.129.39]) by smtp.gmail.com with ESMTPSA id q9-20020adfcd89000000b0030ae3a6be4asm1202600wrj.72.2023.07.20.05.18.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Jul 2023 05:18:47 -0700 (PDT) From: Jiri Pirko To: netdev@vger.kernel.org Cc: kuba@kernel.org, pabeni@redhat.com, davem@davemloft.net, edumazet@google.com, moshe@nvidia.com, saeedm@nvidia.com, idosch@nvidia.com, petrm@nvidia.com Subject: [patch net-next v2 11/11] devlink: extend health reporter dump selector by port index Date: Thu, 20 Jul 2023 14:18:29 +0200 Message-ID: <20230720121829.566974-12-jiri@resnulli.us> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230720121829.566974-1-jiri@resnulli.us> References: <20230720121829.566974-1-jiri@resnulli.us> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org From: Jiri Pirko Introduce a possibility for devlink object to expose attributes it supports for selection of dumped objects. Use this by health reporter to indicate it supports port index based selection of dump objects. Implement this selection mechanism in devlink_nl_cmd_health_reporter_get_dump_one() Example: $ devlink health pci/0000:08:00.0: reporter fw state healthy error 0 recover 0 auto_dump true reporter fw_fatal state healthy error 0 recover 0 grace_period 60000 auto_recover true auto_dump true reporter vnic state healthy error 0 recover 0 pci/0000:08:00.0/32768: reporter vnic state healthy error 0 recover 0 pci/0000:08:00.0/32769: reporter vnic state healthy error 0 recover 0 pci/0000:08:00.0/32770: reporter vnic state healthy error 0 recover 0 pci/0000:08:00.1: reporter fw state healthy error 0 recover 0 auto_dump true reporter fw_fatal state healthy error 0 recover 0 grace_period 60000 auto_recover true auto_dump true reporter vnic state healthy error 0 recover 0 pci/0000:08:00.1/98304: reporter vnic state healthy error 0 recover 0 pci/0000:08:00.1/98305: reporter vnic state healthy error 0 recover 0 pci/0000:08:00.1/98306: reporter vnic state healthy error 0 recover 0 $ devlink health show pci/0000:08:00.0 pci/0000:08:00.0: reporter fw state healthy error 0 recover 0 auto_dump true reporter fw_fatal state healthy error 0 recover 0 grace_period 60000 auto_recover true auto_dump true reporter vnic state healthy error 0 recover 0 pci/0000:08:00.0/32768: reporter vnic state healthy error 0 recover 0 pci/0000:08:00.0/32769: reporter vnic state healthy error 0 recover 0 pci/0000:08:00.0/32770: reporter vnic state healthy error 0 recover 0 $ devlink health show pci/0000:08:00.0/32768 pci/0000:08:00.0/32768: reporter vnic state healthy error 0 recover 0 The last command is possible because of this patch. Signed-off-by: Jiri Pirko --- net/devlink/devl_internal.h | 2 ++ net/devlink/health.c | 21 +++++++++++++++++++-- net/devlink/netlink.c | 8 ++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/net/devlink/devl_internal.h b/net/devlink/devl_internal.h index 168d36dbc6f7..510b66806341 100644 --- a/net/devlink/devl_internal.h +++ b/net/devlink/devl_internal.h @@ -115,6 +115,8 @@ struct devlink_nl_dump_state { struct devlink_cmd { int (*dump_one)(struct sk_buff *msg, struct devlink *devlink, struct netlink_callback *cb); + const u16 *dump_selector_attrs; + unsigned int dump_selector_attrs_count; }; extern const struct genl_small_ops devlink_nl_ops[40]; diff --git a/net/devlink/health.c b/net/devlink/health.c index 194340a8bb86..74d322ee5b83 100644 --- a/net/devlink/health.c +++ b/net/devlink/health.c @@ -390,12 +390,21 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg, struct netlink_callback *cb) { struct devlink_nl_dump_state *state = devlink_dump_state(cb); + struct nlattr **selector = state->selector; struct devlink_health_reporter *reporter; + unsigned long port_index_end = ULONG_MAX; + unsigned long port_index_start = 0; struct devlink_port *port; unsigned long port_index; int idx = 0; int err; + if (selector && selector[DEVLINK_ATTR_PORT_INDEX]) { + port_index_start = nla_get_u32(selector[DEVLINK_ATTR_PORT_INDEX]); + port_index_end = port_index_start; + goto per_port_dump; + } + list_for_each_entry(reporter, &devlink->reporter_list, list) { if (idx < state->idx) { idx++; @@ -412,7 +421,9 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg, } idx++; } - xa_for_each(&devlink->ports, port_index, port) { +per_port_dump: + xa_for_each_range(&devlink->ports, port_index, port, + port_index_start, port_index_end) { list_for_each_entry(reporter, &port->reporter_list, list) { if (idx < state->idx) { idx++; @@ -434,8 +445,14 @@ devlink_nl_cmd_health_reporter_get_dump_one(struct sk_buff *msg, return 0; } +static const u16 devl_cmd_health_reporter_dump_selector_attrs[] = { + DEVLINK_ATTR_PORT_INDEX, +}; + const struct devlink_cmd devl_cmd_health_reporter_get = { - .dump_one = devlink_nl_cmd_health_reporter_get_dump_one, + .dump_one = devlink_nl_cmd_health_reporter_get_dump_one, + .dump_selector_attrs = devl_cmd_health_reporter_dump_selector_attrs, + .dump_selector_attrs_count = ARRAY_SIZE(devl_cmd_health_reporter_dump_selector_attrs), }; int devlink_nl_cmd_health_reporter_set_doit(struct sk_buff *skb, diff --git a/net/devlink/netlink.c b/net/devlink/netlink.c index c2083398bd73..bd60d229cfbe 100644 --- a/net/devlink/netlink.c +++ b/net/devlink/netlink.c @@ -265,8 +265,16 @@ static void devlink_nl_policy_cpy(struct nla_policy *policy, unsigned int attr) static void devlink_nl_dump_selector_policy_init(const struct devlink_cmd *cmd, struct nla_policy *policy) { + int i; + devlink_nl_policy_cpy(policy, DEVLINK_ATTR_BUS_NAME); devlink_nl_policy_cpy(policy, DEVLINK_ATTR_DEV_NAME); + + for (i = 0; i < cmd->dump_selector_attrs_count; i++) { + unsigned int attr = cmd->dump_selector_attrs[i]; + + memcpy(&policy[attr], &devlink_nl_policy[attr], sizeof(*policy)); + } } static int devlink_nl_start(struct netlink_callback *cb)