OpenAFS
OpenAFS distributed network file system
|
00001 /* 00002 * Copyright 2000, International Business Machines Corporation and others. 00003 * All Rights Reserved. 00004 * 00005 * This software has been released under the terms of the IBM Public 00006 * License. For details, see the LICENSE file in the top-level source 00007 * directory or online at http://www.openafs.org/dl/license10.html 00008 */ 00009 00010 /* Copyright (C) 1994 Cazamar Systems, Inc. */ 00011 00012 #ifndef OPENAFS_WINNT_AFSD_BUF_H 00013 #define OPENAFS_WINNT_AFSD_BUF_H 1 00014 00015 #include <osi.h> 00016 #include <opr/jhash.h> 00017 00018 #ifdef DISKCACHE95 00019 #include "cm_diskcache.h" 00020 #endif /* DISKCACHE95 */ 00021 00022 /* default # of buffers if not changed */ 00023 #define CM_BUF_BUFFERS 100 00024 00025 /* default buffer size */ 00026 #define CM_BUF_BLOCKSIZE CM_CONFIGDEFAULT_BLOCKSIZE 00027 00028 /* cache type */ 00029 #define CM_BUF_CACHETYPE_FILE 1 00030 #define CM_BUF_CACHETYPE_VIRTUAL 2 00031 extern int buf_cacheType; 00032 00033 #define BUF_HASH(fidp, offsetp) \ 00034 (opr_jhash((uint32_t *)(offsetp), 2, (fidp)->hash) & (cm_data.buf_hashSize - 1)) 00035 00036 #define BUF_FILEHASH(fidp) ((fidp)->hash & (cm_data.buf_hashSize - 1)) 00037 00038 #define CM_BUF_MAGIC ('B' | 'U' <<8 | 'F'<<16 | 'F'<<24) 00039 00040 #define CM_BUF_VERSION_BAD 0xFFFFFFFFFFFFFFFF 00041 00042 /* represents a single buffer */ 00043 typedef struct cm_buf { 00044 osi_queue_t q; /* queue: buf_freeList and buf_redirList */ 00045 afs_uint32 qFlags; /* queue/hash state flags - buf_globalLock */ 00046 afs_uint32 magic; 00047 struct cm_buf *allp; /* next in all list */ 00048 struct cm_buf *hashp; /* hash bucket pointer */ 00049 struct cm_buf *fileHashp; /* file hash bucket pointer */ 00050 struct cm_buf *fileHashBackp; /* file hash bucket back pointer */ 00051 /* 00052 * The file hash chain is doubly linked, since 00053 * these chains can get rather long. The 00054 * regular hash chain is only singly linked, 00055 * since the chains should be short if the 00056 * hash function is good and if there are 00057 * enough buckets for the size of the cache. 00058 */ 00059 struct cm_buf *dirtyp; /* next in the dirty list */ 00060 osi_mutex_t mx; /* mutex protecting structure except refcount */ 00061 afs_int32 refCount; /* reference count (buf_globalLock) */ 00062 afs_uint32 dirtyCounter; /* bumped at each dirty->clean transition */ 00063 osi_hyper_t offset; /* offset */ 00064 cm_fid_t fid; /* file ID */ 00065 char *datap; /* data in this buffer */ 00066 afs_uint32 flags; /* flags we're using - mx */ 00067 afs_uint32 error; /* last error code, if CM_BUF_ERROR is set */ 00068 cm_user_t *userp; /* user who wrote to the buffer last */ 00069 00070 /* fields added for the CM; locked by scp->mx */ 00071 afs_uint64 dataVersion; /* data version of this page */ 00072 afs_uint32 cmFlags; /* flags for cm */ 00073 00074 /* syncop state */ 00075 afs_uint32 waitCount; /* number of threads waiting */ 00076 afs_uint32 waitRequests; /* num of thread wait requests */ 00077 00078 afs_uint32 dirty_offset; /* offset from beginning of buffer containing dirty bytes */ 00079 afs_uint32 dirty_length; /* number of dirty bytes within the buffer */ 00080 00081 #ifdef DISKCACHE95 00082 cm_diskcache_t *dcp; /* diskcache structure */ 00083 #endif /* DISKCACHE95 */ 00084 #ifdef DEBUG 00085 cm_scache_t *scp; /* for debugging, the scache object belonging to */ 00086 /* the fid at the time of fid assignment. */ 00087 #else 00088 void * dummy; 00089 #endif 00090 00091 /* redirector state - protected by buf_globalLock */ 00092 osi_queue_t redirq; /* queue: cm_scache_t redirList */ 00093 time_t redirLastAccess;/* last time redir accessed the buffer */ 00094 time_t redirReleaseRequested; 00095 00096 unsigned char md5cksum[16]; /* md5 checksum of the block pointed to by datap */ 00097 } cm_buf_t; 00098 00099 #define redirq_to_cm_buf_t(q) ((q) ? (cm_buf_t *)((char *) (q) - offsetof(cm_buf_t, redirq)) : NULL) 00100 00101 /* values for cmFlags */ 00102 #define CM_BUF_CMFETCHING 1 /* fetching this buffer */ 00103 #define CM_BUF_CMSTORING 2 /* storing this buffer */ 00104 #define CM_BUF_CMFULLYFETCHED 4 /* read-while-fetching optimization */ 00105 #define CM_BUF_CMWRITING 8 /* writing to this buffer */ 00106 /* waiting is done based on scp->flags. Removing bits from cmFlags 00107 should be followed by waking the scp. */ 00108 00109 /* values for qFlags */ 00110 #define CM_BUF_QINHASH 1 /* in the hash table */ 00111 #define CM_BUF_QINLRU 2 /* in lru queue (aka free list) */ 00112 #define CM_BUF_QINDL 4 /* in the dirty list */ 00113 #define CM_BUF_QREDIR 8 /* buffer held by the redirector */ 00114 00115 /* values for flags */ 00116 #define CM_BUF_READING 1 /* now reading buffer from the disk */ 00117 #define CM_BUF_WRITING 2 /* now writing buffer to the disk */ 00118 #define CM_BUF_DIRTY 8 /* buffer is dirty */ 00119 #define CM_BUF_ERROR 0x20 /* something went wrong on delayed write */ 00120 #define CM_BUF_WAITING 0x40 /* someone's waiting for a flag to change */ 00121 #define CM_BUF_EOF 0x80 /* read 0 bytes; used for detecting EOF */ 00122 00123 typedef struct cm_buf_ops { 00124 long (*Writep)(void *vscp, osi_hyper_t *offsetp, 00125 long length, long flags, 00126 struct cm_user *userp, 00127 struct cm_req *reqp); 00128 long (*Readp)(cm_buf_t *bufp, long length, 00129 long *bytesReadp, struct cm_user *userp); 00130 long (*Stabilizep)(void *vscp, struct cm_user *userp, struct cm_req *reqp); 00131 long (*Unstabilizep)(void *vscp, struct cm_user *userp); 00132 } cm_buf_ops_t; 00133 00134 #define CM_BUF_WRITE_SCP_LOCKED 0x1 00135 00136 /* global locks */ 00137 extern osi_rwlock_t buf_globalLock; 00138 00139 extern long buf_Init(int newFile, cm_buf_ops_t *, afs_uint64 nbuffers); 00140 00141 extern void buf_Shutdown(void); 00142 00143 #ifdef DEBUG_REFCOUNT 00144 extern void buf_ReleaseDbg(cm_buf_t *, char *, long); 00145 00146 extern void buf_HoldDbg(cm_buf_t *, char *, long); 00147 00148 extern void buf_ReleaseLockedDbg(cm_buf_t *, afs_uint32, char *, long); 00149 00150 extern void buf_HoldLockedDbg(cm_buf_t *, char *, long); 00151 00152 #define buf_Release(bufp) buf_ReleaseDbg(bufp, __FILE__, __LINE__) 00153 #define buf_Hold(bufp) buf_HoldDbg(bufp, __FILE__, __LINE__) 00154 #define buf_ReleaseLocked(bufp, lock) buf_ReleaseLockedDbg(bufp, lock, __FILE__, __LINE__) 00155 #define buf_HoldLocked(bufp) buf_HoldLockedDbg(bufp, __FILE__, __LINE__) 00156 #else 00157 extern void buf_Release(cm_buf_t *); 00158 00159 extern void buf_Hold(cm_buf_t *); 00160 00161 extern void buf_ReleaseLocked(cm_buf_t *, afs_uint32); 00162 00163 extern void buf_HoldLocked(cm_buf_t *); 00164 #endif 00165 00166 extern void buf_WaitIO(cm_scache_t *, cm_buf_t *); 00167 00168 extern cm_buf_t *buf_FindLocked(struct cm_fid *, osi_hyper_t *); 00169 00170 extern cm_buf_t *buf_Find(struct cm_fid *, osi_hyper_t *); 00171 00172 extern cm_buf_t *buf_FindAllLocked(struct cm_fid *, osi_hyper_t *, afs_uint32 flags); 00173 00174 extern cm_buf_t *buf_FindAll(struct cm_fid *, osi_hyper_t *, afs_uint32 flags); 00175 00176 extern long buf_GetNewLocked(struct cm_scache *, osi_hyper_t *, cm_req_t *, cm_buf_t **); 00177 00178 extern long buf_Get(struct cm_scache *, osi_hyper_t *, cm_req_t *, cm_buf_t **); 00179 00180 extern afs_uint32 buf_CleanLocked(cm_scache_t *, cm_buf_t *, cm_req_t *, afs_uint32 flags, afs_uint32 *); 00181 00182 extern afs_uint32 buf_Clean(cm_scache_t *, cm_buf_t *, cm_req_t *, afs_uint32 flags, afs_uint32 *); 00183 00184 extern void buf_CleanWait(cm_scache_t *, cm_buf_t *, afs_uint32 locked); 00185 00186 extern void buf_SetDirty(cm_buf_t *, cm_req_t *, afs_uint32 offset, afs_uint32 length, cm_user_t *); 00187 00188 extern long buf_CleanAndReset(void); 00189 00190 extern void buf_ReserveBuffers(afs_uint64); 00191 00192 extern int buf_TryReserveBuffers(afs_uint64); 00193 00194 extern void buf_UnreserveBuffers(afs_uint64); 00195 00196 #ifdef TESTING 00197 extern void buf_ValidateBufQueues(void); 00198 #endif /* TESTING */ 00199 00200 extern osi_log_t *buf_logp; 00201 00202 extern long buf_Truncate(struct cm_scache *scp, cm_user_t *userp, 00203 cm_req_t *reqp, osi_hyper_t *sizep); 00204 00205 extern long buf_CleanVnode(struct cm_scache *scp, cm_user_t *userp, 00206 cm_req_t *reqp); 00207 00208 extern long buf_FlushCleanPages(cm_scache_t *scp, cm_user_t *userp, 00209 cm_req_t *reqp); 00210 00211 extern long buf_SetNBuffers(afs_uint64 nbuffers); 00212 00213 extern long buf_ValidateBuffers(void); 00214 00215 extern void buf_ForceTrace(BOOL flush); 00216 00217 extern long buf_DirtyBuffersExist(cm_fid_t * fidp); 00218 00219 extern long buf_CleanDirtyBuffers(cm_scache_t *scp); 00220 00221 extern long buf_InvalidateBuffers(cm_scache_t * scp); 00222 00223 extern long buf_RDRBuffersExist(cm_fid_t *fidp); 00224 00225 extern long buf_ClearRDRFlag(cm_scache_t *scp, char * reason); 00226 00227 extern long buf_ForceDataVersion(cm_scache_t * scp, afs_uint64 fromVersion, afs_uint64 toVersion); 00228 00229 extern int cm_DumpBufHashTable(FILE *outputFile, char *cookie, int lock); 00230 00231 extern void buf_ComputeCheckSum(cm_buf_t *bp); 00232 00233 extern int buf_ValidateCheckSum(cm_buf_t *bp); 00234 00235 extern const char *buf_HexCheckSum(cm_buf_t * bp); 00236 00237 extern afs_uint32 00238 buf_RDRShakeSomeExtentsFree(cm_req_t *reqp, afs_uint32 oneFid, afs_uint32 minage); 00239 00240 extern afs_uint32 00241 buf_RDRShakeAnExtentFree(cm_buf_t *bufp, cm_req_t *reqp); 00242 00243 extern afs_uint32 00244 buf_RDRShakeFileExtentsFree(cm_scache_t *scp, cm_req_t *reqp); 00245 00246 extern void 00247 buf_InsertToRedirQueue(cm_scache_t *scp, cm_buf_t *bufp); 00248 00249 extern void 00250 buf_RemoveFromRedirQueue(cm_scache_t *scp, cm_buf_t *bufp); 00251 00252 extern void 00253 buf_MoveToHeadOfRedirQueue(cm_scache_t *scp, cm_buf_t *bufp); 00254 00255 #ifdef _M_IX86 00256 #define buf_IncrementRedirCount() InterlockedIncrement(&cm_data.buf_redirCount) 00257 #define buf_DecrementRedirCount() InterlockedDecrement(&cm_data.buf_redirCount) 00258 #define buf_IncrementFreeCount() InterlockedIncrement(&cm_data.buf_freeCount) 00259 #define buf_DecrementFreeCount() InterlockedDecrement(&cm_data.buf_freeCount) 00260 #else 00261 #define buf_IncrementRedirCount() InterlockedIncrement64(&cm_data.buf_redirCount) 00262 #define buf_DecrementRedirCount() InterlockedDecrement64(&cm_data.buf_redirCount) 00263 #define buf_IncrementFreeCount() InterlockedIncrement64(&cm_data.buf_freeCount) 00264 #define buf_DecrementFreeCount() InterlockedDecrement64(&cm_data.buf_freeCount) 00265 #endif 00266 00267 /* error codes */ 00268 #define CM_BUF_EXISTS 1 /* buffer exists, and shouldn't */ 00269 00270 #endif /* OPENAFS_WINNT_AFSD_BUF_H */