Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/scsipi Factor out the lun detection code to simplify...
details: https://anonhg.NetBSD.org/src/rev/3de8ef98f65c
branches: trunk
changeset: 359860:3de8ef98f65c
user: christos <christos%NetBSD.org@localhost>
date: Fri Jan 28 18:23:28 2022 +0000
description:
Factor out the lun detection code to simplify control flow.
diffstat:
sys/dev/scsipi/scsiconf.c | 49 +++++++++++++++++++++++++---------------------
1 files changed, 27 insertions(+), 22 deletions(-)
diffs (85 lines):
diff -r 3ba5c9ab7e5b -r 3de8ef98f65c sys/dev/scsipi/scsiconf.c
--- a/sys/dev/scsipi/scsiconf.c Fri Jan 28 16:38:56 2022 +0000
+++ b/sys/dev/scsipi/scsiconf.c Fri Jan 28 18:23:28 2022 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: scsiconf.c,v 1.295 2022/01/28 14:02:45 jakllsch Exp $ */
+/* $NetBSD: scsiconf.c,v 1.296 2022/01/28 18:23:28 christos Exp $ */
/*-
* Copyright (c) 1998, 1999, 2004 The NetBSD Foundation, Inc.
@@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.295 2022/01/28 14:02:45 jakllsch Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.296 2022/01/28 18:23:28 christos Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -474,6 +474,30 @@
return error;
}
+static void
+scsi_discover_luns(struct scsibus_softc *sc, int target, int minlun, int maxlun)
+{
+ uint16_t *luns;
+ size_t nluns;
+
+ if (scsi_report_luns(sc, target, &luns, &nluns) == 0) {
+ for (size_t i = 0; i < nluns; i++)
+ if (luns[i] >= minlun && luns[i] <= maxlun)
+ scsi_probe_device(sc, target, luns[i]);
+ kmem_free(luns, sizeof(*luns) * nluns);
+ return;
+ }
+
+ for (int lun = minlun; lun <= maxlun; lun++) {
+ /*
+ * See if there's a device present, and configure it.
+ */
+ if (scsi_probe_device(sc, target, lun) == 0)
+ break;
+ /* otherwise something says we should look further */
+ }
+}
+
/*
* Probe the requested scsi bus. It must be already set up.
* target and lun optionally narrow the search if not -1
@@ -482,8 +506,6 @@
scsi_probe_bus(struct scsibus_softc *sc, int target, int lun)
{
struct scsipi_channel *chan = sc->sc_channel;
- uint16_t *luns;
- size_t nluns = 0; /* XXXGCC */
int maxtarget, mintarget, maxlun, minlun;
int error;
@@ -516,25 +538,8 @@
for (target = mintarget; target <= maxtarget; target++) {
if (target == chan->chan_id)
continue;
- if (scsi_report_luns(sc, target, &luns, &nluns) == 0) {
- for (size_t i = 0; i < nluns; i++)
- if (luns[i] >= minlun && luns[i] <= maxlun)
- scsi_probe_device(sc, target, luns[i]);
- } else
- for (lun = minlun; lun <= maxlun; lun++) {
- /*
- * See if there's a device present, and configure it.
- */
- if (scsi_probe_device(sc, target, lun) == 0)
- break;
- /* otherwise something says we should look further */
- }
- if (luns != NULL) {
- kmem_free(luns, sizeof(*luns) * nluns);
- luns = NULL;
- nluns = 0;
- }
+ scsi_discover_luns(sc, target, minlun, maxlun);
/*
* Now that we've discovered all of the LUNs on this
Home |
Main Index |
Thread Index |
Old Index