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