Patchwork Add firmware label support to iproute2

login
register
mail settings
Submitter Matt Domsch
Date Aug. 25, 2010, 10:03 p.m.
Message ID <20100825220323.GA12671@auslistsprd01.us.dell.com>
Download mbox | patch
Permalink /patch/62741/
State Rejected
Delegated to: stephen hemminger
Headers show

Comments

Matt Domsch - Aug. 25, 2010, 10:03 p.m.
On Thu, Aug 19, 2010 at 02:53:08PM -0700, Stephen Hemminger wrote:
> On Thu, 19 Aug 2010 16:33:14 -0500
> Matt Domsch <Matt_Domsch@Dell.com> wrote:
> 
> > On Wed, Aug 18, 2010 at 02:41:24PM -0700, Stephen Hemminger wrote:
> > > The netdev_alias_to_kernelname should only happen after normal lookup failed.
> > 
> > Stephen, can you enlighten me as to the "right" way to do interface
> > name lookups?  While I can still find examples of parsing
> > /proc/net/dev, or globbing /sys/class/net/*, I expect these aren't the
> > preferred method anymore.  Your own iproute2 suite uses RTM_GETLINK
> > netlink calls, though for the seeming simple case of "give me a list of all
> > interfaces", your path through there is far more capable (and
> > complex) than I would hope to need.
> 
> There is no magic right way. We have to support multiple interfaces.
> I am really concerned that all this alias stuff will turn into a
> disaster when there are 10,000 interfaces (Vlans).  The kernel has
> lots of tables and hashes to handle this but if the utilities
> are doing a dumb scan of all names it will not work.

We can remove the dumb scan of names if we expose the labels in a
second way.  For consideration of the approach:


From 86b8ab8d24df722073d1118659c1eb269c5d9dd7 Mon Sep 17 00:00:00 2001
From: Matt Domsch <Matt_Domsch@dell.com>
Date: Wed, 25 Aug 2010 15:31:01 -0500
Subject: [PATCH] create /sys/firmware/pci for firmware-exposed label lookup

libnetdevname needs to be able to look up a (PCI) device by label.  It
currently does this by glob()ing /sys/class/net/*/device/label to find
all network interfaces that have a PCI device label exposed.  There can
be arbitrarily many network interfaces, making this a very expensive
operation.

This patch creates a new directory /sys/firmware/pci. This directory
contains symlinks, named for the PCI device labels that are exposed in
the 'label' file of each PCI device already.  Here is an example on a
Dell PowerEdge R610 server:

$ ls -l /sys/firmware/pci/
total 0
lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 1 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/
lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 2 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.1/
lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 3 -> ../../devices/pci0000:00/0000:00:03.0/0000:02:00.0/
lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 4 -> ../../devices/pci0000:00/0000:00:03.0/0000:02:00.1/
lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded Video -> ../../devices/pci0000:00/0000:00:1e.0/0000:09:03.0/
lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Integrated SAS -> ../../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/

$ cat /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/label
Embedded NIC 1

Using this, libnetdevname can remove it's glob() call, and instead can
look up the PCI device corresponding to a given label directly.  It
can then find the network interface name for that PCI device by
looking in the net/ directory of that device.

This makes no attempt to deal with SMBIOS that reports the same label
for two different PCI devices (if such were to exist).

Signed-off-by: Matt Domsch <Matt_Domsch@dell.com>
---
 drivers/pci/pci-label.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 66 insertions(+), 0 deletions(-)
