Thanks for sharing your thoughts with us. But the question isn't about
if it's possible to implement what we need locklessly. The question is
in two approaches how to synchronously delete objects with entries on SYSFS:
1. struct object_x {
...
struct kobject kobj;
struct completion *release_completion;
};
static void x_release(struct kobject *kobj)
{
struct object_x *x;
struct completion *c;
x = container_of(kobj, struct object_x, kobj);
c = x->release_completion;
kfree(x);
complete_all(c);
}
void del_object(struct object_x *x)
{
DECLARE_COMPLETION_ONSTACK(completion);
...
x->release_completion = &completion;
kobject_put(&x->kobj);
wait_for_completion(&completion);
}
and
2. struct object_x {
...
struct kobject kobj;
struct completion release_completion;
};
static void x_release(struct kobject *kobj)
{
struct object_x *x;
x = container_of(kobj, struct object_x, kobj);
complete_all(&x->release_completion);
}
void del_object(struct object_x *x)
{
...
kobject_put(&x->kobj);
wait_for_completion(&completion);
...
kfree(x);
}
Greg asserts that (1) is the only correct approach while (2) is
incorrect, and I'm trying to justify that (2) is correct too and
sometimes could be better, i.e. simpler and clearer, because it
decouples object_x from SYSFS and its kobj. Then kobj becomes an
ordinary member of struct object_x without any special treatment and
with the same lifetime rules as other members of struct object_x. While
in (1) all lifetime of struct object_x is strictly attached to kobj, so
it needs be specially handled with additional code for that if struct
object_x has many other members which needed to be initialized/deleted
_before and after_ kobj as we have in SCST.
Vlad
--