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