Greg KH - Aug. 25, 2010, 10:16 p.m.
On Wed, Aug 25, 2010 at 05:03:23PM -0500, Matt Domsch wrote:
> On Thu, Aug 19, 2010 at 02:53:08PM -0700, Stephen Hemminger wrote:
> > On Thu, 19 Aug 2010 16:33:14 -0500
> > Matt Domsch <Matt_Domsch@Dell.com> wrote:
> > 
> > > On Wed, Aug 18, 2010 at 02:41:24PM -0700, Stephen Hemminger wrote:
> > > > The netdev_alias_to_kernelname should only happen after normal lookup failed.
> > > 
> > > Stephen, can you enlighten me as to the "right" way to do interface
> > > name lookups?  While I can still find examples of parsing
> > > /proc/net/dev, or globbing /sys/class/net/*, I expect these aren't the
> > > preferred method anymore.  Your own iproute2 suite uses RTM_GETLINK
> > > netlink calls, though for the seeming simple case of "give me a list of all
> > > interfaces", your path through there is far more capable (and
> > > complex) than I would hope to need.
> > 
> > There is no magic right way. We have to support multiple interfaces.
> > I am really concerned that all this alias stuff will turn into a
> > disaster when there are 10,000 interfaces (Vlans).  The kernel has
> > lots of tables and hashes to handle this but if the utilities
> > are doing a dumb scan of all names it will not work.
> 
> We can remove the dumb scan of names if we expose the labels in a
> second way.  For consideration of the approach:
> 
> 
> >From 86b8ab8d24df722073d1118659c1eb269c5d9dd7 Mon Sep 17 00:00:00 2001
> From: Matt Domsch <Matt_Domsch@dell.com>
> Date: Wed, 25 Aug 2010 15:31:01 -0500
> Subject: [PATCH] create /sys/firmware/pci for firmware-exposed label lookup
> 
> libnetdevname needs to be able to look up a (PCI) device by label.  It
> currently does this by glob()ing /sys/class/net/*/device/label to find
> all network interfaces that have a PCI device label exposed.  There can
> be arbitrarily many network interfaces, making this a very expensive
> operation.

So you want to add code to the kernel to make userspace have an easier
'find' path?  I'm all for making stuff easier, but just how "expensive"
is such an operation today?

> This patch creates a new directory /sys/firmware/pci. This directory
> contains symlinks, named for the PCI device labels that are exposed in
> the 'label' file of each PCI device already.  Here is an example on a
> Dell PowerEdge R610 server:
> 
> $ ls -l /sys/firmware/pci/
> total 0
> lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 1 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.0/
> lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 2 -> ../../devices/pci0000:00/0000:00:01.0/0000:01:00.1/
> lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 3 -> ../../devices/pci0000:00/0000:00:03.0/0000:02:00.0/
> lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded NIC 4 -> ../../devices/pci0000:00/0000:00:03.0/0000:02:00.1/
> lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Embedded Video -> ../../devices/pci0000:00/0000:00:1e.0/0000:09:03.0/
> lrwxrwxrwx. 1 root root 0 2010-08-25 15:28 Integrated SAS -> ../../devices/pci0000:00/0000:00:1c.0/0000:03:00.0/
> 
> $ cat /sys/devices/pci0000:00/0000:00:01.0/0000:01:00.0/label
> Embedded NIC 1
> 
> Using this, libnetdevname can remove it's glob() call, and instead can
> look up the PCI device corresponding to a given label directly.  It
> can then find the network interface name for that PCI device by
> looking in the net/ directory of that device.
> 
> This makes no attempt to deal with SMBIOS that reports the same label
> for two different PCI devices (if such were to exist).

I'm sure it does, and I will end up getting the bugs reported to me as
it shows a sysfs WARN_ON() when that happens.

So please, handle this case to properly fail if there are duplicate
names, as we all know it will happen (look at all of the duplicate slot
names that have been found already as proof of this...)



