Windows: fix build with DEBUG_REFCOUNT
[openafs.git] / src / WINNT / afsd / cm_scache.h
index b32a1e9..c01dfc8 100644 (file)
@@ -1,14 +1,16 @@
 /*
  * 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
  */
 
-#ifndef __CM_SCACHE_H_ENV__
-#define __CM_SCACHE_H_ENV__ 1
+#ifndef OPENAFS_WINNT_AFSD_CM_SCACHE_H
+#define OPENAFS_WINNT_AFSD_CM_SCACHE_H 1
+
+#include <opr/jhash.h>
 
 #define MOUNTPOINTLEN   1024    /* max path length for symlink; same as AFSPATHMAX */
 
@@ -26,7 +28,7 @@ typedef struct cm_fid {
 typedef struct cm_key {
     afs_offs_t process_id;      /* process IDs can be 64bit on 64bit environments */
     afs_uint16 session_id;
-    afs_uint16 file_id;
+    afs_uint64 file_id;         /* afs redir uses File Object pointers as file id */
 } cm_key_t;
 
 typedef struct cm_range {
@@ -43,7 +45,7 @@ typedef struct cm_file_lock {
                                    cm_scacheLock] */
     osi_queue_t fileq;         /* per-file list of locks [protected
                                    by scp->rw]*/
-    
+
     cm_user_t *userp;           /* The user to which this lock belongs
                                    to [immutable; held] */
     cm_scache_t *scp;           /* The scache to which this lock
@@ -62,6 +64,8 @@ typedef struct cm_file_lock {
                                  * cm_scacheLock] */
 } cm_file_lock_t;
 
+#define fileq_to_cm_file_lock_t(q) ((cm_file_lock_t *)((char *) (q) - offsetof(cm_file_lock_t, fileq)))
+
 #define CM_FILELOCK_FLAG_DELETED         0x01
 #define CM_FILELOCK_FLAG_LOST            0x02
 
@@ -123,7 +127,8 @@ typedef struct cm_scache {
     afs_uint32 unixModeBits;           /* unix protection mode bits */
     afs_uint32 linkCount;              /* link count */
     afs_uint64 dataVersion;            /* data version */
-    afs_uint64 bufDataVersionLow;       /* range of valid cm_buf_t dataVersions */
+    afs_uint64 bufDataVersionLow;       /* range of valid cm_buf_t dataVersions;
+                                           does not apply to directory buffers */
     afs_uint32 owner;                  /* file owner */
     afs_uint32 group;                  /* file owning group */
     cm_user_t *creator;                        /* user, if new file */
@@ -145,12 +150,13 @@ typedef struct cm_scache {
                                         * the link contents here.
                                          */
     cm_fid_t  mountRootFid;            /* mounted on root */
-    time_t    mountRootGen;            /* time to update mountRootFidp? */
+    time_t    mountRootGen;            /* time to update mountRootFid? */
     cm_fid_t  dotdotFid;               /* parent of volume root */
 
     /* callback info */
     struct cm_server *cbServerp;       /* server granting callback */
     time_t cbExpires;                  /* time callback expires */
+    time_t cbIssued;                    /* time callback was issued */
 
     /* access cache */
     long anyAccess;                    /* anonymous user's access */
@@ -193,11 +199,13 @@ typedef struct cm_scache {
                                    have CM_FILELOCK_FLAG_CLIENTONLY
                                    set. */
 
-    afs_uint32   fsLockCount;   /* number of locks held as reported
+    afs_int32    fsLockCount;   /* number of locks held as reported
                                  * by the file server in the most
-                                 * recent fetch status.
+                                 * recent fetch status.  Updated by
+                                 * the locks known to have been acquired
+                                 * or released by this client.
                                  */
-       
+
     /* bulk stat progress */
     osi_hyper_t bulkStatProgress;      /* track bulk stats of large dirs */
 
@@ -221,8 +229,19 @@ typedef struct cm_scache {
                                        Holds queue of
                                        cm_scache_waiter_t
                                        objects. Protected by
-                                       cm_cacheLock. */
+                                       cm_scacheLock. */
     osi_queue_t * waitQueueT;       /* locked by cm_scacheLock */
+
+    /* redirector state - protected by scp->redirMx */
+    osi_queue_t * redirQueueH;      /* LRU queue of buffers for this
+                                       file that are assigned to the
+                                       afsredir kernel module. */
+    osi_queue_t * redirQueueT;
+    afs_uint32    redirBufCount;    /* Number of buffers held by the redirector */
+    time_t        redirLastAccess;  /* last time redir accessed the vnode */
+    osi_mutex_t   redirMx;
+
+    afs_uint32 activeRPCs;              /* atomic */
 } cm_scache_t;
 
 /* dataVersion */
@@ -253,6 +272,7 @@ typedef struct cm_scache {
                                                 * this is a truncate op. */
 #define CM_SCACHEFLAG_INHASH           0x40    /* in the hash table */
 #define CM_SCACHEFLAG_BULKSTATTING     0x80    /* doing a bulk stat */
+#define CM_SCACHEFLAG_SIZESETTING       0x100   /* Stabilized; Truncate */
 #define CM_SCACHEFLAG_WAITING          0x200   /* waiting for fetch/store
                                                 * state to change */
 #define CM_SCACHEFLAG_PURERO           0x400   /* read-only (not even backup);
@@ -271,9 +291,10 @@ typedef struct cm_scache {
 #define CM_SCACHEFLAG_ANYWATCH \
                        (CM_SCACHEFLAG_WATCHED | CM_SCACHEFLAG_WATCHEDSUBTREE)
 
-#define CM_SCACHEFLAG_EACCESS           0x200000 /* Bulk Stat returned EACCES */
 #define CM_SCACHEFLAG_SMB_FID          0x400000
 #define CM_SCACHEFLAG_LOCAL             0x800000 /* Locally modified */
+#define CM_SCACHEFLAG_BULKREADING       0x1000000/* Bulk read in progress */
+#define CM_SCACHEFLAG_RDR_IN_USE        0x2000000/* in use by Redirector; advisory */
 
 /* sync flags for calls to the server.  The CM_SCACHEFLAG_FETCHING,
  * CM_SCACHEFLAG_STORING and CM_SCACHEFLAG_SIZESTORING flags correspond to the
@@ -311,6 +332,8 @@ typedef struct cm_scache {
 #define CM_SCACHESYNC_FORCECB          0x200000/* when calling cm_GetCallback()
                                                  * set the force flag */
 
+#define CM_SCACHESYNC_BULKREAD          0x400000/* reading many buffers */
+
 /* flags for cm_RecycleSCache  */
 #define CM_SCACHE_RECYCLEFLAG_DESTROY_BUFFERS  0x1
 
@@ -320,17 +343,19 @@ typedef struct cm_scache {
                                                 * in old info.
                                                  */
 #define CM_MERGEFLAG_STOREDATA         2       /* Merge due to storedata op */
-#define CM_MERGEFLAG_DIROP              4       /* Merge due to directory op */ 
+#define CM_MERGEFLAG_DIROP              4       /* Merge due to directory op */
+#define CM_MERGEFLAG_FETCHDATA          8       /* Merge due to fetchdata op */
 
 /* hash define.  Must not include the cell, since the callback revocation code
  * doesn't necessarily know the cell in the case of a multihomed server
  * contacting us from a mystery address.
  */
-#define CM_SCACHE_HASH(fidp)   (((unsigned long)       \
-                                  ((fidp)->volume +    \
-                                   (fidp)->vnode +     \
-                                   (fidp)->unique))    \
-                                       % cm_data.scacheHashTableSize)
+
+#define CM_FID_GEN_HASH(fidp) do { \
+    (fidp)->hash = opr_jhash(&(fidp)->volume, 3, 0); \
+} while(0)
+
+#define CM_SCACHE_HASH(fidp) ((fidp)->hash & (cm_data.scacheHashTableSize - 1))
 
 #include "cm_conn.h"
 #include "cm_buf.h"
@@ -347,16 +372,16 @@ typedef struct cm_scache_waiter {
 extern void cm_InitSCache(int, long);
 
 #ifdef DEBUG_REFCOUNT
-extern long cm_GetSCacheDbg(cm_fid_t *, cm_scache_t **, struct cm_user *,
+extern long cm_GetSCacheDbg(cm_fid_t *, cm_fid_t *, cm_scache_t **, struct cm_user *,
        struct cm_req *, char *, long);
 
-#define cm_GetSCache(a,b,c,d)  cm_GetSCacheDbg(a,b,c,d,__FILE__,__LINE__)
+#define cm_GetSCache(a,b,c,d,e)  cm_GetSCacheDbg(a,b,c,d,e,__FILE__,__LINE__)
 #else
-extern long cm_GetSCache(cm_fid_t *, cm_scache_t **, struct cm_user *,
+extern long cm_GetSCache(cm_fid_t *, cm_fid_t *, cm_scache_t **, struct cm_user *,
        struct cm_req *);
 #endif
 
-extern cm_scache_t *cm_GetNewSCache(void);
+extern cm_scache_t *cm_GetNewSCache(afs_uint32 locked);
 
 extern __inline int cm_FidCmp(cm_fid_t *, cm_fid_t *);
 
@@ -367,10 +392,10 @@ extern long cm_SyncOp(cm_scache_t *, struct cm_buf *, struct cm_user *,
 
 extern void cm_SyncOpDone(cm_scache_t *, struct cm_buf *, afs_uint32);
 
-extern void cm_MergeStatus(cm_scache_t * dscp, cm_scache_t * scp, 
-                          struct AFSFetchStatus * statusp, 
+extern void cm_MergeStatus(cm_scache_t * dscp, cm_scache_t * scp,
+                          struct AFSFetchStatus * statusp,
                           struct AFSVolSync * volsyncp,
-                          struct cm_user *userp, 
+                          struct cm_user *userp,
                            cm_req_t *reqp,
                           afs_uint32 flags);
 
@@ -431,4 +456,4 @@ extern int cm_DumpSCache(FILE *outputFile, char *cookie, int lock);
 extern void cm_ResetSCacheDirectory(cm_scache_t *scp, afs_int32 locked);
 
 extern cm_scache_t * cm_RootSCachep(cm_user_t *userp, cm_req_t *reqp);
-#endif /*  __CM_SCACHE_H_ENV__ */
+#endif /*  OPENAFS_WINNT_AFSD_CM_SCACHE_H */