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