Skip to contentSkip to conversation

class device: add attribute_group creation

PATCH In review Stephen Hemminger 3 participants 7 messages Apr 21, 2006 – May 7, 2006

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 class device: add attribute_group creation

Extend the support of attribute groups in class_device's to allow groups to be created as part of the registration process. This allows network device's to avoid race between registration and creating groups.

Note that unlike attributes that are a property of the class object, the groups are a property of the class_device object. This is done because there are different types of network devices (wireless for example).

drivers/base/class.c +32 -0
@@ -456,6 +456,35 @@
 	}
 }
 
+static int class_device_add_groups(struct class_device * cd)
+{
+	int i;
+	int error = 0;
+
+	if (cd->groups) {
+		for (i = 0; cd->groups[i]; i++) {
+			error = sysfs_create_group(&cd->kobj, cd->groups[i]);
+			if (error) {
+				while (--i >= 0)
+					sysfs_remove_group(&cd->kobj, cd->groups[i]);
+				goto out;
+			}
+		}
+	}
+out:
+	return error;
+}
+
+static void class_device_remove_groups(struct class_device * cd)
+{
+	int i;
+	if (cd->groups) {
+		for (i = 0; cd->groups[i]; i++) {
+			sysfs_remove_group(&cd->kobj, cd->groups[i]);
+		}
+	}
+}
+
 static ssize_t show_dev(struct class_device *class_dev, char *buf)
 {
 	return print_dev_t(buf, class_dev->devt);
@@ -559,6 +588,8 @@
 				  class_name);
 	}
 
+	class_device_add_groups(class_dev);
+
 	kobject_uevent(&class_dev->kobj, KOBJ_ADD);
 
 	/* notify any interfaces this device is now here */
@@ -672,6 +703,7 @@
 	if (class_dev->devt_attr)
 		class_device_remove_file(class_dev, class_dev->devt_attr);
 	class_device_remove_attrs(class_dev);
+	class_device_remove_groups(class_dev);
 
 	kobject_uevent(&class_dev->kobj, KOBJ_REMOVE);
 	kobject_del(&class_dev->kobj);
include/linux/device.h +2 -0
@@ -200,6 +200,7 @@
  * @node: for internal use by the driver core only.
  * @kobj: for internal use by the driver core only.
  * @devt_attr: for internal use by the driver core only.
+ * @groups: optional additional groups to be created
  * @dev: if set, a symlink to the struct device is created in the sysfs
  * directory for this struct class device.
  * @class_data: pointer to whatever you want to store here for this struct
@@ -228,6 +229,7 @@
 	struct device		* dev;		/* not necessary, but nice to have */
 	void			* class_data;	/* class-specific data */
 	struct class_device	*parent;	/* parent of this child device, if there is one */