> 
> Signed-off-by: Matt Domsch <Matt_Domsch@dell.com>
> ---
>  drivers/pci/pci-label.c |   66 +++++++++++++++++++++++++++++++++++++++++++++++
>  1 files changed, 66 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/pci/pci-label.c b/drivers/pci/pci-label.c
> index 111500e..a48eedb 100644
> --- a/drivers/pci/pci-label.c
> +++ b/drivers/pci/pci-label.c
> @@ -19,6 +19,7 @@
>  #include <linux/pci_ids.h>
>  #include <linux/module.h>
>  #include <linux/device.h>
> +#include <linux/string.h>
>  #include "pci.h"
>  
>  enum smbios_attr_enum {
> @@ -131,13 +132,78 @@ pci_remove_smbiosname_file(struct pci_dev *pdev)
>  	sysfs_remove_group(&pdev->dev.kobj, &smbios_attr_group);
>  }
>  
> +static struct kobject *pci_label_kobj;
> +
> +static int pci_label_kobj_init(void)
> +{
> +	pci_label_kobj = kobject_create_and_add("pci", firmware_kobj);
> +	if (pci_label_kobj == NULL)
> +		return -ENOMEM;
> +	return 0;
> +}
> +
> +static int
> +pci_create_smbios_label_symlink(struct pci_dev *pdev)
> +{
> +	char *label, *p;
> +	mode_t mode;
> +	int ret=-ENOMEM;
> +
> +	if (!pdev)
> +		return -ENODEV;
> +	if (pci_label_kobj == NULL)
> +		if (pci_label_kobj_init())
> +			return -ENOMEM;
> +	label = kmalloc(PAGE_SIZE, GFP_KERNEL);
> +	if (label == NULL)
> +		return -ENOMEM;
> +	mode = find_smbios_instance_string(pdev, label, SMBIOS_ATTR_LABEL_SHOW);
> +	if (mode == 0) {
> +		ret = -ENODEV;
> +		goto out_free;
> +	}
> +	p = strim(label);
> +	ret = sysfs_create_link_nowarn(pci_label_kobj, &pdev->dev.kobj, p);
> +out_free:
> +	kfree(label);
> +	return ret;
> +}
> +
> +static void
> +pci_delete_smbios_label_symlink(struct pci_dev *pdev)
> +{
> +	char *label, *p;
> +	mode_t mode;
> +
> +	if (!pdev)
> +		return;
> +	if (pci_label_kobj == NULL)
> +		return;
> +	label = kmalloc(PAGE_SIZE, GFP_KERNEL);
> +	if (label == NULL)
> +		return;
> +	mode = find_smbios_instance_string(pdev, label, SMBIOS_ATTR_LABEL_SHOW);
> +	if (mode == 0) {
> +		goto out_free;
> +	}
> +	p = strim(label);
> +	sysfs_delete_link(pci_label_kobj, &pdev->dev.kobj, p);
> +
> +out_free:
> +	kfree(label);
> +}
> +
> +
>  void pci_create_firmware_label_files(struct pci_dev *pdev)
>  {
>  	if (!pci_create_smbiosname_file(pdev))
>  		;
> +	if (!pci_create_smbios_label_symlink(pdev))
> +		;

Why even have this check at all, if nothing is going to be done with it?
I missed this last time around for the smbios name stuff, but come on
people, that's horrible code.

thanks,

greg k-h
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
stephen hemminger - Aug. 26, 2010, 12:16 a.m.
On Wed, 25 Aug 2010 17:03:23 -0500
Matt Domsch <Matt_Domsch@Dell.com> wrote:

> On Thu, Aug 19, 2010 at 02:53:08PM -0700, Stephen Hemminger wrote:
> > On Thu, 19 Aug 2010 16:33:14 -0500
> > Matt Domsch <Matt_Domsch@Dell.com> wrote:
> > 
> > > On Wed, Aug 18, 2010 at 02:41:24PM -0700, Stephen Hemminger wrote:
> > > > The netdev_alias_to_kernelname should only happen after normal lookup failed.
> > > 
> > > Stephen, can you enlighten me as to the "right" way to do interface
> > > name lookups?  While I can still find examples of parsing
> > > /proc/net/dev, or globbing /sys/class/net/*, I expect these aren't the
> > > preferred method anymore.  Your own iproute2 suite uses RTM_GETLINK
> > > netlink calls, though for the seeming simple case of "give me a list of all
> > > interfaces", your path through there is far more capable (and
> > > complex) than I would hope to need.
> > 
> > There is no magic right way. We have to support multiple interfaces.
> > I am really concerned that all this alias stuff will turn into a
> > disaster when there are 10,000 interfaces (Vlans).  The kernel has
> > lots of tables and hashes to handle this but if the utilities
> > are doing a dumb scan of all names it will not work.
> 

Is it really a good idea to have to change every utility that could
alter network devices?  There is iproute2, iputils, tcpdump, wireshark,
quagga, snmp, ...  Many of the utilities come from a BSD world,
and will be less likely to accept some Linux specific wart.

I have lost faith in this library wrapper support everywhere method.
Let's just keep the firmware stuff in udev. If the user wants to
have a policy that renames device from eth0 to "Embedded BIOS LAN1" then
do it in udev. Or if you want to keep the ethX naming convention
and stuff the firmware label into ifAlias or other sysfs field
so it can be displayed that will be not a big issue.

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Matt Domsch - Aug. 26, 2010, 2:10 p.m.
On Wed, Aug 25, 2010 at 03:16:28PM -0700, Greg KH wrote:
> On Wed, Aug 25, 2010 at 05:03:23PM -0500, Matt Domsch wrote:
> > libnetdevname needs to be able to look up a (PCI) device by label.  It
> > currently does this by glob()ing /sys/class/net/*/device/label to find
> > all network interfaces that have a PCI device label exposed.  There can
> > be arbitrarily many network interfaces, making this a very expensive
> > operation.
> 
> So you want to add code to the kernel to make userspace have an easier
> 'find' path?  I'm all for making stuff easier, but just how "expensive"
> is such an operation today?

it's one newfstatat and one stat for each network interface,
including interfaces for each vlan, which as Stephen had noted,
could be tens of thousands.  Just to test, on a system with ~20k vlans
configured across 5 physical interfaces, the glob() took just over 4
minutes.  Now, that may not be the typical case, but it does show the
scalability problem Stephen is concerned about.

Thanks also for the patch review.  Yes, we'll clean up the items
noted, if we (collectively) come to agreement that this approach to
solve device naming is valid and warranted.  From Stephen's other
comments, we're not quite there yet. :-)
Matt Domsch - Aug. 26, 2010, 3:01 p.m.
On Wed, Aug 25, 2010 at 05:16:46PM -0700, Stephen Hemminger wrote:
> On Wed, 25 Aug 2010 17:03:23 -0500
On Wed, Aug 25, 2010 at 05:16:46PM -0700, Stephen Hemminger wrote:
> Is it really a good idea to have to change every utility that could
> alter network devices?  There is iproute2, iputils, tcpdump, wireshark,
> quagga, snmp, ...  Many of the utilities come from a BSD world,
> and will be less likely to accept some Linux specific wart.

I agree, I don't want to have to change all those userspace apps
either.  We've started creating patches and are willing to do so if it
will yield the result we want though.
 
> I have lost faith in this library wrapper support everywhere method.
> Let's just keep the firmware stuff in udev. If the user wants to
> have a policy that renames device from eth0 to "Embedded BIOS LAN1" then
> do it in udev. Or if you want to keep the ethX naming convention
> and stuff the firmware label into ifAlias or other sysfs field
> so it can be displayed that will be not a big issue.

1) we remain constrained to IFNAMSIZ named arguments.  There is no
   such constraint on BIOS-provided names.  Dell BIOS presently uses
   'Embedded NIC 1' which (fortunately) is 14 chars. We're cutting it
   awfully close already.  I can't dictate to non-Dell BIOS vendors
   what to use as their strings, or how long to make them.

