Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/scsipi reference count adapter mutex possibly shared...



details:   https://anonhg.NetBSD.org/src/rev/d1da89b99c17
branches:  trunk
changeset: 819342:d1da89b99c17
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Tue Nov 29 03:23:00 2016 +0000

description:
reference count adapter mutex possibly shared by multiple channels.

fix error in atapibusdetach, when a child device cannot be detached,
keep atapibus instance alive.

diffstat:

 sys/dev/scsipi/atapiconf.c   |  15 ++++++++++-----
 sys/dev/scsipi/scsiconf.c    |  15 +++++++++------
 sys/dev/scsipi/scsipi_base.c |   8 ++++----
 sys/dev/scsipi/scsipiconf.h  |   4 ++--
 4 files changed, 25 insertions(+), 17 deletions(-)

diffs (164 lines):

diff -r cd9a13752290 -r d1da89b99c17 sys/dev/scsipi/atapiconf.c
--- a/sys/dev/scsipi/atapiconf.c        Mon Nov 28 21:37:00 2016 +0000
+++ b/sys/dev/scsipi/atapiconf.c        Tue Nov 29 03:23:00 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: atapiconf.c,v 1.89 2016/11/20 15:37:19 mlelstv Exp $   */
+/*     $NetBSD: atapiconf.c,v 1.90 2016/11/29 03:23:00 mlelstv Exp $   */
 
 /*
  * Copyright (c) 1996, 2001 Manuel Bouyer.  All rights reserved.
@@ -25,7 +25,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.89 2016/11/20 15:37:19 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: atapiconf.c,v 1.90 2016/11/29 03:23:00 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -34,6 +34,7 @@
 #include <sys/buf.h>
 #include <sys/proc.h>
 #include <sys/kthread.h>
+#include <sys/atomic.h>
 
 #include <dev/scsipi/scsipi_all.h>
 #include <dev/scsipi/scsipiconf.h>
@@ -152,7 +153,9 @@
        aprint_naive("\n");
        aprint_normal(": %d targets\n", chan->chan_ntargets);
 
-       mutex_init(&chan->chan_adapter->adapt_mtx, MUTEX_DEFAULT, IPL_BIO);
+       if (atomic_inc_uint_nv(&chan_running(chan)) == 1)
+               mutex_init(chan_mtx(chan), MUTEX_DEFAULT, IPL_BIO);
+
        cv_init(&chan->chan_cv_thr, "scshut");
        cv_init(&chan->chan_cv_comp, "sccomp");
        cv_init(&chan->chan_cv_xs, "xscmd");
@@ -222,12 +225,14 @@
        }
        mutex_exit(chan_mtx(chan));
 
-out:
        cv_destroy(&chan->chan_cv_xs);
        cv_destroy(&chan->chan_cv_comp);
        cv_destroy(&chan->chan_cv_thr);
-       mutex_destroy(chan_mtx(chan));
 
+       if (atomic_dec_uint_nv(&chan_running(chan)) == 0)
+               mutex_destroy(chan_mtx(chan));
+
+out:
        /* XXXSMP scsipi */
        KERNEL_UNLOCK_ONE(curlwp);
        return error;
diff -r cd9a13752290 -r d1da89b99c17 sys/dev/scsipi/scsiconf.c
--- a/sys/dev/scsipi/scsiconf.c Mon Nov 28 21:37:00 2016 +0000
+++ b/sys/dev/scsipi/scsiconf.c Tue Nov 29 03:23:00 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsiconf.c,v 1.276 2016/11/20 15:37:19 mlelstv Exp $   */
+/*     $NetBSD: scsiconf.c,v 1.277 2016/11/29 03:23:00 mlelstv 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.276 2016/11/20 15:37:19 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsiconf.c,v 1.277 2016/11/29 03:23:00 mlelstv Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -63,6 +63,7 @@
 #include <sys/fcntl.h>
 #include <sys/scsiio.h>
 #include <sys/queue.h>
+#include <sys/atomic.h>
 
 #include <dev/scsipi/scsi_all.h>
 #include <dev/scsipi/scsipi_all.h>
@@ -240,11 +241,12 @@
                        chan->chan_adapter->adapt_max_periph = 256;
        }
 
-       mutex_init(chan_mtx(chan), MUTEX_DEFAULT, IPL_BIO);
+       if (atomic_inc_uint_nv(&chan_running(chan)) == 1)
+               mutex_init(chan_mtx(chan), MUTEX_DEFAULT, IPL_BIO);
+
        cv_init(&chan->chan_cv_thr, "scshut");
        cv_init(&chan->chan_cv_comp, "sccomp");
        cv_init(&chan->chan_cv_xs, "xscmd");
-       chan_running(chan) = true;
 
        if (scsipi_adapter_addref(chan->chan_adapter))
                return;
@@ -371,11 +373,12 @@
         */
        scsipi_channel_shutdown(chan);
 
-       chan_running(chan) = false;
        cv_destroy(&chan->chan_cv_xs);
        cv_destroy(&chan->chan_cv_comp);
        cv_destroy(&chan->chan_cv_thr);
-       mutex_destroy(chan_mtx(chan));
+
+       if (atomic_dec_uint_nv(&chan_running(chan)) == 0)
+               mutex_destroy(chan_mtx(chan));
 
        return 0;
 }
diff -r cd9a13752290 -r d1da89b99c17 sys/dev/scsipi/scsipi_base.c
--- a/sys/dev/scsipi/scsipi_base.c      Mon Nov 28 21:37:00 2016 +0000
+++ b/sys/dev/scsipi/scsipi_base.c      Tue Nov 29 03:23:00 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipi_base.c,v 1.168 2016/11/21 21:03:22 mlelstv Exp $        */
+/*     $NetBSD: scsipi_base.c,v 1.169 2016/11/29 03:23:00 mlelstv Exp $        */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2002, 2003, 2004 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.168 2016/11/21 21:03:22 mlelstv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: scsipi_base.c,v 1.169 2016/11/29 03:23:00 mlelstv Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_scsi.h"
@@ -571,7 +571,7 @@
 void
 scsipi_channel_freeze(struct scsipi_channel *chan, int count)
 {
-       bool lock = chan_running(chan);
+       bool lock = chan_running(chan) > 0;
 
        if (lock)
                mutex_enter(chan_mtx(chan));
@@ -595,7 +595,7 @@
 void
 scsipi_channel_thaw(struct scsipi_channel *chan, int count)
 {
-       bool lock = chan_running(chan);
+       bool lock = chan_running(chan) > 0;
 
        if (lock)
                mutex_enter(chan_mtx(chan));
diff -r cd9a13752290 -r d1da89b99c17 sys/dev/scsipi/scsipiconf.h
--- a/sys/dev/scsipi/scsipiconf.h       Mon Nov 28 21:37:00 2016 +0000
+++ b/sys/dev/scsipi/scsipiconf.h       Tue Nov 29 03:23:00 2016 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: scsipiconf.h,v 1.125 2016/11/25 02:23:14 christos Exp $        */
+/*     $NetBSD: scsipiconf.h,v 1.126 2016/11/29 03:23:00 mlelstv Exp $ */
 
 /*-
  * Copyright (c) 1998, 1999, 2000, 2004 The NetBSD Foundation, Inc.
@@ -206,7 +206,7 @@
                        struct scsipi_inquiry_pattern *);
 
        kmutex_t adapt_mtx;
-       bool    adapt_running;  /* attachment initialized */
+       volatile int    adapt_running;  /* how many users of mutex */
 };
 
 /* adapt_flags */



Home | Main Index | Thread Index | Old Index