Windows: AFSVolSync creationDate based readonly volume versioning
[openafs.git] / src / WINNT / afsd / cm_scache.h
index 586b67a..2da484b 100644 (file)
 #define MOUNTPOINTLEN   1024    /* max path length for symlink; same as AFSPATHMAX */
 
 typedef struct cm_fid {
-       unsigned long cell;
-        unsigned long volume;
-        unsigned long vnode;
-        unsigned long unique;
+    afs_uint32 cell;
+    afs_uint32 volume;
+    afs_uint32 vnode;
+    afs_uint32 unique;
+    afs_uint32 hash;
 } cm_fid_t;
 
+
 /* Key used for byte range locking.  Each unique key identifies a
    unique client per cm_scache_t for the purpose of locking. */
-typedef afs_uint64 cm_key_t;
+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;
+} cm_key_t;
 
 typedef struct cm_range {
     afs_int64 offset;
@@ -36,7 +42,7 @@ typedef struct cm_file_lock {
     osi_queue_t q;              /* list of all locks [protected by
                                    cm_scacheLock] */
     osi_queue_t fileq;         /* per-file list of locks [protected
-                                   by scp->mx]*/
+                                   by scp->rw]*/
     
     cm_user_t *userp;           /* The user to which this lock belongs
                                    to [immutable; held] */
@@ -87,15 +93,15 @@ typedef struct cm_scache {
     struct cm_scache *nextp;           /* next in hash; cm_scacheLock */
     struct cm_scache *allNextp;         /* next in all scache list; cm_scacheLock */
     cm_fid_t fid;
-    afs_uint32 flags;                  /* flags; locked by mx */
+    afs_uint32 flags;                  /* flags; locked by rw */
 
     /* synchronization stuff */
-    osi_mutex_t mx;                    /* mutex for this structure */
+    osi_rwlock_t rw;                   /* rwlock for this structure */
     osi_rwlock_t bufCreateLock;                /* read-locked during buffer creation;
                                          * write-locked to prevent buffers from
                                         * being created during a truncate op, etc.
                                         */
-    afs_uint32 refCount;               /* reference count; cm_scacheLock */
+    afs_int32 refCount;                        /* reference count; cm_scacheLock */
     osi_queueData_t *bufReadsp;                /* queue of buffers being read */
     osi_queueData_t *bufWritesp;       /* queue of buffers being written */
 
@@ -116,11 +122,15 @@ typedef struct cm_scache {
     cm_prefetch_t prefetch;            /* prefetch info structure */
     afs_uint32 unixModeBits;           /* unix protection mode bits */
     afs_uint32 linkCount;              /* link count */
-    afs_uint32 dataVersion;            /* data version */
+    afs_uint64 dataVersion;            /* data version */
+    afs_uint64 bufDataVersionLow;       /* range of valid cm_buf_t dataVersions */
     afs_uint32 owner;                  /* file owner */
     afs_uint32 group;                  /* file owning group */
     cm_user_t *creator;                        /* user, if new file */
 
+    /* volume status */
+    time_t volumeCreationDate;          /* volume creation date from AFSVolSync */
+
     /* pseudo file status */
     osi_hyper_t serverLength;          /* length known to server */
 
@@ -150,7 +160,7 @@ typedef struct cm_scache {
     afs_int32    serverLock;    /* current lock we have acquired on
                                  * this file.  One of (-1), LockRead
                                  * or LockWrite. [protected by
-                                 * scp->mx].  In the future, this
+                                 * scp->rw].  In the future, this
                                  * should be replaced by a queue of
                                  * cm_server_lock_t objects which keep
                                  * track of lock type, the user for
@@ -161,7 +171,7 @@ typedef struct cm_scache {
                                  */
     unsigned long lastRefreshCycle; /* protected with cm_scacheLock
                                      * for all scaches. */
-    afs_uint32 lockDataVersion; /* dataVersion of the scp at the time
+    afs_uint64  lockDataVersion; /* dataVersion of the scp at the time
                                    the server lock for the scp was
                                    asserted for this lock the last
                                    time. */
@@ -182,17 +192,19 @@ typedef struct cm_scache {
     afs_uint32   clientLocks;   /* number of locks on ::fileLocks that
                                    have CM_FILELOCK_FLAG_CLIENTONLY
                                    set. */
-       
-    /* volume info */
-    struct cm_volume *volp;            /* volume info; held reference */
 
+    afs_uint32   fsLockCount;   /* number of locks held as reported
+                                 * by the file server in the most
+                                 * recent fetch status.
+                                 */
+       
     /* bulk stat progress */
     osi_hyper_t bulkStatProgress;      /* track bulk stats of large dirs */
 
 #ifdef USE_BPLUS
     /* directory B+ tree */             /* only allocated if is directory */
     osi_rwlock_t dirlock;               /* controls access to dirBplus */
-    afs_uint32   dirDataVersion;        /* data version represented by dirBplus */
+    afs_uint64   dirDataVersion;        /* data version represented by dirBplus */
     struct tree *dirBplus;              /* dirBplus */
 #endif
 
@@ -213,12 +225,16 @@ typedef struct cm_scache {
     osi_queue_t * waitQueueT;       /* locked by cm_scacheLock */
 } cm_scache_t;
 
+/* dataVersion */
+#define CM_SCACHE_VERSION_BAD           0xFFFFFFFFFFFFFFFF
+
 /* mask field - tell what has been modified */
 #define CM_SCACHEMASK_CLIENTMODTIME    1       /* client mod time */
 #define CM_SCACHEMASK_LENGTH           2       /* length */
 #define CM_SCACHEMASK_TRUNCPOS         4       /* truncation position */
 
 /* fileType values */
+#define CM_SCACHETYPE_UNKNOWN           0       /* unknown */
 #define CM_SCACHETYPE_FILE             1       /* a file */
 #define CM_SCACHETYPE_DIRECTORY                2       /* a dir */
 #define CM_SCACHETYPE_SYMLINK          3       /* a symbolic link */
@@ -257,6 +273,7 @@ typedef struct cm_scache {
 
 #define CM_SCACHEFLAG_EACCESS           0x200000 /* Bulk Stat returned EACCES */
 #define CM_SCACHEFLAG_SMB_FID          0x400000
+#define CM_SCACHEFLAG_LOCAL             0x800000 /* Locally modified */
 
 /* sync flags for calls to the server.  The CM_SCACHEFLAG_FETCHING,
  * CM_SCACHEFLAG_STORING and CM_SCACHEFLAG_SIZESTORING flags correspond to the
@@ -303,6 +320,7 @@ 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 */ 
 
 /* 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
@@ -314,18 +332,18 @@ typedef struct cm_scache {
                                    (fidp)->unique))    \
                                        % cm_data.scacheHashTableSize)
 
+#include "cm_conn.h"
+#include "cm_buf.h"
+
 typedef struct cm_scache_waiter {
     osi_queue_t q;
     afs_int32   threadId;
 
     cm_scache_t *scp;
     afs_int32   flags;
-    void        *bufp;
+    cm_buf_t    *bufp;
 } cm_scache_waiter_t;
 
-#include "cm_conn.h"
-#include "cm_buf.h"
-
 extern void cm_InitSCache(int, long);
 
 #ifdef DEBUG_REFCOUNT
@@ -340,7 +358,9 @@ extern long cm_GetSCache(cm_fid_t *, cm_scache_t **, struct cm_user *,
 
 extern cm_scache_t *cm_GetNewSCache(void);
 
-extern int cm_FidCmp(cm_fid_t *, cm_fid_t *);
+extern __inline int cm_FidCmp(cm_fid_t *, cm_fid_t *);
+
+extern void cm_SetFid(cm_fid_t *, afs_uint32 cell, afs_uint32 volume, afs_uint32 vnode, afs_uint32 unique);
 
 extern long cm_SyncOp(cm_scache_t *, struct cm_buf *, struct cm_user *,
        struct cm_req *, afs_uint32, afs_uint32);
@@ -351,6 +371,7 @@ extern void cm_MergeStatus(cm_scache_t * dscp, cm_scache_t * scp,
                           struct AFSFetchStatus * statusp, 
                           struct AFSVolSync * volsyncp,
                           struct cm_user *userp, 
+                           cm_req_t *reqp,
                           afs_uint32 flags);
 
 extern void cm_AFSFidFromFid(struct AFSFid *, cm_fid_t *);
@@ -402,4 +423,10 @@ extern void cm_SuspendSCache(void);
 extern long cm_RecycleSCache(cm_scache_t *scp, afs_int32 flags);
 
 extern void cm_RemoveSCacheFromHashTable(cm_scache_t *scp);
+
+extern void cm_AdjustScacheLRU(cm_scache_t *scp);
+
+extern int cm_DumpSCache(FILE *outputFile, char *cookie, int lock);
+
+extern void cm_ResetSCacheDirectory(cm_scache_t *scp, afs_int32 locked);
 #endif /*  __CM_SCACHE_H_ENV__ */