digression 1a) udev has a replace-spaces-with-underscores feature I used in
    the biosdevname udev rules.  That's a reasonable munging of the
    provided strings.  Much more than that and I'm not sure we could
    consistently get it right.

2) there are apps which use a regexp for device names.  We'd have to
   find and fix those too.  Arguably we'd have to do this when we
   patch them to use libnetdevname. [1]

3) it continues to force a single naming convention for NICs, where
   for other types of devices we can have several independent naming
   conventions.  I have end users who wish to name their interfaces by
   the BIOS label, others by the function (public, dmz,
   backup, storage, ...) that the network segment provides.  While we
   could have different policies, each system can have only one policy
   at a time.
  

David Miller had suggested [2] that we could add a method to get
alternate labels for devices by querying them.  We've got something
similar now by exporting the labels for devices in sysfs.  Yea -
progress!

But we can't _use_ those labels for more than display
(meaning a human is doing the mapping in their heads), or to rename
devices.  We can't use the labels in scripts without doing the label->kernel
name lookups, and then using the kernel name.

I'm open to revisiting the "have udev rename devices", but I tried
that with biosdevname 2 years ago, with little success.  Adding in the
hotplug dev team to the thread.


[1] http://marc.info/?l=linux-netdev&m=125522163322610&w=2 (Marco d'Itri)
[2] http://marc.info/?l=linux-hotplug&m=123793549323431&w=2
Loke, Chetan - Aug. 26, 2010, 3:17 p.m.
What if we extend 'IFNAMSIZ'(beyond 16 chars. Older apps don't need to
worry because they have been working w/ 16 chars anyways) and also get
ifalias to work in udev(Or is ifalias a bad idea?)?

Chetan

> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-
> owner@vger.kernel.org] On Behalf Of Matt Domsch
> Sent: August 26, 2010 11:01 AM
> To: Stephen Hemminger
> Cc: Narendra_K@Dell.com; netdev@vger.kernel.org;
Charles_Rose@Dell.com;
> Jordan_Hargrave@Dell.com; linux-pci@vger.kernel.org; linux-
> hotplug@vger.kernel.org
> Subject: Re: [PATCH] Add firmware label support to iproute2
> 
> On Wed, Aug 25, 2010 at 05:16:46PM -0700, Stephen Hemminger wrote:
> > On Wed, 25 Aug 2010 17:03:23 -0500
> On Wed, Aug 25, 2010 at 05:16:46PM -0700, Stephen Hemminger wrote:
> > Is it really a good idea to have to change every utility that could
> > alter network devices?  There is iproute2, iputils, tcpdump,
> wireshark,
> > quagga, snmp, ...  Many of the utilities come from a BSD world,
> > and will be less likely to accept some Linux specific wart.
> 
> I agree, I don't want to have to change all those userspace apps
> either.  We've started creating patches and are willing to do so if it
> will yield the result we want though.
> 
> > I have lost faith in this library wrapper support everywhere method.
> > Let's just keep the firmware stuff in udev. If the user wants to
> > have a policy that renames device from eth0 to "Embedded BIOS LAN1"
> then
> > do it in udev. Or if you want to keep the ethX naming convention
> > and stuff the firmware label into ifAlias or other sysfs field
> > so it can be displayed that will be not a big issue.
> 
> 1) we remain constrained to IFNAMSIZ named arguments.  There is no
>    such constraint on BIOS-provided names.  Dell BIOS presently uses
>    'Embedded NIC 1' which (fortunately) is 14 chars. We're cutting it
>    awfully close already.  I can't dictate to non-Dell BIOS vendors
>    what to use as their strings, or how long to make them.
> 
> digression 1a) udev has a replace-spaces-with-underscores feature I
> used in
>     the biosdevname udev rules.  That's a reasonable munging of the
>     provided strings.  Much more than that and I'm not sure we could
>     consistently get it right.
> 
> 2) there are apps which use a regexp for device names.  We'd have to
>    find and fix those too.  Arguably we'd have to do this when we
>    patch them to use libnetdevname. [1]
> 
> 3) it continues to force a single naming convention for NICs, where
>    for other types of devices we can have several independent naming
>    conventions.  I have end users who wish to name their interfaces by
>    the BIOS label, others by the function (public, dmz,
>    backup, storage, ...) that the network segment provides.  While we
>    could have different policies, each system can have only one policy
>    at a time.
> 
> 
> David Miller had suggested [2] that we could add a method to get
> alternate labels for devices by querying them.  We've got something
> similar now by exporting the labels for devices in sysfs.  Yea -
> progress!
> 
> But we can't _use_ those labels for more than display
> (meaning a human is doing the mapping in their heads), or to rename
> devices.  We can't use the labels in scripts without doing the label-
> >kernel
> name lookups, and then using the kernel name.
> 
> I'm open to revisiting the "have udev rename devices", but I tried
> that with biosdevname 2 years ago, with little success.  Adding in the
> hotplug dev team to the thread.
> 
> 
> [1] http://marc.info/?l=linux-netdev&m=125522163322610&w=2 (Marco
> d'Itri)
> [2] http://marc.info/?l=linux-hotplug&m=123793549323431&w=2
> 
> --
> Matt Domsch
> Technology Strategist
> Dell | Office of the CTO
> --
> To unsubscribe from this list: send the line "unsubscribe netdev" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
stephen hemminger - Aug. 26, 2010, 3:21 p.m.
On Thu, 26 Aug 2010 11:17:51 -0400
"Loke, Chetan" <Chetan.Loke@netscout.com> wrote:

> What if we extend 'IFNAMSIZ'(beyond 16 chars. Older apps don't need to
> worry because they have been working w/ 16 chars anyways) and also get
> ifalias to work in udev(Or is ifalias a bad idea?)?
> 
> Chetan
>
That is  non-starter for the ioctl() style interface.

struct ifreq {
#define IFHWADDRLEN	6
	union
	{
		char	ifrn_name[IFNAMSIZ];		/* if name, e.g. "en0" */
	} ifr_ifrn;
	
	union {
		struct	sockaddr ifru_addr;
		struct	sockaddr ifru_dstaddr;
		struct	sockaddr ifru_broadaddr;
		struct	sockaddr ifru_netmask;
		struct  sockaddr ifru_hwaddr;
		short	ifru_flags;
		int	ifru_ivalue;
		int	ifru_mtu;
		struct  ifmap ifru_map;
		char	ifru_slave[IFNAMSIZ];	/* Just fits the size */
		char	ifru_newname[IFNAMSIZ];
		void __user *	ifru_data;
		struct	if_settings ifru_settings;
	} ifr_ifru;
};

