summaryrefslogtreecommitdiffstats
path: root/sys/scsi/scsi_base.c
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-01-22 00:17:46 +0000
committercheloha <cheloha@openbsd.org>2020-01-22 00:17:46 +0000
commit911b201f191bd5f277cb7a29d9f60e2ac4058552 (patch)
tree1c13b9091043d238982df0dad7b4ecd696871a01 /sys/scsi/scsi_base.c
parentremove mutex.h etc. since this code is now unthreaded. (diff)
downloadwireguard-openbsd-911b201f191bd5f277cb7a29d9f60e2ac4058552.tar.xz
wireguard-openbsd-911b201f191bd5f277cb7a29d9f60e2ac4058552.zip
scsi_delay(): sleep without lbolt
If we want to sleep for a multiple of seconds we can do that without involving lbolt. This may cause some paths to sleep longer than they have on average, as sleeping on lbolt wakes you up within one second, not after one second. If this is a problem we will need to shorten the intervals given to scsi_delay(). With insight from deraadt@. ok krw@
Diffstat (limited to 'sys/scsi/scsi_base.c')
-rw-r--r--sys/scsi/scsi_base.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c
index 114b1d1f7d8..4befb67ddc3 100644
--- a/sys/scsi/scsi_base.c
+++ b/sys/scsi/scsi_base.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: scsi_base.c,v 1.260 2019/12/06 13:53:26 krw Exp $ */
+/* $OpenBSD: scsi_base.c,v 1.261 2020/01/22 00:17:46 cheloha Exp $ */
/* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */
/*
@@ -1559,6 +1559,8 @@ scsi_xs_error(struct scsi_xfer *xs)
int
scsi_delay(struct scsi_xfer *xs, int seconds)
{
+ int ret;
+
switch (xs->flags & (SCSI_POLL | SCSI_NOSLEEP)) {
case SCSI_POLL:
delay(1000000 * seconds);
@@ -1571,12 +1573,11 @@ scsi_delay(struct scsi_xfer *xs, int seconds)
return EIO;
}
- while (seconds-- > 0) {
- if (tsleep_nsec(&lbolt, PRIBIO|PCATCH, "scbusy", INFSLP)) {
- /* Signal == abort xs. */
- return EIO;
- }
- }
+ ret = tsleep_nsec(&ret, PRIBIO|PCATCH, "scbusy", SEC_TO_NSEC(seconds));
+
+ /* Signal == abort xs. */
+ if (ret == ERESTART || ret == EINTR)
+ return EIO;
return ERESTART;
}