Home | History | Annotate | Line # | Download | only in kern
kern_acct.c revision 1.23
      1  1.23  cgd /*-
      2  1.23  cgd  * Copyright (c) 1982, 1986, 1989, 1993
      3  1.23  cgd  *	The Regents of the University of California.  All rights reserved.
      4  1.22  cgd  * (c) UNIX System Laboratories, Inc.
      5  1.22  cgd  * All or some portions of this file are derived from material licensed
      6  1.22  cgd  * to the University of California by American Telephone and Telegraph
      7  1.22  cgd  * Co. or Unix System Laboratories, Inc. and are reproduced herein with
      8  1.22  cgd  * the permission of UNIX System Laboratories, Inc.
      9  1.22  cgd  *
     10  1.22  cgd  * Redistribution and use in source and binary forms, with or without
     11  1.22  cgd  * modification, are permitted provided that the following conditions
     12  1.22  cgd  * are met:
     13  1.22  cgd  * 1. Redistributions of source code must retain the above copyright
     14  1.22  cgd  *    notice, this list of conditions and the following disclaimer.
     15  1.22  cgd  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.22  cgd  *    notice, this list of conditions and the following disclaimer in the
     17  1.22  cgd  *    documentation and/or other materials provided with the distribution.
     18  1.22  cgd  * 3. All advertising materials mentioning features or use of this software
     19  1.22  cgd  *    must display the following acknowledgement:
     20  1.22  cgd  *	This product includes software developed by the University of
     21  1.22  cgd  *	California, Berkeley and its contributors.
     22  1.22  cgd  * 4. Neither the name of the University nor the names of its contributors
     23  1.22  cgd  *    may be used to endorse or promote products derived from this software
     24  1.22  cgd  *    without specific prior written permission.
     25  1.22  cgd  *
     26  1.22  cgd  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.22  cgd  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.22  cgd  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.22  cgd  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.22  cgd  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.22  cgd  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.22  cgd  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.22  cgd  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.22  cgd  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.22  cgd  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.22  cgd  * SUCH DAMAGE.
     37  1.22  cgd  *
     38  1.23  cgd  *	from: @(#)kern_acct.c	8.1 (Berkeley) 6/14/93
     39  1.22  cgd  */
     40  1.22  cgd 
     41  1.22  cgd #include <sys/param.h>
     42  1.22  cgd #include <sys/proc.h>
     43  1.23  cgd #include <sys/mount.h>
     44  1.22  cgd #include <sys/vnode.h>
     45  1.22  cgd #include <sys/file.h>
     46  1.22  cgd #include <sys/syslog.h>
     47  1.23  cgd #include <sys/kernel.h>
     48  1.22  cgd 
     49  1.22  cgd struct acct_args {
     50  1.23  cgd 	char	*fname;
     51  1.22  cgd };
     52  1.23  cgd acct(a1, a2, a3)
     53  1.23  cgd 	struct proc *a1;
     54  1.23  cgd 	struct acct_args *a2;
     55  1.23  cgd 	int *a3;
     56  1.22  cgd {
     57  1.22  cgd 	/*
     58  1.23  cgd 	 * Body deleted.
     59  1.22  cgd 	 */
     60  1.23  cgd 	return (ENOSYS);
     61  1.23  cgd }
     62  1.22  cgd 
     63  1.23  cgd acct_process(a1)
     64  1.23  cgd 	struct proc *a1;
     65  1.23  cgd {
     66  1.22  cgd 
     67  1.22  cgd 	/*
     68  1.23  cgd 	 * Body deleted.
     69  1.22  cgd 	 */
     70  1.23  cgd 	return;
     71  1.22  cgd }
     72  1.22  cgd 
     73  1.22  cgd /*
     74  1.22  cgd  * Periodically check the file system to see if accounting
     75  1.22  cgd  * should be turned on or off.
     76  1.22  cgd  */
     77  1.23  cgd 
     78  1.23  cgd /*
     79  1.23  cgd  * Values associated with enabling and disabling accounting
     80  1.23  cgd  */
     81  1.23  cgd int	acctsuspend = 2;	/* stop accounting when < 2% free space left */
     82  1.23  cgd int	acctresume = 4;		/* resume when free space risen to > 4% */
     83  1.23  cgd int	acctchkfreq = 15;	/* frequency (in seconds) to check space */
     84  1.23  cgd 
     85  1.23  cgd /*
     86  1.23  cgd  * SHOULD REPLACE THIS WITH A DRIVER THAT CAN BE READ TO SIMPLIFY.
     87  1.23  cgd  */
     88  1.23  cgd struct	vnode *acctp;
     89  1.23  cgd struct	vnode *savacctp;
     90  1.23  cgd 
     91  1.23  cgd /* ARGSUSED */
     92  1.22  cgd void
     93  1.23  cgd acctwatch(a)
     94  1.23  cgd 	void *a;
     95  1.22  cgd {
     96  1.22  cgd 	struct statfs sb;
     97  1.22  cgd 
     98  1.23  cgd 	if (savacctp) {
     99  1.22  cgd 		(void)VFS_STATFS(savacctp->v_mount, &sb, (struct proc *)0);
    100  1.22  cgd 		if (sb.f_bavail > acctresume * sb.f_blocks / 100) {
    101  1.22  cgd 			acctp = savacctp;
    102  1.22  cgd 			savacctp = NULL;
    103  1.22  cgd 			log(LOG_NOTICE, "Accounting resumed\n");
    104  1.22  cgd 		}
    105  1.23  cgd 	} else {
    106  1.23  cgd 		if (acctp == NULL)
    107  1.23  cgd 			return;
    108  1.22  cgd 		(void)VFS_STATFS(acctp->v_mount, &sb, (struct proc *)0);
    109  1.22  cgd 		if (sb.f_bavail <= acctsuspend * sb.f_blocks / 100) {
    110  1.22  cgd 			savacctp = acctp;
    111  1.22  cgd 			acctp = NULL;
    112  1.22  cgd 			log(LOG_NOTICE, "Accounting suspended\n");
    113  1.22  cgd 		}
    114  1.22  cgd 	}
    115  1.23  cgd 	timeout(acctwatch, NULL, acctchkfreq * hz);
    116  1.22  cgd }
    117