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_FS_CACHEFS_FSCACHE_H 28*7c478bd9Sstevel@tonic-gate #define _SYS_FS_CACHEFS_FSCACHE_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 #define CFS_FS_FGP_BUCKET_SIZE 64 /* must be a power of 2 */ 37*7c478bd9Sstevel@tonic-gate #define CFS_FS_MAXIDLE 100 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate enum cachefs_connected { 40*7c478bd9Sstevel@tonic-gate CFS_CD_CONNECTED = 0x801, /* connected to back fs */ 41*7c478bd9Sstevel@tonic-gate CFS_CD_DISCONNECTED, /* disconnected from back fs */ 42*7c478bd9Sstevel@tonic-gate CFS_CD_RECONNECTING /* rolling log to back fs */ 43*7c478bd9Sstevel@tonic-gate }; 44*7c478bd9Sstevel@tonic-gate 45*7c478bd9Sstevel@tonic-gate typedef struct cachefs_stats { 46*7c478bd9Sstevel@tonic-gate uint_t st_hits; 47*7c478bd9Sstevel@tonic-gate uint_t st_misses; 48*7c478bd9Sstevel@tonic-gate uint_t st_passes; 49*7c478bd9Sstevel@tonic-gate uint_t st_fails; 50*7c478bd9Sstevel@tonic-gate uint_t st_modifies; 51*7c478bd9Sstevel@tonic-gate uint_t st_gc_count; 52*7c478bd9Sstevel@tonic-gate cfs_time_t st_gc_time; 53*7c478bd9Sstevel@tonic-gate cfs_time_t st_gc_before_atime; 54*7c478bd9Sstevel@tonic-gate cfs_time_t st_gc_after_atime; 55*7c478bd9Sstevel@tonic-gate } cachefs_stats_t; 56*7c478bd9Sstevel@tonic-gate 57*7c478bd9Sstevel@tonic-gate /* file system persistant state */ 58*7c478bd9Sstevel@tonic-gate struct cachefs_fsinfo { 59*7c478bd9Sstevel@tonic-gate uint_t fi_mntflags; /* mount flags */ 60*7c478bd9Sstevel@tonic-gate int fi_popsize; /* cache population size */ 61*7c478bd9Sstevel@tonic-gate ino64_t fi_root; /* inode # of root of fs */ 62*7c478bd9Sstevel@tonic-gate uint_t fi_resettimes; /* when to reset local times */ 63*7c478bd9Sstevel@tonic-gate uint_t fi_resetfileno; /* when to reset local fileno */ 64*7c478bd9Sstevel@tonic-gate ino64_t fi_localfileno; /* next local fileno to use */ 65*7c478bd9Sstevel@tonic-gate int fi_fgsize; /* filegrp size, default 256 */ 66*7c478bd9Sstevel@tonic-gate uint_t fi_pad[1]; /* pad field */ 67*7c478bd9Sstevel@tonic-gate }; 68*7c478bd9Sstevel@tonic-gate typedef struct cachefs_fsinfo cachefs_fsinfo_t; 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate /* 71*7c478bd9Sstevel@tonic-gate * used to translate the server's idea of inode numbers into the 72*7c478bd9Sstevel@tonic-gate * client's idea, after a reconnect, in a directory entry a la 73*7c478bd9Sstevel@tonic-gate * readdir() 74*7c478bd9Sstevel@tonic-gate */ 75*7c478bd9Sstevel@tonic-gate 76*7c478bd9Sstevel@tonic-gate typedef struct cachefs_inum_trans { 77*7c478bd9Sstevel@tonic-gate ino64_t cit_real; 78*7c478bd9Sstevel@tonic-gate ino64_t cit_fake; 79*7c478bd9Sstevel@tonic-gate } cachefs_inum_trans_t; 80*7c478bd9Sstevel@tonic-gate 81*7c478bd9Sstevel@tonic-gate extern int cachefs_hash_sizes[]; 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate /* 84*7c478bd9Sstevel@tonic-gate * fscache structure contains per-filesystem information, both filesystem 85*7c478bd9Sstevel@tonic-gate * cache directory information and mount-specific information. 86*7c478bd9Sstevel@tonic-gate */ 87*7c478bd9Sstevel@tonic-gate struct fscache { 88*7c478bd9Sstevel@tonic-gate ino64_t fs_cfsid; /* File system ID */ 89*7c478bd9Sstevel@tonic-gate int fs_flags; 90*7c478bd9Sstevel@tonic-gate struct vnode *fs_fscdirvp; /* vp to fs cache dir */ 91*7c478bd9Sstevel@tonic-gate struct vnode *fs_fsattrdir; /* vp to attrcache dir */ 92*7c478bd9Sstevel@tonic-gate struct vnode *fs_infovp; /* vp to fsinfo file */ 93*7c478bd9Sstevel@tonic-gate struct cachefscache *fs_cache; /* back ptr to cache struct */ 94*7c478bd9Sstevel@tonic-gate cachefs_fsinfo_t fs_info; /* fs persistant state */ 95*7c478bd9Sstevel@tonic-gate struct vfs *fs_cfsvfsp; /* cfs vfsp */ 96*7c478bd9Sstevel@tonic-gate struct vfs *fs_backvfsp; /* back file system vfsp */ 97*7c478bd9Sstevel@tonic-gate struct vnode *fs_rootvp; /* root vnode ptr */ 98*7c478bd9Sstevel@tonic-gate offset_t fs_offmax; /* maximum offset if backvp */ 99*7c478bd9Sstevel@tonic-gate int fs_ref; /* ref count on fscache */ 100*7c478bd9Sstevel@tonic-gate int fs_cnodecnt; /* cnt of cnodes on fscache */ 101*7c478bd9Sstevel@tonic-gate int fs_consttype; /* type of consistency check */ 102*7c478bd9Sstevel@tonic-gate struct cachefsops *fs_cfsops; /* cfsops vector pointer */ 103*7c478bd9Sstevel@tonic-gate uint_t fs_acregmin; /* same as nfs values */ 104*7c478bd9Sstevel@tonic-gate uint_t fs_acregmax; 105*7c478bd9Sstevel@tonic-gate uint_t fs_acdirmin; 106*7c478bd9Sstevel@tonic-gate uint_t fs_acdirmax; 107*7c478bd9Sstevel@tonic-gate struct fscache *fs_next; /* ptr to next fscache */ 108*7c478bd9Sstevel@tonic-gate struct cachefs_workq fs_workq; /* async thread work queue */ 109*7c478bd9Sstevel@tonic-gate 110*7c478bd9Sstevel@tonic-gate kmutex_t fs_fslock; /* contents lock */ 111*7c478bd9Sstevel@tonic-gate 112*7c478bd9Sstevel@tonic-gate struct vnode *fs_dlogfile; /* log file */ 113*7c478bd9Sstevel@tonic-gate off_t fs_dlogoff; /* offset into log file */ 114*7c478bd9Sstevel@tonic-gate uint_t fs_dlogseq; /* sequence number */ 115*7c478bd9Sstevel@tonic-gate struct vnode *fs_dmapfile; /* map file */ 116*7c478bd9Sstevel@tonic-gate off_t fs_dmapoff; /* offset into map file */ 117*7c478bd9Sstevel@tonic-gate off_t fs_dmapsize; /* size of map file */ 118*7c478bd9Sstevel@tonic-gate kmutex_t fs_dlock; /* protects d* variables */ 119*7c478bd9Sstevel@tonic-gate 120*7c478bd9Sstevel@tonic-gate kmutex_t fs_idlelock; /* idle* lock */ 121*7c478bd9Sstevel@tonic-gate int fs_idlecnt; /* number of idle cnodes */ 122*7c478bd9Sstevel@tonic-gate int fs_idleclean; /* cleaning idle list */ 123*7c478bd9Sstevel@tonic-gate struct cnode *fs_idlefront; /* front of idle list */ 124*7c478bd9Sstevel@tonic-gate 125*7c478bd9Sstevel@tonic-gate /* related to connected or disconnected (cd) */ 126*7c478bd9Sstevel@tonic-gate kmutex_t fs_cdlock; /* protects fs_cd* variables */ 127*7c478bd9Sstevel@tonic-gate kcondvar_t fs_cdwaitcv; /* signal state transitions */ 128*7c478bd9Sstevel@tonic-gate enum cachefs_connected fs_cdconnected; /* how connected to backfs */ 129*7c478bd9Sstevel@tonic-gate int fs_cdtransition; /* 1 transitioning, 0 not */ 130*7c478bd9Sstevel@tonic-gate pid_t fs_cddaemonid; /* pid of cachefsd */ 131*7c478bd9Sstevel@tonic-gate int fs_cdrefcnt; /* # threads in cachefs */ 132*7c478bd9Sstevel@tonic-gate 133*7c478bd9Sstevel@tonic-gate struct cnode *fs_idleback; /* back of idle list */ 134*7c478bd9Sstevel@tonic-gate 135*7c478bd9Sstevel@tonic-gate cachefs_inum_trans_t *fs_inum_trans; /* real->fake inums */ 136*7c478bd9Sstevel@tonic-gate int fs_inum_size; /* # fs_inum_trans alloced */ 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate /* list of fgps */ 139*7c478bd9Sstevel@tonic-gate struct filegrp *fs_filegrp[CFS_FS_FGP_BUCKET_SIZE]; 140*7c478bd9Sstevel@tonic-gate 141*7c478bd9Sstevel@tonic-gate timestruc_t fs_cod_time; /* time of CoD event */ 142*7c478bd9Sstevel@tonic-gate int fs_kstat_id; 143*7c478bd9Sstevel@tonic-gate cachefs_stats_t fs_stats; 144*7c478bd9Sstevel@tonic-gate char *fs_mntpt; 145*7c478bd9Sstevel@tonic-gate char *fs_hostname; 146*7c478bd9Sstevel@tonic-gate char *fs_backfsname; 147*7c478bd9Sstevel@tonic-gate }; 148*7c478bd9Sstevel@tonic-gate typedef struct fscache fscache_t; 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate extern struct kmem_cache *cachefs_fscache_cache; 151*7c478bd9Sstevel@tonic-gate 152*7c478bd9Sstevel@tonic-gate /* valid fscache flags */ 153*7c478bd9Sstevel@tonic-gate #define CFS_FS_MOUNTED 0x01 /* fscache is mounted */ 154*7c478bd9Sstevel@tonic-gate #define CFS_FS_READ 0x02 /* fscache can be read */ 155*7c478bd9Sstevel@tonic-gate #define CFS_FS_WRITE 0x04 /* fscache can be written */ 156*7c478bd9Sstevel@tonic-gate #define CFS_FS_ROOTFS 0x08 /* fscache is / */ 157*7c478bd9Sstevel@tonic-gate #define CFS_FS_DIRTYINFO 0x10 /* fs_info needs to be written */ 158*7c478bd9Sstevel@tonic-gate #define CFS_FS_HASHPRINT 0x20 /* hash warning already printed once */ 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gate /* types of consistency checking */ 161*7c478bd9Sstevel@tonic-gate #define CFS_FS_CONST_STRICT 11 /* strict consistency */ 162*7c478bd9Sstevel@tonic-gate #define CFS_FS_CONST_NOCONST 12 /* no consistency */ 163*7c478bd9Sstevel@tonic-gate #define CFS_FS_CONST_CODCONST 13 /* consistency on demand */ 164*7c478bd9Sstevel@tonic-gate 165*7c478bd9Sstevel@tonic-gate #define CFSOP_INIT_COBJECT(FSCP, CP, VAP, CR) \ 166*7c478bd9Sstevel@tonic-gate (*(FSCP)->fs_cfsops->co_init_cobject)(FSCP, CP, VAP, CR) 167*7c478bd9Sstevel@tonic-gate #define CFSOP_CHECK_COBJECT(FSCP, CP, WHAT, CR) \ 168*7c478bd9Sstevel@tonic-gate (*(FSCP)->fs_cfsops->co_check_cobject)(FSCP, CP, WHAT, CR) 169*7c478bd9Sstevel@tonic-gate #define CFSOP_MODIFY_COBJECT(FSCP, CP, CR) \ 170*7c478bd9Sstevel@tonic-gate (*(FSCP)->fs_cfsops->co_modify_cobject)(FSCP, CP, CR) 171*7c478bd9Sstevel@tonic-gate #define CFSOP_INVALIDATE_COBJECT(FSCP, CP, CR) \ 172*7c478bd9Sstevel@tonic-gate (*(FSCP)->fs_cfsops->co_invalidate_cobject)(FSCP, CP, CR) 173*7c478bd9Sstevel@tonic-gate #define CFSOP_CONVERT_COBJECT(FSCP, CP, CR) \ 174*7c478bd9Sstevel@tonic-gate (*(FSCP)->fs_cfsops->co_convert_cobject)(FSCP, CP, CR) 175*7c478bd9Sstevel@tonic-gate 176*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_SNR(FSCP) \ 177*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_DISCONNECTABLE) 178*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_SOFT(FSCP) \ 179*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_SOFT) 180*7c478bd9Sstevel@tonic-gate 181*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_WRITE_AROUND(FSCP) \ 182*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_WRITE_AROUND) 183*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_NONSHARED(FSCP) \ 184*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_NONSHARED) 185*7c478bd9Sstevel@tonic-gate 186*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_STRICT(FSCP) \ 187*7c478bd9Sstevel@tonic-gate (((FSCP)->fs_info.fi_mntflags & CFS_WRITE_AROUND) && \ 188*7c478bd9Sstevel@tonic-gate (((FSCP)->fs_info.fi_mntflags & \ 189*7c478bd9Sstevel@tonic-gate (CFS_NOCONST_MODE | CFS_CODCONST_MODE)) == 0)) 190*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_NOCONST(FSCP) \ 191*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_NOCONST_MODE) 192*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_CODCONST(FSCP) \ 193*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_CODCONST_MODE) 194*7c478bd9Sstevel@tonic-gate 195*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_LLOCK(FSCP) \ 196*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_LLOCK) 197*7c478bd9Sstevel@tonic-gate #define CFS_ISFS_BACKFS_NFSV4(FSCP) \ 198*7c478bd9Sstevel@tonic-gate ((FSCP)->fs_info.fi_mntflags & CFS_BACKFS_NFSV4) 199*7c478bd9Sstevel@tonic-gate 200*7c478bd9Sstevel@tonic-gate fscache_t *fscache_create(cachefscache_t *cachep); 201*7c478bd9Sstevel@tonic-gate void fscache_destory(fscache_t *fscp); 202*7c478bd9Sstevel@tonic-gate int fscache_activate(fscache_t *fscp, ino64_t fsid, char *namep, 203*7c478bd9Sstevel@tonic-gate struct cachefsoptions *optp, ino64_t backfileno); 204*7c478bd9Sstevel@tonic-gate int fscache_enable(fscache_t *fscp, ino64_t fsid, char *namep, 205*7c478bd9Sstevel@tonic-gate struct cachefsoptions *optp, ino64_t backfileno); 206*7c478bd9Sstevel@tonic-gate void fscache_activate_rw(fscache_t *fscp); 207*7c478bd9Sstevel@tonic-gate void fscache_hold(fscache_t *fscp); 208*7c478bd9Sstevel@tonic-gate void fscache_rele(fscache_t *fscp); 209*7c478bd9Sstevel@tonic-gate int fscache_cnodecnt(fscache_t *fscp, int cnt); 210*7c478bd9Sstevel@tonic-gate int fscache_mounted(fscache_t *fscp, struct vfs *cfsvfsp, struct vfs *backvfsp); 211*7c478bd9Sstevel@tonic-gate int fscache_compare_options(fscache_t *fscp, struct cachefsoptions *opnewp); 212*7c478bd9Sstevel@tonic-gate void fscache_sync(fscache_t *fscp); 213*7c478bd9Sstevel@tonic-gate void fscache_acset(fscache_t *fscp, 214*7c478bd9Sstevel@tonic-gate uint_t acregmin, uint_t acregmax, uint_t acdirmin, uint_t acdirmax); 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate fscache_t *fscache_list_find(cachefscache_t *cachep, ino64_t fsid); 217*7c478bd9Sstevel@tonic-gate void fscache_list_add(cachefscache_t *cachep, fscache_t *fscp); 218*7c478bd9Sstevel@tonic-gate void fscache_list_remove(cachefscache_t *cachep, fscache_t *fscp); 219*7c478bd9Sstevel@tonic-gate void fscache_list_gc(cachefscache_t *cachep); 220*7c478bd9Sstevel@tonic-gate int fscache_list_mounted(cachefscache_t *cachep); 221*7c478bd9Sstevel@tonic-gate 222*7c478bd9Sstevel@tonic-gate int fscache_name_to_fsid(cachefscache_t *cachep, char *namep, ino64_t *fsidp); 223*7c478bd9Sstevel@tonic-gate 224*7c478bd9Sstevel@tonic-gate int cachefs_cd_access(fscache_t *fscp, int waitconnected, int writing); 225*7c478bd9Sstevel@tonic-gate int cachefs_cd_access_miss(fscache_t *fscp); 226*7c478bd9Sstevel@tonic-gate void cachefs_cd_release(fscache_t *fscp); 227*7c478bd9Sstevel@tonic-gate void cachefs_cd_timedout(fscache_t *fscp); 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 230*7c478bd9Sstevel@tonic-gate } 231*7c478bd9Sstevel@tonic-gate #endif 232*7c478bd9Sstevel@tonic-gate 233*7c478bd9Sstevel@tonic-gate #endif /* _SYS_FS_CACHEFS_FSCACHE_H */ 234