/* default buffer size */
#define CM_BUF_BLOCKSIZE CM_CONFIGDEFAULT_BLOCKSIZE
-/* default hash size */
-#define CM_BUF_HASHSIZE 1024
-
/* cache type */
#define CM_BUF_CACHETYPE_FILE 1
#define CM_BUF_CACHETYPE_VIRTUAL 2
extern int buf_cacheType;
/* force it to be signed so that mod comes out positive or 0 */
-#define BUF_HASH(fidp,offsetp) ((((fidp)->vnode+((fidp)->unique << 5) \
- +(fidp)->volume+(fidp)->cell \
- +((offsetp)->LowPart / cm_data.buf_blockSize)) \
- & 0x7fffffff) \
+#define BUF_HASH(fidp,offsetp) ((((fidp)->hash \
+ +(offsetp)->LowPart) / cm_data.buf_blockSize) \
% cm_data.buf_hashSize)
/* another hash fn */
-#define BUF_FILEHASH(fidp) ((((fidp)->vnode+((fidp)->unique << 5) \
- +(fidp)->volume+(fidp)->cell) \
- & 0x7fffffff) \
- % cm_data.buf_hashSize)
-
-/* backup over pointer to the buffer */
-#define BUF_OVERTOBUF(op) ((cm_buf_t *)(((char *)op) - ((long)(&((cm_buf_t *)0)->over))))
-
-#ifdef notdef
-/* pretend we have logs, too */
-typedef char cm_log_t;
-#endif
+#define BUF_FILEHASH(fidp) ((fidp)->hash % cm_data.buf_hashSize)
#define CM_BUF_MAGIC ('B' | 'U' <<8 | 'F'<<16 | 'F'<<24)
+#define CM_BUF_VERSION_BAD 0xFFFFFFFFFFFFFFFF
+
/* represents a single buffer */
typedef struct cm_buf {
osi_queue_t q; /* queue of all zero-refcount buffers */
*/
struct cm_buf *dirtyp; /* next in the dirty list */
osi_mutex_t mx; /* mutex protecting structure except refcount */
- unsigned long refCount; /* reference count (buf_globalLock) */
- long idCounter; /* counter for softrefs; bumped at each recycle */
- long dirtyCounter; /* bumped at each dirty->clean transition */
-#ifdef notdef
- cm_log_t *logp; /* log for this buffer, if any */
- osi_hyper_t lsn; /* lsn to force to (last LSN changing this buffer) */
-#endif /* notdef */
+ afs_int32 refCount; /* reference count (buf_globalLock) */
+ afs_uint32 dirtyCounter; /* bumped at each dirty->clean transition */
osi_hyper_t offset; /* offset */
cm_fid_t fid; /* file ID */
-#ifdef DEBUG
- cm_scache_t *scp; /* for debugging, the scache object belonging to */
- /* the fid at the time of fid assignment. */
-#endif
- long flags; /* flags we're using */
- long size; /* size in bytes of this buffer */
+ afs_uint32 flags; /* flags we're using */
char *datap; /* data in this buffer */
- unsigned long error; /* last error code, if CM_BUF_ERROR is set */
+ afs_uint32 error; /* last error code, if CM_BUF_ERROR is set */
cm_user_t *userp; /* user who wrote to the buffer last */
- OVERLAPPED over; /* overlapped structure for I/O */
/* fields added for the CM; locked by scp->mx */
- long dataVersion; /* data version of this page */
- long cmFlags; /* flags for cm */
+ afs_uint64 dataVersion; /* data version of this page */
+ afs_uint32 cmFlags; /* flags for cm */
+
+ /* syncop state */
+ afs_uint32 waitCount; /* number of threads waiting */
+ afs_uint32 waitRequests; /* num of thread wait requests */
+
+ afs_uint32 dirty_offset; /* offset from beginning of buffer containing dirty bytes */
+ afs_uint32 dirty_length; /* number of dirty bytes within the buffer */
+
#ifdef DISKCACHE95
cm_diskcache_t *dcp; /* diskcache structure */
#endif /* DISKCACHE95 */
-
- /* syncop state */
- afs_uint32 waitCount; /* number of threads waiting */
- afs_uint32 waitRequests; /* num of thread wait requests */
+#ifdef DEBUG
+ cm_scache_t *scp; /* for debugging, the scache object belonging to */
+ /* the fid at the time of fid assignment. */
+#else
+ void * dummy;
+#endif
} cm_buf_t;
/* values for cmFlags */
#define CM_BUF_CMFETCHING 1 /* fetching this buffer */
#define CM_BUF_CMSTORING 2 /* storing this buffer */
#define CM_BUF_CMFULLYFETCHED 4 /* read-while-fetching optimization */
-/* waiting is done based on scp->flags */
-
-/* represents soft reference which is OK to lose on a recycle */
-typedef struct cm_softRef {
- cm_buf_t *bufp; /* buffer (may get reused) */
- long counter; /* counter of changes to identity */
-} cm_softRef_t;
+#define CM_BUF_CMWRITING 8 /* writing to this buffer */
+/* waiting is done based on scp->flags. Removing bits from cmFlags
+ should be followed by waking the scp. */
#define CM_BUF_READING 1 /* now reading buffer from the disk */
#define CM_BUF_WRITING 2 /* now writing buffer to the disk */
#define CM_BUF_INHASH 4 /* in the hash table */
-#define CM_BUF_DIRTY 8 /* buffer is dirty */
-#define CM_BUF_INLRU 0x10 /* in lru queue */
-#define CM_BUF_ERROR 0x20 /* something went wrong on delayed write */
+#define CM_BUF_DIRTY 8 /* buffer is dirty */
+#define CM_BUF_INLRU 0x10 /* in lru queue */
+#define CM_BUF_ERROR 0x20 /* something went wrong on delayed write */
#define CM_BUF_WAITING 0x40 /* someone's waiting for a flag to change */
-#define CM_BUF_EVWAIT 0x80 /* someone's waiting for the buffer event */
-#define CM_BUF_EOF 0x100 /* read 0 bytes; used for detecting EOF */
+#define CM_BUF_INDL 0x80 /* in the dirty list */
+#define CM_BUF_EOF 0x100 /* read 0 bytes; used for detecting EOF */
+#define CM_BUF_REDIR 0x200 /* buffer held by the redirector */
typedef struct cm_buf_ops {
long (*Writep)(void *, osi_hyper_t *, long, long, struct cm_user *,
extern long buf_CountFreeList(void);
+#ifdef DEBUG_REFCOUNT
+extern void buf_ReleaseDbg(cm_buf_t *, char *, long);
+
+extern void buf_HoldDbg(cm_buf_t *, char *, long);
+
+extern void buf_ReleaseLockedDbg(cm_buf_t *, afs_uint32, char *, long);
+
+extern void buf_HoldLockedDbg(cm_buf_t *, char *, long);
+
+#define buf_Release(bufp) buf_ReleaseDbg(bufp, __FILE__, __LINE__)
+#define buf_Hold(bufp) buf_HoldDbg(bufp, __FILE__, __LINE__)
+#define buf_ReleaseLocked(bufp, lock) buf_ReleaseLockedDbg(bufp, lock, __FILE__, __LINE__)
+#define buf_HoldLocked(bufp) buf_HoldLockedDbg(bufp, __FILE__, __LINE__)
+#else
extern void buf_Release(cm_buf_t *);
extern void buf_Hold(cm_buf_t *);
-extern void buf_WaitIO(cm_scache_t *, cm_buf_t *);
-
-extern void buf_ReleaseLocked(cm_buf_t *);
+extern void buf_ReleaseLocked(cm_buf_t *, afs_uint32);
extern void buf_HoldLocked(cm_buf_t *);
+#endif
+
+extern void buf_WaitIO(cm_scache_t *, cm_buf_t *);
extern cm_buf_t *buf_FindLocked(struct cm_scache *, osi_hyper_t *);
extern cm_buf_t *buf_Find(struct cm_scache *, osi_hyper_t *);
-extern HANDLE buf_GetFileHandle(long);
-
-extern long buf_GetNewLocked(struct cm_scache *, osi_hyper_t *, cm_buf_t **);
+extern cm_buf_t *buf_FindAllLocked(struct cm_scache *, osi_hyper_t *, afs_uint32 flags);
+
+extern cm_buf_t *buf_FindAll(struct cm_scache *, osi_hyper_t *, afs_uint32 flags);
+
+extern long buf_GetNewLocked(struct cm_scache *, osi_hyper_t *, cm_req_t *, cm_buf_t **);
-extern long buf_Get(struct cm_scache *, osi_hyper_t *, cm_buf_t **);
+extern long buf_Get(struct cm_scache *, osi_hyper_t *, cm_req_t *, cm_buf_t **);
-extern long buf_GetNew(struct cm_scache *, osi_hyper_t *, cm_buf_t **);
+extern long buf_GetNew(struct cm_scache *, osi_hyper_t *, cm_req_t *, cm_buf_t **);
-extern long buf_CleanAsyncLocked(cm_buf_t *, cm_req_t *);
+extern afs_uint32 buf_CleanAsyncLocked(cm_buf_t *, cm_req_t *, afs_uint32 *);
-extern long buf_CleanAsync(cm_buf_t *, cm_req_t *);
+extern afs_uint32 buf_CleanAsync(cm_buf_t *, cm_req_t *, afs_uint32 *);
-extern void buf_CleanWait(cm_scache_t *, cm_buf_t *);
+extern void buf_CleanWait(cm_scache_t *, cm_buf_t *, afs_uint32 locked);
-extern void buf_SetDirty(cm_buf_t *);
+extern void buf_SetDirty(cm_buf_t *, afs_uint32 offset, afs_uint32 length, cm_user_t *);
extern long buf_CleanAndReset(void);
extern long buf_CleanDirtyBuffers(cm_scache_t *scp);
+extern long buf_ForceDataVersion(cm_scache_t * scp, afs_uint64 fromVersion, afs_uint64 toVersion);
+
+extern int cm_DumpBufHashTable(FILE *outputFile, char *cookie, int lock);
+
/* error codes */
#define CM_BUF_EXISTS 1 /* buffer exists, and shouldn't */
#endif /* _BUF_H__ENV_ */