Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/raidframe Modularize the raidframe driver, including...



details:   https://anonhg.NetBSD.org/src/rev/fae3242368dc
branches:  trunk
changeset: 812650:fae3242368dc
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Dec 26 00:58:45 2015 +0000

description:
Modularize the raidframe driver, including rework of the unit attach
code to permit detaching (and possible module unloading).  Also,
convert tsleep()/wakeup() locking to use cv_wait_sig()/cv_broadcast().

Tested in non-modular, modular-builtin, and modular-loaded-at-runtime
environments.

diffstat:

 sys/dev/raidframe/rf_driver.c      |   25 +-
 sys/dev/raidframe/rf_driver.h      |    4 +-
 sys/dev/raidframe/rf_netbsdkintf.c |  289 +++++++++++++++++++++++++++++-------
 3 files changed, 251 insertions(+), 67 deletions(-)

diffs (truncated from 601 to 300 lines):

diff -r 3e2173f4c3de -r fae3242368dc sys/dev/raidframe/rf_driver.c
--- a/sys/dev/raidframe/rf_driver.c     Fri Dec 25 18:50:48 2015 +0000
+++ b/sys/dev/raidframe/rf_driver.c     Sat Dec 26 00:58:45 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_driver.c,v 1.131 2012/12/10 08:36:03 msaitoh Exp $  */
+/*     $NetBSD: rf_driver.c,v 1.132 2015/12/26 00:58:45 pgoyette Exp $ */
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -66,7 +66,7 @@
 
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_driver.c,v 1.131 2012/12/10 08:36:03 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_driver.c,v 1.132 2015/12/26 00:58:45 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_raid_diagnostic.h"
@@ -158,16 +158,21 @@
 
 /* called at system boot time */
 int
-rf_BootRaidframe(void)
+rf_BootRaidframe(bool boot)
 {
 
-       if (raidframe_booted)
-               return (EBUSY);
-       raidframe_booted = 1;
-       rf_init_mutex2(configureMutex, IPL_NONE);
-       configureCount = 0;
-       isconfigged = 0;
-       globalShutdown = NULL;
+       if (boot) {
+               if (raidframe_booted)
+                       return (EBUSY);
+               raidframe_booted = 1;
+               rf_init_mutex2(configureMutex, IPL_NONE);
+               configureCount = 0;
+               isconfigged = 0;
+               globalShutdown = NULL;
+       } else {
+               rf_destroy_mutex2(configureMutex);
+               raidframe_booted = 0;
+       }
        return (0);
 }
 
diff -r 3e2173f4c3de -r fae3242368dc sys/dev/raidframe/rf_driver.h
--- a/sys/dev/raidframe/rf_driver.h     Fri Dec 25 18:50:48 2015 +0000
+++ b/sys/dev/raidframe/rf_driver.h     Sat Dec 26 00:58:45 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_driver.h,v 1.19 2011/04/30 01:44:36 mrg Exp $       */
+/*     $NetBSD: rf_driver.h,v 1.20 2015/12/26 00:58:45 pgoyette Exp $  */
 /*
  * rf_driver.h
  */
@@ -42,7 +42,7 @@
 #endif
 
 extern rf_declare_mutex2(rf_printf_mutex);
-int rf_BootRaidframe(void);
+int rf_BootRaidframe(bool);
 int rf_UnbootRaidframe(void);
 int rf_Shutdown(RF_Raid_t *);
 int rf_Configure(RF_Raid_t *, RF_Config_t *, RF_AutoConfig_t *);
