Netdev List
 help / color / mirror / Atom feed
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, dirk.vandermerwe@netronome.com,
	f.fainelli@gmail.com, andrew@lunn.ch, vivien.didelot@gmail.com
Subject: Re: [patch net-next 2/5] net: devlink: introduce devlink_compat_phys_port_name_get()
Date: Fri, 1 Mar 2019 17:21:59 +0100	[thread overview]
Message-ID: <20190301162159.GK2314@nanopsycho> (raw)
In-Reply-To: <20190301081458.7bb00480@cakuba.netronome.com>

Fri, Mar 01, 2019 at 05:14:58PM CET, jakub.kicinski@netronome.com wrote:
>On Fri,  1 Mar 2019 09:13:59 +0100, Jiri Pirko wrote:
>> From: Jiri Pirko <jiri@mellanox.com>
>> 
>> Introduce devlink_compat_phys_port_name_get() helper that
>> gets the physical port name for specified netdevice
>> according to devlink port attributes.
>> Call this helper from dev_get_phys_port_name()
>> in case ndo_get_phys_port_name is not defined.
>> 
>> Signed-off-by: Jiri Pirko <jiri@mellanox.com>
>> ---
>>  include/net/devlink.h |  9 +++++++++
>>  net/core/dev.c        |  3 ++-
>>  net/core/devlink.c    | 30 ++++++++++++++++++++++++++++--
>>  3 files changed, 39 insertions(+), 3 deletions(-)
>> 
>> diff --git a/include/net/devlink.h b/include/net/devlink.h
>> index f34107def48e..ae2cd34da99e 100644
>> --- a/include/net/devlink.h
>> +++ b/include/net/devlink.h
>> @@ -729,6 +729,8 @@ int devlink_health_report(struct devlink_health_reporter *reporter,
>>  void devlink_compat_running_version(struct net_device *dev,
>>  				    char *buf, size_t len);
>>  int devlink_compat_flash_update(struct net_device *dev, const char *file_name);
>> +int devlink_compat_phys_port_name_get(struct net_device *dev,
>> +				      char *name, size_t len);
>>  
>>  #else
>>  
>> @@ -1224,6 +1226,13 @@ devlink_compat_flash_update(struct net_device *dev, const char *file_name)
>>  {
>>  	return -EOPNOTSUPP;
>>  }
>> +
>> +static inline int
>> +devlink_compat_phys_port_name_get(struct net_device *dev,
>> +				  char *name, size_t len)
>> +{
>> +	return -EOPNOTSUPP;
>> +}
>>  #endif
>>  
>>  #endif /* _NET_DEVLINK_H_ */
>> diff --git a/net/core/dev.c b/net/core/dev.c
>> index 2b67f2aa59dd..a614b26b0842 100644
>> --- a/net/core/dev.c
>> +++ b/net/core/dev.c
>> @@ -146,6 +146,7 @@
>>  #include <net/udp_tunnel.h>
>>  #include <linux/net_namespace.h>
>>  #include <linux/indirect_call_wrapper.h>
>> +#include <net/devlink.h>
>>  
>>  #include "net-sysfs.h"
>>  
>> @@ -7872,7 +7873,7 @@ int dev_get_phys_port_name(struct net_device *dev,
>>  	const struct net_device_ops *ops = dev->netdev_ops;
>>  
>>  	if (!ops->ndo_get_phys_port_name)
>> -		return -EOPNOTSUPP;
>> +		return devlink_compat_phys_port_name_get(dev, name, len);
>>  	return ops->ndo_get_phys_port_name(dev, name, len);
>>  }
>>  EXPORT_SYMBOL(dev_get_phys_port_name);
>> diff --git a/net/core/devlink.c b/net/core/devlink.c
>> index a49dee67e66f..4fd45d4a4818 100644
>> --- a/net/core/devlink.c
>> +++ b/net/core/devlink.c
>> @@ -5419,8 +5419,8 @@ void devlink_port_attrs_set(struct devlink_port *devlink_port,
>>  }
>>  EXPORT_SYMBOL_GPL(devlink_port_attrs_set);
>>  
>> -int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
>> -				    char *name, size_t len)
>> +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;
>> @@ -5450,6 +5450,12 @@ int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
>>  
>>  	return 0;
>>  }
>> +
>> +int devlink_port_get_phys_port_name(struct devlink_port *devlink_port,
>> +				    char *name, size_t len)
>> +{
>> +	return __devlink_port_phys_port_name_get(devlink_port, name, len);
>> +}
>>  EXPORT_SYMBOL_GPL(devlink_port_get_phys_port_name);
>>  
>>  int devlink_sb_register(struct devlink *devlink, unsigned int sb_index,
>> @@ -6469,6 +6475,26 @@ int devlink_compat_flash_update(struct net_device *dev, const char *file_name)
>>  	return ret;
>>  }
>>  
>> +int devlink_compat_phys_port_name_get(struct net_device *dev,
>> +				      char *name, size_t len)
>> +{
>> +	struct devlink_port *devlink_port;
>> +	int err = -EOPNOTSUPP;
>> +
>> +	mutex_lock(&devlink_mutex);
>> +	devlink_port = netdev_to_devlink_port(dev);
>> +	if (!devlink_port)
>> +		goto unlock_list;
>> +
>> +	mutex_lock(&devlink_port->devlink->lock);
>
>I'm moderately confident you won't be able to take devlink locks from
>RTNL code :(  I think the locking order is:
>
>  devlink_mutex -> devlink->lock -> rtnl_lock
>
>No? :(  At least NFP assumes that, but I think port splitting does, too.

Oh right, thanks for spotting this. Will fix.


>
>> +	err = __devlink_port_phys_port_name_get(devlink_port, name, len);
>> +	mutex_unlock(&devlink_port->devlink->lock);
>> +unlock_list:
>> +	mutex_unlock(&devlink_mutex);
>> +
>> +	return err;
>> +}
>> +
>>  static int __init devlink_init(void)
>>  {
>>  	return genl_register_family(&devlink_nl_family);
>

  reply	other threads:[~2019-03-01 16:31 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-01  8:13 [patch net-next 0/5] net: call for phys_port_name into devlink directly is possible Jiri Pirko
2019-03-01  8:13 ` [patch net-next 1/5] net: replace ndo_get_devlink for ndo_get_devlink_port Jiri Pirko
2019-03-01 12:45   ` Michal Kubecek
2019-03-01 13:42     ` Jiri Pirko
2019-03-02  2:20   ` Florian Fainelli
2019-03-01  8:13 ` [patch net-next 2/5] net: devlink: introduce devlink_compat_phys_port_name_get() Jiri Pirko
2019-03-01 16:14   ` Jakub Kicinski
2019-03-01 16:21     ` Jiri Pirko [this message]
2019-03-01  8:14 ` [patch net-next 3/5] mlxsw: spectrum: Implement ndo_get_devlink_port Jiri Pirko
2019-03-01  8:14 ` [patch net-next 4/5] mlxsw: Remove ndo_get_phys_port_name implementation Jiri Pirko
2019-03-01  8:14 ` [patch net-next 5/5] net: devlink: remove unused devlink_port_get_phys_port_name() function Jiri Pirko
2019-03-01 16:25   ` Jakub Kicinski
2019-03-01 16:27     ` Jiri Pirko
2019-03-01 16:48       ` 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=20190301162159.GK2314@nanopsycho \
    --to=jiri@resnulli.us \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=dirk.vandermerwe@netronome.com \
    --cc=f.fainelli@gmail.com \
    --cc=idosch@mellanox.com \
    --cc=jakub.kicinski@netronome.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