xref: /netbsd/sys/dev/raidframe/rf_shutdown.c (revision bf9ec67e)
1 /*	$NetBSD: rf_shutdown.c,v 1.9 2001/11/13 07:11:16 lukem 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.9 2001/11/13 07:11:16 lukem Exp $");
38 
39 #include <dev/raidframe/raidframevar.h>
40 
41 #include "rf_archs.h"
42 #include "rf_threadstuff.h"
43 #include "rf_shutdown.h"
44 #include "rf_debugMem.h"
45 #include "rf_freelist.h"
46 
47 static void
48 rf_FreeShutdownEnt(RF_ShutdownList_t * ent)
49 {
50 	FREE(ent, M_RAIDFRAME);
51 }
52 
53 int
54 _rf_ShutdownCreate(
55     RF_ShutdownList_t ** listp,
56     void (*cleanup) (void *arg),
57     void *arg,
58     char *file,
59     int line)
60 {
61 	RF_ShutdownList_t *ent;
62 
63 	/*
64          * Have to directly allocate memory here, since we start up before
65          * and shutdown after RAIDframe internal allocation system.
66          */
67 	/* 	ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t),
68 		M_RAIDFRAME, M_WAITOK); */
69 	ent = (RF_ShutdownList_t *) malloc(sizeof(RF_ShutdownList_t),
70 					   M_RAIDFRAME, M_NOWAIT);
71 	if (ent == NULL)
72 		return (ENOMEM);
73 	ent->cleanup = cleanup;
74 	ent->arg = arg;
75 	ent->file = file;
76 	ent->line = line;
77 	ent->next = *listp;
78 	*listp = ent;
79 	return (0);
80 }
81 
82 int
83 rf_ShutdownList(RF_ShutdownList_t ** list)
84 {
85 	RF_ShutdownList_t *r, *next;
86 	char   *file;
87 	int     line;
88 
89 	for (r = *list; r; r = next) {
90 		next = r->next;
91 		file = r->file;
92 		line = r->line;
93 
94 		if (rf_shutdownDebug) {
95 			printf("call shutdown, created %s:%d\n", file, line);
96 		}
97 		r->cleanup(r->arg);
98 
99 		if (rf_shutdownDebug) {
100 			printf("completed shutdown, created %s:%d\n", file, line);
101 		}
102 		rf_FreeShutdownEnt(r);
103 	}
104 	*list = NULL;
105 	return (0);
106 }
107