Re: [PATCH 8/19]: SCST SYSFS interface implementation

From: Vladislav Bolkhovitin
Date: Wed Nov 10 2010 - 15:39:05 EST


Joe Eykholt, on 11/10/2010 11:29 PM wrote:
>> 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);
>> }
>
> I'll admit I don't understand this all that well, but
> why not just have x_release() (based on (2))
> do free(x), and have del_object
> do the kobject_put(&x->kobj) as its very last thing?
> Then you don't need the completion.

We are discussing _synchronous_ delete of x, so need to wait until
x->kobj released, hence the completion is needed in both cases.

For instance, the sync delete is needed for targets to let the
corresponding target driver be safely unloaded after its target
unregistered.

Vlad
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/