diff options
author | 2002-03-06 11:28:27 +0000 | |
---|---|---|
committer | 2002-03-06 11:28:27 +0000 | |
commit | 1df2d881f554dd52bbc1f18d4829a3d2c618eaf7 (patch) | |
tree | 0a5ae07cc2afa23b000e0c0c0792c8ba2c9eafaf /sys/dev/raidframe | |
parent | Fix a couple of snprintf length bugs. Same problem <chris@stallion.oz.au> (diff) | |
download | wireguard-openbsd-1df2d881f554dd52bbc1f18d4829a3d2c618eaf7.tar.xz wireguard-openbsd-1df2d881f554dd52bbc1f18d4829a3d2c618eaf7.zip |
Implement a shutdown hook.
We now can safely swap on raid.
Diffstat (limited to 'sys/dev/raidframe')
-rw-r--r-- | sys/dev/raidframe/rf_engine.c | 40 | ||||
-rw-r--r-- | sys/dev/raidframe/rf_openbsdkintf.c | 109 | ||||
-rw-r--r-- | sys/dev/raidframe/rf_shutdown.h | 4 |
3 files changed, 84 insertions, 69 deletions
diff --git a/sys/dev/raidframe/rf_engine.c b/sys/dev/raidframe/rf_engine.c index 84222fe63ea..7e0efe03bcc 100644 --- a/sys/dev/raidframe/rf_engine.c +++ b/sys/dev/raidframe/rf_engine.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rf_engine.c,v 1.8 2002/02/16 00:56:23 tdeval Exp $ */ +/* $OpenBSD: rf_engine.c,v 1.9 2002/03/06 11:28:27 tdeval Exp $ */ /* $NetBSD: rf_engine.c,v 1.10 2000/08/20 16:51:03 thorpej Exp $ */ /* * Copyright (c) 1995 Carnegie-Mellon University. @@ -71,10 +71,10 @@ #define RF_ENGINE_PID 10 extern int numraid; extern pid_t lastpid; -static void **rf_startuphook_cookie; -void DAGExecutionThread_pre(RF_ThreadArg_t arg); +void DAGExecutionThread_pre(RF_ThreadArg_t arg); #endif /* RAID_AUTOCONFIG */ -void DAGExecutionThread(RF_ThreadArg_t arg); +void DAGExecutionThread(RF_ThreadArg_t arg); +void **rf_hook_cookies; #define DO_INIT(_l_,_r_) { \ int _rc; \ @@ -149,17 +149,17 @@ rf_ConfigureEngine( if (rf_engineDebug) { printf("raid%d: Creating engine thread\n", raidPtr->raidid); } + if (rf_hook_cookies == NULL) { + rf_hook_cookies = + malloc(numraid * sizeof(void*), + M_RAIDFRAME, M_NOWAIT); + if (rf_hook_cookies == NULL) + return (ENOMEM); + bzero(rf_hook_cookies, numraid * sizeof(void*)); + } #ifdef RAID_AUTOCONFIG if (initproc == NULL) { - if (rf_startuphook_cookie == NULL) { - rf_startuphook_cookie = - malloc(numraid * sizeof(void*), - M_RAIDFRAME, M_NOWAIT); - if (rf_startuphook_cookie == NULL) - return (ENOMEM); - bzero(rf_startuphook_cookie, numraid * sizeof(void*)); - } - rf_startuphook_cookie[raidPtr->raidid] = + rf_hook_cookies[raidPtr->raidid] = startuphook_establish(DAGExecutionThread_pre, raidPtr); } else { #endif /* RAID_AUTOCONFIG */ @@ -754,8 +754,10 @@ DAGExecutionThread_pre(RF_ThreadArg_t arg) raidPtr = (RF_Raid_t *) arg; - if (rf_startuphook_cookie && rf_startuphook_cookie[raidPtr->raidid]) - startuphook_disestablish(rf_startuphook_cookie[raidPtr->raidid]); + if (rf_hook_cookies && rf_hook_cookies[raidPtr->raidid] != NULL) { + startuphook_disestablish(rf_hook_cookies[raidPtr->raidid]); + rf_hook_cookies[raidPtr->raidid] = NULL; + } if (rf_engineDebug) { printf("raid%d: Creating engine thread\n", raidPtr->raidid); @@ -805,6 +807,9 @@ DAGExecutionThread(RF_ThreadArg_t arg) RF_THREADGROUP_RUNNING(&raidPtr->engine_tg); + rf_hook_cookies[raidPtr->raidid] = + shutdownhook_establish(rf_shutdown_hook, (void*)raidPtr); + DO_LOCK(raidPtr); while (!raidPtr->shutdown_engine) { @@ -873,6 +878,11 @@ DAGExecutionThread(RF_ThreadArg_t arg) } DO_UNLOCK(raidPtr); + if (rf_hook_cookies && rf_hook_cookies[raidPtr->raidid] != NULL) { + shutdownhook_disestablish(rf_hook_cookies[raidPtr->raidid]); + rf_hook_cookies[raidPtr->raidid] = NULL; + } + RF_THREADGROUP_DONE(&raidPtr->engine_tg); splx(s); diff --git a/sys/dev/raidframe/rf_openbsdkintf.c b/sys/dev/raidframe/rf_openbsdkintf.c index 0c6b5861bbc..8321535eb73 100644 --- a/sys/dev/raidframe/rf_openbsdkintf.c +++ b/sys/dev/raidframe/rf_openbsdkintf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rf_openbsdkintf.c,v 1.13 2002/01/23 00:39:47 art Exp $ */ +/* $OpenBSD: rf_openbsdkintf.c,v 1.14 2002/03/06 11:28:27 tdeval Exp $ */ /* $NetBSD: rf_netbsdkintf.c,v 1.109 2001/07/27 03:30:07 oster Exp $ */ /*- * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc. @@ -278,6 +278,7 @@ struct cfattach raid_ca = { struct raid_softc *raid_softc; struct raid_softc **raid_scPtrs; +void rf_shutdown_hook(RF_ThreadArg_t); void raidgetdefaultlabel __P((RF_Raid_t *, struct raid_softc *, struct disklabel *)); void raidgetdisklabel __P((dev_t)); @@ -287,7 +288,6 @@ int raidlock __P((struct raid_softc *)); void raidunlock __P((struct raid_softc *)); void rf_markalldirty __P((RF_Raid_t *)); -void rf_mountroot_hook __P((struct device *)); struct device *raidrootdev; @@ -467,30 +467,27 @@ raidattach(num) #ifdef RAID_AUTOCONFIG raidautoconfig = 1; -if (raidautoconfig) { - /* 1. locate all RAID components on the system */ + if (raidautoconfig) { + /* 1. locate all RAID components on the system */ #ifdef DEBUG - printf("Searching for raid components...\n"); + printf("Searching for raid components...\n"); #endif - ac_list = rf_find_raid_components(); + ac_list = rf_find_raid_components(); - /* 2. sort them into their respective sets */ + /* 2. sort them into their respective sets */ - config_sets = rf_create_auto_sets(ac_list); + config_sets = rf_create_auto_sets(ac_list); - /* 3. evaluate each set and configure the valid ones - This gets done in rf_buildroothack() */ + /* 3. evaluate each set and configure the valid ones + This gets done in rf_buildroothack() */ - /* schedule the creation of the thread to do the - "/ on RAID" stuff */ + /* schedule the creation of the thread to do the + "/ on RAID" stuff */ - rf_buildroothack(config_sets); + rf_buildroothack(config_sets); -#if 0 - mountroothook_establish(rf_mountroot_hook, &raidrootdev[0]); -#endif -} + } #endif } @@ -562,6 +559,38 @@ rf_buildroothack(arg) } #endif +void +rf_shutdown_hook(arg) + RF_ThreadArg_t arg; +{ + int unit; + struct raid_softc *rs; + RF_Raid_t *raidPtr; + + /* Don't do it if we are not "safe" */ + if (boothowto & RB_NOSYNC) + return; + + raidPtr = (RF_Raid_t *) arg; + unit = raidPtr->raidid; + rs = &raid_softc[unit]; + + /* Shutdown the system */ + + rf_Shutdown(raidPtr); + + pool_destroy(&rs->sc_cbufpool); + + /* It's no longer initialized... */ + rs->sc_flags &= ~RAIDF_INITED; + + /* config_detach the device. */ + config_detach(device_lookup(&raid_cd, unit), 0); + + /* Detach the disk. */ + disk_detach(&rs->sc_dkdev); +} + int raidsize(dev) dev_t dev; @@ -726,29 +755,9 @@ raidclose(dev, flags, fmt, p) Device shutdown has taken care of setting the clean bits if RAIDF_INITED is not set mark things as clean... */ -#if 0 - printf("Last one on raid%d. Updating status.\n",unit); -#endif + db1_printf(("Last one on raid%d. Updating status.\n",unit)); rf_update_component_labels(raidPtrs[unit], RF_FINAL_COMPONENT_UPDATE); -#if 0 - if (doing_shutdown) { -/* #endif */ - /* last one, and we're going down, so - lights out for this RAID set too. */ - error = rf_Shutdown(raidPtrs[unit]); - pool_destroy(&rs->sc_cbufpool); - - /* It's no longer initialized... */ - rs->sc_flags &= ~RAIDF_INITED; - - /* config_detach the device. */ - config_detach(device_lookup(&raid_cd, unit), 0); - - disk_detach(&rs->sc_dkdev); -/* #if 0 */ - } -#endif } raidunlock(rs); @@ -1063,18 +1072,19 @@ raidioctl(dev, cmd, data, flag, p) return (EBUSY); } - retcode = rf_Shutdown(raidPtr); + if ((retcode = rf_Shutdown(raidPtr)) == 0) { - pool_destroy(&rs->sc_cbufpool); + pool_destroy(&rs->sc_cbufpool); - /* It's no longer initialized... */ - rs->sc_flags &= ~RAIDF_INITED; + /* It's no longer initialized... */ + rs->sc_flags &= ~RAIDF_INITED; - /* config_detach the device. */ - config_detach(device_lookup(&raid_cd, unit), 0); + /* config_detach the device. */ + config_detach(device_lookup(&raid_cd, unit), 0); - /* Detach the disk. */ - disk_detach(&rs->sc_dkdev); + /* Detach the disk. */ + disk_detach(&rs->sc_dkdev); + } raidunlock(rs); @@ -2757,13 +2767,6 @@ rf_ReconstructInPlaceThread(req) kthread_exit(0); /* does not return */ } -void -rf_mountroot_hook(dev) - struct device *dev; -{ - -} - RF_AutoConfig_t * rf_find_raid_components() diff --git a/sys/dev/raidframe/rf_shutdown.h b/sys/dev/raidframe/rf_shutdown.h index 002dad7fbc6..77ff2a14fe2 100644 --- a/sys/dev/raidframe/rf_shutdown.h +++ b/sys/dev/raidframe/rf_shutdown.h @@ -1,4 +1,4 @@ -/* $OpenBSD: rf_shutdown.h,v 1.2 1999/02/16 00:03:26 niklas Exp $ */ +/* $OpenBSD: rf_shutdown.h,v 1.3 2002/03/06 11:28:27 tdeval Exp $ */ /* $NetBSD: rf_shutdown.h,v 1.2 1999/02/05 00:06:17 oster Exp $ */ /* * rf_shutdown.h @@ -64,4 +64,6 @@ int _rf_ShutdownCreate(RF_ShutdownList_t ** listp, void (*cleanup) (void *ar void *arg, char *file, int line); int rf_ShutdownList(RF_ShutdownList_t ** listp); +void rf_shutdown_hook(RF_ThreadArg_t); + #endif /* !_RF__RF_SHUTDOWN_H_ */ |