4d74dbdfd831d67e56a8db0cab9b5156ad8c5832
[openafs.git] / src / WINNT / afsd / cm_scache.h
1 /*
2  * Copyright 2000, International Business Machines Corporation and others.
3  * All Rights Reserved.
4  * 
5  * This software has been released under the terms of the IBM Public
6  * License.  For details, see the LICENSE file in the top-level source
7  * directory or online at http://www.openafs.org/dl/license10.html
8  */
9
10 #ifndef __CM_SCACHE_H_ENV__
11 #define __CM_SCACHE_H_ENV__ 1
12
13 typedef struct cm_fid {
14         unsigned long cell;
15         unsigned long volume;
16         unsigned long vnode;
17         unsigned long unique;
18 } cm_fid_t;
19
20 typedef struct cm_accessCache {
21         osi_queue_t q;                  /* queue header */
22         struct cm_user *userp;          /* user having access rights */
23         long rights;                    /* rights */
24 } cm_accessCache_t;
25
26 typedef struct cm_file_lock {
27         osi_queue_t q;                  /* list of all locks */
28         osi_queue_t fileq;              /* per-file list of locks */
29         cm_user_t *userp;
30         LARGE_INTEGER LOffset;
31         LARGE_INTEGER LLength;
32         cm_fid_t fid;
33         unsigned char LockType;
34         unsigned char flags;
35 } cm_file_lock_t;
36
37 #define CM_FILELOCK_FLAG_INVALID        0x1
38 #define CM_FILELOCK_FLAG_WAITING        0x2
39
40 typedef struct cm_prefetch {            /* last region scanned for prefetching */
41         osi_hyper_t base;               /* start of region */
42         osi_hyper_t end;                /* first char past region */
43 } cm_prefetch_t;
44
45 typedef struct cm_scache {
46         osi_queue_t q;                  /* lru queue; cm_scacheLock */
47         struct cm_scache *nextp;        /* next in hash; cm_scacheLock */
48         cm_fid_t fid;
49         long flags;                     /* flags; locked by mx */
50
51         /* synchronization stuff */
52         osi_mutex_t mx;                 /* mutex for this structure */
53         osi_rwlock_t bufCreateLock;     /* read-locked during buffer creation;
54                                          * write-locked to prevent buffers from
55                                          * being created during a truncate op, etc.
56                                          */
57         int refCount;                   /* reference count; cm_scacheLock */
58         osi_queueData_t *bufReadsp;     /* queue of buffers being read */
59         osi_queueData_t *bufWritesp;    /* queue of buffers being written */
60
61         /* parent info for ACLs */
62         long parentVnode;               /* parent vnode for ACL callbacks */
63         long parentUnique;              /* for ACL callbacks */
64
65         /* local modification stat */
66         long mask;                      /* for clientModTime, length and
67                                          * truncPos */
68
69         /* file status */
70         int fileType;                   /* file type */
71         unsigned long clientModTime;    /* mtime */
72         unsigned long serverModTime;    /* at server, for concurrent call
73                                          * comparisons */
74         osi_hyper_t length;             /* file length */
75         cm_prefetch_t prefetch;         /* prefetch info structure */
76         int unixModeBits;               /* unix protection mode bits */
77         int linkCount;                  /* link count */
78         long dataVersion;               /* data version */
79         long owner;                     /* file owner */
80         long group;                     /* file owning group */
81
82         /* pseudo file status */
83         osi_hyper_t serverLength;       /* length known to server */
84
85         /* aux file status */
86         osi_hyper_t truncPos;           /* file size to truncate to before
87                                          * storing data */
88
89         /* symlink and mount point info */
90         char *mountPointStringp;        /* the string stored in a mount point;
91                                          * first char is type, then vol name.
92                                          * If this is a normal symlink, we store
93                                          * the link contents here.
94                                          */
95         cm_fid_t *mountRootFidp;        /* mounted on root */
96         unsigned int mountRootGen;      /* time to update mountRootFidp? */
97         cm_fid_t *dotdotFidp;           /* parent of volume root */
98
99         /* callback info */
100         struct cm_server *cbServerp;    /* server granting callback */
101         long cbExpires;                 /* time callback expires */
102
103         /* access cache */
104         long anyAccess;                 /* anonymous user's access */
105         struct cm_aclent *randomACLp;   /* access cache entries */
106
107         /* file locks */
108         osi_queue_t *fileLocks;
109         
110         /* volume info */
111         struct cm_volume *volp;         /* volume info; held reference */
112   
113         /* bulk stat progress */
114         osi_hyper_t bulkStatProgress;   /* track bulk stats of large dirs */
115
116         /* open state */
117         short openReads;                /* opens for reading */
118         short openWrites;               /* open for writing */
119         short openShares;               /* open for read excl */
120         short openExcls;                /* open for exclusives */
121 } cm_scache_t;
122
123 /* mask field - tell what has been modified */
124 #define CM_SCACHEMASK_CLIENTMODTIME     1       /* client mod time */
125 #define CM_SCACHEMASK_LENGTH            2       /* length */
126 #define CM_SCACHEMASK_TRUNCPOS          4       /* truncation position */
127
128 /* fileType values */
129 #define CM_SCACHETYPE_FILE              1       /* a file */
130 #define CM_SCACHETYPE_DIRECTORY         2       /* a dir */
131 #define CM_SCACHETYPE_SYMLINK           3       /* a symbolic link */
132 #define CM_SCACHETYPE_MOUNTPOINT        4       /* a mount point */
133
134 /* flag bits */
135 #define CM_SCACHEFLAG_STATD             1       /* status info is valid */
136 #define CM_SCACHEFLAG_DELETED           2       /* file has been deleted */
137 #define CM_SCACHEFLAG_CALLBACK          4       /* have a valid callback */
138 #define CM_SCACHEFLAG_STORING           8       /* status being stored back */
139 #define CM_SCACHEFLAG_FETCHING          0x10    /* status being fetched */
140 #define CM_SCACHEFLAG_SIZESTORING       0x20    /* status being stored that
141                                                  * changes the data; typically,
142                                                  * this is a truncate op. */
143 #define CM_SCACHEFLAG_INHASH            0x40    /* in the hash table */
144 #define CM_SCACHEFLAG_BULKSTATTING      0x80    /* doing a bulk stat */
145 #define CM_SCACHEFLAG_WAITING           0x200   /* waiting for fetch/store
146                                                  * state to change */
147 #define CM_SCACHEFLAG_PURERO            0x400   /* read-only (not even backup);
148                                                  * for mount point eval */
149 #define CM_SCACHEFLAG_RO                0x800   /* read-only
150                                                  * (can't do write ops) */
151 #define CM_SCACHEFLAG_GETCALLBACK       0x1000  /* we're getting a callback */
152 #define CM_SCACHEFLAG_DATASTORING       0x2000  /* data being stored */
153 #define CM_SCACHEFLAG_PREFETCHING       0x4000  /* somebody is prefetching */
154 #define CM_SCACHEFLAG_OVERQUOTA         0x8000  /* over quota */
155 #define CM_SCACHEFLAG_OUTOFSPACE        0x10000 /* out of space */
156 #define CM_SCACHEFLAG_ASYNCSTORING      0x20000 /* scheduled to store back */
157 #define CM_SCACHEFLAG_LOCKING           0x40000 /* setting/clearing file lock */
158 #define CM_SCACHEFLAG_WATCHED           0x80000 /* directory being watched */
159 #define CM_SCACHEFLAG_WATCHEDSUBTREE    0x100000 /* dir subtree being watched */
160 #define CM_SCACHEFLAG_ANYWATCH \
161                         (CM_SCACHEFLAG_WATCHED | CM_SCACHEFLAG_WATCHEDSUBTREE)
162
163 /* sync flags for calls to the server.  The CM_SCACHEFLAG_FETCHING,
164  * CM_SCACHEFLAG_STORING and CM_SCACHEFLAG_SIZESTORING flags correspond to the
165  * below, except for FETCHDATA and STOREDATA, which correspond to non-null
166  * buffers in bufReadsp and bufWritesp.
167  * These flags correspond to individual RPCs that we may be making, and at most
168  * one can be set in any one call to SyncOp.
169  */
170 #define CM_SCACHESYNC_FETCHSTATUS       1       /* fetching status info */
171 #define CM_SCACHESYNC_STORESTATUS       2       /* storing status info */
172 #define CM_SCACHESYNC_FETCHDATA         4       /* fetch data */
173 #define CM_SCACHESYNC_STOREDATA         8       /* store data */
174 #define CM_SCACHESYNC_STORESIZE         0x10    /* store new file size */
175 #define CM_SCACHESYNC_GETCALLBACK       0x20    /* fetching a callback */
176 #define CM_SCACHESYNC_STOREDATA_EXCL    0x40    /* store data */
177 #define CM_SCACHESYNC_ASYNCSTORE        0x80    /* schedule data store */
178 #define CM_SCACHESYNC_LOCK              0x100   /* set/clear file lock */
179
180 /* sync flags for calls within the client; there are no corresponding flags
181  * in the scache entry, because we hold the scache entry locked during the
182  * operations below.
183  */
184 #define CM_SCACHESYNC_GETSTATUS         0x1000  /* read the status */
185 #define CM_SCACHESYNC_SETSTATUS         0x2000  /* e.g. utimes */
186 #define CM_SCACHESYNC_READ              0x4000  /* read data from a chunk */
187 #define CM_SCACHESYNC_WRITE             0x8000  /* write data to a chunk */
188 #define CM_SCACHESYNC_SETSIZE           0x10000 /* shrink the size of a file,
189                                                  * e.g. truncate */
190 #define CM_SCACHESYNC_NEEDCALLBACK      0x20000 /* need a callback on the file */
191 #define CM_SCACHESYNC_CHECKRIGHTS       0x40000 /* check that user has desired
192                                                  * access rights */
193 #define CM_SCACHESYNC_BUFLOCKED         0x80000 /* the buffer is locked */
194 #define CM_SCACHESYNC_NOWAIT            0x100000/* don't wait for the state,
195                                                  * just fail */
196
197 /* flags for cm_MergeStatus */
198 #define CM_MERGEFLAG_FORCE              1       /* check mtime before merging;
199                                                  * used to see if we're merging
200                                                  * in old info.
201                                                  */
202
203 /* hash define.  Must not include the cell, since the callback revocation code
204  * doesn't necessarily know the cell in the case of a multihomed server
205  * contacting us from a mystery address.
206  */
207 #define CM_SCACHE_HASH(fidp)    (((unsigned long)       \
208                                    ((fidp)->volume +    \
209                                     (fidp)->vnode +     \
210                                     (fidp)->unique))    \
211                                         % cm_hashTableSize)
212
213 extern cm_scache_t cm_fakeSCache;
214
215 extern void cm_InitSCache(long);
216
217 extern long cm_GetSCache(cm_fid_t *, cm_scache_t **, struct cm_user *,
218         struct cm_req *);
219
220 extern void cm_PutSCache(cm_scache_t *);
221
222 extern cm_scache_t *cm_GetNewSCache(void);
223
224 extern int cm_FidCmp(cm_fid_t *, cm_fid_t *);
225
226 extern long cm_SyncOp(cm_scache_t *, struct cm_buf *, struct cm_user *,
227         struct cm_req *, long, long);
228
229 extern void cm_SyncOpDone(cm_scache_t *, struct cm_buf *, long);
230
231 extern void cm_MergeStatus(cm_scache_t *, struct AFSFetchStatus *, struct AFSVolSync *,
232         struct cm_user *, int flags);
233
234 extern void cm_AFSFidFromFid(struct AFSFid *, cm_fid_t *);
235
236 extern void cm_HoldSCache(cm_scache_t *);
237
238 extern void cm_ReleaseSCache(cm_scache_t *);
239
240 extern cm_scache_t *cm_FindSCache(cm_fid_t *fidp);
241
242 extern long cm_hashTableSize;
243
244 extern osi_rwlock_t cm_scacheLock;
245
246 extern osi_queue_t *cm_allFileLocks;
247
248 extern cm_scache_t **cm_hashTablep;
249
250 extern void cm_DiscardSCache(cm_scache_t *scp);
251
252 #endif /*  __CM_SCACHE_H_ENV__ */