net devices: Get network devices to show up in sysfs.
A message that is not in the archive (sent off-list or not yet received): [email protected]
Quoted 21 lines · Linux Kernel Mailing List
ChangeSet 1.838.151.11, 2003/01/06 13:50:37-06:00, [email protected]
net devices: Get network devices to show up in sysfs.
- declare
net_subsys, and register duringnet_dev_init().
- Add kobject to structnet_device.
- initialize name and register inregister_netdevice().
- remove inunregister_netdevice().diff -Nru
a/include/linux/netdevice.hb/include/linux/netdevice.hinclude/linux/netdevice.h +1
-0@@ -28,6 +28,7 @@#include <linux/if.h> #include <linux/if_ether.h> #include <linux/if_packet.h> +#include <linux/kobject.h> #include <asm/atomic.h> #include <asm/cache.h>
include/linux/netdevice.h line 445
Quoted 7 lines
include/linux/netdevice.h +3
-0@@ -438,6 +439,9 @@/* this will get initialized at each interface type init routine */ struct divert_blk *divert;#endif /* CONFIG_NET_DIVERT */ + +/* generic object representation */ +struct kobject kobj; };
Just curious, is this needed purely for reference counting, or mainly to hook into sysfs? If the former, net devices already have reference counting, so I want to make sure kobjects do not run afoul of that.
Quoted 6 lines
include/linux/netdevice.h +2
-0+static struct subsystem net_subsys; +/*******************************************************************************
include/linux/netdevice.h line 2553
Quoted 8 lines
include/linux/netdevice.h +4
-1@@ -2545,7 +2547,10 @@notifier_call_chain (&netdev_chain,NETDEV_REGISTER , dev);net_run_sbin_hotplug (dev,"register" ); - ret =0 ; + +snprintf (dev->kobj.name,KOBJ_NAME_LEN ,dev->name); +kobj_set_kset_s (dev,net_subsys); + ret =kobject_register (&dev->kobj);
If the return code matters, shouldn't you be checking for its success?
include/linux/netdevice.h line 2680
Quoted 6 lines
include/linux/netdevice.h +2
-0@@ -2671,6 +2676,8 @@ goto out; } +kobject_unregister (&dev->kobj); +
...especially if kobject_register failed above
Jeff
Quoted 19 lines · Jeff Garzik
Quoted 18 lines · Linux Kernel Mailing List
ChangeSet 1.838.151.11, 2003/01/06 13:50:37-06:00, [email protected]
net devices: Get network devices to show up in sysfs.
- declare
net_subsys, and register duringnet_dev_init().
- Add kobject to structnet_device.
- initialize name and register inregister_netdevice().
- remove inunregister_netdevice().diff -Nru
a/include/linux/netdevice.hb/include/linux/netdevice.hinclude/linux/netdevice.h +1
-0@@ -28,6 +28,7 @@#include <linux/if.h> #include <linux/if_ether.h> #include <linux/if_packet.h> +#include <linux/kobject.h>
Quoted 14 lines
include/linux/netdevice.h line 445
Quoted 10 lines
include/linux/netdevice.h +3
-0#include <asm/atomic.h> #include <asm/cache.h> @@ -438,6 +439,9 @@/* this will get initialized at each interface type init routine */ struct divert_blk *divert;#endif /* CONFIG_NET_DIVERT */ + +/* generic object representation */ +struct kobject kobj; };Just curious, is this needed purely for reference counting, or mainly to hook into sysfs? If the former, net devices already have reference counting, so I want to make sure kobjects do not run afoul of that.
The latter. If desired, the reference counting can be converted to use kobject refcounting. I can look into this, if you like.
Quoted 5 lines
include/linux/netdevice.h
Quoted 3 lines
include/linux/netdevice.h +3
-0+snprintf (dev->kobj.name,KOBJ_NAME_LEN ,dev->name); +kobj_set_kset_s (dev,net_subsys); + ret =kobject_register (&dev->kobj);If the return code matters, shouldn't you be checking for its success?
Bah. How about the attached patch instead?
-pat
===== net/core/dev.c 1.51 vs edited =====
net/core/dev.c +6 -4
@@ -2520,6 +2520,11 @@if (d == dev || !strcmp (d->name, dev->name)) goto out_err; } +snprintf (dev->kobj.name,KOBJ_NAME_LEN ,dev->name); +kobj_set_kset_s (dev,net_subsys); +if ((ret =kobject_register (&dev->kobj))) + goto out_err; +/* * nil rebuild_header routine, * that should be never called and used as just bug trap.
@@ -2547,10 +2552,7 @@notifier_call_chain (&netdev_chain,NETDEV_REGISTER , dev);net_run_sbin_hotplug (dev,"register" ); - -snprintf (dev->kobj.name,KOBJ_NAME_LEN ,dev->name); -kobj_set_kset_s (dev,net_subsys); - ret =kobject_register (&dev->kobj); + ret =0 ; out:return ret;