Applications do:
   	strncpy(ifr.ifr_name, "my name", IFNAMSIZ);
	ioctl(fd, SIOCGHWADDR, &ifr)

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Loke, Chetan - Aug. 26, 2010, 3:38 p.m.
Sorry, my bad.
I agree w/ your recommendation then - 
1) stuff it in ifalias(or create a new alias if net_device::ifalias is
used for snmp etc).

But how do we consume it? 
   1.1) spit it out via sysfs? But Doc/sysfsrules.txt says "Accessing
/sys/class/net/eth0/device is a bug in the application"


Chetan

> -----Original Message-----
> From: Stephen Hemminger [mailto:shemminger@vyatta.com]
> Sent: August 26, 2010 11:22 AM
> To: Loke, Chetan
> Cc: Matt Domsch; Narendra_K@Dell.com; netdev@vger.kernel.org;
> Charles_Rose@Dell.com; Jordan_Hargrave@Dell.com; linux-
> pci@vger.kernel.org; linux-hotplug@vger.kernel.org
> Subject: Re: [PATCH] Add firmware label support to iproute2
> 
> On Thu, 26 Aug 2010 11:17:51 -0400
> "Loke, Chetan" <Chetan.Loke@netscout.com> wrote:
> 
> > What if we extend 'IFNAMSIZ'(beyond 16 chars. Older apps don't need
> to
> > worry because they have been working w/ 16 chars anyways) and also
> get
> > ifalias to work in udev(Or is ifalias a bad idea?)?
> >
> > Chetan
> >
> That is  non-starter for the ioctl() style interface.
> 
> struct ifreq {
> #define IFHWADDRLEN	6
> 	union
> 	{
> 		char	ifrn_name[IFNAMSIZ];		/* if name, e.g.
"en0"
> */
> 	} ifr_ifrn;
> 
> 	union {
> 		struct	sockaddr ifru_addr;
> 		struct	sockaddr ifru_dstaddr;
> 		struct	sockaddr ifru_broadaddr;
> 		struct	sockaddr ifru_netmask;
> 		struct  sockaddr ifru_hwaddr;
> 		short	ifru_flags;
> 		int	ifru_ivalue;
> 		int	ifru_mtu;
> 		struct  ifmap ifru_map;
> 		char	ifru_slave[IFNAMSIZ];	/* Just fits the size */
> 		char	ifru_newname[IFNAMSIZ];
> 		void __user *	ifru_data;
> 		struct	if_settings ifru_settings;
> 	} ifr_ifru;
> };
> 
> Applications do:
>    	strncpy(ifr.ifr_name, "my name", IFNAMSIZ);
> 	ioctl(fd, SIOCGHWADDR, &ifr)

--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Matt Domsch - Aug. 26, 2010, 4:38 p.m.
On Thu, Aug 26, 2010 at 10:01:16AM -0500, Matt Domsch wrote:
> On Wed, Aug 25, 2010 at 05:16:46PM -0700, Stephen Hemminger wrote:
> > On Wed, 25 Aug 2010 17:03:23 -0500
> On Wed, Aug 25, 2010 at 05:16:46PM -0700, Stephen Hemminger wrote:
> > Is it really a good idea to have to change every utility that could
> > alter network devices?  There is iproute2, iputils, tcpdump, wireshark,
> > quagga, snmp, ...  Many of the utilities come from a BSD world,
> > and will be less likely to accept some Linux specific wart.
> 
> I agree, I don't want to have to change all those userspace apps
> either.  We've started creating patches and are willing to do so if it
> will yield the result we want though.
>  
> > I have lost faith in this library wrapper support everywhere method.
> > Let's just keep the firmware stuff in udev. If the user wants to
> > have a policy that renames device from eth0 to "Embedded BIOS LAN1" then
> > do it in udev. Or if you want to keep the ethX naming convention
> > and stuff the firmware label into ifAlias or other sysfs field
> > so it can be displayed that will be not a big issue.
> 
> 1) we remain constrained to IFNAMSIZ named arguments.  There is no
>    such constraint on BIOS-provided names.  Dell BIOS presently uses
>    'Embedded NIC 1' which (fortunately) is 14 chars. We're cutting it
>    awfully close already.  I can't dictate to non-Dell BIOS vendors
>    what to use as their strings, or how long to make them.

