afs: Never use GetNewDSlot after init
[openafs.git] / src / afs / afs_chunkops.h
index fa246da..3babf89 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Copyright 2000, International Business Machines Corporation and others.
  * All Rights Reserved.
- * 
+ *
  * This software has been released under the terms of the IBM Public
  * License.  For details, see the LICENSE file in the top-level source
  * directory or online at http://www.openafs.org/dl/license10.html
       Chunks are 0 based and go up by exactly 1, covering the file.
       The other fields are internal and shouldn't be used */
 /* basic parameters */
-#ifdef AFS_NOCHUNKING
-
-#define        AFS_OTHERCSIZE  0x10000
-#define        AFS_LOGCHUNK    16
-#define        AFS_FIRSTCSIZE  0x40000000
-
-#else /* AFS_NOCHUNKING */
-
-extern afs_int32 afs_OtherCSize, afs_LogChunk, afs_FirstCSize;
-#ifdef AFS_64BIT_CLIENT
-#ifdef AFS_VM_RDWR_ENV
-extern afs_size_t afs_vmMappingEnd;
-#endif /* AFS_VM_RDWR_ENV */
-#endif /* AFS_64BIT_CLIENT */
 
 #define AFS_OTHERCSIZE  (afs_OtherCSize)
 #define AFS_LOGCHUNK    (afs_LogChunk)
@@ -40,24 +26,6 @@ extern afs_size_t afs_vmMappingEnd;
 #define AFS_DEFAULTCSIZE 0x10000
 #define AFS_DEFAULTLSIZE 16
 
-#endif /* AFS_NOCHUNKING */
-
-#define AFS_MINCHUNK 13  /* 8k is minimum */
-#define AFS_MAXCHUNK 18  /* 256K is maximum */
-
-#ifdef notdef
-extern int afs_ChunkOffset(), afs_Chunk(), afs_ChunkBase(), afs_ChunkSize(), 
-    afs_ChunkToBase(), afs_ChunkToSize();
-
-/* macros */
-#define        AFS_CHUNKOFFSET(x) afs_ChunkOffset(x)
-#define        AFS_CHUNK(x) afs_Chunk(x)
-#define        AFS_CHUNKBASE(x) afs_ChunkBase(x)
-#define        AFS_CHUNKSIZE(x) afs_ChunkSize(x)
-#define        AFS_CHUNKTOBASE(x) afs_ChunkToBase(x)
-#define        AFS_CHUNKTOSIZE(x) afs_ChunkToSize(x)
-#endif
-
 #define AFS_CHUNKOFFSET(offset) ((offset < afs_FirstCSize) ? offset : \
                         ((offset - afs_FirstCSize) & (afs_OtherCSize - 1)))
 
@@ -79,28 +47,22 @@ extern int afs_ChunkOffset(), afs_Chunk(), afs_ChunkBase(), afs_ChunkSize(),
 #define AFS_SETCHUNKSIZE(chunk) { afs_LogChunk = chunk; \
                      afs_FirstCSize = afs_OtherCSize = (1 << chunk);  }
 
-
-extern void afs_CacheTruncateDaemon();
-
 /*
- * Functions exported by a cache type 
+ * Functions exported by a cache type
  */
 
-extern struct afs_cacheOps *afs_cacheType;
-
 struct afs_cacheOps {
-    void *(*open)();
-    int (*truncate)();
-    int (*fread)();
-    int (*fwrite)();
-    int (*close)();
-    int (*vread)();
-    int (*vwrite)();
-    int (*FetchProc)();
-    int (*StoreProc)();
-    struct dcache *(*GetDSlot)();
-    struct volume *(*GetVolSlot)();
-    int (*HandleLink)();
+    void *(*open) (afs_dcache_id_t *ainode);
+    int (*truncate) (struct osi_file * fp, afs_int32 len);
+    int (*fread) (struct osi_file * fp, int offset, void *buf, afs_int32 len);
+    int (*fwrite) (struct osi_file * fp, afs_int32 offset, void *buf,
+                  afs_int32 len);
+    int (*close) (struct osi_file * fp);
+    int (*vreadUIO) (afs_dcache_id_t *, struct uio *);
+    int (*vwriteUIO) (struct vcache *, afs_dcache_id_t *, struct uio *);
+    struct dcache *(*GetDSlot) (afs_int32 aslot, int indexvalid, int datavalid);
+    struct volume *(*GetVolSlot) (void);
+    int (*HandleLink) (struct vcache * avc, struct vrequest * areq);
 };
 
 /* Ideally we should have used consistent naming - like COP_OPEN, COP_TRUNCATE, etc. */
@@ -109,16 +71,35 @@ struct afs_cacheOps {
 #define        afs_CFileRead(file, offset, data, size) (*(afs_cacheType->fread))(file, offset, data, size)
 #define        afs_CFileWrite(file, offset, data, size) (*(afs_cacheType->fwrite))(file, offset, data, size)
 #define        afs_CFileClose(handle)          (*(afs_cacheType->close))(handle)
-#define        afs_GetDSlot(slot, adc)         (*(afs_cacheType->GetDSlot))(slot, adc)
 #define        afs_GetVolSlot()                (*(afs_cacheType->GetVolSlot))()
 #define        afs_HandleLink(avc, areq)       (*(afs_cacheType->HandleLink))(avc, areq)
 
-#define        afs_CacheFetchProc(call, file, base, adc, avc, toxfer, xfered, length) \
-          (*(afs_cacheType->FetchProc))(call, file, (afs_size_t)base, adc, avc, (afs_size_t *)toxfer, (afs_size_t *)xfered, length)
-#define        afs_CacheStoreProc(call, file, bytes, avc, wake, toxfer, xfered) \
-          (*(afs_cacheType->StoreProc))(call, file, bytes, avc, wake, toxfer, xfered)
-
-#endif /* AFS_CHUNKOPS */
-
+/* Use afs_GetValidDSlot to get a dcache from a dcache slot number when we
+ * know the dcache contains data we want (e.g. it's on the hash table) */
+#define        afs_GetValidDSlot(slot) (*(afs_cacheType->GetDSlot))(slot, 1, 1)
+/* Use afs_GetUnusedDSlot when loading a dcache entry that is on the free or
+ * discard lists (the dcache does not contain valid data, but we know the
+ * dcache entry itself exists). */
+#define        afs_GetUnusedDSlot(slot)        (*(afs_cacheType->GetDSlot))(slot, 1, 0)
+/* Use afs_GetNewDSlot only when initializing dcache slots (the given slot
+ * number may not exist at all). */
+#define        afs_GetNewDSlot(slot)   (*(afs_cacheType->GetDSlot))(slot, 0, 0)
+
+/* These memcpys should get optimised to simple assignments when afs_dcache_id_t
+ * is simple */
+static_inline void afs_copy_inode(afs_dcache_id_t *dst, afs_dcache_id_t *src) {
+    memcpy(dst, src, sizeof(afs_dcache_id_t));
+}
+
+static_inline void afs_reset_inode(afs_dcache_id_t *i) {
+    memset(i, 0, sizeof(afs_dcache_id_t));
+}
+
+/* We need to have something we can output as the 'inode' for fstrace calls.
+ * This is a hack */
+static_inline int afs_inode2trace(afs_dcache_id_t *i) {
+    return i->mem;
+}
 
 
+#endif /* AFS_CHUNKOPS */