From: Ben Pfaff Date: Wed, 5 Aug 2009 20:45:13 +0000 (-0700) Subject: datapath: Prepare to extend lifetime of kobjects. X-Git-Tag: v0.90.5~72 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=3de35df914e39692470a5d4546cb1fae2d93a316;p=sliver-openvswitch.git datapath: Prepare to extend lifetime of kobjects. 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. --- diff --git a/datapath/dp_sysfs_dp.c b/datapath/dp_sysfs_dp.c index 714a4b2ef..5764a3a35 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//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 f118818bd..2771d6501 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//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)