diff options
author | tegge <tegge@FreeBSD.org> | 1997-06-25 19:07:43 +0000 |
---|---|---|
committer | tegge <tegge@FreeBSD.org> | 1997-06-25 19:07:43 +0000 |
commit | 988f978710326fc294e3ebe6b7231a5b2807c6f8 (patch) | |
tree | ab7e9ccf1be3e96bf94b4abd5d5faf132b743dd1 /sys/scsi/scsi_driver.c | |
parent | 228f6410f312edf048c05ed76a7d84d3d954a339 (diff) | |
download | FreeBSD-src-988f978710326fc294e3ebe6b7231a5b2807c6f8.zip FreeBSD-src-988f978710326fc294e3ebe6b7231a5b2807c6f8.tar.gz |
Introduce an advisory exclusive lock on the scsi link structure.
Change sd_open, sd_close and sd_ioctl to use this lock to ensure
serialization of some critical operations, thus avoiding some
race conditions. Ideas picked from NetBSD (ccd and sd devices).
This fixes one of the problems noted in PR kern/3688.
Reviewed by: "Justin T. Gibbs" <gibbs@plutotech.com>
Diffstat (limited to 'sys/scsi/scsi_driver.c')
-rw-r--r-- | sys/scsi/scsi_driver.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/sys/scsi/scsi_driver.c b/sys/scsi/scsi_driver.c index 06c1ebf..32d9c7b 100644 --- a/sys/scsi/scsi_driver.c +++ b/sys/scsi/scsi_driver.c @@ -35,7 +35,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: scsi_driver.c,v 1.22 1997/02/22 09:44:31 peter Exp $ + * $Id: scsi_driver.c,v 1.23 1997/03/23 06:33:47 bde Exp $ * */ @@ -232,3 +232,25 @@ scsi_strategy(struct buf *bp, struct scsi_device *device) } } } + +int scsi_device_lock(struct scsi_link *sc_link) +{ + int error; + while (sc_link->flags & SDEV_XLOCK) { + sc_link->flags |= SDEV_WANT; + error = tsleep(&sc_link->flags, PRIBIO | PCATCH, "sdevlk",0); + if (error) + return error; + } + sc_link->flags |= SDEV_XLOCK; + return 0; +} + +void scsi_device_unlock(struct scsi_link *sc_link) +{ + sc_link->flags &= ~SDEV_XLOCK; + if (sc_link->flags & SDEV_WANT) { + sc_link->flags &= ~SDEV_WANT; + wakeup(&sc_link->flags); + } +} |