summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2020-08-19 14:53:39 +0000
committerkrw <krw@openbsd.org>2020-08-19 14:53:39 +0000
commit9ed449b75b8278ebe864e1314bab1bf77bf11cb6 (patch)
tree0c663086b5bcd79ffd299865faf04d22ddbabf79
parentadd unveil(2) again (diff)
downloadwireguard-openbsd-9ed449b75b8278ebe864e1314bab1bf77bf11cb6.tar.xz
wireguard-openbsd-9ed449b75b8278ebe864e1314bab1bf77bf11cb6.zip
Nuke SDF_DYING, CDF_DYING and ST_DYING flags. Use the scsi_link flag
SDEV_S_DYING instead. Makes it clear that the scsi_link and the [cd|sd|st] device always agree on their state.
-rw-r--r--sys/scsi/cd.c16
-rw-r--r--sys/scsi/sd.c75
-rw-r--r--sys/scsi/sdvar.h3
-rw-r--r--sys/scsi/st.c16
4 files changed, 55 insertions, 55 deletions
diff --git a/sys/scsi/cd.c b/sys/scsi/cd.c
index 4bc46cd1aec..a47b998fc05 100644
--- a/sys/scsi/cd.c
+++ b/sys/scsi/cd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cd.c,v 1.249 2020/08/15 17:50:45 krw Exp $ */
+/* $OpenBSD: cd.c,v 1.250 2020/08/19 14:53:39 krw Exp $ */
/* $NetBSD: cd.c,v 1.100 1997/04/02 02:29:30 mycroft Exp $ */
/*
@@ -67,6 +67,7 @@
#include <sys/scsiio.h>
#include <sys/dkio.h>
#include <sys/vnode.h>
+#include <sys/atomic.h>
#include <scsi/scsi_all.h>
#include <scsi/cd.h>
@@ -100,7 +101,6 @@ struct cd_softc {
int sc_flags;
#define CDF_ANCIENT 0x10 /* disk is ancient; for cdminphys */
-#define CDF_DYING 0x40 /* dying, when deactivated */
struct scsi_link *sc_link; /* contains targ, lun, etc. */
struct cd_parms {
u_int32_t secsize;
@@ -251,7 +251,7 @@ cdactivate(struct device *self, int act)
SCSI_SILENT | SCSI_AUTOCONF);
break;
case DVACT_DEACTIVATE:
- SET(sc->sc_flags, CDF_DYING);
+ atomic_setbits_int(&sc->sc_link->state, SDEV_S_DYING);
scsi_xsh_del(&sc->sc_xsh);
break;
}
@@ -292,7 +292,7 @@ cdopen(dev_t dev, int flag, int fmt, struct proc *p)
sc = cdlookup(unit);
if (sc == NULL)
return ENXIO;
- if (ISSET(sc->sc_flags, CDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
device_unref(&sc->sc_dev);
return ENXIO;
}
@@ -402,7 +402,7 @@ cdclose(dev_t dev, int flag, int fmt, struct proc *p)
sc = cdlookup(DISKUNIT(dev));
if (sc == NULL)
return ENXIO;
- if (ISSET(sc->sc_flags, CDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
device_unref(&sc->sc_dev);
return ENXIO;
}
@@ -451,7 +451,7 @@ cdstrategy(struct buf *bp)
bp->b_error = ENXIO;
goto bad;
}
- if (ISSET(sc->sc_flags, CDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
bp->b_error = ENXIO;
goto bad;
}
@@ -524,7 +524,7 @@ cdstart(struct scsi_xfer *xs)
SC_DEBUG(link, SDEV_DB2, ("cdstart\n"));
- if (ISSET(sc->sc_flags, CDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
scsi_xs_put(xs);
return;
}
@@ -729,7 +729,7 @@ cdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
sc = cdlookup(DISKUNIT(dev));
if (sc == NULL)
return ENXIO;
- if (ISSET(sc->sc_flags, CDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
device_unref(&sc->sc_dev);
return ENXIO;
}
diff --git a/sys/scsi/sd.c b/sys/scsi/sd.c
index f209bfa0a3b..c48ae3ffef0 100644
--- a/sys/scsi/sd.c
+++ b/sys/scsi/sd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sd.c,v 1.315 2020/08/15 17:50:45 krw Exp $ */
+/* $OpenBSD: sd.c,v 1.316 2020/08/19 14:53:39 krw Exp $ */
/* $NetBSD: sd.c,v 1.111 1997/04/02 02:29:41 mycroft Exp $ */
/*-
@@ -68,6 +68,7 @@
#include <sys/scsiio.h>
#include <sys/dkio.h>
#include <sys/reboot.h>
+#include <sys/atomic.h>
#include <scsi/scsi_all.h>
#include <scsi/scsi_debug.h>
@@ -259,7 +260,7 @@ sdactivate(struct device *self, int act)
struct scsi_link *link;
struct sd_softc *sc = (struct sd_softc *)self;
- if (ISSET(sc->flags, SDF_DYING))
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING))
return ENXIO;
link = sc->sc_link;
@@ -291,7 +292,7 @@ sdactivate(struct device *self, int act)
SCSI_IGNORE_ILLEGAL_REQUEST | SCSI_AUTOCONF);
break;
case DVACT_DEACTIVATE:
- SET(sc->flags, SDF_DYING);
+ atomic_setbits_int(&sc->sc_link->state, SDEV_S_DYING);
timeout_del(&sc->sc_timeout);
scsi_xsh_del(&sc->sc_xsh);
break;
@@ -333,7 +334,7 @@ sdopen(dev_t dev, int flag, int fmt, struct proc *p)
sc = sdlookup(unit);
if (sc == NULL)
return ENXIO;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
device_unref(&sc->sc_dev);
return ENXIO;
}
@@ -358,7 +359,7 @@ sdopen(dev_t dev, int flag, int fmt, struct proc *p)
* If any partition is open, but the disk has been invalidated,
* disallow further opens of non-raw partition.
*/
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -370,7 +371,7 @@ sdopen(dev_t dev, int flag, int fmt, struct proc *p)
}
} else {
/* Spin up non-UMASS devices ready or not. */
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -386,7 +387,7 @@ sdopen(dev_t dev, int flag, int fmt, struct proc *p)
* device returns "Initialization command required." and causes
* a loop of scsi_start() calls.
*/
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -404,7 +405,7 @@ sdopen(dev_t dev, int flag, int fmt, struct proc *p)
}
/* Check that it is still responding and ok. */
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -420,13 +421,13 @@ sdopen(dev_t dev, int flag, int fmt, struct proc *p)
}
/* Load the physical device parameters. */
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
SET(link->flags, SDEV_MEDIA_LOADED);
if (sd_get_parms(sc, (rawopen ? SCSI_SILENT : 0)) == -1) {
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -452,7 +453,7 @@ out:
/* It's OK to fall through because dk_openmask is now non-zero. */
bad:
if (sc->sc_dk.dk_openmask == 0) {
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -460,7 +461,7 @@ bad:
scsi_prevent(link, PR_ALLOW, SCSI_SILENT |
SCSI_IGNORE_ILLEGAL_REQUEST |
SCSI_IGNORE_MEDIA_CHANGE);
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -488,7 +489,7 @@ sdclose(dev_t dev, int flag, int fmt, struct proc *p)
sc = sdlookup(DISKUNIT(dev));
if (sc == NULL)
return ENXIO;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
device_unref(&sc->sc_dev);
return ENXIO;
}
@@ -503,7 +504,7 @@ sdclose(dev_t dev, int flag, int fmt, struct proc *p)
sd_flush(sc, 0);
if (sc->sc_dk.dk_openmask == 0) {
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -511,7 +512,7 @@ sdclose(dev_t dev, int flag, int fmt, struct proc *p)
scsi_prevent(link, PR_ALLOW,
SCSI_IGNORE_ILLEGAL_REQUEST |
SCSI_IGNORE_NOT_READY | SCSI_SILENT);
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -519,7 +520,7 @@ sdclose(dev_t dev, int flag, int fmt, struct proc *p)
if (ISSET(link->flags, SDEV_EJECTING)) {
scsi_start(link, SSS_STOP|SSS_LOEJ, 0);
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto die;
}
@@ -553,7 +554,7 @@ sdstrategy(struct buf *bp)
bp->b_error = ENXIO;
goto bad;
}
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
bp->b_error = ENXIO;
goto bad;
}
@@ -670,7 +671,7 @@ sdstart(struct scsi_xfer *xs)
int nsecs, read;
u_int64_t secno;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
scsi_xs_put(xs);
return;
}
@@ -807,7 +808,7 @@ sdminphys(struct buf *bp)
sc = sdlookup(DISKUNIT(bp->b_dev));
if (sc == NULL)
return; /* XXX - right way to fail this? */
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
device_unref(&sc->sc_dev);
return;
}
@@ -867,7 +868,7 @@ sdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
sc = sdlookup(DISKUNIT(dev));
if (sc == NULL)
return ENXIO;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
device_unref(&sc->sc_dev);
return ENXIO;
}
@@ -1008,7 +1009,7 @@ sd_ioctl_inquiry(struct sd_softc *sc, struct dk_inquiry *di)
vpd = dma_alloc(sizeof(*vpd), PR_WAITOK | PR_ZERO);
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
dma_free(vpd, sizeof(*vpd));
return ENXIO;
}
@@ -1041,7 +1042,7 @@ sd_ioctl_cache(struct sd_softc *sc, long cmd, struct dk_cache *dkc)
u_int wrcache, rdcache;
int big, rv;
- if (ISSET(sc->flags, SDF_DYING))
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING))
return ENXIO;
link = sc->sc_link;
@@ -1057,7 +1058,7 @@ sd_ioctl_cache(struct sd_softc *sc, long cmd, struct dk_cache *dkc)
if (buf == NULL)
return ENOMEM;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = ENXIO;
goto done;
}
@@ -1091,7 +1092,7 @@ sd_ioctl_cache(struct sd_softc *sc, long cmd, struct dk_cache *dkc)
else
SET(mode->flags, PG_CACHE_FL_RCD);
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = ENXIO;
goto done;
}
@@ -1122,7 +1123,7 @@ sdgetdisklabel(dev_t dev, struct sd_softc *sc, struct disklabel *lp,
struct scsi_link *link;
size_t len;
- if (ISSET(sc->flags, SDF_DYING))
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING))
return ENXIO;
link = sc->sc_link;
@@ -1248,7 +1249,7 @@ sdsize(dev_t dev)
sc = sdlookup(DISKUNIT(dev));
if (sc == NULL)
return -1;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
size = -1;
goto exit;
}
@@ -1262,7 +1263,7 @@ sdsize(dev_t dev)
}
lp = sc->sc_dk.dk_label;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
size = -1;
goto exit;
}
@@ -1417,7 +1418,7 @@ sd_read_cap_10(struct sd_softc *sc, int flags)
if (rdcap == NULL)
return -1;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = -1;
goto done;
}
@@ -1449,7 +1450,7 @@ sd_read_cap_16(struct sd_softc *sc, int flags)
if (rdcap == NULL)
return -1;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = -1;
goto done;
}
@@ -1513,7 +1514,7 @@ sd_thin_pages(struct sd_softc *sc, int flags)
if (pg == NULL)
return ENOMEM;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = ENXIO;
goto done;
}
@@ -1530,7 +1531,7 @@ sd_thin_pages(struct sd_softc *sc, int flags)
if (pg == NULL)
return ENOMEM;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = ENXIO;
goto done;
}
@@ -1573,7 +1574,7 @@ sd_vpd_block_limits(struct sd_softc *sc, int flags)
if (pg == NULL)
return ENOMEM;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = ENXIO;
goto done;
}
@@ -1604,7 +1605,7 @@ sd_vpd_thin(struct sd_softc *sc, int flags)
if (pg == NULL)
return ENOMEM;
- if (ISSET(sc->flags, SDF_DYING)) {
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING)) {
rv = ENXIO;
goto done;
}
@@ -1685,7 +1686,7 @@ sd_get_parms(struct sd_softc *sc, int flags)
if (buf == NULL)
goto validate;
- if (ISSET(sc->flags, SDF_DYING))
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING))
goto die;
/*
@@ -1696,7 +1697,7 @@ sd_get_parms(struct sd_softc *sc, int flags)
*/
err = scsi_do_mode_sense(link, 0, buf, (void **)&page0, 1,
flags | SCSI_SILENT, &big);
- if (ISSET(sc->flags, SDF_DYING))
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING))
goto die;
if (err == 0) {
if (big && buf->hdr_big.dev_spec & SMH_DSP_WRITE_PROT)
@@ -1762,7 +1763,7 @@ sd_get_parms(struct sd_softc *sc, int flags)
dp.cyls);
}
} else {
- if (ISSET(sc->flags, SDF_DYING))
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING))
goto die;
err = scsi_do_mode_sense(link, PAGE_FLEX_GEOMETRY, buf,
(void **)&flex, sizeof(*flex) - 4,
@@ -1873,7 +1874,7 @@ sd_flush(struct sd_softc *sc, int flags)
struct scsi_synchronize_cache *cmd;
int error;
- if (ISSET(sc->flags, SDF_DYING))
+ if (ISSET(sc->sc_link->state, SDEV_S_DYING))
return ENXIO;
link = sc->sc_link;
diff --git a/sys/scsi/sdvar.h b/sys/scsi/sdvar.h
index 7ef85f99244..69a2aab05fb 100644
--- a/sys/scsi/sdvar.h
+++ b/sys/scsi/sdvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: sdvar.h,v 1.47 2020/08/15 17:50:45 krw Exp $ */
+/* $OpenBSD: sdvar.h,v 1.48 2020/08/19 14:53:39 krw Exp $ */
/* $NetBSD: sdvar.h,v 1.7 1998/08/17 00:49:03 mycroft Exp $ */
/*-
@@ -59,7 +59,6 @@ struct sd_softc {
int flags;
#define SDF_ANCIENT 0x10 /* disk is ancient; for sdminphys */
#define SDF_DIRTY 0x20 /* disk is dirty; needs cache flush */
-#define SDF_DYING 0x40 /* dying, when deactivated */
#define SDF_THIN 0x01 /* disk is thin provisioned */
struct scsi_link *sc_link; /* contains our targ, lun, etc. */
struct disk_parms {
diff --git a/sys/scsi/st.c b/sys/scsi/st.c
index 9e26fabca87..6d29deca5c9 100644
--- a/sys/scsi/st.c
+++ b/sys/scsi/st.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: st.c,v 1.181 2020/08/15 17:50:45 krw Exp $ */
+/* $OpenBSD: st.c,v 1.182 2020/08/19 14:53:39 krw Exp $ */
/* $NetBSD: st.c,v 1.71 1997/02/21 23:03:49 thorpej Exp $ */
/*
@@ -67,6 +67,7 @@
#include <sys/device.h>
#include <sys/conf.h>
#include <sys/vnode.h>
+#include <sys/atomic.h>
#include <scsi/scsi_all.h>
#include <scsi/scsi_debug.h>
@@ -171,7 +172,6 @@ struct st_softc {
#define ST_2FM_AT_EOD 0x00000400
#define ST_MOUNTED 0x00000800
#define ST_DONTBUFFER 0x00001000
-#define ST_DYING 0x00004000
#define ST_BOD_DETECTED 0x00008000
#define ST_MODE_DENSITY 0x00010000
#define ST_MODE_BLKSIZE 0x00040000
@@ -321,7 +321,7 @@ stactivate(struct device *self, int act)
switch (act) {
case DVACT_DEACTIVATE:
- SET(st->flags, ST_DYING);
+ atomic_setbits_int(&st->sc_link->state, SDEV_S_DYING);
scsi_xsh_del(&st->sc_xsh);
break;
}
@@ -362,7 +362,7 @@ stopen(dev_t dev, int flags, int fmt, struct proc *p)
st = stlookup(STUNIT(dev));
if (st == NULL)
return ENXIO;
- if (ISSET(st->flags, ST_DYING)) {
+ if (ISSET(st->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto done;
}
@@ -441,7 +441,7 @@ stclose(dev_t dev, int flags, int mode, struct proc *p)
st = stlookup(STUNIT(dev));
if (st == NULL)
return ENXIO;
- if (ISSET(st->flags, ST_DYING)) {
+ if (ISSET(st->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto done;
}
@@ -729,7 +729,7 @@ ststrategy(struct buf *bp)
bp->b_error = ENXIO;
goto bad;
}
- if (ISSET(st->flags, ST_DYING)) {
+ if (ISSET(st->sc_link->state, SDEV_S_DYING)) {
bp->b_error = ENXIO;
goto bad;
}
@@ -804,7 +804,7 @@ ststart(struct scsi_xfer *xs)
SC_DEBUG(link, SDEV_DB2, ("ststart\n"));
- if (ISSET(st->flags, ST_DYING)) {
+ if (ISSET(st->sc_link->state, SDEV_S_DYING)) {
scsi_xs_put(xs);
return;
}
@@ -1049,7 +1049,7 @@ stioctl(dev_t dev, u_long cmd, caddr_t arg, int flag, struct proc *p)
if (st == NULL)
return ENXIO;
- if (ISSET(st->flags, ST_DYING)) {
+ if (ISSET(st->sc_link->state, SDEV_S_DYING)) {
error = ENXIO;
goto done;
}