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