From owner-freebsd-hackers Fri Feb 6 11:02:06 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA04105 for hackers-outgoing; Fri, 6 Feb 1998 11:02:06 -0800 (PST) (envelope-from owner-freebsd-hackers@FreeBSD.ORG) Received: from callisto.fortean.com (callisto.fortean.com [209.42.194.97]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA03982 for ; Fri, 6 Feb 1998 11:01:09 -0800 (PST) (envelope-from walter@fortean.com) Received: from localhost (walter@localhost) by callisto.fortean.com (8.8.8/8.8.5) with SMTP id NAA25514; Fri, 6 Feb 1998 13:57:41 -0500 (EST) X-Authentication-Warning: callisto.fortean.com: walter owned process doing -bs Date: Fri, 6 Feb 1998 13:57:40 -0500 (EST) From: "Bruce M. Walter" To: John Fieber , Mike Smith , Calin Andrian cc: hackers@FreeBSD.ORG Subject: Re: Powering off the system/UPS In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG X-To-Unsubscribe: mail to majordomo@FreeBSD.org "unsubscribe hackers" Alright, here's my first cut at patches to add a third at_shutdown queue and for adding ordered queues to the at_shutdown interface. They are against 2.2-STABLE (sorry) but should apply with very little modification to 3.0-CURRENT. I'd appreciate anyone with an inclination to look these over and let me know what you think. - Bruce *** sys/systm.h.orig Sun Aug 10 22:04:12 1997 --- sys/systm.h Fri Feb 6 13:24:15 1998 *************** *** 168,176 **** --- 168,181 ---- /* shutdown callout list definitions */ typedef void (*bootlist_fn)(int,void *); int at_shutdown(bootlist_fn function, void *arg, int); + int pri_at_shutdown(bootlist_fn function, void *arg, int, int); int rm_at_shutdown(bootlist_fn function, void *arg); #define SHUTDOWN_PRE_SYNC 0 #define SHUTDOWN_POST_SYNC 1 + #define SHUTDOWN_PRE_HALT 2 + #define SHUTDOWN_PRI_MAX 1 + #define SHUTDOWN_PRI_MIN 20 + #define SHUTDOWN_PRI_DEFAULT 10 /* forking */ /* XXX not yet */ typedef void (*forklist_fn)(struct proc *parent,struct proc *child,int flags); *** kern/kern_shutdown.c.orig Sun Aug 10 22:04:14 1997 --- kern/kern_shutdown.c Fri Feb 6 13:34:10 1998 *************** *** 110,115 **** --- 110,116 ---- struct shutdown_list_element *next; bootlist_fn function; void *arg; + int priority; } *sle_p; /* *************** *** 118,123 **** --- 119,125 ---- */ static sle_p shutdown_list1; static sle_p shutdown_list2; + static sle_p shutdown_list3; static void dumpsys(void); *************** *** 248,253 **** --- 250,266 ---- ep = ep->next; } splhigh(); + + /* + * Ok, now do any last things we need to before cpu death + */ + ep = shutdown_list3; + while (ep) { + shutdown_list3 = ep->next; + (*ep->function)(howto, ep->arg); + ep = ep->next; + } + if (howto & RB_HALT) { printf("\n"); printf("The operating system has halted.\n"); *************** *** 391,397 **** } /* ! * Two routines to handle adding/deleting items on the * shutdown callout lists * * at_shutdown(): --- 404,410 ---- } /* ! * Three routines to handle adding/deleting items on the * shutdown callout lists * * at_shutdown(): *************** *** 402,408 **** int at_shutdown(bootlist_fn function, void *arg, int position) { ! sle_p ep, *epp; switch(position) { case SHUTDOWN_PRE_SYNC: --- 415,436 ---- int at_shutdown(bootlist_fn function, void *arg, int position) { ! return (pri_at_shutdown(function,arg,position,SHUTDOWN_PRI_DEFAULT)); ! } ! ! /* ! * Three routines to handle adding/deleting items on the ! * shutdown callout lists ! * ! * pri_at_shutdown(): ! * Take the arguments given and put them onto the shutdown callout list with ! * the given execution priority. ! * returns 0 on success. ! */ ! int ! pri_at_shutdown(bootlist_fn function, void *arg, int position, int priority) ! { ! sle_p ep, ip, lp, *epp; switch(position) { case SHUTDOWN_PRE_SYNC: *************** *** 411,429 **** case SHUTDOWN_POST_SYNC: epp = &shutdown_list2; break; default: printf("bad exit callout list specified\n"); return (EINVAL); } if (rm_at_shutdown(function, arg)) printf("exit callout entry already present\n"); ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT); if (ep == NULL) return (ENOMEM); - ep->next = *epp; ep->function = function; ep->arg = arg; ! *epp = ep; return (0); } --- 439,482 ---- case SHUTDOWN_POST_SYNC: epp = &shutdown_list2; break; + case SHUTDOWN_PRE_HALT: + epp = &shutdown_list3; + break; default: printf("bad exit callout list specified\n"); return (EINVAL); } + if ((priority < SHUTDOWN_PRI_MAX) || (priority > SHUTDOWN_PRI_MIN)) { + printf("bad callout priority specified\n"); + return (EINVAL); + } if (rm_at_shutdown(function, arg)) printf("exit callout entry already present\n"); ep = malloc(sizeof(*ep), M_TEMP, M_NOWAIT); if (ep == NULL) return (ENOMEM); ep->function = function; ep->arg = arg; ! ep->priority = priority; ! ! lp = NULL; ! ip = *epp; ! if (*epp) { ! while (ip) { ! if (ip->priority >= priority) ! break; ! lp = ip; ! ip = ip->next; ! } ! } ! if (lp) { ! ep->next = lp->next; ! lp->next = ep; ! } else { ! ep->next = ip; ! *epp = ep; ! } ! return (0); } *************** *** 451,456 **** --- 504,521 ---- ep = *epp; } epp = &shutdown_list2; + ep = *epp; + while (ep) { + if ((ep->function == function) && (ep->arg == arg)) { + *epp = ep->next; + free(ep, M_TEMP); + count++; + } else { + epp = &ep->next; + } + ep = *epp; + } + epp = &shutdown_list3; ep = *epp; while (ep) { if ((ep->function == function) && (ep->arg == arg)) { ======================================================================== || Bruce M. Walter || 107 Timber Hollow Court #335 || || Senior Network Consultant || Chapel Hill, NC 27514 || || Fortean Technologies, Inc. || Tel: 919-967-4766 || || Information Technology Consultants || Fax: 919-967-4395 || ======================================================================== || BSD Unix -- It's not just a job, it's a way of life! || ========================================================================