allow access to sysfs_groups member
Subsystems (2)
PATCH 1/1 allow access to sysfs_groups member
In a recent post, I asked for way to hold the uevent that adds a net_device until a driver had added some extra sysfs files.
The use-case for such thing is a (PCMCIA) CAN card, that has 2 (CAN) network chips. The driver could add a 'channel' sysfs file that indicates the channel on the card, but this sysfs file is not present yet when the uevent is generated.
This patch applied to a 2.6.30 kernel did allow to use non-standard sysfs properties in udev rules (together with a match on device/driver).
I believe the above use-case is not limited to CAN, but any other network type.
This patch allows adding sysfs attribute groups during netdevice registration. The idea is that before the register_netdev call, several calls to netdev_sysfs_add_group can be done.
The existing sysfs groups that are added in netdev_register_kobject use the same function too.
I did not touch the number of possible groups (currently still 3).
---
include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 28 +++++++++++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-)
include/linux/netdevice.h +2 -0
@@ -1115,6 +1115,8 @@ extern int dev_open(struct net_device *dev);extern int dev_close (struct net_device *dev);extern void dev_disable_lro (struct net_device *dev);extern int dev_queue_xmit (struct sk_buff *skb); +extern int netdev_sysfs_add_group (struct net_device *net, +struct attribute_group *grp);extern int register_netdevice (struct net_device *dev);extern void unregister_netdevice (struct net_device *dev);extern void free_netdev (struct net_device *dev);
net/core/net-sysfs.c +23 -5
@@ -527,27 +527,45 @@ void netdev_unregister_kobject(struct net_device * net)device_del (dev); } +/* Add a sysfs group to the netdev groups */ +int netdev_sysfs_add_group (struct net_device *net, +struct attribute_group *grp) +{ +struct attribute_group **groups = net->sysfs_groups; +struct attribute_group **end; + +/* end pointer, with room for null terminator */ + end = &net->sysfs_groups[ARRAY_SIZE (net->sysfs_groups) -1 ]; +for (; groups < end; ++groups) { +if (!*groups) { + *groups = grp; +return 0 ; + } + } +return -ENOSPC ; +} +EXPORT_SYMBOL (netdev_sysfs_add_group); +/* Create sysfs entries for network device. */ int netdev_register_kobject (struct net_device *net) {struct device *dev = &(net->dev); -const struct attribute_group **groups = net->sysfs_groups; dev->class = &net_class; dev->platform_data = net; - dev->groups = groups; + dev->groups = net->sysfs_groups;dev_set_name (dev,"%s" , net->name);#ifdef CONFIG_SYSFS - *groups++ = &netstat_group; +netdev_sysfs_add_group (net, &netstat_group);#ifdef CONFIG_WIRELESS_EXT_SYSFS if (net->ieee80211_ptr) - *groups++ = &wireless_group; +netdev_sysfs_add_group (net, &wireless_group);#ifdef CONFIG_WIRELESS_EXT else if (net->wireless_handlers) - *groups++ = &wireless_group; + netdev_sysfs_add_group(net, &wireless_group);#endif #endif #endif /* CONFIG_SYSFS */
Quoted 8 lines · On Fri, 13 Nov 2009 11:51:57 +0100 Kurt Van Dijck <[email protected]> wrote:
net/core/net-sysfs.c +8
-0+/* Add a sysfs group to the netdev groups */ +int netdev_sysfs_add_group (struct net_device *net, +struct attribute_group *grp) +{ +struct attribute_group **groups = net->sysfs_groups; +struct attribute_group **end; + +/* end pointer, with room for null terminator */
net/core/net-sysfs.c void netdev_unregister_kobject(struct net_device * net) · line 547
Quoted 10 lines
net/core/net-sysfs.c +10
-0+ end = &net->sysfs_groups[ARRAY_SIZE (net->sysfs_groups) -1 ]; +for (; groups < end; ++groups) { +if (!*groups) { + *groups = grp; +return 0 ; + } + } +return -ENOSPC ; +} +EXPORT_SYMBOL (netdev_sysfs_add_group);
EXPORT_SYMBOL_GPL() for all device/sysfs related stuff.
Also, need some way to BUG() if this is done after device has been registered.
Another way to add sub-directories which is what bridge, bonding, and others do is to use another kobject. I think this is what you want for the case of two CAN objects under one netdevice.
PATCH v2 1/1 allow access to sysfs_groups member
Quoted 2 lines · Stephen Hemminger
On Fri, 13 Nov 2009 11:51:57 +0100
Kurt Van Dijck <[email protected]> wrote:
[...]
Quoted 1 line
EXPORT_SYMBOL_GPL()for all device/sysfs related stuff.
Ok, no problem
Quoted 3 lines
Also, need some way to
BUG()if this is done after device has been registered.
Ok. I gave it a try. I _think_ I did it write, but a second look would not harm :-). I was not able to run a real test yet.
Quoted 4 lines
Another way to add sub-directories which is what bridge, bonding, and others do is to use another kobject. I think this is what you want for the case of two CAN objects under one netdevice.
In fact, I wanted to add this for cards that have multiple seperate CAN network device, combined on 1 PCI or PCMCIA device.
In the 'add network' uevent, a udev rule could find properties of the card (device/ symlink). Right now, there is no way to tell if a network device is bus 1 or 2 on the card. in CAN, there's no such thing as a MAC address.
I encountered this issue with a softing CAN card (not yet in mainline), and there are other drivers in the socketCAN queue that have the same problem.
The ethernet cards with multiple busses (that I've seen yet :-) ) combine multiple PCI devices on 1 card, and identification of the 'instance on the card' can happen with the sysfs properties delivered by the PCI bus.
CAN devices with multiple busses typically are combined all together on 1 single device on the PCI or PCMCIA bus.
So, I wanted to add a 'channel' property in /sys/class/net/canX, which could indicate the instance on the device. Such property must be installed by the driver, not the bus the device is on.
This patch allows me to have this channel property present at the moment of the uevent.
I can imagine other subsystems may benefit from this too.
Regards,
Kurt Van Dijck
---
This patch allows adding sysfs attribute groups during netdevice registration. The idea is that before the register_netdev call, several calls to netdev_sysfs_add_group can be done.
--- include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-)
include/linux/netdevice.h +2 -0
@@ -1115,6 +1115,8 @@ extern int dev_open(struct net_device *dev);extern int dev_close (struct net_device *dev);extern void dev_disable_lro (struct net_device *dev);extern int dev_queue_xmit (struct sk_buff *skb); +extern int netdev_sysfs_add_group (struct net_device *net, +const struct attribute_group *grp);extern int register_netdevice (struct net_device *dev);extern void unregister_netdevice (struct net_device *dev);extern void free_netdev (struct net_device *dev);
net/core/net-sysfs.c +24 -5
@@ -527,27 +527,46 @@ void netdev_unregister_kobject(struct net_device * net)device_del (dev); } +/* Add a sysfs group to the netdev groups */ +int netdev_sysfs_add_group (struct net_device *net, +const struct attribute_group *grp) +{ +struct attribute_group **groups = net->sysfs_groups; +struct attribute_group **end; + +BUG_ON (net->reg_state >=NETREG_REGISTERED ); +/* end pointer, with room for null terminator */ + end = &net->sysfs_groups[ARRAY_SIZE (net->sysfs_groups) -1 ]; +for (; groups < end; ++groups) { +if (!*groups) { + *groups = grp; +return 0 ; + } + } +return -ENOSPC ; +} +EXPORT_SYMBOL_GPL (netdev_sysfs_add_group); +/* Create sysfs entries for network device. */ int netdev_register_kobject (struct net_device *net) {struct device *dev = &(net->dev); -const struct attribute_group **groups = net->sysfs_groups; dev->class = &net_class; dev->platform_data = net; - dev->groups = groups; + dev->groups = net->sysfs_groups;dev_set_name (dev,"%s" , net->name);#ifdef CONFIG_SYSFS - *groups++ = &netstat_group; +netdev_sysfs_add_group (net, &netstat_group);#ifdef CONFIG_WIRELESS_EXT_SYSFS if (net->ieee80211_ptr) - *groups++ = &wireless_group; +netdev_sysfs_add_group (net, &wireless_group);#ifdef CONFIG_WIRELESS_EXT else if (net->wireless_handlers) - *groups++ = &wireless_group; + netdev_sysfs_add_group(net, &wireless_group);#endif #endif #endif /* CONFIG_SYSFS */
Quoted 32 lines · On Sat, 14 Nov 2009 17:54:09 +0100 Kurt Van Dijck <[email protected]> wrote:
Quoted 2 lines · Stephen Hemminger
On Fri, 13 Nov 2009 11:51:57 +0100
Kurt Van Dijck <[email protected]> wrote:[...]
Quoted 1 line
EXPORT_SYMBOL_GPL()for all device/sysfs related stuff.Ok, no problem
Quoted 3 lines
Also, need some way to
BUG()if this is done after device has been registered.Ok. I gave it a try. I _think_ I did it write, but a second look would not harm :-). I was not able to run a real test yet.
Quoted 4 lines
Another way to add sub-directories which is what bridge, bonding, and others do is to use another kobject. I think this is what you want for the case of two CAN objects under one netdevice.
In fact, I wanted to add this for cards that have multiple seperate CAN network device, combined on 1 PCI or PCMCIA device.
In the 'add network' uevent, a udev rule could find properties of the card (device/ symlink). Right now, there is no way to tell if a network device is bus 1 or 2 on the card. in CAN, there's no such thing as a MAC address.
I encountered this issue with a softing CAN card (not yet in mainline), and there are other drivers in the socketCAN queue that have the same problem.The ethernet cards with multiple busses (that I've seen yet :-) ) combine multiple PCI devices on 1 card, and identification of the 'instance on the card' can happen with the sysfs properties delivered by the PCI bus.
CAN devices with multiple busses typically are combined all together on 1 single device on the PCI or PCMCIA bus.
Quoted 7 lines
So, I wanted to add a 'channel' property in
/sys/class/net/canX, which could indicate the instance on the device. Such property must be installed by the driver, not the bus the device is on.
This patch allows me to have this channel property present at the moment of the uevent.I can imagine other subsystems may benefit from this too.
Okay by me.
Quoted 1 line · Stephen Hemminger
[...]
Quoted 1 line
Stephen,
Thanks for your review.
Kurt
Quoted 3 lines · Stephen Hemminger
Okay by me.
Sorry for asking.
I'm not very experienced yet with git etc.
Is there anything I'm supposed to do/deliver to get the patch committed?
kind regards,
Kurt
David Miller
maintainerFrom: Kurt Van Dijck <[email protected]>
Date: Wed, 18 Nov 2009 16:43:13 +0100
Quoted 1 line
Is there anything I'm supposed to do/deliver to get the patch committed?
Please just resubmit it fully with full changelog and signoffs.
Thanks.
Kurt Van Dijck
Acked-by Stephen HemmingerThis patch allows adding sysfs attribute groups during netdevice registration. The idea is that before the register_netdev call, several calls to netdev_sysfs_add_group can be done. These attributes are accessible (by udev) during the uevent.
--- include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-)
include/linux/netdevice.h +2 -0
@@ -1115,6 +1115,8 @@ extern int dev_open(struct net_device *dev);extern int dev_close (struct net_device *dev);extern void dev_disable_lro (struct net_device *dev);extern int dev_queue_xmit (struct sk_buff *skb); +extern int netdev_sysfs_add_group (struct net_device *net, +const struct attribute_group *grp);extern int register_netdevice (struct net_device *dev);extern void unregister_netdevice (struct net_device *dev);extern void free_netdev (struct net_device *dev);
net/core/net-sysfs.c +24 -5
@@ -527,27 +527,46 @@ void netdev_unregister_kobject(struct net_device * net)device_del (dev); } +/* Add a sysfs group to the netdev groups */ +int netdev_sysfs_add_group (struct net_device *net, +const struct attribute_group *grp) +{ +struct attribute_group **groups = net->sysfs_groups; +struct attribute_group **end; + +BUG_ON (net->reg_state >=NETREG_REGISTERED ); +/* end pointer, with room for null terminator */ + end = &net->sysfs_groups[ARRAY_SIZE (net->sysfs_groups) -1 ]; +for (; groups < end; ++groups) { +if (!*groups) { + *groups = grp; +return 0 ; + } + } +return -ENOSPC ; +} +EXPORT_SYMBOL_GPL (netdev_sysfs_add_group); +/* Create sysfs entries for network device. */ int netdev_register_kobject (struct net_device *net) {struct device *dev = &(net->dev); -const struct attribute_group **groups = net->sysfs_groups; dev->class = &net_class; dev->platform_data = net; - dev->groups = groups; + dev->groups = net->sysfs_groups;dev_set_name (dev,"%s" , net->name);#ifdef CONFIG_SYSFS - *groups++ = &netstat_group; +netdev_sysfs_add_group (net, &netstat_group);#ifdef CONFIG_WIRELESS_EXT_SYSFS if (net->ieee80211_ptr) - *groups++ = &wireless_group; +netdev_sysfs_add_group (net, &wireless_group);#ifdef CONFIG_WIRELESS_EXT else if (net->wireless_handlers) - *groups++ = &wireless_group; + netdev_sysfs_add_group(net, &wireless_group);#endif #endif #endif /* CONFIG_SYSFS */
David Miller
maintainerFrom: Kurt Van Dijck <[email protected]>
Date: Wed, 18 Nov 2009 17:41:26 +0100
Quoted 7 lines
This patch allows adding sysfs attribute groups during netdevice registration. The idea is that before the
register_netdevcall, several calls tonetdev_sysfs_add_groupcan be done. These attributes are accessible (by udev) during the uevent.Signed-off-by Kurt Van Dijck <[email protected]>
Patch is corrupted by your email client. Tab characters have been turned into spaces, etc.
Please fix this up and resubmit.
Thanks.
Quoted 10 lines · David Miller
Quoted 7 lines
This patch allows adding sysfs attribute groups during netdevice registration. The idea is that before the
register_netdevcall, several calls tonetdev_sysfs_add_groupcan be done. These attributes are accessible (by udev) during the uevent.Signed-off-by Kurt Van Dijck <[email protected]>Patch is corrupted by your email client. Tab characters have been turned into spaces, etc.
Oops. My fault. I did an copy in X ...
Sorry for that.
Quoted 4 lines
Please fix this up and resubmit.
Thanks.
Kurt Van Dijck
Acked-by Stephen HemmingerThis patch allows adding sysfs attribute groups during netdevice registration. The idea is that before the register_netdev call, several calls to netdev_sysfs_add_group can be done. These attributes are accessible (by udev) during the uevent.
--- include/linux/netdevice.h | 2 ++ net/core/net-sysfs.c | 29 ++++++++++++++++++++++++----- 2 files changed, 26 insertions(+), 5 deletions(-)
include/linux/netdevice.h +2 -0
@@ -1115,6 +1115,8 @@ extern int dev_open(struct net_device *dev);extern int dev_close (struct net_device *dev);extern void dev_disable_lro (struct net_device *dev);extern int dev_queue_xmit (struct sk_buff *skb); +extern int netdev_sysfs_add_group (struct net_device *net, +const struct attribute_group *grp);extern int register_netdevice (struct net_device *dev);extern void unregister_netdevice (struct net_device *dev);extern void free_netdev (struct net_device *dev);
net/core/net-sysfs.c +24 -5
@@ -527,27 +527,46 @@ void netdev_unregister_kobject(struct net_device * net)device_del (dev); } +/* Add a sysfs group to the netdev groups */ +int netdev_sysfs_add_group (struct net_device *net, +const struct attribute_group *grp) +{ +struct attribute_group **groups = net->sysfs_groups; +struct attribute_group **end; + +BUG_ON (net->reg_state >=NETREG_REGISTERED ); +/* end pointer, with room for null terminator */ + end = &net->sysfs_groups[ARRAY_SIZE (net->sysfs_groups) -1 ]; +for (; groups < end; ++groups) { +if (!*groups) { + *groups = grp; +return 0 ; + } + } +return -ENOSPC ; +} +EXPORT_SYMBOL_GPL (netdev_sysfs_add_group); +/* Create sysfs entries for network device. */ int netdev_register_kobject (struct net_device *net) {struct device *dev = &(net->dev); -const struct attribute_group **groups = net->sysfs_groups; dev->class = &net_class; dev->platform_data = net; - dev->groups = groups; + dev->groups = net->sysfs_groups;dev_set_name (dev,"%s" , net->name);#ifdef CONFIG_SYSFS - *groups++ = &netstat_group; +netdev_sysfs_add_group (net, &netstat_group);#ifdef CONFIG_WIRELESS_EXT_SYSFS if (net->ieee80211_ptr) - *groups++ = &wireless_group; +netdev_sysfs_add_group (net, &wireless_group);#ifdef CONFIG_WIRELESS_EXT else if (net->wireless_handlers) - *groups++ = &wireless_group; + netdev_sysfs_add_group(net, &wireless_group);#endif #endif #endif /* CONFIG_SYSFS */
David Miller
maintainerFrom: Kurt Van Dijck <[email protected]>
Date: Wed, 18 Nov 2009 21:59:52 +0100
Quoted 7 lines
This patch allows adding sysfs attribute groups during netdevice registration. The idea is that before the
register_netdevcall, several calls tonetdev_sysfs_add_groupcan be done. These attributes are accessible (by udev) during the uevent.Signed-off-by Kurt Van Dijck <[email protected]>
Unfortunately, the code in this function is much different in net-next-2.6 which is where I want to add this, and your patch doesn't apply.
Please rebase your patch on that tree, thank you.
Quoted 6 lines · David Miller
Unfortunately, the code in this function is much different in net-next-2.6 which is where I want to add this, and your patch doesn't apply.
Please rebase your patch on that tree, thank you.
As I mentioned, I'm not experienced with using git yet. Is there a fine manual I can inspect? I get lost in the man-pages.
Sorry for generating so much noise.
Kurt
Quoted 9 lines · Kurt Van Dijck
Quoted 6 lines · David Miller
Unfortunately, the code in this function is much different in net-next-2.6 which is where I want to add this, and your patch doesn't apply.
Please rebase your patch on that tree, thank you.
As I mentioned, I'm not experienced with using git yet. Is there a fine manual I can inspect? I get lost in the man-pages.
git clone git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.git
Should get you started.
In this case please look at how I modified the bonding driver to do what you are trying to do. That is the conflict in net-next and I think it was actually less code.
The other very useful command is: git log -u some/path/
Git has fine manual pages and git command --help works for the builtin git commands.
Eric
Quoted 8 lines · Eric W. Biederman
Quoted 6 lines · Kurt Van Dijck
Quoted 5 lines · David Miller
Unfortunately, the code in this function is much different in net-next-2.6 which is where I want to add this, and your patch doesn't apply.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
Please rebase your patch on that tree, thank you.
As I mentioned, I'm not experienced with using git yet. Is there a fine manual I can inspect? I get lost in the man-pages.
git clone
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.gitShould get you started.
$ git pull git://git.kernel.... master did the job today. It took me a while
Quoted 4 lines
In this case please look at how I modified the bonding driver to do what you are trying to do. That is the conflict in net-next and I think it was actually less code.
It _is_ less code (does a little less too :-) ). It solves the problem anyway. I'll stop with my patch.
Thanks.
Kurt
Quoted 10 lines · Kurt Van Dijck
Quoted 9 lines · Eric W. Biederman
Quoted 7 lines · Kurt Van Dijck
Quoted 6 lines · David Miller
Unfortunately, the code in this function is much different in net-next-2.6 which is where I want to add this, and your patch doesn't apply.
Please rebase your patch on that tree, thank you.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
As I mentioned, I'm not experienced with using git yet. Is there a fine manual I can inspect? I get lost in the man-pages.
git clone
git://git.kernel.org/pub/scm/linux/kernel/git/davem/net-next-2.6.gitShould get you started.
$ git pull git://git.kernel.... master did the job today. It took me a while
An incremental pull typically much faster than the initial one.
Quoted 6 lines
Quoted 3 lines
In this case please look at how I modified the bonding driver to do what you are trying to do. That is the conflict in net-next and I think it was actually less code.
It _is_ less code (does a little less too :-) ). It solves the problem anyway. I'll stop with my patch.
You were just worried about CAN devices and not all network devices correct?
Eric
Quoted 7 lines · Eric W. Biederman
Quoted 3 lines · Kurt Van Dijck
Quoted 3 lines
In this case please look at how I modified the bonding driver to do what you are trying to do. That is the conflict in net-next and I think it was actually less code.
Quoted 5 lines
Quoted 2 lines
It _is_ less code (does a little less too :-) ). It solves the problem anyway. I'll stop with my patch.
You were just worried about CAN devices and not all network devices correct?
Yes, but even not _every_ CAN device. It's driver dependant issue.
Quoted 6 lines
Eric
--
To unsubscribe from this list: send the line "unsubscribe netdev" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html