1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _SYS_ACCTCTL_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_ACCTCTL_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #include <sys/types.h> 33*7c478bd9Sstevel@tonic-gate #include <sys/bitmap.h> 34*7c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 37*7c478bd9Sstevel@tonic-gate extern "C" { 38*7c478bd9Sstevel@tonic-gate #endif 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * Definitions for acctctl() system call 42*7c478bd9Sstevel@tonic-gate */ 43*7c478bd9Sstevel@tonic-gate 44*7c478bd9Sstevel@tonic-gate /* 45*7c478bd9Sstevel@tonic-gate * modes 46*7c478bd9Sstevel@tonic-gate */ 47*7c478bd9Sstevel@tonic-gate #define AC_PROC (0x1 << 28) /* change process accounting settings */ 48*7c478bd9Sstevel@tonic-gate #define AC_TASK (0x2 << 28) /* change task accounting settings */ 49*7c478bd9Sstevel@tonic-gate #define AC_FLOW (0x4 << 28) /* change flow accounting settings */ 50*7c478bd9Sstevel@tonic-gate #define AC_MODE(x) ((x) & 0xf0000000) 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate /* 53*7c478bd9Sstevel@tonic-gate * options 54*7c478bd9Sstevel@tonic-gate */ 55*7c478bd9Sstevel@tonic-gate #define AC_FILE_SET (0x01) /* set accounting file name */ 56*7c478bd9Sstevel@tonic-gate #define AC_FILE_GET (0x02) /* get accounting file name */ 57*7c478bd9Sstevel@tonic-gate #define AC_RES_SET (0x04) /* set (enable/disable) resources */ 58*7c478bd9Sstevel@tonic-gate #define AC_RES_GET (0x08) /* get a list of enabled resources */ 59*7c478bd9Sstevel@tonic-gate #define AC_STATE_SET (0x10) /* set accounting mode state (on/off) */ 60*7c478bd9Sstevel@tonic-gate #define AC_STATE_GET (0x20) /* get accounting mode state */ 61*7c478bd9Sstevel@tonic-gate #define AC_OPTION(x) ((x) & 0x0fffffff) 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate /* 64*7c478bd9Sstevel@tonic-gate * Process accounting resource IDs 65*7c478bd9Sstevel@tonic-gate */ 66*7c478bd9Sstevel@tonic-gate #define AC_NONE 0 /* special end-of-list identifier */ 67*7c478bd9Sstevel@tonic-gate #define AC_PROC_PID 1 /* process ID */ 68*7c478bd9Sstevel@tonic-gate #define AC_PROC_UID 2 /* user ID */ 69*7c478bd9Sstevel@tonic-gate #define AC_PROC_GID 3 /* group ID */ 70*7c478bd9Sstevel@tonic-gate #define AC_PROC_PROJID 4 /* project ID */ 71*7c478bd9Sstevel@tonic-gate #define AC_PROC_TASKID 5 /* task ID */ 72*7c478bd9Sstevel@tonic-gate #define AC_PROC_CPU 6 /* user/system cpu time */ 73*7c478bd9Sstevel@tonic-gate #define AC_PROC_TIME 7 /* start/finish time */ 74*7c478bd9Sstevel@tonic-gate #define AC_PROC_COMMAND 8 /* command name */ 75*7c478bd9Sstevel@tonic-gate #define AC_PROC_TTY 9 /* control tty */ 76*7c478bd9Sstevel@tonic-gate #define AC_PROC_HOSTNAME 10 /* hostname */ 77*7c478bd9Sstevel@tonic-gate #define AC_PROC_MICROSTATE 11 /* microstate accounting */ 78*7c478bd9Sstevel@tonic-gate #define AC_PROC_FLAG 12 /* accounting flags */ 79*7c478bd9Sstevel@tonic-gate #define AC_PROC_ANCPID 13 /* ancestor process's ID */ 80*7c478bd9Sstevel@tonic-gate #define AC_PROC_WAIT_STATUS 14 /* process wait status */ 81*7c478bd9Sstevel@tonic-gate #define AC_PROC_ZONENAME 15 /* zone name */ 82*7c478bd9Sstevel@tonic-gate #define AC_PROC_MEM 16 /* memory usage */ 83*7c478bd9Sstevel@tonic-gate #define AC_PROC_MAX_RES 16 /* must be equal to the number above */ 84*7c478bd9Sstevel@tonic-gate 85*7c478bd9Sstevel@tonic-gate /* 86*7c478bd9Sstevel@tonic-gate * Task accounting resource IDs 87*7c478bd9Sstevel@tonic-gate */ 88*7c478bd9Sstevel@tonic-gate #define AC_TASK_TASKID 1 /* task ID */ 89*7c478bd9Sstevel@tonic-gate #define AC_TASK_PROJID 2 /* project ID */ 90*7c478bd9Sstevel@tonic-gate #define AC_TASK_CPU 3 /* user/system cpu time */ 91*7c478bd9Sstevel@tonic-gate #define AC_TASK_TIME 4 /* start/finish time */ 92*7c478bd9Sstevel@tonic-gate #define AC_TASK_HOSTNAME 5 /* hostname */ 93*7c478bd9Sstevel@tonic-gate #define AC_TASK_MICROSTATE 6 /* microstate accounting */ 94*7c478bd9Sstevel@tonic-gate #define AC_TASK_ANCTASKID 7 /* ancestor task's taskid */ 95*7c478bd9Sstevel@tonic-gate #define AC_TASK_ZONENAME 8 /* zone name */ 96*7c478bd9Sstevel@tonic-gate #define AC_TASK_MAX_RES 8 /* must be equal to the number above */ 97*7c478bd9Sstevel@tonic-gate 98*7c478bd9Sstevel@tonic-gate /* 99*7c478bd9Sstevel@tonic-gate * Flow accounting resource IDs 100*7c478bd9Sstevel@tonic-gate */ 101*7c478bd9Sstevel@tonic-gate #define AC_FLOW_SADDR 1 /* source address */ 102*7c478bd9Sstevel@tonic-gate #define AC_FLOW_DADDR 2 /* destination address */ 103*7c478bd9Sstevel@tonic-gate #define AC_FLOW_SPORT 3 /* source port */ 104*7c478bd9Sstevel@tonic-gate #define AC_FLOW_DPORT 4 /* destination port */ 105*7c478bd9Sstevel@tonic-gate #define AC_FLOW_PROTOCOL 5 /* protocol */ 106*7c478bd9Sstevel@tonic-gate #define AC_FLOW_DSFIELD 6 /* dsfield */ 107*7c478bd9Sstevel@tonic-gate #define AC_FLOW_CTIME 7 /* creation time for this flow */ 108*7c478bd9Sstevel@tonic-gate #define AC_FLOW_LSEEN 8 /* pkt last seen for this flow */ 109*7c478bd9Sstevel@tonic-gate #define AC_FLOW_NBYTES 9 /* no. of bytes in this flow */ 110*7c478bd9Sstevel@tonic-gate #define AC_FLOW_NPKTS 10 /* no. of packets for this flow */ 111*7c478bd9Sstevel@tonic-gate #define AC_FLOW_PROJID 11 /* project id */ 112*7c478bd9Sstevel@tonic-gate #define AC_FLOW_UID 12 /* user id */ 113*7c478bd9Sstevel@tonic-gate #define AC_FLOW_ANAME 13 /* action instance name */ 114*7c478bd9Sstevel@tonic-gate #define AC_FLOW_MAX_RES 13 /* must be equal to the number above */ 115*7c478bd9Sstevel@tonic-gate 116*7c478bd9Sstevel@tonic-gate #define AC_MAX_RES_TMP MAX(AC_PROC_MAX_RES, AC_TASK_MAX_RES) 117*7c478bd9Sstevel@tonic-gate #define AC_MAX_RES MAX(AC_MAX_RES_TMP, AC_FLOW_MAX_RES) 118*7c478bd9Sstevel@tonic-gate #define AC_MASK_SZ BT_BITOUL(AC_MAX_RES + 1) 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate /* 121*7c478bd9Sstevel@tonic-gate * resource states 122*7c478bd9Sstevel@tonic-gate */ 123*7c478bd9Sstevel@tonic-gate #define AC_ON 1 /* enabled resource */ 124*7c478bd9Sstevel@tonic-gate #define AC_OFF 0 /* disabled resource */ 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate typedef struct ac_res { 127*7c478bd9Sstevel@tonic-gate int ar_id; /* resource ID */ 128*7c478bd9Sstevel@tonic-gate int ar_state; /* resource state; see above */ 129*7c478bd9Sstevel@tonic-gate } ac_res_t; 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate #ifdef _KERNEL 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 134*7c478bd9Sstevel@tonic-gate #include <sys/zone.h> 135*7c478bd9Sstevel@tonic-gate #include <sys/list.h> 136*7c478bd9Sstevel@tonic-gate 137*7c478bd9Sstevel@tonic-gate typedef struct ac_info { 138*7c478bd9Sstevel@tonic-gate kmutex_t ac_lock; /* protects the structure */ 139*7c478bd9Sstevel@tonic-gate vnode_t *ac_vnode; /* exacct file vnode pointer */ 140*7c478bd9Sstevel@tonic-gate char *ac_file; /* exacct file name */ 141*7c478bd9Sstevel@tonic-gate int ac_state; /* accounting state */ 142*7c478bd9Sstevel@tonic-gate ulong_t ac_mask[AC_MASK_SZ]; /* bitmask of resources */ 143*7c478bd9Sstevel@tonic-gate } ac_info_t; 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * Key used for retrieving per-zone exacct settings. This remains 147*7c478bd9Sstevel@tonic-gate * uninitialized (ZONE_KEY_UNINITIALIZED) until the acctctl module is loaded. 148*7c478bd9Sstevel@tonic-gate */ 149*7c478bd9Sstevel@tonic-gate extern zone_key_t exacct_zone_key; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate /* 152*7c478bd9Sstevel@tonic-gate * Per-zone exacct settings. Each zone may have its own settings for 153*7c478bd9Sstevel@tonic-gate * process, task, and flow accounting. 154*7c478bd9Sstevel@tonic-gate * 155*7c478bd9Sstevel@tonic-gate * Per-zone flow accounting has not yet been implemented, so this 156*7c478bd9Sstevel@tonic-gate * provides zones with the view that flow accounting in the zone hasn't 157*7c478bd9Sstevel@tonic-gate * been initialized (which is true). The various system calls will fail 158*7c478bd9Sstevel@tonic-gate * to set flow accounting parameters from within a zone. 159*7c478bd9Sstevel@tonic-gate * 160*7c478bd9Sstevel@tonic-gate * The global list of accounting settings is used when we check to see 161*7c478bd9Sstevel@tonic-gate * if the accounting file is already in use by any zone. 162*7c478bd9Sstevel@tonic-gate */ 163*7c478bd9Sstevel@tonic-gate struct exacct_globals { 164*7c478bd9Sstevel@tonic-gate ac_info_t ac_task; 165*7c478bd9Sstevel@tonic-gate ac_info_t ac_proc; 166*7c478bd9Sstevel@tonic-gate ac_info_t ac_flow; 167*7c478bd9Sstevel@tonic-gate list_node_t ac_link; 168*7c478bd9Sstevel@tonic-gate }; 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate #else 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gate extern int acctctl(int cmd, void *buf, size_t bufsz); 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate #endif /* ifdef _KERNEL */ 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 177*7c478bd9Sstevel@tonic-gate } 178*7c478bd9Sstevel@tonic-gate #endif 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate #endif /* _SYS_ACCTCTL_H */ 181