From 988f978710326fc294e3ebe6b7231a5b2807c6f8 Mon Sep 17 00:00:00 2001 From: tegge Date: Wed, 25 Jun 1997 19:07:43 +0000 Subject: 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" --- sys/scsi/scsi_driver.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'sys/scsi/scsi_driver.c') 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); + } +} -- cgit v1.1