From: Jiri Pirko <jiri@resnulli.us>
To: Jakub Kicinski <jakub.kicinski@netronome.com>
Cc: netdev@vger.kernel.org, davem@davemloft.net, mlxsw@mellanox.com,
idosch@mellanox.com, f.fainelli@gmail.com, andrew@lunn.ch,
vivien.didelot@gmail.com, michael.chan@broadcom.com
Subject: Re: [patch net-next v2 11/12] net: devlink: expose phys port name
Date: Wed, 27 Mar 2019 12:56:05 +0100 [thread overview]
Message-ID: <20190327115605.GA14297@nanopsycho> (raw)
In-Reply-To: <20190327074538.GA3111@nanopsycho>
Wed, Mar 27, 2019 at 08:45:38AM CET, jiri@resnulli.us wrote:
>Tue, Mar 26, 2019 at 09:35:58PM CET, jakub.kicinski@netronome.com wrote:
>>On Tue, 26 Mar 2019 13:03:06 +0100, Jiri Pirko wrote:
>>> From: Jiri Pirko <jiri@mellanox.com>
>>>
>>> Currently, it is exposed via rtnetlink. But it is relevant to devlink
>>> ports, so expose it here too.
>>>
>>> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
>>
>>Why? User space has access to all the components which are used to
>>generate the name in a typed, structured form. That's strictly
>
>Nope. It does has access only to flavour. Not to port number for
>example. So I thought either expose that or the generated name.
To correct myself, all is exposed by kernel, just not implemented in
userspace. I thought that generated port name would be good to have.
Not really good idea to generate it again in userspace. Anyway, I'll
leave this patch out for now, I can send it separatelly later on.
>
>>superior to the string netdev string.
>>
>>Do you have some use in mind for the new attribute?
>>
>>> diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h
>>> index 5bb4ea67d84f..2d0365e45141 100644
>>> --- a/include/uapi/linux/devlink.h
>>> +++ b/include/uapi/linux/devlink.h
>>> @@ -332,6 +332,8 @@ enum devlink_attr {
>>> DEVLINK_ATTR_FLASH_UPDATE_FILE_NAME, /* string */
>>> DEVLINK_ATTR_FLASH_UPDATE_COMPONENT, /* string */
>>>
>>> + DEVLINK_ATTR_PORT_PHYS_NAME, /* string */
>>> +
>>> /* add new attributes above here, update the policy in devlink.c */
>>>
>>> __DEVLINK_ATTR_MAX,
>>> diff --git a/net/core/devlink.c b/net/core/devlink.c
>>> index 6bbd07e3861e..356d7ee7c404 100644
>>> --- a/net/core/devlink.c
>>> +++ b/net/core/devlink.c
>>> @@ -508,6 +508,57 @@ static void devlink_notify(struct devlink *devlink, enum devlink_command cmd)
>>> msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL);
>>> }
>>>
>>> +static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
>>> + char *name, size_t len)
>>> +{
>>> + struct devlink_port_attrs *attrs = &devlink_port->attrs;
>>> + int n = 0;
>>> +
>>> + if (!attrs->set)
>>> + return -EOPNOTSUPP;
>>> +
>>> + switch (attrs->flavour) {
>>> + case DEVLINK_PORT_FLAVOUR_PHYSICAL:
>>> + if (!attrs->split)
>>> + n = snprintf(name, len, "p%u", attrs->port_number);
>>> + else
>>> + n = snprintf(name, len, "p%us%u", attrs->port_number,
>>> + attrs->split_subport_number);
>>> + break;
>>> + case DEVLINK_PORT_FLAVOUR_CPU:
>>> + case DEVLINK_PORT_FLAVOUR_DSA:
>>> + /* As CPU and DSA ports do not have a netdevice associated
>>> + * case should not ever happen.
>>> + */
>>> + WARN_ON(1);
>>> + return -EINVAL;
>>> + }
>>> +
>>> + if (n >= len)
>>> + return -EINVAL;
>>> +
>>> + return 0;
>>> +}
>>> +
>>> +static int devlink_nl_port_phys_port_name_put(struct sk_buff *msg,
>>> + struct devlink_port *devlink_port)
>>> +{
>>> + struct devlink_port_attrs *attrs = &devlink_port->attrs;
>>> + char phys_name[IFNAMSIZ];
>>> + int err;
>>> +
>>> + if (attrs->flavour != DEVLINK_PORT_FLAVOUR_PHYSICAL)
>>> + return 0;
>>> +
>>> + err = __devlink_port_phys_port_name_get(devlink_port,
>>> + phys_name, sizeof(phys_name));
>>> + if (err)
>>> + return err;
>>> + if (nla_put_string(msg, DEVLINK_ATTR_PORT_PHYS_NAME, phys_name))
>>> + return -EMSGSIZE;
>>> + return 0;
>>> +}
>>> +
>>> static int devlink_nl_port_attrs_put(struct sk_buff *msg,
>>> struct devlink_port *devlink_port)
>>> {
>>> @@ -526,6 +577,9 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg,
>>> if (nla_put_u32(msg, DEVLINK_ATTR_PORT_SPLIT_SUBPORT_NUMBER,
>>> attrs->split_subport_number))
>>> return -EMSGSIZE;
>>> + if (devlink_nl_port_phys_port_name_put(msg, devlink_port))
>>> + return -EMSGSIZE;
>>> +
>>> return 0;
>>> }
>>>
>>> @@ -5414,38 +5468,6 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
>>> }
>>> EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
>>>
>>> -static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port,
>>> - char *name, size_t len)
>>> -{
>>> - struct devlink_port_attrs *attrs = &devlink_port->attrs;
>>> - int n = 0;
>>> -
>>> - if (!attrs->set)
>>> - return -EOPNOTSUPP;
>>> -
>>> - switch (attrs->flavour) {
>>> - case DEVLINK_PORT_FLAVOUR_PHYSICAL:
>>> - if (!attrs->split)
>>> - n = snprintf(name, len, "p%u", attrs->port_number);
>>> - else
>>> - n = snprintf(name, len, "p%us%u", attrs->port_number,
>>> - attrs->split_subport_number);
>>> - break;
>>> - case DEVLINK_PORT_FLAVOUR_CPU:
>>> - case DEVLINK_PORT_FLAVOUR_DSA:
>>> - /* As CPU and DSA ports do not have a netdevice associated
>>> - * case should not ever happen.
>>> - */
>>> - WARN_ON(1);
>>> - return -EINVAL;
>>> - }
>>> -
>>> - if (n >= len)
>>> - return -EINVAL;
>>> -
>>> - return 0;
>>> -}
>>> -
>>> int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
>>> u32 size, u16 ingress_pools_count,
>>> u16 egress_pools_count, u16 ingress_tc_count,
>>
next prev parent reply other threads:[~2019-03-27 11:56 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-26 12:02 [patch net-next v2 00/12] net: call for phys_port_name into devlink directly if possible Jiri Pirko
2019-03-26 12:02 ` [patch net-next v2 01/12] net: replace ndo_get_devlink with ndo_get_devlink_port Jiri Pirko
2019-03-26 20:27 ` Jakub Kicinski
2019-03-27 7:47 ` Jiri Pirko
2019-03-26 12:02 ` [patch net-next v2 02/12] net: devlink: introduce devlink_compat_phys_port_name_get() Jiri Pirko
2019-03-26 20:30 ` Jakub Kicinski
2019-03-26 12:02 ` [patch net-next v2 03/12] mlxsw: Implement ndo_get_devlink_port Jiri Pirko
2019-03-26 12:02 ` [patch net-next v2 04/12] mlxsw: Remove ndo_get_phys_port_name implementation Jiri Pirko
2019-03-26 12:03 ` [patch net-next v2 05/12] net: devlink: remove unused devlink_port_get_phys_port_name() function Jiri Pirko
2019-03-26 20:31 ` Jakub Kicinski
2019-03-26 12:03 ` [patch net-next v2 06/12] bnxt: implement ndo_get_devlink_port Jiri Pirko
2019-03-26 12:03 ` [patch net-next v2 07/12] bnxt: remove ndo_get_phys_port_name implementation Jiri Pirko
2019-03-26 12:03 ` [patch net-next v2 08/12] dsa: implement ndo_get_devlink_port Jiri Pirko
2019-03-27 19:54 ` Florian Fainelli
2019-03-27 20:01 ` Jiri Pirko
2019-03-27 20:13 ` Florian Fainelli
2019-03-27 23:46 ` Jiri Pirko
2019-03-26 12:03 ` [patch net-next v2 09/12] dsa: don't fill-up remove ndo_get_phys_port_name for slaves Jiri Pirko
2019-03-26 12:03 ` [patch net-next v2 10/12] nfp: do not handle nn->port defined case in nfp_net_get_phys_port_name() Jiri Pirko
2019-03-26 20:31 ` Jakub Kicinski
2019-03-26 12:03 ` [patch net-next v2 11/12] net: devlink: expose phys port name Jiri Pirko
2019-03-26 20:35 ` Jakub Kicinski
2019-03-27 7:45 ` Jiri Pirko
2019-03-27 11:56 ` Jiri Pirko [this message]
2019-03-26 12:03 ` [patch net-next v2 12/12] net: devlink: add warning for ndo_get_phys_port_name set when not needed Jiri Pirko
2019-03-26 20:36 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190327115605.GA14297@nanopsycho \
--to=jiri@resnulli.us \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=f.fainelli@gmail.com \
--cc=idosch@mellanox.com \
--cc=jakub.kicinski@netronome.com \
--cc=michael.chan@broadcom.com \
--cc=mlxsw@mellanox.com \
--cc=netdev@vger.kernel.org \
--cc=vivien.didelot@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).