All of lore.kernel.org
 help / color / mirror / Atom feed
* [block subsystem] Need help to prevent races on unexpected device removal
@ 2010-01-03 19:13 Maxim Levitsky
  2010-01-04 19:56 ` Maxim Levitsky
  2010-01-20  2:53 ` Tejun Heo
  0 siblings, 2 replies; 3+ messages in thread
From: Maxim Levitsky @ 2010-01-03 19:13 UTC (permalink / raw)
  To: linux-kernel

During development of hotplug support for mtd translation layer I seems
to be unable to figure a way to prevent following race:

First of all, a block device is registered. I attach a private structure
to that device to save all internal information.

Then out of the blue (when user pulls off the card) I receive a request
to remove the device.

In the function that handles such removal, I do:

del_gendisk(...
blk_start_queue

stop thread that processes the requests

blk_cleanup_queue(old->rq);


The problem is that I don't know where/when to free the private
structure.

I though about adding a field to the structure, with name 'invalid', so
that release will not attempt to go futher, but free the structure, but
what happens if release is never called?
In other words this will work as long as there is a user of the block
device.

I thought then that I can detect that condition and free the structure
in the removal function itself, but then I get a race with ->open
running in same time, and mutex will not prevent it, I will have to
release it somwhen, and then ->open will access a freed structure....


Best regards,
Maxim Levitsky


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-20  2:47 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-01-03 19:13 [block subsystem] Need help to prevent races on unexpected device removal Maxim Levitsky
2010-01-04 19:56 ` Maxim Levitsky
2010-01-20  2:53 ` Tejun Heo

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.