Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/thorpej_scsipi]: src/sys/dev/scsipi Make scsipi_channel_init a function ...



details:   https://anonhg.NetBSD.org/src/rev/ed21cde73023
branches:  thorpej_scsipi
changeset: 477473:ed21cde73023
user:      mjacob <mjacob%NetBSD.org@localhost>
date:      Wed Apr 11 01:16:04 2001 +0000

description:
Make scsipi_channel_init a function returning an int- non-zero means
it failed to initialize the channel (this should be acceptable)- in
which case we complain and don't schedule bus probing for later.

We make the internal memory allocations for the periph and the chan_periphs
array M_NOWAIT- this way we have a hope of booting instead of silently hanging
during boot if we've run out of memory.

diffstat:

 sys/dev/scsipi/scsiconf.c    |  19 +++++++++++++++----
 sys/dev/scsipi/scsipi_base.c |  18 ++++++++++++++----
 sys/dev/scsipi/scsipiconf.h  |   4 ++--
 3 files changed, 31 insertions(+), 10 deletions(-)

diffs (110 lines):

diff -r 39445fda61de -r ed21cde73023 sys/dev/scsipi/scsiconf.c
--- a/sys/dev/scsipi/scsiconf.c Sun Apr 08 13:20:16 2001 +0000
+++ b/sys/dev/scsipi/scsiconf.c Wed Apr 11 01:16:04 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsiconf.c,v 1.130.2.10 2001/03/12 13:31:24 bouyer Exp $       */
+/*     $NetBSD: scsiconf.c,v 1.130.2.11 2001/04/11 01:16:04 mjacob Exp $       */
 
 /*-
  * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
@@ -155,11 +155,15 @@
 
        sc->sc_channel = chan;
 
+       /* Initialize the channel structure first */
+       if (scsipi_channel_init(chan) == 0) {
+               printf(": failed to init channel\n");
+               return;
+       }
+
        printf(": %d targets, %d luns per target\n",
            chan->chan_ntargets, chan->chan_nluns);
 
-       /* Initialize the channel. */
-       scsipi_channel_init(chan);
 
        /*
         * Defer configuration of the children until interrupts
@@ -674,7 +678,14 @@
        if (scsipi_lookup_periph(chan, target, lun) != NULL)
                return (docontinue);
 
-       periph = scsipi_alloc_periph(M_WAITOK);
+       periph = scsipi_alloc_periph(M_NOWAIT);
+       if (periph == NULL) {
+#ifdef DIAGNOSTIC
+               printf("%s: cannot allocate periph for target %d lun %d\n",
+                   sc->sc_dev.dv_xname, target, lun);
+#endif
+               return (ENOMEM);
+       }
        periph->periph_channel = chan;
        periph->periph_switch = &scsi_probe_dev;
 
diff -r 39445fda61de -r ed21cde73023 sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c      Sun Apr 08 13:20:16 2001 +0000
+++ b/sys/dev/scsipi/scsipi_base.c      Wed Apr 11 01:16:04 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipi_base.c,v 1.26.2.13 2001/04/03 15:27:18 bouyer Exp $     */
+/*     $NetBSD: scsipi_base.c,v 1.26.2.14 2001/04/11 01:16:05 mjacob Exp $     */
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -107,7 +107,7 @@
  *
  *     Initialize a scsipi_channel when it is attached.
  */
-void
+int
 scsipi_channel_init(chan)
        struct scsipi_channel *chan;
 {
@@ -122,11 +122,20 @@
        TAILQ_INIT(&chan->chan_complete);
 
        nbytes = chan->chan_ntargets * sizeof(struct scsipi_periph **);
-       chan->chan_periphs = malloc(nbytes, M_DEVBUF, M_WAITOK);
+       chan->chan_periphs = malloc(nbytes, M_DEVBUF, M_NOWAIT);
+       if (chan->chan_periphs == NULL)
+               return (ENOMEM);
+       
 
        nbytes = chan->chan_nluns * sizeof(struct scsipi_periph *);
        for (i = 0; i < chan->chan_ntargets; i++) { 
-               chan->chan_periphs[i] = malloc(nbytes, M_DEVBUF, M_WAITOK);
+               chan->chan_periphs[i] = malloc(nbytes, M_DEVBUF, M_NOWAIT);
+               if (chan->chan_periphs[i] == NULL) {
+                       while (--i >= 0) {
+                               free(chan->chan_periphs[i], M_DEVBUF);
+                       }
+                       return (ENOMEM);
+               }
                memset(chan->chan_periphs[i], 0, nbytes);
        }
 
@@ -134,6 +143,7 @@
         * Create the asynchronous completion thread.
         */
        kthread_create(scsipi_create_completion_thread, chan);
+       return (0);
 }
 
 /*
diff -r 39445fda61de -r ed21cde73023 sys/dev/scsipi/scsipiconf.h
--- a/sys/dev/scsipi/scsipiconf.h       Sun Apr 08 13:20:16 2001 +0000
+++ b/sys/dev/scsipi/scsipiconf.h       Wed Apr 11 01:16:04 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipiconf.h,v 1.32.2.12 2001/04/03 15:27:18 bouyer Exp $      */
+/*     $NetBSD: scsipiconf.h,v 1.32.2.13 2001/04/11 01:16:05 mjacob Exp $      */
 
 /*-
  * Copyright (c) 1998, 1999, 2000 The NetBSD Foundation, Inc.
@@ -623,7 +623,7 @@
 void   scsipi_print_xfer_mode __P((struct scsipi_periph *));
 void   scsipi_set_xfer_mode __P((struct scsipi_channel *, int, int));
 
-void   scsipi_channel_init __P((struct scsipi_channel *));
+int    scsipi_channel_init __P((struct scsipi_channel *));
 void   scsipi_channel_shutdown __P((struct scsipi_channel *));
 
 void   scsipi_insert_periph __P((struct scsipi_channel *,



Home | Main Index | Thread Index | Old Index