[ovs-discuss] [NIC-20 05/11] datapath: Prepare to extend lifetime of kobjects.

Ben Pfaff blp at nicira.com
Wed Aug 5 22:37:08 UTC 2009


The following commit will move the initialization of the datapath and
net_bridge_port kobjects earlier and the destruction later, without
changing when those kobjects are attached to sysfs.  To do so, the
initialization of kobjects and attaching to sysfs has to be done as
separate steps.  That's already the case for net_bridge_port kobjects, and
this commit makes it so for datapath kobjects too.

This commit also simplifies some code, since the split API exists both
before and after 2.6.25, but the combined functions changed names.

Also, in dp_sysfs_add_if() call kobject_init() after initializing the
kset member, since kobject_init() expects that.  This makes no actual
difference in this case since the kobj is obtained from kzalloc(), but
it still seems better.
---
 datapath/dp_sysfs_dp.c |   20 +++++---------------
 datapath/dp_sysfs_if.c |    2 +-
 2 files changed, 6 insertions(+), 16 deletions(-)

diff --git a/datapath/dp_sysfs_dp.c b/datapath/dp_sysfs_dp.c
index 714a4b2..5764a3a 100644
--- a/datapath/dp_sysfs_dp.c
+++ b/datapath/dp_sysfs_dp.c
@@ -487,26 +487,19 @@ int dp_sysfs_add_dp(struct datapath *dp)
 	}
 
 	/* Create /sys/class/net/<devname>/bridge directory. */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
 	kobject_set_name(&dp->ifobj, SYSFS_BRIDGE_PORT_SUBDIR); /* "bridge" */
 	dp->ifobj.ktype = NULL;
 	dp->ifobj.kset = NULL;
 	dp->ifobj.parent = kobj;
+	kboject_init(&dp->ifobj);
 
-	err = kobject_register(&dp->ifobj);
+	err = kobject_add(&dp->ifobj);
 	if (err) {
 		pr_info("%s: can't add kobject (directory) %s/%s\n",
 				__FUNCTION__, dp_name(dp), dp->ifobj.name);
 		goto out2;
 	}
-#else
-	br->ifobj = kobject_create_and_add(SYSFS_BRIDGE_PORT_SUBDIR, kobj);
-	if (!br->ifobj) {
-		pr_info("%s: can't add kobject (directory) %s/%s\n",
-			__func__, dp_name(dp), SYSFS_BRIDGE_PORT_SUBDIR);
-		goto out2;
-	}
-#endif
+	kobject_uevent(&dp->ifobj, KOBJ_ADD);
 	return 0;
 
  out2:
@@ -519,11 +512,8 @@ int dp_sysfs_del_dp(struct datapath *dp)
 {
 	struct kobject *kobj = to_kobj(dp->ports[ODPP_LOCAL]->dev);
 
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
-	kobject_unregister(&dp->ifobj);
-#else 
-	kobject_put(dp->ifobj);
-#endif
+	kobject_del(&dp->ifobj);
+	kobject_put(&dp->ifobj);
 	sysfs_remove_group(kobj, &bridge_group);
 
 	return 0;
diff --git a/datapath/dp_sysfs_if.c b/datapath/dp_sysfs_if.c
index f118818..2771d65 100644
--- a/datapath/dp_sysfs_if.c
+++ b/datapath/dp_sysfs_if.c
@@ -290,11 +290,11 @@ int dp_sysfs_add_if(struct net_bridge_port *p)
 	int err;
 
 	/* Create /sys/class/net/<devname>/brport directory. */
-	kobject_init(&p->kobj);
 	kobject_set_name(&p->kobj, SYSFS_BRIDGE_PORT_ATTR); /* "brport" */
 	p->kobj.ktype = &brport_ktype;
 	p->kobj.kset = NULL;
 	p->kobj.parent = &(p->dev->class_dev.kobj);
+	kobject_init(&p->kobj);
 
 	err = kobject_add(&p->kobj);
 	if (err)
-- 
1.6.3.3





More information about the discuss mailing list