xref: /titanic_44/usr/src/cmd/fs.d/cachefs/common/stats.h (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
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 1996-2002 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 _CACHEFS_LIB_STATS_H
28*7c478bd9Sstevel@tonic-gate #define	_CACHEFS_LIB_STATS_H
29*7c478bd9Sstevel@tonic-gate 
30*7c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
31*7c478bd9Sstevel@tonic-gate 
32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
33*7c478bd9Sstevel@tonic-gate extern "C" {
34*7c478bd9Sstevel@tonic-gate #endif
35*7c478bd9Sstevel@tonic-gate 
36*7c478bd9Sstevel@tonic-gate #include <stdio.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/ioctl.h>
39*7c478bd9Sstevel@tonic-gate #include <rpc/types.h>
40*7c478bd9Sstevel@tonic-gate #include <rpc/xdr.h>
41*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_fs.h>
42*7c478bd9Sstevel@tonic-gate #include <sys/fs/cachefs_log.h>
43*7c478bd9Sstevel@tonic-gate #include <kstat.h>
44*7c478bd9Sstevel@tonic-gate #include <ndbm.h>
45*7c478bd9Sstevel@tonic-gate 
46*7c478bd9Sstevel@tonic-gate #ifndef DEBUG
47*7c478bd9Sstevel@tonic-gate #define	NDEBUG
48*7c478bd9Sstevel@tonic-gate #endif /* DEBUG */
49*7c478bd9Sstevel@tonic-gate 
50*7c478bd9Sstevel@tonic-gate #define	STATS_MAGIC	54545
51*7c478bd9Sstevel@tonic-gate 
52*7c478bd9Sstevel@tonic-gate typedef struct stats_cookie {
53*7c478bd9Sstevel@tonic-gate 	int st_magic;
54*7c478bd9Sstevel@tonic-gate 
55*7c478bd9Sstevel@tonic-gate 	char *st_progname;
56*7c478bd9Sstevel@tonic-gate 
57*7c478bd9Sstevel@tonic-gate 	uint_t st_flags;	/* misc. flags */
58*7c478bd9Sstevel@tonic-gate 	int st_fsid;		/* id # for kstat `cachefs.#.stat' */
59*7c478bd9Sstevel@tonic-gate 
60*7c478bd9Sstevel@tonic-gate 	FILE *st_logstream;	/* stream for logfile */
61*7c478bd9Sstevel@tonic-gate 	XDR st_logxdr;
62*7c478bd9Sstevel@tonic-gate 	struct cachefs_log_logfile_header st_loghead;
63*7c478bd9Sstevel@tonic-gate 	char st_asciirec[BUFSIZ];
64*7c478bd9Sstevel@tonic-gate 
65*7c478bd9Sstevel@tonic-gate 	DBM *st_dbm;
66*7c478bd9Sstevel@tonic-gate 	char st_dbm_name[MAXPATHLEN];
67*7c478bd9Sstevel@tonic-gate 
68*7c478bd9Sstevel@tonic-gate 	int st_ws_init;
69*7c478bd9Sstevel@tonic-gate 	u_offset_t st_ws_current;
70*7c478bd9Sstevel@tonic-gate 	u_offset_t st_ws_high;
71*7c478bd9Sstevel@tonic-gate 	int st_ws_expensive;
72*7c478bd9Sstevel@tonic-gate 
73*7c478bd9Sstevel@tonic-gate 	char st_errorstr[BUFSIZ];
74*7c478bd9Sstevel@tonic-gate 	int st_errno;
75*7c478bd9Sstevel@tonic-gate 
76*7c478bd9Sstevel@tonic-gate 	kstat_ctl_t *st_kstat_cookie;
77*7c478bd9Sstevel@tonic-gate } stats_cookie_t;
78*7c478bd9Sstevel@tonic-gate 
79*7c478bd9Sstevel@tonic-gate /*
80*7c478bd9Sstevel@tonic-gate  * error types for the API (given by stats_errno())
81*7c478bd9Sstevel@tonic-gate  */
82*7c478bd9Sstevel@tonic-gate 
83*7c478bd9Sstevel@tonic-gate enum stats_error {
84*7c478bd9Sstevel@tonic-gate 	SE_NOERROR,	/* placeholder so no errors == 0 */
85*7c478bd9Sstevel@tonic-gate 	SE_INVAL,	/* invalid use of the API */
86*7c478bd9Sstevel@tonic-gate 	SE_NOMEM,	/* ran out of memory */
87*7c478bd9Sstevel@tonic-gate 	SE_FILE,	/* trouble with file i/o */
88*7c478bd9Sstevel@tonic-gate 	SE_CORRUPT,	/* trouble with a corrupt file */
89*7c478bd9Sstevel@tonic-gate 	SE_KERNEL	/* trouble coming from communication with the kernel */
90*7c478bd9Sstevel@tonic-gate };
91*7c478bd9Sstevel@tonic-gate 
92*7c478bd9Sstevel@tonic-gate /*
93*7c478bd9Sstevel@tonic-gate  * flags in cookie->st_flags
94*7c478bd9Sstevel@tonic-gate  */
95*7c478bd9Sstevel@tonic-gate 
96*7c478bd9Sstevel@tonic-gate #define	ST_VALID	0x0001 /* initialized completely */
97*7c478bd9Sstevel@tonic-gate #define	ST_BOUND	0x0002 /* bound to a particular filesystem or cache */
98*7c478bd9Sstevel@tonic-gate #define	ST_ERROR	0x0004 /* an error has occured */
99*7c478bd9Sstevel@tonic-gate #define	ST_LFOPEN	0x0008 /* logstream is open */
100*7c478bd9Sstevel@tonic-gate #define	ST_DBMOPEN	0x0010 /* dbm descriptor is open */
101*7c478bd9Sstevel@tonic-gate #define	ST_WSCOMP	0x0020 /* working set size computed */
102*7c478bd9Sstevel@tonic-gate 
103*7c478bd9Sstevel@tonic-gate /*
104*7c478bd9Sstevel@tonic-gate  * flags for logfile-to-workingset
105*7c478bd9Sstevel@tonic-gate  */
106*7c478bd9Sstevel@tonic-gate 
107*7c478bd9Sstevel@tonic-gate #define	GRI_ADD		0x01	/* we may have added to the alloc map	*/
108*7c478bd9Sstevel@tonic-gate #define	GRI_TRUNC	0x02	/* we may have truncated the alloc map	*/
109*7c478bd9Sstevel@tonic-gate #define	GRI_MODIFY	0x04	/* we modified this file		*/
110*7c478bd9Sstevel@tonic-gate #define	GRI_METADATA	0x08	/* we created metadata			*/
111*7c478bd9Sstevel@tonic-gate #define	GRI_EXPENSIVE	0x10	/* record indicates `expensive' logging */
112*7c478bd9Sstevel@tonic-gate 
113*7c478bd9Sstevel@tonic-gate /*
114*7c478bd9Sstevel@tonic-gate  * structures for logfile-to-workingset
115*7c478bd9Sstevel@tonic-gate  */
116*7c478bd9Sstevel@tonic-gate 
117*7c478bd9Sstevel@tonic-gate #define	FI_METADATA	0x01	/* this file has metadata */
118*7c478bd9Sstevel@tonic-gate 
119*7c478bd9Sstevel@tonic-gate /*
120*7c478bd9Sstevel@tonic-gate  * len and offset are now u_offset_t in sync with struct cachefs_allocmap in
121*7c478bd9Sstevel@tonic-gate  * file cachefs_fs.h
122*7c478bd9Sstevel@tonic-gate  */
123*7c478bd9Sstevel@tonic-gate typedef struct fid_info {
124*7c478bd9Sstevel@tonic-gate 	int fi_magic;
125*7c478bd9Sstevel@tonic-gate 
126*7c478bd9Sstevel@tonic-gate 	uint_t fi_flags;
127*7c478bd9Sstevel@tonic-gate 
128*7c478bd9Sstevel@tonic-gate 	caddr_t fi_vfsp;
129*7c478bd9Sstevel@tonic-gate 
130*7c478bd9Sstevel@tonic-gate 	uint_t fi_ent_n;
131*7c478bd9Sstevel@tonic-gate 	struct fid_info_allocent {
132*7c478bd9Sstevel@tonic-gate 		u_offset_t offset;
133*7c478bd9Sstevel@tonic-gate 		u_offset_t len;
134*7c478bd9Sstevel@tonic-gate 	} fi_ent[C_MAX_ALLOCINFO_SLOTS];
135*7c478bd9Sstevel@tonic-gate 
136*7c478bd9Sstevel@tonic-gate 	u_offset_t fi_total;
137*7c478bd9Sstevel@tonic-gate } fid_info;
138*7c478bd9Sstevel@tonic-gate 
139*7c478bd9Sstevel@tonic-gate #define	FI_MAGIC	(3748321)
140*7c478bd9Sstevel@tonic-gate 
141*7c478bd9Sstevel@tonic-gate typedef struct mount_info {
142*7c478bd9Sstevel@tonic-gate 	int mi_magic;
143*7c478bd9Sstevel@tonic-gate 
144*7c478bd9Sstevel@tonic-gate 	uint_t mi_mounted:1;
145*7c478bd9Sstevel@tonic-gate 	uint_t mi_used:1;
146*7c478bd9Sstevel@tonic-gate 
147*7c478bd9Sstevel@tonic-gate 	u_offset_t mi_current;
148*7c478bd9Sstevel@tonic-gate 	u_offset_t mi_high;
149*7c478bd9Sstevel@tonic-gate 
150*7c478bd9Sstevel@tonic-gate 	uint_t mi_flags;
151*7c478bd9Sstevel@tonic-gate 	uint_t mi_filegrp_size;
152*7c478bd9Sstevel@tonic-gate 	char mi_path[2];
153*7c478bd9Sstevel@tonic-gate } mount_info;
154*7c478bd9Sstevel@tonic-gate 
155*7c478bd9Sstevel@tonic-gate #define	MI_MAGIC	(837492)
156*7c478bd9Sstevel@tonic-gate 
157*7c478bd9Sstevel@tonic-gate /*
158*7c478bd9Sstevel@tonic-gate  * Define the maximum size of char mi_path[]
159*7c478bd9Sstevel@tonic-gate  *
160*7c478bd9Sstevel@tonic-gate  * The maximum size of mi_path is a path (MAXPATHLEN) and a cacheid
161*7c478bd9Sstevel@tonic-gate  * (C_MAX_MOUNT_FSCDIRNAME) plus terminating nulls (2).
162*7c478bd9Sstevel@tonic-gate  *
163*7c478bd9Sstevel@tonic-gate  * Additional space is allocated to mi_path at runtime using malloc().
164*7c478bd9Sstevel@tonic-gate  */
165*7c478bd9Sstevel@tonic-gate 
166*7c478bd9Sstevel@tonic-gate #define	MI_MAX_MI_PATH	(MAXPATHLEN + C_MAX_MOUNT_FSCDIRNAME + 2)
167*7c478bd9Sstevel@tonic-gate 
168*7c478bd9Sstevel@tonic-gate typedef struct filegrp_info {
169*7c478bd9Sstevel@tonic-gate 	int fg_magic;
170*7c478bd9Sstevel@tonic-gate 
171*7c478bd9Sstevel@tonic-gate 	uint_t fg_count;  /* high-water known # of attrcache entries */
172*7c478bd9Sstevel@tonic-gate 	uint_t fg_bcount; /* # of bits set in fg_bits */
173*7c478bd9Sstevel@tonic-gate 	uchar_t fg_bits[DEF_FILEGRP_SIZE / NBBY];
174*7c478bd9Sstevel@tonic-gate 
175*7c478bd9Sstevel@tonic-gate 	size_t fg_size;	 /* high-water attrcache size (MAXBSIZE ceiling) */
176*7c478bd9Sstevel@tonic-gate } fg_info;
177*7c478bd9Sstevel@tonic-gate 
178*7c478bd9Sstevel@tonic-gate #define	FG_MAGIC	(673492)
179*7c478bd9Sstevel@tonic-gate 
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate  * the cachefs stats (stats_*) API.
182*7c478bd9Sstevel@tonic-gate  */
183*7c478bd9Sstevel@tonic-gate 
184*7c478bd9Sstevel@tonic-gate /* stats_create.c */
185*7c478bd9Sstevel@tonic-gate stats_cookie_t *stats_create_mountpath(char *, char *);
186*7c478bd9Sstevel@tonic-gate stats_cookie_t *stats_create_unbound(char *);
187*7c478bd9Sstevel@tonic-gate cachefs_kstat_key_t *stats_next(stats_cookie_t *);
188*7c478bd9Sstevel@tonic-gate cachefs_kstat_key_t *stats_getkey(stats_cookie_t *);
189*7c478bd9Sstevel@tonic-gate void stats_destroy(stats_cookie_t *);
190*7c478bd9Sstevel@tonic-gate int stats_good(stats_cookie_t *);
191*7c478bd9Sstevel@tonic-gate char *stats_errorstr(stats_cookie_t *);
192*7c478bd9Sstevel@tonic-gate int stats_errno(stats_cookie_t *);
193*7c478bd9Sstevel@tonic-gate int stats_inerror(stats_cookie_t *);
194*7c478bd9Sstevel@tonic-gate void stats_perror(stats_cookie_t *, int, char *, ...);
195*7c478bd9Sstevel@tonic-gate 
196*7c478bd9Sstevel@tonic-gate /* stats_log.c */
197*7c478bd9Sstevel@tonic-gate int stats_log_kernel_setname(stats_cookie_t *, char *);
198*7c478bd9Sstevel@tonic-gate int stats_log_which(stats_cookie_t *, int, int);
199*7c478bd9Sstevel@tonic-gate char *stats_log_kernel_getname(stats_cookie_t *);
200*7c478bd9Sstevel@tonic-gate int stats_log_logfile_open(stats_cookie_t *, char *);
201*7c478bd9Sstevel@tonic-gate void *stats_log_logfile_read(stats_cookie_t *, int *);
202*7c478bd9Sstevel@tonic-gate char *stats_log_record_toascii(stats_cookie_t *, void *);
203*7c478bd9Sstevel@tonic-gate uint_t stats_log_get_record_info(stats_cookie_t *,
204*7c478bd9Sstevel@tonic-gate     void *, caddr_t *, cfs_fid_t **, ino64_t *, u_offset_t *, u_offset_t *);
205*7c478bd9Sstevel@tonic-gate void stats_log_fi_add(stats_cookie_t *, fid_info *, u_offset_t, u_offset_t);
206*7c478bd9Sstevel@tonic-gate void stats_log_fi_trunc(stats_cookie_t *, fid_info *, u_offset_t, u_offset_t);
207*7c478bd9Sstevel@tonic-gate struct cachefs_log_logfile_header *stats_log_getheader(stats_cookie_t *);
208*7c478bd9Sstevel@tonic-gate void stats_log_compute_wssize(stats_cookie_t *);
209*7c478bd9Sstevel@tonic-gate int stats_log_wssize_init(stats_cookie_t *);
210*7c478bd9Sstevel@tonic-gate u_offset_t stats_log_wssize_current(stats_cookie_t *);
211*7c478bd9Sstevel@tonic-gate u_offset_t stats_log_wssize_high(stats_cookie_t *);
212*7c478bd9Sstevel@tonic-gate int stats_log_wssize_expensive(stats_cookie_t *);
213*7c478bd9Sstevel@tonic-gate 
214*7c478bd9Sstevel@tonic-gate /* stats_stats.c */
215*7c478bd9Sstevel@tonic-gate uint_t stats_hits(stats_cookie_t *);
216*7c478bd9Sstevel@tonic-gate uint_t stats_misses(stats_cookie_t *);
217*7c478bd9Sstevel@tonic-gate uint_t stats_passes(stats_cookie_t *);
218*7c478bd9Sstevel@tonic-gate uint_t stats_fails(stats_cookie_t *);
219*7c478bd9Sstevel@tonic-gate uint_t stats_modifies(stats_cookie_t *);
220*7c478bd9Sstevel@tonic-gate uint_t stats_gc_count(stats_cookie_t *);
221*7c478bd9Sstevel@tonic-gate time_t stats_gc_time(stats_cookie_t *);
222*7c478bd9Sstevel@tonic-gate time_t stats_gc_before(stats_cookie_t *);
223*7c478bd9Sstevel@tonic-gate time_t stats_gc_after(stats_cookie_t *);
224*7c478bd9Sstevel@tonic-gate int stats_zero_stats(stats_cookie_t *);
225*7c478bd9Sstevel@tonic-gate 
226*7c478bd9Sstevel@tonic-gate /* stats_dbm.c */
227*7c478bd9Sstevel@tonic-gate void stats_dbm_open(stats_cookie_t *);
228*7c478bd9Sstevel@tonic-gate void stats_dbm_rm(stats_cookie_t *);
229*7c478bd9Sstevel@tonic-gate void stats_dbm_close(stats_cookie_t *);
230*7c478bd9Sstevel@tonic-gate fid_info *stats_dbm_fetch_byfid(stats_cookie_t *, cfs_fid_t *);
231*7c478bd9Sstevel@tonic-gate void stats_dbm_store_byfid(stats_cookie_t *, cfs_fid_t *, fid_info *);
232*7c478bd9Sstevel@tonic-gate mount_info *stats_dbm_fetch_byvfsp(stats_cookie_t *, caddr_t);
233*7c478bd9Sstevel@tonic-gate void stats_dbm_store_byvfsp(stats_cookie_t *, caddr_t, mount_info *);
234*7c478bd9Sstevel@tonic-gate void stats_dbm_delete_byvfsp(stats_cookie_t *, caddr_t);
235*7c478bd9Sstevel@tonic-gate size_t stats_dbm_attrcache_addsize(stats_cookie_t *, mount_info *,
236*7c478bd9Sstevel@tonic-gate     ino64_t, uint_t);
237*7c478bd9Sstevel@tonic-gate datum stats_dbm_firstkey(stats_cookie_t *);
238*7c478bd9Sstevel@tonic-gate datum stats_dbm_nextkey(stats_cookie_t *);
239*7c478bd9Sstevel@tonic-gate 
240*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus
241*7c478bd9Sstevel@tonic-gate }
242*7c478bd9Sstevel@tonic-gate #endif
243*7c478bd9Sstevel@tonic-gate 
244*7c478bd9Sstevel@tonic-gate #endif /* _CACHEFS_LIB_STATS_H */
245