From: Boaz Harrosh <bharrosh@panasas.com>
To: Vladislav Bolkhovitin <vst@vlnb.net>
Cc: Greg KH <greg@kroah.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
scst-devel <scst-devel@lists.sourceforge.net>,
James Bottomley <James.Bottomley@HansenPartnership.com>,
Andrew Morton <akpm@linux-foundation.org>,
FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>,
Mike Christie <michaelc@cs.wisc.edu>,
Vu Pham <vuhuong@mellanox.com>,
Bart Van Assche <bart.vanassche@gmail.com>,
James Smart <James.Smart@Emulex.Com>,
Joe Eykholt <jeykholt@cisco.com>, Andy Yan <ayan@marvell.com>,
Chetan Loke <generationgnu@yahoo.com>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Hannes Reinecke <hare@suse.de>,
Richard Sharpe <realrichardsharpe@gmail.com>,
Daniel Henrique Debonzi <debonzi@linux.vnet.ibm.com>
Subject: Re: [PATCH 8/19]: SCST SYSFS interface implementation
Date: Thu, 11 Nov 2010 11:59:28 +0200 [thread overview]
Message-ID: <4CDBBE80.40908@panasas.com> (raw)
In-Reply-To: <4CDAFE6E.7050200@vlnb.net>
On 11/10/2010 10:19 PM, Vladislav Bolkhovitin wrote:
> Boaz Harrosh, on 11/10/2010 12:58 PM wrote:
>> On 11/09/2010 10:06 PM, Vladislav Bolkhovitin wrote:
>>>
>>> Sorry, but what is incorrect in the working implementation without any
>>> bugs doing its job in the simplest, smallest and clearest way?
>>>
>>> If those objects remade to free themselves in the kobjects release(),
>>> what value would it add to them? Would the implementation be simpler,
>>> smaller or clearer? Not, I believe, new implementation would be only
>>> bigger and less clear. So, what's the point to do it to make the code worse?
>>>
>>
>> Totally theoretically speaking, since I have not inspected the code.
>>
>> If today you wait for the count to reach zero, then unregister
>> and send an event to some other subsystem to free the object.
>>
>> Is it not the same as if you take an extra refcount, unregister and
>> send the event at count=1. Then at that other place decrement the last
>> count to cause the object to be freed.
>>
>> I agree that it is hard to do lockless. what some places do is have
>> an extra kref. The kobj has a single ref on it. everything takes the
>> other kref. when that reaches zero the unregister and event fires
>> and at free you decrement the only kobj ref to deallocate. This is one
>> way. In some situations you can manage with a single counter it all
>> depends.
>
> 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:
>
Thanks for putting up an example we can now speak more specifically.
(And saved me the time to actually look at code)
I'll first comment on your code below and I have some questions, please
see if I understood you correctly. Later below I'll try to explain what I
meant.
> 1. struct object_x {
> ...
> struct kobject kobj;
> struct completion *release_completion;
release_completion is only to be used by del_object!
> };
>
> static void x_release(struct kobject *kobj)
This one is put on the kobj.release Right?
> {
> struct object_x *x;
> struct completion *c;
>
> x = container_of(kobj, struct object_x, kobj);
> c = x->release_completion;
> kfree(x);
> complete_all(c);
> }
>
I don't see the unregister of the object_x.kobj, where do
you do this one in x_release or del_object below?
> void del_object(struct object_x *x)
> {
> DECLARE_COMPLETION_ONSTACK(completion);
>
> ...
> x->release_completion = &completion;
> kobject_put(&x->kobj);
This put might not be the last put on the object, IOs in flight
and/or open files might have extra reference on the object.
We release our initial ref, and below wait for all operations
to complete. (Is there a matter of timeout like files not closing?)
> 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)
> {
DECLARE_COMPLETION_ONSTACK(completion);
x->release_completion = &completion;
Right?
> ...
> 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
One possibility (There are others)
3. struct object_x {
...
struct kref kref;
struct kobject kobj;
struct completion *release_completion;
};
Every body takes kref_put(&object_x.kref) and kref_get(&object_x.kref)
I hope you have x_get/x_put, Yes?
static void x_kref_release(struct kref *kref)
{
struct object_x *x = container_of(kref, struct object_x, kref);
complete_all(&x->release_completion);
}
static void x_obj_release(struct kobject *kobj)
{
struct object_x *x = container_of(kobj, struct object_x, kobj);
kfree(x);
}
int x_put(struct object_x *x)
{
return kref_put(&x->kref, x_kref_release);
}
void del_object(struct object_x *x)
{
DECLARE_COMPLETION_ONSTACK(completion);
...
x->release_completion = &completion;
x_put(x)
wait_for_completion(&completion);
kobject_put(&x->kobj);
}
Or
4. Exactly Like 3 but without the extra kref member
Only x_put() changes and x_kref_release() now receives
an x_object
int x_put(struct object_x *x)
{
if (kobject_put(&x->kobj) == 1)
// Like above [3] x_kref_release()
x_kref_release(x);
}
Note that in 4 you don't actually have a kref member, and that you have
one extra ref on kobj from the beginning. In del_object above the first
x_put(x) makes it possible to reach the "1" count and then the final
kobject_put(&x->kobj); frees the object.
(You need to be carfull with [4] because it must have a refcount==2 before
you expose it to any IO or sysfs.)
So this is what I meant.
Cheers
Boaz
next prev parent reply other threads:[~2010-11-11 9:59 UTC|newest]
Thread overview: 98+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-10-01 21:34 [PATCHv4 0/19]: New SCSI target framework (SCST) with dev handlers and 2 target drivers Vladislav Bolkhovitin
2010-10-01 21:36 ` [PATCH 1/19]: Integration of SCST into the Linux kernel tree Vladislav Bolkhovitin
2010-10-01 21:36 ` [PATCH 2/19]: SCST core's Makefile and Kconfig Vladislav Bolkhovitin
2010-10-01 21:38 ` [PATCH 3/19]: SCST public headers Vladislav Bolkhovitin
2010-10-01 21:39 ` [PATCH 4/19]: SCST main management files and private headers Vladislav Bolkhovitin
2010-10-01 21:42 ` [PATCH 5/19]: SCST implementation of the SCSI target state machine Vladislav Bolkhovitin
2010-10-01 21:43 ` [PATCH 6/19]: SCST internal library functions Vladislav Bolkhovitin
2010-10-01 21:44 ` [PATCH 7/19]: SCST Persistent Reservations implementation Vladislav Bolkhovitin
2010-10-01 21:46 ` [PATCH 8/19]: SCST SYSFS interface implementation Vladislav Bolkhovitin
2010-10-09 21:20 ` Greg KH
2010-10-11 19:29 ` Vladislav Bolkhovitin
2010-10-11 21:32 ` Greg KH
2010-10-12 18:53 ` Vladislav Bolkhovitin
2010-10-12 19:03 ` Greg KH
2010-10-14 19:48 ` Vladislav Bolkhovitin
2010-10-14 20:04 ` Greg KH
2010-10-22 17:30 ` Vladislav Bolkhovitin
2010-10-22 17:56 ` Greg KH
2010-10-22 18:40 ` Vladislav Bolkhovitin
2010-10-22 18:54 ` Greg KH
2010-11-08 19:58 ` Vladislav Bolkhovitin
2010-11-09 0:28 ` Greg KH
2010-11-09 20:06 ` Vladislav Bolkhovitin
2010-11-10 9:58 ` Boaz Harrosh
2010-11-10 20:19 ` Vladislav Bolkhovitin
2010-11-10 20:29 ` Joe Eykholt
2010-11-10 20:38 ` Vladislav Bolkhovitin
2010-11-10 20:42 ` Joe Eykholt
2010-11-11 9:59 ` Boaz Harrosh [this message]
2010-11-11 12:04 ` Greg KH
2010-11-11 14:05 ` Boaz Harrosh
2010-11-11 14:16 ` Greg KH
2010-11-11 14:19 ` Boaz Harrosh
2010-11-11 20:50 ` Vladislav Bolkhovitin
2010-11-12 1:23 ` Dmitry Torokhov
2010-11-12 12:09 ` Bart Van Assche
2010-11-12 12:09 ` Bart Van Assche
2010-11-12 18:44 ` Dmitry Torokhov
2010-11-13 10:52 ` Bart Van Assche
2010-11-13 10:52 ` Bart Van Assche
2010-11-13 17:20 ` Vladislav Bolkhovitin
2010-11-13 23:59 ` Greg KH
2010-11-15 6:59 ` Dmitry Torokhov
2010-11-15 17:53 ` Bart Van Assche
2010-11-15 20:36 ` Vladislav Bolkhovitin
2010-11-15 9:46 ` Boaz Harrosh
2010-11-15 16:16 ` Greg KH
2010-11-15 17:19 ` Boaz Harrosh
2010-11-15 17:49 ` Bart Van Assche
2010-11-15 20:19 ` Nicholas A. Bellinger
2010-11-16 13:12 ` Vladislav Bolkhovitin
2010-11-16 11:59 ` [Scst-devel] " Richard Williams
2010-11-16 13:17 ` Vladislav Bolkhovitin
2010-11-18 21:02 ` Vladislav Bolkhovitin
2010-11-18 21:46 ` Greg KH
2010-11-19 18:00 ` Vladislav Bolkhovitin
2010-11-19 20:22 ` Dmitry Torokhov
2010-11-19 20:50 ` Vladislav Bolkhovitin
2010-11-19 21:16 ` Greg KH
2010-11-24 20:35 ` Vladislav Bolkhovitin
2010-11-19 21:19 ` Greg KH
2010-12-10 12:06 ` Bart Van Assche
2010-12-10 19:36 ` Greg KH
2010-12-14 14:10 ` Bart Van Assche
2010-11-19 18:01 ` Bart Van Assche
2010-11-19 18:01 ` Bart Van Assche
2010-11-15 20:39 ` Vladislav Bolkhovitin
2010-11-15 20:39 ` Vladislav Bolkhovitin
2010-11-15 17:45 ` Bart Van Assche
2010-11-15 18:44 ` Greg KH
2010-11-15 20:39 ` Vladislav Bolkhovitin
2010-11-15 22:13 ` Greg KH
2010-11-16 5:04 ` Joe Eykholt
2010-11-16 6:03 ` Nicholas A. Bellinger
2010-11-16 8:49 ` Florian Mickler
2010-11-16 13:18 ` Vladislav Bolkhovitin
2010-11-16 7:15 ` Bart Van Assche
2010-11-16 13:19 ` Vladislav Bolkhovitin
2010-11-15 20:36 ` Vladislav Bolkhovitin
2010-11-15 7:04 ` Dmitry Torokhov
2010-11-15 20:37 ` Vladislav Bolkhovitin
2010-11-15 21:14 ` Dmitry Torokhov
2010-11-16 13:13 ` Vladislav Bolkhovitin
2010-10-01 21:46 ` [PATCH 9/19]: SCST debugging support routines Vladislav Bolkhovitin
2010-10-01 21:48 ` [PATCH 10/19]: SCST SGV cache Vladislav Bolkhovitin
2010-10-01 21:48 ` [PATCH 11/19]: SCST core's docs Vladislav Bolkhovitin
2010-10-01 21:48 ` Vladislav Bolkhovitin
2010-10-01 21:49 ` [PATCH 12/19]: SCST dev handlers' Makefile Vladislav Bolkhovitin
2010-10-01 21:50 ` [PATCH 13/19]: SCST vdisk dev handler Vladislav Bolkhovitin
2010-10-01 21:51 ` [PATCH 14/19]: SCST pass-through dev handlers Vladislav Bolkhovitin
2010-10-01 21:53 ` [PATCH 15/19]: Implementation of blk_rq_map_kern_sg() Vladislav Bolkhovitin
2010-10-01 21:57 ` [PATCH 16/19]: scst_local target driver Vladislav Bolkhovitin
2010-10-01 21:58 ` [PATCH 17/19]: SCST InfiniBand SRP " Vladislav Bolkhovitin
2010-10-01 22:04 ` [PATCH 18/19]: ibmvstgt: Port from tgt to SCST Vladislav Bolkhovitin
2010-10-01 22:05 ` [PATCH 19/19]: tgt: Removal Vladislav Bolkhovitin
2010-10-02 7:40 ` [PATCHv4 0/19]: New SCSI target framework (SCST) with dev handlers and 2 target drivers Bart Van Assche
2010-10-02 7:40 ` Bart Van Assche
2010-10-06 20:21 ` [Scst-devel] " Steve Modica
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4CDBBE80.40908@panasas.com \
--to=bharrosh@panasas.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=James.Smart@Emulex.Com \
--cc=akpm@linux-foundation.org \
--cc=ayan@marvell.com \
--cc=bart.vanassche@gmail.com \
--cc=debonzi@linux.vnet.ibm.com \
--cc=dmitry.torokhov@gmail.com \
--cc=fujita.tomonori@lab.ntt.co.jp \
--cc=generationgnu@yahoo.com \
--cc=greg@kroah.com \
--cc=hare@suse.de \
--cc=jeykholt@cisco.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=michaelc@cs.wisc.edu \
--cc=realrichardsharpe@gmail.com \
--cc=scst-devel@lists.sourceforge.net \
--cc=vst@vlnb.net \
--cc=vuhuong@mellanox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.