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