Re: When must the io_request_lock be held?

James Bottomley
2002-08-07T15:26:28Z

dledford@redhat.com said:
> I can't, for the life of me, remember right now if the new_eh
> strategy, abort, device_reset, and bus_reset routines are called with
> a lock held, you'll have to look that up by going into scsi_error.c
> and checking it out.

They are, but you can drop it (as long as you reacquire it before exit).

dledford@redhat.com said:
> You can use the spin_unlock() variant if you wish, but that will leave
> interrupts disabled and therefore buy you exactly zero benefit on UP
> systems.

This isn't necessarily true. Some SCSI cards have a single mailbox for
outgoing and incoming transfer parameters and commands. If you have one of
these, you need to keep interrupts disabled as you set up a command so that
your own interrupt routine doesn't overwrite the values if you get a reconnect
interrupt while you're programming the card.

dledford@redhat.com said:
> You are, of course, responsible for doing sane locking in your driver
> if you choose to unlock the locks the mid layer holds for you.

This is a very important point to bear in mind. Since the io_request_lock
must be held when calling the done() routine, you are asking to create a
deadlock if you use your own locks in the driver (it's not impossible to get
this correct, just very difficult).

Basically, the io_request_lock is used to protect structures within the SCSI
and block layer. Once you get into the LLD, you may extend it if you wish to
protect the individual data structures of your driver (which is why it's held
on entry to most of the LLD API) but if you don't want to, it is safe to drop
it (as long as your queuecommand is re-entrant and you re-acquire it before
exiting the API routines).

James