|| ||Tejun Heo <firstname.lastname@example.org>|
|| ||email@example.com, firstname.lastname@example.org, email@example.com,
firstname.lastname@example.org, email@example.com, firstname.lastname@example.org,
|| ||[PATCHSET #master] sysfs: make sysfs disconnect immediately on deletion, take 2|
|| ||Mon, 9 Apr 2007 13:18:46 +0900|
This is the second take of sysfs-immediate-disconnct patchset.
In the last take, rwsem was added to s_elem.dir to protect kobj only.
This wasn't enough because attr and bin_attr need to hold onto not
only the kobject of their parents but also the module backing
themselves and ops too, so the first set still needed separate and
duplicate attribute file orphaning mechanism.
In this take, the rwsem is generalized to become active reference
count. Now each sysfs_dirent has two reference counts - s_count and
s_active. s_count is a regular reference count which guarantees that
the containing sysfs_dirent is accessible. As long as s_count
reference is held, all sysfs internal fields in sysfs_dirent are
accessible including s_parent and s_name.
The newly added s_active is active reference count. This is acquired
by invoking sysfs_get_active() and it's the caller's responsibility to
ensure sysfs_dirent itself is accessible (should be holding s_count
one way or the other). Dereferencing sysfs_dirent to access objects
out of sysfs proper requires active reference. This includes access
to the associated kobjects, attributes and ops.
Because attr/bin_attr ops access both the node itself and its parent
for kobject, they need to hold active references to both.
sysfs_get/put_active_two() helpers are provided to help grabbing both
references. Parent's is acquired first and released last.
Basically, s_count provides the reference counted objects to the upper
layer while s_active guards low level access such that low level
objects can just go away when they want to, and the same mechanism is
applied to all types of sysfs nodes. I think it's conceptually
cleaner and thus easier to understand this way.
With all the patches applied, the same test used in the last take ran
9+hrs without any problem.
Change from the last take are...
* Patch 3 now doesn't move sysfs_get_kobject() as the it's replaced by
active references later.
* Patch 12 updated such that sdir->rwsem is generalized into active
Please read the original lifetime rules discussion and description
of the last take for more info.