1 /* $NetBSD: rf_shutdown.c,v 1.13 2002/09/23 03:42:50 oster Exp $ */ 2 /* 3 * rf_shutdown.c 4 */ 5 /* 6 * Copyright (c) 1996 Carnegie-Mellon University. 7 * All rights reserved. 8 * 9 * Author: Jim Zelenka 10 * 11 * Permission to use, copy, modify and distribute this software and 12 * its documentation is hereby granted, provided that both the copyright 13 * notice and this permission notice appear in all copies of the 14 * software, derivative works or modified versions, and any portions 15 * thereof, and that both notices appear in supporting documentation. 16 * 17 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 18 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 19 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 20 * 21 * Carnegie Mellon requests users of this software to return to 22 * 23 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 24 * School of Computer Science 25 * Carnegie Mellon University 26 * Pittsburgh PA 15213-3890 27 * 28 * any improvements or extensions that they make and grant Carnegie the 29 * rights to redistribute these changes. 30 */ 31 /* 32 * Maintain lists of cleanup functions. Also, mechanisms for coordinating 33 * thread startup and shutdown. 34 */ 35 36 #include <sys/cdefs.h> 37 __KERNEL_RCSID(0, "$NetBSD: rf_shutdown.c,v 1.13 2002/09/23 03:42:50 oster Exp $"); 38 39 #include <dev/raidframe/raidframevar.h> 40 41 #include "rf_archs.h" 42 #include "rf_shutdown.h" 43 #include "rf_freelist.h" 44 45 46 #ifndef RF_DEBUG_SHUTDOWN 47 #define RF_DEBUG_SHUTDOWN 0 48 #endif 49 50 static void rf_FreeShutdownEnt(RF_ShutdownList_t *); 51 52 static void 53 rf_FreeShutdownEnt(RF_ShutdownList_t * ent) 54 { 55 FREE(ent, M_RAIDFRAME); 56 } 57 58 int 59 _rf_ShutdownCreate( 60 RF_ShutdownList_t ** listp, 61 void (*cleanup) (void *arg), 62 void *arg, 63 char *file, 64 int line) 65 { 66 RF_ShutdownList_t *ent; 67 68 /* 69 * Have to directly allocate memory here, since we start up before 70 * and shutdown after RAIDframe internal allocation system. 71 */ 72 /* ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t), 73 M_RAIDFRAME, M_WAITOK); */ 74 ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t), 75 M_RAIDFRAME, M_NOWAIT); 76 if (ent == NULL) 77 return (ENOMEM); 78 ent->cleanup = cleanup; 79 ent->arg = arg; 80 ent->file = file; 81 ent->line = line; 82 ent->next = *listp; 83 *listp = ent; 84 return (0); 85 } 86 87 int 88 rf_ShutdownList(RF_ShutdownList_t ** list) 89 { 90 RF_ShutdownList_t *r, *next; 91 #if RF_DEBUG_SHUTDOWN 92 char *file; 93 int line; 94 #endif 95 96 for (r = *list; r; r = next) { 97 next = r->next; 98 #if RF_DEBUG_SHUTDOWN 99 file = r->file; 100 line = r->line; 101 102 if (rf_shutdownDebug) { 103 printf("call shutdown, created %s:%d\n", file, line); 104 } 105 #endif 106 r->cleanup(r->arg); 107 #if RF_DEBUG_SHUTDOWN 108 if (rf_shutdownDebug) { 109 printf("completed shutdown, created %s:%d\n", file, line); 110 } 111 #endif 112 rf_FreeShutdownEnt(r); 113 } 114 *list = NULL; 115 return (0); 116 } 117