vlan usage requires 5 characters from IFNAMSIZ (eth0.4095).  So my
example with 'Embedded NIC 1' plus a vlan doesn't fit.
Kay Sievers - Aug. 27, 2010, 7:54 a.m.
On Thu, Aug 26, 2010 at 17:38, Loke, Chetan <Chetan.Loke@netscout.com> wrote:
> Sorry, my bad.
> I agree w/ your recommendation then -
> 1) stuff it in ifalias(or create a new alias if net_device::ifalias is
> used for snmp etc).
>
> But how do we consume it?
>   1.1) spit it out via sysfs? But Doc/sysfsrules.txt says "Accessing
> /sys/class/net/eth0/device is a bug in the application"

You walk up the parent devices of the netdev until you find the one
you are looking for. The "device" link is broken by design and might
just point to the first parent device. The kernel is free to insert
devices into the device tree if needed, and then the device link
target may change.

/sys/class/net/eth0 is a symlink pointing to a location the
/sys/devices tree, like:
  ../../devices/pci0000:00/0000:00:19.0/net/eth0
One of the parent devices of the eth0 device has this attribute., but
you can never be sure that it's just the next parent (broken concept
of the device link), you have to walk up the chain of parents.

You can just use udev to that automatically and extract the value, and
pass it with the event for the eth0 device.

Kay
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Patch

diff --git a/drivers/pci/pci-label.c b/drivers/pci/pci-label.c
index 111500e..a48eedb 100644
--- a/drivers/pci/pci-label.c
+++ b/drivers/pci/pci-label.c
@@ -19,6 +19,7 @@ 
 #include <linux/pci_ids.h>
 #include <linux/module.h>
 #include <linux/device.h>
+#include <linux/string.h>
 #include "pci.h"
 
 enum smbios_attr_enum {
@@ -131,13 +132,78 @@  pci_remove_smbiosname_file(struct pci_dev *pdev)
 	sysfs_remove_group(&pdev->dev.kobj, &smbios_attr_group);
 }
 
+static struct kobject *pci_label_kobj;
+
+static int pci_label_kobj_init(void)
+{
+	pci_label_kobj = kobject_create_and_add("pci", firmware_kobj);
+	if (pci_label_kobj == NULL)
+		return -ENOMEM;
+	return 0;
+}
+
+static int
+pci_create_smbios_label_symlink(struct pci_dev *pdev)
+{
+	char *label, *p;
+	mode_t mode;
+	int ret=-ENOMEM;
+
+	if (!pdev)
+		return -ENODEV;
+	if (pci_label_kobj == NULL)
+		if (pci_label_kobj_init())
+			return -ENOMEM;
+	label = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (label == NULL)
+		return -ENOMEM;
+	mode = find_smbios_instance_string(pdev, label, SMBIOS_ATTR_LABEL_SHOW);
+	if (mode == 0) {
+		ret = -ENODEV;
+		goto out_free;
+	}
+	p = strim(label);
+	ret = sysfs_create_link_nowarn(pci_label_kobj, &pdev->dev.kobj, p);
+out_free:
+	kfree(label);
+	return ret;
+}
+
+static void
+pci_delete_smbios_label_symlink(struct pci_dev *pdev)
+{
+	char *label, *p;
+	mode_t mode;
+
+	if (!pdev)
+		return;
+	if (pci_label_kobj == NULL)
+		return;
+	label = kmalloc(PAGE_SIZE, GFP_KERNEL);
+	if (label == NULL)
+		return;
+	mode = find_smbios_instance_string(pdev, label, SMBIOS_ATTR_LABEL_SHOW);
+	if (mode == 0) {
+		goto out_free;
+	}
+	p = strim(label);
+	sysfs_delete_link(pci_label_kobj, &pdev->dev.kobj, p);
+
+out_free:
+	kfree(label);
+}
+
+
 void pci_create_firmware_label_files(struct pci_dev *pdev)
 {
 	if (!pci_create_smbiosname_file(pdev))
 		;
+	if (!pci_create_smbios_label_symlink(pdev))
+		;
 }
 
 void pci_remove_firmware_label_files(struct pci_dev *pdev)
 {
 	pci_remove_smbiosname_file(pdev);
+	pci_delete_smbios_label_symlink(pdev);
 }