Re: Q: Block drivers and the io_request_lock

From: Jens Axboe (axboe@suse.de)
Date: Tue Aug 08 2000 - 08:26:11 EST


On Mon, Aug 07 2000, Jonathan Corbet wrote:
> The request method in a block driver should, it would seem, drop the
> io_request_lock once it has pulled the request(s) off the queue and is
> ready to get down to work. That's not too hard to understand. But then...

Are these questions about 2.2 or 2.4? I'll assume the latter.

It doesn't need to drop the lock, it depends entirely on how requests
are handled. If requests are simply queued to the hardware (or
otherwise quickly dispensed) you may as well keep the lock.

> - Once the lock has been dropped, it would seem that nothing prevents
> the system from calling _request() again, should more requests be added
> to the queue - perhaps even when the first invocation is still running.
> Correct?

The request fn will not be reinvoked until the queue has been plugged
again, and that requires that the queue has been emptied. In 2.4
devices use plugging by default.

> - Multiple invocations could also happen if the request method simply
> returns without completing the request(s).

You must finish the queue. Otherwise the device will not be plugged
again...

> - It seems that you need to reacquire the lock before calling end_request,
> especially if the active request is still on the queue. Certainly some
> of the functions that get called want the lock to be held. But some
> drivers (i.e. floppy) do not reacquire the lock, which makes me wonder.

You can get away with not holding io_request_lock when calling
end_request (or end_that_request_*) if it is the first request on the
queue. By default devices have an active queue head, and the block
layer will not touch that one once the queue is unplugged. For all
other cases, the lock should be held.

> - It would appear that _request() should not sleep, even if you don't call
> it from your interrupt handler, for a number of reasons.

Right, this would be bad. Devices that do need to sleep, can move the
requests to an internal queue and process them out of request fn
context.

> Finally, is there any problem if a block driver plugs its own queue as a
> simple-minded way of avoiding reentrant _request() calls? (Yes, I agree
> there are probably better ways...).

?? You specifically must not replug the queue, if you don't want to
be reentered. If you exit before having processed all requests in
the queue, you need to replug -- but I would consider doing that from
the driver pretty hacky.

-- 
* Jens Axboe <axboe@suse.de>
* SuSE Labs

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



This archive was generated by hypermail 2b29 : Tue Aug 15 2000 - 21:00:15 EST