+	struct attribute_group  ** groups;	/* optional groups */
 
 	void	(*release)(struct class_device *dev);
 	int	(*uevent)(struct class_device *dev, char **envp,
#1 lore raw

PATCH 2/2 netdev: create attribute_groups with class_device_add

Atomically create attributes when class device is added. This avoids the race between registering class_device (which generates hotplug event), and the creation of attribute groups.

net/core/dev.c +1 -1
@@ -3043,11 +3043,11 @@
 
 		switch(dev->reg_state) {
 		case NETREG_REGISTERING:
-			dev->reg_state = NETREG_REGISTERED;
 			err = netdev_register_sysfs(dev);
 			if (err)
 				printk(KERN_ERR "%s: failed sysfs registration (%d)\n",
 				       dev->name, err);
+			dev->reg_state = NETREG_REGISTERED;
 			break;
 
 		case NETREG_UNREGISTERING:
net/core/net-sysfs.c +12 -37

77 lines not on this page · raw message

include/linux/netdevice.h +2 -0
@@ -506,6 +506,8 @@
 
 	/* class/net/name entry */
 	struct class_device	class_dev;
+	/* space for optional statistics and wireless sysfs groups */
+	struct attribute_group  *sysfs_groups[3];
 };
 
 #define	NETDEV_ALIGN		32
maintainer
#2 lore raw

Re: [PATCH 2/2] netdev: create attribute_groups with class_device_add

From: Stephen Hemminger <[email protected]>
Date: Fri, 21 Apr 2006 12:54:38 -0700

Quoted 5 lines

Atomically create attributes when class device is added. This avoids the race between registering class_device (which generates hotplug event), and the creation of attribute groups.

Did the first patch that adds the attribute_group creation infrastructure go in so that we can get this networking fix in?

#3 lore raw

Re: [PATCH 2/2] netdev: create attribute_groups with class_device_add

Quoted 11 lines · David S. Miller

From: Stephen Hemminger <[email protected]>
Date: Fri, 21 Apr 2006 12:54:38 -0700

Quoted 5 lines

Atomically create attributes when class device is added. This avoids the race between registering class_device (which generates hotplug event), and the creation of attribute groups.

Did the first patch that adds the attribute_group creation infrastructure go in so that we can get this networking fix in?

It and the netdev patch are setting in my tree which is showing up in -mm. I'm going to wait until 2.6.17 is out to send the first patch. I can send the second one then too if you want me to (probably make it easier that way.)

thanks,

greg k-h

maintainer
#4 lore raw

Re: [PATCH 2/2] netdev: create attribute_groups with class_device_add

From: Greg KH <[email protected]>
Date: Fri, 5 May 2006 21:08:39 -0700

Quoted 10 lines · David S. Miller
Quoted 9 lines

From: Stephen Hemminger <[email protected]>
Date: Fri, 21 Apr 2006 12:54:38 -0700

Quoted 5 lines

Atomically create attributes when class device is added. This avoids the race between registering class_device (which generates hotplug event), and the creation of attribute groups.

Quoted 7 lines
Quoted 2 lines

Did the first patch that adds the attribute_group creation infrastructure go in so that we can get this networking fix in?

It and the netdev patch are setting in my tree which is showing up in -mm. I'm going to wait until 2.6.17 is out to send the first patch. I can send the second one then too if you want me to (probably make it easier that way.)

The networking bit by Stephen is a bug fix.

#5 lore raw

Re: [PATCH 2/2] netdev: create attribute_groups with class_device_add

Quoted 16 lines · David S. Miller

From: Greg KH <[email protected]>
Date: Fri, 5 May 2006 21:08:39 -0700

Quoted 13 lines · David S. Miller
Quoted 11 lines

From: Stephen Hemminger <[email protected]>
Date: Fri, 21 Apr 2006 12:54:38 -0700

Quoted 5 lines

Atomically create attributes when class device is added. This avoids the race between registering class_device (which generates hotplug event), and the creation of attribute groups.

Did the first patch that adds the attribute_group creation infrastructure go in so that we can get this networking fix in?

Quoted 6 lines
Quoted 4 lines

It and the netdev patch are setting in my tree which is showing up in -mm. I'm going to wait until 2.6.17 is out to send the first patch. I can send the second one then too if you want me to (probably make it easier that way.)

The networking bit by Stephen is a bug fix.

Good point. Ok, feel free to send both patches to Linus now if you want. You can add my:

to the driver core change as I have no problems with it.
Or I can send them on Monday if you wish. Whatever is easier for you.

thanks,

greg k-h

maintainer
#6 lore raw

Re: [PATCH 2/2] netdev: create attribute_groups with class_device_add

From: Greg KH <[email protected]>
Date: Sat, 6 May 2006 15:59:04 -0700

Quoted 8 lines · David S. Miller
Quoted 1 line

The networking bit by Stephen is a bug fix.

Good point. Ok, feel free to send both patches to Linus now if you want. You can add my:

to the driver core change as I have no problems with it.
Or I can send them on Monday if you wish. Whatever is easier for you.

I'll take care of pushing the changes, thanks Greg.