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