Skip to contentSkip to conversation

When must the io_request_lock be held?

DISCUSSION Jamie Wellnitz 3 participants 3 messages Aug 5, 2002 – Aug 7, 2002 SCSI

lore
Share & tools
lore
#0 lore raw

When does a low-level driver have to hold the io_request_lock? I know that a driver should take the lock when it calls a SCSI command's done function. Also, when the driver's queuecommand is entered, it already holds this lock.

I've seen some drivers that drop the lock (via either spin_unlock or spin_unlock_irq) inside their queuecommand. What are the rules for dropping (and reacquiring) the lock here?

Thanks,
Jamie Wellnitz

#1 lore raw
Quoted 8 lines · --- Jamie Wellnitz

When does a low-level driver have to hold the io_request_lock? I know
that a driver should take the lock when it calls a SCSI command's done
function. Also, when the driver's queuecommand is entered, it already
holds this lock.

Quoted 6 lines

I've seen some drivers that drop the lock (via either spin_unlock or
spin_unlock_irq) inside their queuecommand. What are the rules for
dropping (and reacquiring) the lock here?

If you drop the lock, you are responsible for the synchronization of the driver. From what I know, the io_request_lock is going to be removed from the code in the later versions, so it is always a good idea not to depend on the lock for synchronization and define ur own, so that it becomes easier in the future.

You can drop the lock at the start if u have ur own locks, and reacquire it at the end, because the mid level expects it to be in the acquired state.

Mukul

Quoted 7 lines

Thanks,
Jamie Wellnitz
-
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to [email protected] More majordomo info at

http://vger.kernel.org/majordomo-info.html

__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

#2 lore raw
In reply to Jamie Wellnitz
Quoted 1 line · Jamie Wellnitz

When does a low-level driver have to hold the io_request_lock?

If you are using the io_request_lock as your driver's only big lock, then you should leave it held in the queuecommand(), abort(), reset() routines. 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. You should grab it prior to entering your interrupt handler body and you should grab it from any timer based entry points in your driver. Releasing of the lock is OK as long as you reacquire it before returning and as long as you know that not owning a lock at that time is safe. 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. The spin_unlock_irq() is what I typically use since that actually allows other interrupts to come in while you are working. 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. In 2.4.19, the io_request_lock would be held. In 2.5.x, the io_request_lock is gone and instead the host->host_lock would be held.

Quoted 3 lines

I know
that a driver should take the lock when it calls a SCSI command's done function.

In both 2.4.x and 2.5.x if your driver uses the new error handling code, then this is not necessary. It may call the done() function without any locks held since all the done function does is grab the bottom half handler lock long enough to stuff the command onto a list and then releases the lock and returns.

Signature · 4 lines
  Doug Ledford <[email protected]>     919-754-3700 x44233
         Red Hat, Inc. 
         1801 Varsity Dr.
         Raleigh, NC 27606