diff -r 3e2173f4c3de -r fae3242368dc sys/dev/raidframe/rf_netbsdkintf.c
--- a/sys/dev/raidframe/rf_netbsdkintf.c        Fri Dec 25 18:50:48 2015 +0000
+++ b/sys/dev/raidframe/rf_netbsdkintf.c        Sat Dec 26 00:58:45 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: rf_netbsdkintf.c,v 1.326 2015/12/08 20:36:15 christos Exp $    */
+/*     $NetBSD: rf_netbsdkintf.c,v 1.327 2015/12/26 00:58:45 pgoyette Exp $    */
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2008-2011 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
  ***********************************************************/
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.326 2015/12/08 20:36:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rf_netbsdkintf.c,v 1.327 2015/12/26 00:58:45 pgoyette Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -126,6 +126,7 @@
 #include <sys/bufq.h>
 #include <sys/reboot.h>
 #include <sys/kauth.h>
+#include <sys/module.h>
 
 #include <prop/proplib.h>
 
@@ -241,6 +242,8 @@
        int     sc_unit;
        int     sc_flags;       /* flags */
        int     sc_cflags;      /* configuration flags */
+       kmutex_t sc_mutex;      /* interlock mutex */
+       kcondvar_t sc_cv;       /* and the condvar */
        uint64_t sc_size;       /* size of the raid device */
        char    sc_xname[20];   /* XXX external name */
        struct disk sc_dkdev;   /* generic disk device info */
@@ -350,17 +353,21 @@
        }
        sc->sc_unit = unit;
        bufq_alloc(&sc->buf_queue, "fcfs", BUFQ_SORT_RAWBLOCK);
+       cv_init(&sc->sc_cv, "raidunit");
+       mutex_init(&sc->sc_mutex, MUTEX_DEFAULT, IPL_NONE);
        return sc;
 }
 
 static void
 raiddestroy(struct raid_softc *sc) {
+       cv_destroy(&sc->sc_cv);
+       mutex_destroy(&sc->sc_mutex);
        bufq_free(sc->buf_queue);
        kmem_free(sc, sizeof(*sc));
 }
 
 static struct raid_softc *
-raidget(int unit) {
+raidget(int unit, bool create) {
        struct raid_softc *sc;
        if (unit < 0) {
 #ifdef DIAGNOSTIC
@@ -376,6 +383,8 @@
                }
        }
        mutex_exit(&raid_lock);
+       if (!create)
+               return NULL;
        if ((sc = raidcreate(unit)) == NULL)
                return NULL;
        mutex_enter(&raid_lock);
@@ -395,34 +404,11 @@
 void
 raidattach(int num)
 {
-       mutex_init(&raid_lock, MUTEX_DEFAULT, IPL_NONE);
-       /* This is where all the initialization stuff gets done. */
-
-#if (RF_INCLUDE_PARITY_DECLUSTERING_DS > 0)
-       rf_init_mutex2(rf_sparet_wait_mutex, IPL_VM);
-       rf_init_cond2(rf_sparet_wait_cv, "sparetw");
-       rf_init_cond2(rf_sparet_resp_cv, "rfgst");
-
-       rf_sparet_wait_queue = rf_sparet_resp_queue = NULL;
-#endif
-
-       if (rf_BootRaidframe() == 0)
-               aprint_verbose("Kernelized RAIDframe activated\n");
-       else
-               panic("Serious error booting RAID!!");
-
-       if (config_cfattach_attach(raid_cd.cd_name, &raid_ca)) {
-               aprint_error("raidattach: config_cfattach_attach failed?\n");
-       }
-
-       raidautoconfigdone = false;
 
        /*
-        * Register a finalizer which will be used to auto-config RAID
-        * sets once all real hardware devices have been found.
+        * Device attachment and associated initialization now occurs
+        * as part of the module initialization.
         */
-       if (config_finalize_register(NULL, rf_autoconfig) != 0)
-               aprint_error("WARNING: unable to register RAIDframe finalizer\n");
 }
 
 int
@@ -606,7 +592,7 @@
        int     part, unit, omask, size;
 
        unit = raidunit(dev);
-       if ((rs = raidget(unit)) == NULL)
+       if ((rs = raidget(unit, false)) == NULL)
                return -1;
        if ((rs->sc_flags & RAIDF_INITED) == 0)
                return (-1);
@@ -643,7 +629,7 @@
        int     part, c, sparecol, j, scol, dumpto;
        int     error = 0;
 
-       if ((rs = raidget(unit)) == NULL)
+       if ((rs = raidget(unit, false)) == NULL)
                return ENXIO;
 
        raidPtr = &rs->sc_r;
@@ -656,7 +642,6 @@
            raidPtr->Layout.numParityCol != 1)
                return EINVAL;
 
