Windows: Use AuthGroups for extent request error reporting
[openafs.git] / src / WINNT / afsrdr / common / AFSRedirCommonStructs.h
1 /*
2  * Copyright (c) 2008-2011 Kernel Drivers, LLC.
3  * Copyright (c) 2009-2011 Your File System, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  *   this list of conditions and the following disclaimer.
12  * - Redistributions in binary form must reproduce the above copyright
13  *   notice,
14  *   this list of conditions and the following disclaimer in the
15  *   documentation
16  *   and/or other materials provided with the distribution.
17  * - Neither the name of Kernel Drivers, LLC nor the names of its
18  *   contributors may be
19  *   used to endorse or promote products derived from this software without
20  *   specific prior written permission from Kernel Drivers, LLC
21  *   and Your File System, Inc.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
26  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
27  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35
36 #ifndef _AFS_REDIR_COMMON_STRUCTS_H
37 #define _AFS_REDIR_COMMON_STRUCTS_H
38
39 //
40 // BTree Entry
41 //
42
43 typedef struct AFS_BTREE_ENTRY
44 {
45
46     void    *parentLink;
47
48     void    *leftLink;
49
50     void    *rightLink;
51
52     ULONGLONG HashIndex;
53
54 } AFSBTreeEntry, *PAFSBTreeEntry;
55
56 typedef struct AFS_LIST_ENTRY
57 {
58
59     void    *fLink;
60
61     void    *bLink;
62
63 } AFSListEntry;
64
65 typedef struct _AFS_TREE_HDR
66 {
67
68     AFSBTreeEntry *TreeHead;
69
70     ERESOURCE     *TreeLock;
71
72 } AFSTreeHdr;
73
74 //
75 // Sys Name Information CB
76 //
77
78 typedef struct _AFS_SYS_NAME_CB
79 {
80
81     struct _AFS_SYS_NAME_CB     *fLink;
82
83     UNICODE_STRING      SysName;
84
85 } AFSSysNameCB;
86
87 //
88 // Communication service control structures
89 //
90
91 typedef struct _AFSFSD_SRVC_CONTROL_BLOCK
92 {
93
94     ULONG                       IrpPoolRequestIndex;
95
96     struct _POOL_ENTRY          *RequestPoolHead;
97
98     struct _POOL_ENTRY          *RequestPoolTail;
99
100     ERESOURCE                   IrpPoolLock;
101
102     struct _POOL_ENTRY          *ResultPoolHead;
103
104     struct _POOL_ENTRY          *ResultPoolTail;
105
106     ERESOURCE                   ResultPoolLock;
107
108     KEVENT                      IrpPoolHasEntries;
109
110     KEVENT                      IrpPoolHasReleaseEntries;
111
112     ULONG                       IrpPoolControlFlag;
113
114     LONG                        QueueCount;
115
116 } AFSCommSrvcCB, *PAFSCommSrvcCB;
117
118 //
119 // Irp Pool entry
120 //
121
122 typedef struct _POOL_ENTRY
123 {
124
125     struct _POOL_ENTRY    *fLink;
126
127     struct _POOL_ENTRY    *bLink;
128
129     KEVENT      Event;
130
131     GUID        AuthGroup;
132
133     AFSFileID    FileId;
134
135     UNICODE_STRING  FileName;
136
137     ULONG       RequestType;
138
139     ULONG       RequestIndex;
140
141     ULONG       RequestFlags;
142
143     ULONG       DataLength;
144
145     void       *Data;
146
147     ULONG       ResultStatus;
148
149     void       *ResultBuffer;
150
151     ULONG      *ResultBufferLength;
152
153 } AFSPoolEntry;
154
155 //
156 // The first portion is the non-paged section of the Fcb
157 //
158
159 typedef struct _AFS_NONPAGED_FCB
160 {
161
162     USHORT          Size;
163     USHORT          Type;
164
165     //
166     // Ranking - File Resource first, then Paging Resource
167     //
168
169     ERESOURCE       Resource;
170
171     ERESOURCE       PagingResource;
172
173     //
174     // The section object pointer
175     //
176
177     SECTION_OBJECT_POINTERS        SectionObjectPointers;
178
179     FAST_MUTEX      AdvancedHdrMutex;
180
181     ERESOURCE       CcbListLock;
182
183     union
184     {
185
186         struct
187         {
188
189             ERESOURCE       ExtentsResource;
190
191             //
192             // This is set when an Extents Request completes.  Do not wait for this
193             // with the Extents resource held!
194             //
195             KEVENT          ExtentsRequestComplete;
196
197             NTSTATUS        ExtentsRequestStatus;
198
199             GUID            ExtentsRequestAuthGroup;
200
201             struct _AFS_FSD_EXTENT  *DirtyListHead;
202
203             struct _AFS_FSD_EXTENT  *DirtyListTail;
204
205             ERESOURCE       DirtyExtentsListLock;
206
207             KEVENT          FlushEvent;
208
209             //
210             // Queued Flush event. This event is set when the queued flush count
211             // is zero, cleared otherwise.
212
213             KEVENT          QueuedFlushEvent;
214
215         } File;
216
217         struct
218         {
219
220             KEVENT          DirectoryEnumEvent;
221
222             LONG            DirectoryEnumCount;
223
224         } Directory;
225
226     } Specific;
227
228 } AFSNonPagedFcb, *PAFSNonPagedFcb;
229
230 typedef struct _AFS_FSD_EXTENT
231 {
232     //
233     // Linked list first - the extents and then the skip list
234     //
235
236     LIST_ENTRY          Lists[AFS_NUM_EXTENT_LISTS];
237
238     AFSListEntry        DirtyList;
239
240     //
241     // And the extent itself
242     //
243
244     LARGE_INTEGER       FileOffset;
245
246     LARGE_INTEGER       CacheOffset;
247
248     ULONG               Size;
249
250     ULONG               Flags;
251
252     LONG                ActiveCount;
253
254 #if GEN_MD5
255     UCHAR               MD5[16];
256 #endif
257
258 } AFSExtent, *PAFSExtent;
259
260 typedef struct AFS_FCB
261 {
262
263     FSRTL_ADVANCED_FCB_HEADER Header;
264
265     //
266     // This is the linked list of nodes processed asynchronously by the respective worker thread
267     //
268
269     AFSListEntry        ListEntry;
270
271     //
272     // The NP portion of the Fcb
273     //
274
275     AFSNonPagedFcb    *NPFcb;
276
277     //
278     // Fcb flags
279     //
280
281     ULONG               Flags;
282
283     //
284     // Share access mapping
285     //
286
287     SHARE_ACCESS        ShareAccess;
288
289     //
290     // Open pointer count on this file
291     //
292
293     LONG                OpenReferenceCount;
294
295     //
296     // Open handle count on this file
297     //
298
299     LONG                OpenHandleCount;
300
301     //
302     // Object info block
303     //
304
305     struct _AFS_OBJECT_INFORMATION_CB   *ObjectInformation;
306
307     //
308     // Ccb list pointers
309     //
310
311     struct _AFS_CCB    *CcbListHead;
312
313     struct _AFS_CCB    *CcbListTail;
314
315     //
316     // Union for node type specific information
317     //
318
319     union
320     {
321
322         struct
323         {
324             //
325             // We set this when a flush has been sent to the
326             // server sucessfully.  We use this to influence when we
327             // write the flush.
328             //
329             LARGE_INTEGER       LastServerFlush;
330
331             //
332             // We set this when the extent ref count goes to zero.
333             // we use this to influence which files to purge
334             //
335             LARGE_INTEGER       LastExtentAccess;
336
337             //
338             // If there has been a RELEASE_FILE_EXTENTS - this is
339             // where we stopped last time this stops us from
340             // constantly refreeing the same extents and then grabbing
341             // them again.
342             //
343             LARGE_INTEGER       LastPurgePoint;
344
345             //
346             // File lock
347             //
348
349             FILE_LOCK           FileLock;
350
351             //
352             // The extents
353             //
354
355             LIST_ENTRY          ExtentsLists[AFS_NUM_EXTENT_LISTS];
356
357             //
358             // There is only ever one request active, so we embed it
359             //
360
361             AFSRequestExtentsCB ExtentsRequest;
362
363             //
364             // Last PID that requested extents, NOT the system process
365             //
366
367             ULONGLONG           ExtentRequestProcessId;
368
369             //
370             // Dirty extent count
371             //
372
373             LONG                ExtentsDirtyCount;
374
375             //
376             // Extent count for this file
377             //
378
379             LONG                ExtentCount;
380
381             //
382             // The Lazy writer thread
383             //
384
385             PETHREAD            LazyWriterThread;
386
387             //
388             // Current count of queued flush items for the file
389             //
390
391             LONG                QueuedFlushCount;
392
393             //
394             // Cache space currently held by extents for the file
395             //
396
397             LONG                ExtentLength; // in KBs
398
399         } File;
400
401         struct
402         {
403
404             ULONG       Reserved;
405
406         } Directory;
407
408     } Specific;
409
410 } AFSFcb, *PAFSFcb;
411
412 typedef struct _AFS_DEVICE_EXTENSION
413 {
414
415     //
416     // Self pointer
417     //
418
419     PDEVICE_OBJECT  Self;
420
421     //
422     // List of device isntances
423     //
424
425     struct _AFS_DEVICE_EXTENSION *DeviceLink;
426
427     //
428     // Device flags
429     //
430
431     ULONG           DeviceFlags;
432
433     union
434     {
435
436         struct
437         {
438
439             //
440             // Volume worker tracking information
441             //
442
443             KEVENT           VolumeWorkerCloseEvent;
444
445             LONG             VolumeWorkerThreadCount;
446
447             //
448             // Fcb lifetime & flush time tickcount. This is calculated
449             // in DriverEntry() for the control device.
450             //
451
452             LARGE_INTEGER           ObjectLifeTimeCount;
453             LARGE_INTEGER           FcbFlushTimeCount;
454             LARGE_INTEGER           FcbPurgeTimeCount;
455             LARGE_INTEGER           ExtentRequestTimeCount;
456
457             //
458             // Comm interface
459             //
460
461             AFSCommSrvcCB    CommServiceCB;
462
463             //
464             // Extent Release Interface
465             //
466
467             ERESOURCE        ExtentReleaseResource;
468
469             KEVENT           ExtentReleaseEvent;
470
471             ULONG            ExtentReleaseSequence;
472
473             PKPROCESS        ServiceProcess;
474
475             //
476             // SysName information control block
477             //
478
479             ERESOURCE       SysName32ListLock;
480
481             AFSSysNameCB    *SysName32ListHead;
482
483             AFSSysNameCB    *SysName32ListTail;
484
485             ERESOURCE       SysName64ListLock;
486
487             AFSSysNameCB    *SysName64ListHead;
488
489             AFSSysNameCB    *SysName64ListTail;
490
491             //
492             // Our process tree information
493             //
494
495             AFSTreeHdr          ProcessTree;
496
497             ERESOURCE           ProcessTreeLock;
498
499             //
500             // SID Entry tree
501             //
502
503             AFSTreeHdr          AuthGroupTree;
504
505             ERESOURCE           AuthGroupTreeLock;
506
507             //
508             // Notificaiton information. This is used for change notification
509             //
510
511             LIST_ENTRY          DirNotifyList;
512
513             PNOTIFY_SYNC        NotifySync;
514
515             //
516             // Library load information
517             //
518
519             KEVENT              LoadLibraryEvent;
520
521             ULONG               LibraryState;
522
523             ERESOURCE           LibraryStateLock;
524
525             LONG                InflightLibraryRequests;
526
527             KEVENT              InflightLibraryEvent;
528
529             ERESOURCE           LibraryQueueLock;
530
531             struct _AFS_LIBRARY_QUEUE_REQUEST_CB    *LibraryQueueHead;
532
533             struct _AFS_LIBRARY_QUEUE_REQUEST_CB    *LibraryQueueTail;
534
535             UNICODE_STRING      LibraryServicePath;
536
537             DEVICE_OBJECT      *LibraryDeviceObject;
538
539             FILE_OBJECT        *LibraryFileObject;
540
541             //
542             // Extent processing information within the library
543             //
544
545             LONG                ExtentCount;
546
547             LONG                ExtentsHeldLength;
548
549             KEVENT              ExtentsHeldEvent;
550
551             //
552             // Outstanding service request information
553             //
554
555             LONG                OutstandingServiceRequestCount;
556
557             KEVENT              OutstandingServiceRequestEvent;
558
559         } Control;
560
561         struct
562         {
563
564             //
565             // Cache file information
566             //
567
568             HANDLE              CacheFileHandle;
569
570             PFILE_OBJECT        CacheFileObject;
571
572             ULONG               CacheBlockSize;
573
574             UNICODE_STRING      CacheFile;
575
576             LARGE_INTEGER       CacheBlockCount; // Total number of cache blocks in the cache file
577
578             void               *CacheBaseAddress;
579
580             LARGE_INTEGER       CacheLength;
581
582             PMDL                CacheMdl;
583
584             //
585             // Throttles on behavior
586             //
587             LARGE_INTEGER       MaxIo;
588
589             LARGE_INTEGER       MaxDirty;
590
591             //
592             // Maximum RPC length that is issued by the service. We should limit our
593             // data requests such as for extents to thsi length
594             //
595
596             ULONG               MaximumRPCLength;
597
598             //
599             // Volume tree
600             //
601
602             AFSTreeHdr          VolumeTree;
603
604             ERESOURCE           VolumeTreeLock;
605
606             struct _AFS_VOLUME_CB        *VolumeListHead;
607
608             struct _AFS_VOLUME_CB        *VolumeListTail;
609
610             ERESOURCE           VolumeListLock;
611
612             //
613             // Queued extent release count and event
614             //
615
616             LONG                QueuedReleaseExtentCount;
617
618             KEVENT              QueuedReleaseExtentEvent;
619
620             //
621             // Name array related information
622             //
623
624             ULONG               NameArrayLength;
625
626             ULONG               MaxLinkCount;
627
628             //
629             // Our root cell tree
630             //
631
632             AFSTreeHdr          RootCellTree;
633
634             ERESOURCE           RootCellTreeLock;
635
636             //
637             // Cache file object access
638             //
639
640             ERESOURCE           CacheFileLock;
641
642             //
643             // NP Connection list information
644             //
645
646             ERESOURCE                 ProviderListLock;
647
648             struct _AFSFSD_PROVIDER_CONNECTION_CB   *ProviderConnectionList;
649
650             struct _AFSFSD_PROVIDER_CONNECTION_CB   *ProviderEnumerationList;
651
652         } RDR;
653
654         struct
655         {
656
657             //
658             // Worker pool information
659             //
660
661             ULONG            WorkerCount;
662
663             struct _AFS_WORKER_QUEUE_HDR *PoolHead;
664
665             ERESOURCE        QueueLock;
666
667             struct _AFS_WORK_ITEM     *QueueHead;
668
669             struct _AFS_WORK_ITEM     *QueueTail;
670
671             KEVENT           WorkerQueueHasItems;
672
673             LONG             QueueItemCount;
674
675             //
676             // IO Worker queue
677             //
678
679             ULONG            IOWorkerCount;
680
681             struct _AFS_WORKER_QUEUE_HDR *IOPoolHead;
682
683             ERESOURCE        IOQueueLock;
684
685             struct _AFS_WORK_ITEM     *IOQueueHead;
686
687             struct _AFS_WORK_ITEM     *IOQueueTail;
688
689             KEVENT           IOWorkerQueueHasItems;
690
691             LONG             IOQueueItemCount;
692
693         } Library;
694
695     } Specific;
696
697 } AFSDeviceExt, *PAFSDeviceExt;
698
699 //
700 // Network provider connection cb
701 //
702 #pragma pack(push, 1)
703 typedef struct _AFSFSD_PROVIDER_CONNECTION_CB
704 {
705
706     struct _AFSFSD_PROVIDER_CONNECTION_CB *fLink;
707
708     struct _AFSFSD_PROVIDER_CONNECTION_CB *EnumerationList;
709
710     ULONG       Flags;
711
712     ULONG       Type;
713
714     ULONG       Scope;
715
716     ULONG       DisplayType;
717
718     ULONG       Usage;
719
720     LARGE_INTEGER AuthenticationId;
721
722     WCHAR       LocalName;
723
724     UNICODE_STRING RemoteName;
725
726     UNICODE_STRING ComponentName;
727
728     UNICODE_STRING Comment;
729
730 } AFSProviderConnectionCB;
731 #pragma pack(pop)
732
733 //
734 // Callbacks defined in the framework
735 //
736
737 typedef
738 NTSTATUS
739 (*PAFSProcessRequest)( IN ULONG RequestType,
740                        IN ULONG RequestFlags,
741                        IN GUID *AuthGroup,
742                        IN PUNICODE_STRING FileName,
743                        IN AFSFileID *FileId,
744                        IN void  *Data,
745                        IN ULONG DataLength,
746                        IN OUT void *ResultBuffer,
747                        IN OUT PULONG ResultBufferLength);
748
749 typedef
750 NTSTATUS
751 (*PAFSDbgLogMsg)( IN ULONG Subsystem,
752                   IN ULONG Level,
753                   IN PCCH Format,
754                   ...);
755
756 typedef
757 NTSTATUS
758 (*PAFSAddConnectionEx)( IN UNICODE_STRING *RemoteName,
759                         IN ULONG DisplayType,
760                         IN ULONG Flags);
761
762 typedef
763 void *
764 (*PAFSExAllocatePoolWithTag)( IN POOL_TYPE  PoolType,
765                               IN SIZE_T  NumberOfBytes,
766                               IN ULONG  Tag);
767
768 typedef
769 void
770 (*PAFSExFreePool)( IN void *Pointer);
771
772 typedef
773 void
774 (*PAFSRetrieveAuthGroup)( IN ULONGLONG ProcessId,
775                           IN ULONGLONG ThreadId,
776                           OUT GUID *AuthGroup);
777
778 typedef struct _AFS_LIBRARY_INIT_CB
779 {
780
781     PDEVICE_OBJECT      AFSControlDeviceObject;
782
783     PDEVICE_OBJECT      AFSRDRDeviceObject;
784
785     UNICODE_STRING      AFSServerName;
786
787     ULONG               AFSDebugFlags;
788
789     AFSFileID           GlobalRootFid;
790
791     CACHE_MANAGER_CALLBACKS *AFSCacheManagerCallbacks;
792
793     void               *AFSCacheBaseAddress;
794
795     LARGE_INTEGER       AFSCacheLength;
796
797     //
798     // Callbacks in the framework
799     //
800
801     PAFSProcessRequest  AFSProcessRequest;
802
803     PAFSDbgLogMsg       AFSDbgLogMsg;
804
805     PAFSAddConnectionEx AFSAddConnectionEx;
806
807     PAFSExAllocatePoolWithTag   AFSExAllocatePoolWithTag;
808
809     PAFSExFreePool      AFSExFreePool;
810
811     PAFSDumpTraceFiles  AFSDumpTraceFiles;
812
813     PAFSRetrieveAuthGroup AFSRetrieveAuthGroup;
814
815 } AFSLibraryInitCB;
816
817
818 #endif
819