diff options
author | 2014-04-22 07:29:11 +0000 | |
---|---|---|
committer | 2014-04-22 07:29:11 +0000 | |
commit | b0b58169a73e54da2b6f2b7096e1f4e2380dfcdb (patch) | |
tree | a5ab6b4d18957eda595a6245e4226e2bd2d12595 | |
parent | errx when errno won't be set. (diff) | |
download | wireguard-openbsd-b0b58169a73e54da2b6f2b7096e1f4e2380dfcdb.tar.xz wireguard-openbsd-b0b58169a73e54da2b6f2b7096e1f4e2380dfcdb.zip |
factor out the code that figures out whether you're probing or detaching
a whole bus, a target, or a specific lun on a target from the bioctl
and scsi_req paths.
i want to reuse this factored code for something claudio wants.
-rw-r--r-- | sys/scsi/scsi_base.c | 26 | ||||
-rw-r--r-- | sys/scsi/scsiconf.c | 59 | ||||
-rw-r--r-- | sys/scsi/scsiconf.h | 4 |
3 files changed, 41 insertions, 48 deletions
diff --git a/sys/scsi/scsi_base.c b/sys/scsi/scsi_base.c index 0487a95fc2f..769815b7cf7 100644 --- a/sys/scsi/scsi_base.c +++ b/sys/scsi/scsi_base.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsi_base.c,v 1.210 2014/01/27 23:44:40 dlg Exp $ */ +/* $OpenBSD: scsi_base.c,v 1.211 2014/04/22 07:29:11 dlg Exp $ */ /* $NetBSD: scsi_base.c,v 1.43 1997/04/02 02:29:36 mycroft Exp $ */ /* @@ -176,17 +176,7 @@ scsi_plug_probe(void *xsc, void *xp) pool_put(&scsi_plug_pool, p); - if (target == -1 && lun == -1) - scsi_probe_bus(sc); - - /* specific lun and wildcard target is bad */ - if (target == -1) - return; - - if (lun == -1) - scsi_probe_target(sc, target); - - scsi_probe_lun(sc, target, lun); + scsi_probe(sc, target, lun); } void @@ -199,17 +189,7 @@ scsi_plug_detach(void *xsc, void *xp) pool_put(&scsi_plug_pool, p); - if (target == -1 && lun == -1) - scsi_detach_bus(sc, how); - - /* specific lun and wildcard target is bad */ - if (target == -1) - return; - - if (lun == -1) - scsi_detach_target(sc, target, how); - - scsi_detach_lun(sc, target, lun, how); + scsi_detach(sc, target, lun, how); } int diff --git a/sys/scsi/scsiconf.c b/sys/scsi/scsiconf.c index ec60a46dd32..43dcd48922d 100644 --- a/sys/scsi/scsiconf.c +++ b/sys/scsi/scsiconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.c,v 1.186 2014/01/31 02:53:41 dlg Exp $ */ +/* $OpenBSD: scsiconf.c,v 1.187 2014/04/22 07:29:11 dlg Exp $ */ /* $NetBSD: scsiconf.c,v 1.57 1996/05/02 01:09:01 neil Exp $ */ /* @@ -305,32 +305,11 @@ scsibus_bioctl(struct device *dev, u_long cmd, caddr_t addr) switch (cmd) { case SBIOCPROBE: sdev = (struct sbioc_device *)addr; - - if (sdev->sd_target == -1 && sdev->sd_lun == -1) - return (scsi_probe_bus(sc)); - - /* specific lun and wildcard target is bad */ - if (sdev->sd_target == -1) - return (EINVAL); - - if (sdev->sd_lun == -1) - return (scsi_probe_target(sc, sdev->sd_target)); - - return (scsi_probe_lun(sc, sdev->sd_target, sdev->sd_lun)); + return (scsi_probe(sc, sdev->sd_target, sdev->sd_lun)); case SBIOCDETACH: sdev = (struct sbioc_device *)addr; - - if (sdev->sd_target == -1 && sdev->sd_lun == -1) - return (scsi_detach_bus(sc, 0)); - - if (sdev->sd_target == -1) - return (EINVAL); - - if (sdev->sd_lun == -1) - return (scsi_detach_target(sc, sdev->sd_target, 0)); - - return (scsi_detach_lun(sc, sdev->sd_target, sdev->sd_lun, 0)); + return (scsi_detach(sc, sdev->sd_target, sdev->sd_lun, 0)); default: return (ENOTTY); @@ -413,6 +392,22 @@ dumbscan: } int +scsi_probe(struct scsibus_softc *sc, int target, int lun) +{ + if (target == -1 && lun == -1) + return (scsi_probe_bus(sc)); + + /* specific lun and wildcard target is bad */ + if (target == -1) + return (EINVAL); + + if (lun == -1) + return (scsi_probe_target(sc, target)); + + return (scsi_probe_lun(sc, target, lun)); +} + +int scsi_probe_lun(struct scsibus_softc *sc, int target, int lun) { struct scsi_link *alink = sc->adapter_link; @@ -441,6 +436,22 @@ scsi_detach_bus(struct scsibus_softc *sc, int flags) } int +scsi_detach(struct scsibus_softc *sc, int target, int lun, int flags) +{ + if (target == -1 && lun == -1) + return (scsi_detach_bus(sc, flags)); + + /* specific lun and wildcard target is bad */ + if (target == -1) + return (EINVAL); + + if (lun == -1) + return (scsi_detach_target(sc, target, flags)); + + return (scsi_detach_lun(sc, target, lun, flags)); +} + +int scsi_detach_target(struct scsibus_softc *sc, int target, int flags) { struct scsi_link *alink = sc->adapter_link; diff --git a/sys/scsi/scsiconf.h b/sys/scsi/scsiconf.h index 511c44b3146..43cfb63916f 100644 --- a/sys/scsi/scsiconf.h +++ b/sys/scsi/scsiconf.h @@ -1,4 +1,4 @@ -/* $OpenBSD: scsiconf.h,v 1.160 2014/01/31 02:53:41 dlg Exp $ */ +/* $OpenBSD: scsiconf.h,v 1.161 2014/04/22 07:29:11 dlg Exp $ */ /* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */ /* @@ -507,10 +507,12 @@ void scsi_show_mem(u_char *, int); void scsi_strvis(u_char *, u_char *, int); int scsi_delay(struct scsi_xfer *, int); +int scsi_probe(struct scsibus_softc *, int, int); int scsi_probe_bus(struct scsibus_softc *); int scsi_probe_target(struct scsibus_softc *, int); int scsi_probe_lun(struct scsibus_softc *, int, int); +int scsi_detach(struct scsibus_softc *, int, int, int); int scsi_detach_bus(struct scsibus_softc *, int); int scsi_detach_target(struct scsibus_softc *, int, int); int scsi_detach_lun(struct scsibus_softc *, int, int, int); |