-
        if ((error = raidlock(rs)) != 0)
                return error;
 
@@ -779,7 +764,7 @@
        int     part, pmask;
        int     error = 0;
 
-       if ((rs = raidget(unit)) == NULL)
+       if ((rs = raidget(unit, true)) == NULL)
                return ENXIO;
        if ((error = raidlock(rs)) != 0)
                return (error);
@@ -863,7 +848,7 @@
        int     error = 0;
        int     part;
 
-       if ((rs = raidget(unit)) == NULL)
+       if ((rs = raidget(unit, false)) == NULL)
                return ENXIO;
 
        if ((error = raidlock(rs)) != 0)
@@ -893,15 +878,31 @@
 
                rf_update_component_labels(&rs->sc_r,
                                                 RF_FINAL_COMPONENT_UPDATE);
-
-               /* If the kernel is shutting down, it will detach
-                * this RAID set soon enough.
+       }
+       if ((rs->sc_dkdev.dk_openmask == 0) &&
+           ((rs->sc_flags & RAIDF_SHUTDOWN) != 0)) {
+               /*
+                * Detach this raid unit
                 */
+               cfdata_t cf = NULL;
+               int retcode = 0;
+
+               if (rs->sc_dev != NULL) {
+                       cf = device_cfdata(rs->sc_dev);
+
+                       raidunlock(rs);
+                       retcode = config_detach(rs->sc_dev, DETACH_QUIET);
+                       if (retcode == 0)
+                               /* free the pseudo device attach bits */
+                               free(cf, M_RAIDFRAME);
+               } else {
+                       raidput(rs);
+               }
+               return retcode;
        }
 
        raidunlock(rs);
        return (0);
-
 }
 
 static void
@@ -912,7 +913,7 @@
        int     wlabel;
        struct raid_softc *rs;
 
-       if ((rs = raidget(unit)) == NULL) {
+       if ((rs = raidget(unit, false)) == NULL) {
                bp->b_error = ENXIO;
                goto done;
        }
@@ -982,7 +983,7 @@
        int     unit = raidunit(dev);
        struct raid_softc *rs;
 
-       if ((rs = raidget(unit)) == NULL)
+       if ((rs = raidget(unit, false)) == NULL)
                return ENXIO;
 
        if ((rs->sc_flags & RAIDF_INITED) == 0)
@@ -999,7 +1000,7 @@
        int     unit = raidunit(dev);
        struct raid_softc *rs;
 
-       if ((rs = raidget(unit)) == NULL)
+       if ((rs = raidget(unit, false)) == NULL)
                return ENXIO;
 
        if ((rs->sc_flags & RAIDF_INITED) == 0)
@@ -1036,6 +1037,9 @@
        disk_detach(&rs->sc_dkdev);
        disk_destroy(&rs->sc_dkdev);
 
+       /* Free the softc */
+       raidput(rs);
+
        aprint_normal_dev(rs->sc_dev, "detached\n");
 
        return 0;
@@ -1070,7 +1074,7 @@
        struct disklabel newlabel;
 #endif
 
-       if ((rs = raidget(unit)) == NULL)
+       if ((rs = raidget(unit, false)) == NULL)
                return ENXIO;
        raidPtr = &rs->sc_r;
 
@@ -1190,23 +1194,27 @@
                        RF_Free(k_cfg, sizeof(RF_Config_t));
                        db1_printf(("rf_ioctl: retcode=%d copyin.1\n",
                                retcode));



Home | Main Index | Thread Index | Old Index