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