block: Check that queue is alive in blk_insert_cloned_request()
On Tue, Jul 12, 2011 at 01:28:18PM -0500, James Bottomley wrote:
[..]
> > > I'm starting to wonder if there's actually any value to
> > > blk_cleanup_queue() and whether its functionality wouldn't be better
> > > assumed by the queue release function on last put.
> >
> > I think one problem point is q->queue_lock. If driver drops its reference
> > on queue and cleans up its data structures, then it will free up memory
> > associated with q->queue_lock too. (If driver provided its own queue
> > lock). In that case anything which is dependent on queue lock, needs
> > to be freed up on blk_cleanup_queue().
>
> I don't quite follow. blk_cleanup_queue() doesn't free anything (well,
> except the elevator). Final put will free the queue structure which
> contains the lock, but if it's really a final put, you have no other
> possible references, so no-one is using the lock ... well, assuming
> there isn't a programming error, of course ...
>
> > If we can make sure that request queue reference will keep the spin lock
> > alive, then i guess all cleanup part might be able to go in release
> > queue function.
>
> As I said: cleanup doesn't free the structure containing the lock,
> release does, so that piece wouldn't be altered by putting
> blk_cleanup_queue() elsewhere.
I thought a driver could either rely on spin lock provided by request
queue or override that by providing its own spinlock.
blk_init_allocated_queue_node()
/* Override internal queue lock with supplied lock pointer */
if (lock)
q->queue_lock = lock;
So if driver calls blk_cleanup_queue() and drops its reference on queue, then
it should be free to release any memory it has allocated for spinlock.
So though queue is around there are no gurantees that q->queue_lock is
still around. That memory might have been freed by driver and reused.
I see many drivers are providing their own locks. Some samples from
drivers/block.