kern_acct.c revision 2807
1251876Speter/*- 2251876Speter * Copyright (c) 1982, 1986, 1989, 1993 3251876Speter * The Regents of the University of California. All rights reserved. 4251876Speter * (c) UNIX System Laboratories, Inc. 5251876Speter * All or some portions of this file are derived from material licensed 6251876Speter * to the University of California by American Telephone and Telegraph 7251876Speter * Co. or Unix System Laboratories, Inc. and are reproduced herein with 8251876Speter * the permission of UNIX System Laboratories, Inc. 9251876Speter * 10251876Speter * Redistribution and use in source and binary forms, with or without 11251876Speter * modification, are permitted provided that the following conditions 12251876Speter * are met: 13251876Speter * 1. Redistributions of source code must retain the above copyright 14251876Speter * notice, this list of conditions and the following disclaimer. 15251876Speter * 2. Redistributions in binary form must reproduce the above copyright 16251876Speter * notice, this list of conditions and the following disclaimer in the 17251876Speter * documentation and/or other materials provided with the distribution. 18253734Speter * 3. All advertising materials mentioning features or use of this software 19253734Speter * must display the following acknowledgement: 20251876Speter * This product includes software developed by the University of 21253734Speter * California, Berkeley and its contributors. 22251876Speter * 4. Neither the name of the University nor the names of its contributors 23251876Speter * may be used to endorse or promote products derived from this software 24251876Speter * without specific prior written permission. 25251876Speter * 26251876Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 27251876Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 28251876Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 29251876Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 30251876Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 31251876Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 32251876Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 33251876Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 34251876Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 35251876Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 36251876Speter * SUCH DAMAGE. 37251876Speter * 38251876Speter * from: @(#)kern_acct.c 8.1 (Berkeley) 6/14/93 39251876Speter * $Id: kern_acct.c,v 1.3 1994/08/02 07:41:52 davidg Exp $ 40251876Speter */ 41251876Speter 42251876Speter#include <sys/param.h> 43251876Speter#include <sys/systm.h> 44251876Speter#include <sys/proc.h> 45251876Speter#include <sys/mount.h> 46251876Speter#include <sys/vnode.h> 47251876Speter#include <sys/file.h> 48253734Speter#include <sys/syslog.h> 49251876Speter#include <sys/kernel.h> 50251876Speter 51251876Speterstruct acct_args { 52251876Speter char *fname; 53251876Speter}; 54251876Speterint 55251876Speteracct(a1, a2, a3) 56251876Speter struct proc *a1; 57251876Speter struct acct_args *a2; 58251876Speter int *a3; 59251876Speter{ 60251876Speter /* 61251876Speter * Body deleted. 62251876Speter */ 63251876Speter return (ENOSYS); 64251876Speter} 65251876Speter 66251876Spetervoid 67251876Speteracct_process(a1) 68251876Speter struct proc *a1; 69251876Speter{ 70251876Speter 71251876Speter /* 72251876Speter * Body deleted. 73251876Speter */ 74251876Speter return; 75251876Speter} 76251876Speter 77251876Speter/* 78251876Speter * Periodically check the file system to see if accounting 79251876Speter * should be turned on or off. 80251876Speter */ 81251876Speter 82251876Speter/* 83251876Speter * Values associated with enabling and disabling accounting 84251876Speter */ 85251876Speterint acctsuspend = 2; /* stop accounting when < 2% free space left */ 86251876Speterint acctresume = 4; /* resume when free space risen to > 4% */ 87251876Speterint acctchkfreq = 15; /* frequency (in seconds) to check space */ 88251876Speter 89251876Speter/* 90251876Speter * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY. 91251876Speter */ 92251876Speterstruct vnode *acctp; 93251876Speterstruct vnode *savacctp; 94251876Speter 95251876Speter/* ARGSUSED */ 96251876Spetervoid 97251876Speteracctwatch(a) 98251876Speter void *a; 99251876Speter{ 100251876Speter struct statfs sb; 101251876Speter 102251876Speter if (savacctp) { 103251876Speter (void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0); 104251876Speter if (sb.f_bavail > acctresume * sb.f_blocks / 100) { 105251876Speter acctp = savacctp; 106251876Speter savacctp = NULL; 107251876Speter log(LOG_NOTICE, "Accounting resumed\n"); 108251876Speter } 109251876Speter } else { 110251876Speter if (acctp == NULL) 111251876Speter return; 112251876Speter (void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0); 113251876Speter if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) { 114251876Speter savacctp = acctp; 115251876Speter acctp = NULL; 116251876Speter log(LOG_NOTICE, "Accounting suspended\n"); 117251876Speter } 118251876Speter } 119251876Speter timeout(acctwatch, NULL, acctchkfreq * hz); 120251876Speter} 121251876Speter