VirtualBox

source: vbox/trunk/src/VBox/VMM/PDMAsyncCompletionFileInternal.h@ 26671

最後變更 在這個檔案從26671是 26671,由 vboxsync 提交於 15 年 前

AsyncCompletion: Make it possible to limit the bandwidth of a VM

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 24.9 KB
 
1/* $Id: PDMAsyncCompletionFileInternal.h 26671 2010-02-22 07:21:34Z vboxsync $ */
2/** @file
3 * PDM Async I/O - Transport data asynchronous in R3 using EMT.
4 */
5
6/*
7 * Copyright (C) 2006-2008 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22#ifndef ___PDMAsyncCompletionFileInternal_h
23#define ___PDMAsyncCompletionFileInternal_h
24
25#include <VBox/cfgm.h>
26#include <VBox/stam.h>
27#include <VBox/tm.h>
28#include <iprt/types.h>
29#include <iprt/file.h>
30#include <iprt/thread.h>
31#include <iprt/semaphore.h>
32#include <iprt/critsect.h>
33#include <iprt/avl.h>
34
35#include "PDMAsyncCompletionInternal.h"
36
37/** @todo: Revise the caching of tasks. We have currently four caches:
38 * Per endpoint task cache
39 * Per class cache
40 * Per endpoint task segment cache
41 * Per class task segment cache
42 *
43 * We could use the RT heap for this probably or extend MMR3Heap (uses RTMemAlloc
44 * instead of managing larger blocks) to have this global for the whole VM.
45 */
46
47RT_C_DECLS_BEGIN
48
49/**
50 * A few forward declerations.
51 */
52typedef struct PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
53/** Pointer to a request segment. */
54typedef struct PDMACTASKFILE *PPDMACTASKFILE;
55/** Pointer to the endpoint class data. */
56typedef struct PDMASYNCCOMPLETIONTASKFILE *PPDMASYNCCOMPLETIONTASKFILE;
57/** Pointer to a cache LRU list. */
58typedef struct PDMACFILELRULIST *PPDMACFILELRULIST;
59/** Pointer to the global cache structure. */
60typedef struct PDMACFILECACHEGLOBAL *PPDMACFILECACHEGLOBAL;
61/** Pointer to a task segment. */
62typedef struct PDMACFILETASKSEG *PPDMACFILETASKSEG;
63
64/**
65 * Blocking event types.
66 */
67typedef enum PDMACEPFILEAIOMGRBLOCKINGEVENT
68{
69 /** Invalid tye */
70 PDMACEPFILEAIOMGRBLOCKINGEVENT_INVALID = 0,
71 /** An endpoint is added to the manager. */
72 PDMACEPFILEAIOMGRBLOCKINGEVENT_ADD_ENDPOINT,
73 /** An endpoint is removed from the manager. */
74 PDMACEPFILEAIOMGRBLOCKINGEVENT_REMOVE_ENDPOINT,
75 /** An endpoint is about to be closed. */
76 PDMACEPFILEAIOMGRBLOCKINGEVENT_CLOSE_ENDPOINT,
77 /** The manager is requested to terminate */
78 PDMACEPFILEAIOMGRBLOCKINGEVENT_SHUTDOWN,
79 /** The manager is requested to suspend */
80 PDMACEPFILEAIOMGRBLOCKINGEVENT_SUSPEND,
81 /** The manager is requested to resume */
82 PDMACEPFILEAIOMGRBLOCKINGEVENT_RESUME,
83 /** 32bit hack */
84 PDMACEPFILEAIOMGRBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
85} PDMACEPFILEAIOMGRBLOCKINGEVENT;
86
87/**
88 * States of the I/O manager.
89 */
90typedef enum PDMACEPFILEMGRSTATE
91{
92 /** Invalid state. */
93 PDMACEPFILEMGRSTATE_INVALID = 0,
94 /** Normal running state accepting new requests
95 * and processing them.
96 */
97 PDMACEPFILEMGRSTATE_RUNNING,
98 /** Fault state - not accepting new tasks for endpoints but waiting for
99 * remaining ones to finish.
100 */
101 PDMACEPFILEMGRSTATE_FAULT,
102 /** Suspending state - not accepting new tasks for endpoints but waiting
103 * for remaining ones to finish.
104 */
105 PDMACEPFILEMGRSTATE_SUSPENDING,
106 /** Shutdown state - not accepting new tasks for endpoints but waiting
107 * for remaining ones to finish.
108 */
109 PDMACEPFILEMGRSTATE_SHUTDOWN,
110 /** 32bit hack */
111 PDMACEPFILEMGRSTATE_32BIT_HACK = 0x7fffffff
112} PDMACEPFILEMGRSTATE;
113
114/**
115 * State of a async I/O manager.
116 */
117typedef struct PDMACEPFILEMGR
118{
119 /** Next Aio manager in the list. */
120 R3PTRTYPE(struct PDMACEPFILEMGR *) pNext;
121 /** Previous Aio manager in the list. */
122 R3PTRTYPE(struct PDMACEPFILEMGR *) pPrev;
123 /** Current state of the manager. */
124 PDMACEPFILEMGRSTATE enmState;
125 /** Event semaphore the manager sleeps on when waiting for new requests. */
126 RTSEMEVENT EventSem;
127 /** Flag whether the thread waits in the event semaphore. */
128 volatile bool fWaitingEventSem;
129 /** Flag whether this manager uses the failsafe method. */
130 bool fFailsafe;
131 /** Thread data */
132 RTTHREAD Thread;
133 /** The async I/O context for this manager. */
134 RTFILEAIOCTX hAioCtx;
135 /** Flag whether the I/O manager was woken up. */
136 volatile bool fWokenUp;
137 /** List of endpoints assigned to this manager. */
138 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointsHead;
139 /** Number of endpoints assigned to the manager. */
140 unsigned cEndpoints;
141 /** Number of requests active currently. */
142 unsigned cRequestsActive;
143 /** Pointer to an array of free async I/O request handles. */
144 RTFILEAIOREQ *pahReqsFree;
145 /** Next free position for a free request handle. */
146 unsigned iFreeEntryNext;
147 /** Position of the next free task handle */
148 unsigned iFreeReqNext;
149 /** Size of the array. */
150 unsigned cReqEntries;
151 /** Flag whether at least one endpoint reached its bandwidth limit. */
152 bool fBwLimitReached;
153 /** Critical section protecting the blocking event handling. */
154 RTCRITSECT CritSectBlockingEvent;
155 /** Event sempahore for blocking external events.
156 * The caller waits on it until the async I/O manager
157 * finished processing the event. */
158 RTSEMEVENT EventSemBlock;
159 /** Flag whether a blocking event is pending and needs
160 * processing by the I/O manager. */
161 volatile bool fBlockingEventPending;
162 /** Blocking event type */
163 volatile PDMACEPFILEAIOMGRBLOCKINGEVENT enmBlockingEvent;
164 /** Event type data */
165 union
166 {
167 /** Add endpoint event. */
168 struct
169 {
170 /** The endpoint to be added */
171 volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
172 } AddEndpoint;
173 /** Remove endpoint event. */
174 struct
175 {
176 /** The endpoint to be removed */
177 volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
178 } RemoveEndpoint;
179 /** Close endpoint event. */
180 struct
181 {
182 /** The endpoint to be closed */
183 volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
184 } CloseEndpoint;
185 } BlockingEventData;
186} PDMACEPFILEMGR;
187/** Pointer to a async I/O manager state. */
188typedef PDMACEPFILEMGR *PPDMACEPFILEMGR;
189/** Pointer to a async I/O manager state pointer. */
190typedef PPDMACEPFILEMGR *PPPDMACEPFILEMGR;
191
192/**
193 * Bandwidth control manager instance data
194 */
195typedef struct PDMACFILEBWMGR
196{
197 /** Maximum number of bytes the VM is allowed to transfer (Max is 4GB/s) */
198 uint32_t cbVMTransferPerSecMax;
199 /** Number of bytes we start with */
200 uint32_t cbVMTransferPerSecStart;
201 /** Step after each update */
202 uint32_t cbVMTransferPerSecStep;
203 /** Number of bytes we are allowed to transfer till the next update.
204 * Resetted by the refresh timer. */
205 volatile uint32_t cbVMTransferAllowed;
206 /** Flag whether a request could not processed due to the limit. */
207 volatile bool fVMTransferLimitReached;
208 /** Reference counter - How many endpoints are associated with this manager. */
209 uint32_t cRefs;
210 /** The refresh timer */
211 PTMTIMERR3 pBwRefreshTimer;
212} PDMACFILEBWMGR;
213/** Pointer to a bandwidth control manager */
214typedef PDMACFILEBWMGR *PPDMACFILEBWMGR;
215/** Pointer to a bandwidth control manager pointer */
216typedef PPDMACFILEBWMGR *PPPDMACFILEBWMGR;
217
218/**
219 * A file access range lock.
220 */
221typedef struct PDMACFILERANGELOCK
222{
223 /** AVL node in the locked range tree of the endpoint. */
224 AVLRFOFFNODECORE Core;
225 /** How many tasks have locked this range. */
226 uint32_t cRefs;
227 /** Flag whether this is a read or write lock. */
228 bool fReadLock;
229 /** List of tasks which are waiting that the range gets unlocked. */
230 PPDMACTASKFILE pWaitingTasksHead;
231 /** List of tasks which are waiting that the range gets unlocked. */
232 PPDMACTASKFILE pWaitingTasksTail;
233} PDMACFILERANGELOCK, *PPDMACFILERANGELOCK;
234
235/**
236 * Data for one request segment waiting for cache entry.
237 */
238typedef struct PDMACFILETASKSEG
239{
240 /** Next task segment in the list. */
241 struct PDMACFILETASKSEG *pNext;
242 /** Task this segment is for. */
243 PPDMASYNCCOMPLETIONTASKFILE pTask;
244 /** Offset into the cache entry buffer to start reading from. */
245 uint32_t uBufOffset;
246 /** Number of bytes to transfer. */
247 size_t cbTransfer;
248 /** Pointer to the buffer. */
249 void *pvBuf;
250 /** Flag whether this entry writes data to the cache. */
251 bool fWrite;
252} PDMACFILETASKSEG;
253
254/**
255 * A cache entry
256 */
257typedef struct PDMACFILECACHEENTRY
258{
259 /** The AVL entry data. */
260 AVLRFOFFNODECORE Core;
261 /** Pointer to the previous element. Used in one of the LRU lists.*/
262 struct PDMACFILECACHEENTRY *pPrev;
263 /** Pointer to the next element. Used in one of the LRU lists.*/
264 struct PDMACFILECACHEENTRY *pNext;
265 /** Pointer to the list the entry is in. */
266 PPDMACFILELRULIST pList;
267 /** Pointer to the global cache structure. */
268 PPDMACFILECACHEGLOBAL pCache;
269 /** Endpoint the entry belongs to. */
270 PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
271 /** Flags for this entry. Combinations of PDMACFILECACHE_* #defines */
272 volatile uint32_t fFlags;
273 /** Reference counter. Prevents eviction of the entry if > 0. */
274 volatile uint32_t cRefs;
275 /** Size of the entry. */
276 size_t cbData;
277 /** Pointer to the memory containing the data. */
278 uint8_t *pbData;
279 /** Pointer to the buffer replacing the current one
280 * if the deprecated flag is set. */
281 uint8_t *pbDataReplace;
282 /** Head of list of tasks waiting for this one to finish. */
283 PPDMACFILETASKSEG pWaitingHead;
284 /** Tail of list of tasks waiting for this one to finish. */
285 PPDMACFILETASKSEG pWaitingTail;
286} PDMACFILECACHEENTRY, *PPDMACFILECACHEENTRY;
287/** I/O is still in progress for this entry. This entry is not evictable. */
288#define PDMACFILECACHE_ENTRY_IO_IN_PROGRESS RT_BIT(0)
289/** Entry is locked and thus not evictable. */
290#define PDMACFILECACHE_ENTRY_LOCKED RT_BIT(1)
291/** Entry is dirty */
292#define PDMACFILECACHE_ENTRY_IS_DIRTY RT_BIT(2)
293/** The current buffer used for the entry is deprecated.
294 * The new one is available and will be replaced as soon as the file update
295 * completed.
296 */
297#define PDMACFILECACHE_ENTRY_IS_DEPRECATED RT_BIT(3)
298/** Entry is not evictable. */
299#define PDMACFILECACHE_NOT_EVICTABLE (PDMACFILECACHE_ENTRY_LOCKED | PDMACFILECACHE_IO_IN_PROGRESS | PDMACFILECACHE_ENTRY_IS_DEPRECATED)
300
301/**
302 * LRU list data
303 */
304typedef struct PDMACFILELRULIST
305{
306 /** Head of the list. */
307 PPDMACFILECACHEENTRY pHead;
308 /** Tail of the list. */
309 PPDMACFILECACHEENTRY pTail;
310 /** Number of bytes cached in the list. */
311 uint32_t cbCached;
312} PDMACFILELRULIST;
313
314/**
315 * Global cache data.
316 */
317typedef struct PDMACFILECACHEGLOBAL
318{
319 /** Maximum size of the cache in bytes. */
320 uint32_t cbMax;
321 /** Current size of the cache in bytes. */
322 uint32_t cbCached;
323 /** Critical section protecting the cache. */
324 RTCRITSECT CritSect;
325 uint32_t cbRecentlyUsedInMax;
326 uint32_t cbRecentlyUsedOutMax;
327 PDMACFILELRULIST LruRecentlyUsedIn;
328 PDMACFILELRULIST LruRecentlyUsedOut;
329 PDMACFILELRULIST LruFrequentlyUsed;
330#ifdef VBOX_WITH_STATISTICS
331 /** Hit counter. */
332 STAMCOUNTER cHits;
333 /** Partial hit counter. */
334 STAMCOUNTER cPartialHits;
335 /** Miss counter. */
336 STAMCOUNTER cMisses;
337 /** Bytes read from cache. */
338 STAMCOUNTER StatRead;
339 /** Bytes written to the cache. */
340 STAMCOUNTER StatWritten;
341 /** Time spend to get an entry in the AVL tree. */
342 STAMPROFILEADV StatTreeGet;
343 /** Time spend to insert an entry in the AVL tree. */
344 STAMPROFILEADV StatTreeInsert;
345 /** Time spend to remove an entry in the AVL tree. */
346 STAMPROFILEADV StatTreeRemove;
347 /** Number of times a buffer could be reused. */
348 STAMCOUNTER StatBuffersReused;
349#endif
350} PDMACFILECACHEGLOBAL;
351
352/**
353 * Per endpoint cache data.
354 */
355typedef struct PDMACFILEENDPOINTCACHE
356{
357 /** AVL tree managing cache entries. */
358 PAVLRFOFFTREE pTree;
359 /** R/W semaphore protecting cached entries for this endpoint. */
360 RTSEMRW SemRWEntries;
361 /** Pointer to the gobal cache data */
362 PPDMACFILECACHEGLOBAL pCache;
363 /** Number of writes outstanding. */
364 volatile uint32_t cWritesOutstanding;
365 /** Handle of the flush request if one is active */
366 volatile PPDMASYNCCOMPLETIONTASKFILE pTaskFlush;
367#ifdef VBOX_WITH_STATISTICS
368 /** Number of times a write was deferred because the cache entry was still in progress */
369 STAMCOUNTER StatWriteDeferred;
370#endif
371} PDMACFILEENDPOINTCACHE, *PPDMACFILEENDPOINTCACHE;
372
373/**
374 * Global data for the file endpoint class.
375 */
376typedef struct PDMASYNCCOMPLETIONEPCLASSFILE
377{
378 /** Common data. */
379 PDMASYNCCOMPLETIONEPCLASS Core;
380 /** Flag whether we use the failsafe method. */
381 bool fFailsafe;
382 /** Flag whether the file data cache is enabled. */
383 bool fCacheEnabled;
384 /** Flag whether the host cache should be used too. */
385 bool fHostCacheEnabled;
386 /** Critical section protecting the list of async I/O managers. */
387 RTCRITSECT CritSect;
388 /** Pointer to the head of the async I/O managers. */
389 R3PTRTYPE(PPDMACEPFILEMGR) pAioMgrHead;
390 /** Number of async I/O managers currently running. */
391 unsigned cAioMgrs;
392 /** Maximum number of segments to cache per endpoint */
393 unsigned cTasksCacheMax;
394 /** Maximum number of simultaneous outstandingrequests. */
395 uint32_t cReqsOutstandingMax;
396 /** Bitmask for checking the alignment of a buffer. */
397 RTR3UINTPTR uBitmaskAlignment;
398 /** Global cache data. */
399 PDMACFILECACHEGLOBAL Cache;
400 /** Flag whether the out of resources warning was printed already. */
401 bool fOutOfResourcesWarningPrinted;
402 /** The global bandwidth control manager */
403 PPDMACFILEBWMGR pBwMgr;
404} PDMASYNCCOMPLETIONEPCLASSFILE;
405/** Pointer to the endpoint class data. */
406typedef PDMASYNCCOMPLETIONEPCLASSFILE *PPDMASYNCCOMPLETIONEPCLASSFILE;
407
408typedef enum PDMACEPFILEBLOCKINGEVENT
409{
410 /** The invalid event type */
411 PDMACEPFILEBLOCKINGEVENT_INVALID = 0,
412 /** A task is about to be canceled */
413 PDMACEPFILEBLOCKINGEVENT_CANCEL,
414 /** Usual 32bit hack */
415 PDMACEPFILEBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
416} PDMACEPFILEBLOCKINGEVENT;
417
418/**
419 * States of the endpoint.
420 */
421typedef enum PDMASYNCCOMPLETIONENDPOINTFILESTATE
422{
423 /** Invalid state. */
424 PDMASYNCCOMPLETIONENDPOINTFILESTATE_INVALID = 0,
425 /** Normal running state accepting new requests
426 * and processing them.
427 */
428 PDMASYNCCOMPLETIONENDPOINTFILESTATE_ACTIVE,
429 /** The endpoint is about to be closed - not accepting new tasks for endpoints but waiting for
430 * remaining ones to finish.
431 */
432 PDMASYNCCOMPLETIONENDPOINTFILESTATE_CLOSING,
433 /** Removing from current I/O manager state - not processing new tasks for endpoints but waiting
434 * for remaining ones to finish.
435 */
436 PDMASYNCCOMPLETIONENDPOINTFILESTATE_REMOVING,
437 /** The current endpoint will be migrated to another I/O manager. */
438 PDMASYNCCOMPLETIONENDPOINTFILESTATE_MIGRATING,
439 /** 32bit hack */
440 PDMASYNCCOMPLETIONENDPOINTFILESTATE_32BIT_HACK = 0x7fffffff
441} PDMASYNCCOMPLETIONENDPOINTFILESTATE;
442
443/**
444 * Data for the file endpoint.
445 */
446typedef struct PDMASYNCCOMPLETIONENDPOINTFILE
447{
448 /** Common data. */
449 PDMASYNCCOMPLETIONENDPOINT Core;
450 /** Current state of the endpoint. */
451 PDMASYNCCOMPLETIONENDPOINTFILESTATE enmState;
452 /** async I/O manager this endpoint is assigned to. */
453 R3PTRTYPE(volatile PPDMACEPFILEMGR) pAioMgr;
454 /** Flags for opening the file. */
455 unsigned fFlags;
456 /** File handle. */
457 RTFILE File;
458 /** Size of the underlying file.
459 * Updated while data is appended. */
460 volatile uint64_t cbFile;
461 /** Flag whether caching is enabled for this file. */
462 bool fCaching;
463 /** Flag whether the file was opened readonly. */
464 bool fReadonly;
465 /** List of new tasks. */
466 R3PTRTYPE(volatile PPDMACTASKFILE) pTasksNewHead;
467
468 /** Head of the small cache for allocated task segments for exclusive
469 * use by this endpoint. */
470 R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeHead;
471 /** Tail of the small cache for allocated task segments for exclusive
472 * use by this endpoint. */
473 R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeTail;
474 /** Number of elements in the cache. */
475 volatile uint32_t cTasksCached;
476
477 /** Cache of endpoint data. */
478 PDMACFILEENDPOINTCACHE DataCache;
479 /** Pointer to the associated bandwidth control manager */
480 PPDMACFILEBWMGR pBwMgr;
481
482 /** Flag whether a flush request is currently active */
483 PPDMACTASKFILE pFlushReq;
484
485 /** Event sempahore for blocking external events.
486 * The caller waits on it until the async I/O manager
487 * finished processing the event. */
488 RTSEMEVENT EventSemBlock;
489 /** Flag whether a blocking event is pending and needs
490 * processing by the I/O manager. */
491 bool fBlockingEventPending;
492 /** Blocking event type */
493 PDMACEPFILEBLOCKINGEVENT enmBlockingEvent;
494
495#ifdef VBOX_WITH_STATISTICS
496 /** Time spend in a read. */
497 STAMPROFILEADV StatRead;
498 /** Time spend in a write. */
499 STAMPROFILEADV StatWrite;
500#endif
501
502 /** Additional data needed for the event types. */
503 union
504 {
505 /** Cancelation event. */
506 struct
507 {
508 /** The task to cancel. */
509 PPDMACTASKFILE pTask;
510 } Cancel;
511 } BlockingEventData;
512 /** Data for exclusive use by the assigned async I/O manager. */
513 struct
514 {
515 /** Pointer to the next endpoint assigned to the manager. */
516 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointNext;
517 /** Pointer to the previous endpoint assigned to the manager. */
518 R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointPrev;
519 /** List of pending requests (not submitted due to usage restrictions
520 * or a pending flush request) */
521 R3PTRTYPE(PPDMACTASKFILE) pReqsPendingHead;
522 /** Tail of pending requests. */
523 R3PTRTYPE(PPDMACTASKFILE) pReqsPendingTail;
524 /** Tree of currently locked ranges.
525 * If a write task is enqueued the range gets locked and any other
526 * task writing to that range has to wait until the task completes.
527 */
528 PAVLRFOFFTREE pTreeRangesLocked;
529 /** Number of requests currently being processed for this endpoint
530 * (excluded flush requests). */
531 unsigned cRequestsActive;
532 /** Number of requests processed during the last second. */
533 unsigned cReqsPerSec;
534 /** Current number of processed requests for the current update period. */
535 unsigned cReqsProcessed;
536 /** Flag whether the endpoint is about to be moved to another manager. */
537 bool fMoving;
538 /** Destination I/O manager. */
539 PPDMACEPFILEMGR pAioMgrDst;
540 } AioMgr;
541} PDMASYNCCOMPLETIONENDPOINTFILE;
542/** Pointer to the endpoint class data. */
543typedef PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
544
545/** Request completion function */
546typedef DECLCALLBACK(void) FNPDMACTASKCOMPLETED(PPDMACTASKFILE pTask, void *pvUser);
547/** Pointer to a request completion function. */
548typedef FNPDMACTASKCOMPLETED *PFNPDMACTASKCOMPLETED;
549
550/**
551 * Transfer type.
552 */
553typedef enum PDMACTASKFILETRANSFER
554{
555 /** Invalid. */
556 PDMACTASKFILETRANSFER_INVALID = 0,
557 /** Read transfer. */
558 PDMACTASKFILETRANSFER_READ,
559 /** Write transfer. */
560 PDMACTASKFILETRANSFER_WRITE,
561 /** Flush transfer. */
562 PDMACTASKFILETRANSFER_FLUSH
563} PDMACTASKFILETRANSFER;
564
565/**
566 * Data of a request.
567 */
568typedef struct PDMACTASKFILE
569{
570 /** Pointer to the range lock we are waiting for */
571 PPDMACFILERANGELOCK pRangeLock;
572 /** Next task in the list. (Depending on the state) */
573 struct PDMACTASKFILE *pNext;
574 /** Endpoint */
575 PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
576 /** Transfer type. */
577 PDMACTASKFILETRANSFER enmTransferType;
578 /** Start offset */
579 RTFOFF Off;
580 /** Data segment. */
581 PDMDATASEG DataSeg;
582 /** Flag whether this segment uses a bounce buffer
583 * because the provided buffer doesn't meet host requirements. */
584 bool fBounceBuffer;
585 /** Pointer to the used bounce buffer if any. */
586 void *pvBounceBuffer;
587 /** Start offset in the bounce buffer to copy from. */
588 uint32_t uBounceBufOffset;
589 /** Flag whether this is a prefetch request. */
590 bool fPrefetch;
591 /** Completion function to call on completion. */
592 PFNPDMACTASKCOMPLETED pfnCompleted;
593 /** User data */
594 void *pvUser;
595} PDMACTASKFILE;
596
597/**
598 * Per task data.
599 */
600typedef struct PDMASYNCCOMPLETIONTASKFILE
601{
602 /** Common data. */
603 PDMASYNCCOMPLETIONTASK Core;
604 /** Number of bytes to transfer until this task completes. */
605 volatile int32_t cbTransferLeft;
606 /** Flag whether the task completed. */
607 volatile bool fCompleted;
608} PDMASYNCCOMPLETIONTASKFILE;
609
610int pdmacFileAioMgrFailsafe(RTTHREAD ThreadSelf, void *pvUser);
611int pdmacFileAioMgrNormal(RTTHREAD ThreadSelf, void *pvUser);
612
613int pdmacFileAioMgrNormalInit(PPDMACEPFILEMGR pAioMgr);
614void pdmacFileAioMgrNormalDestroy(PPDMACEPFILEMGR pAioMgr);
615
616int pdmacFileAioMgrCreate(PPDMASYNCCOMPLETIONEPCLASSFILE pEpClass, PPPDMACEPFILEMGR ppAioMgr, bool fFailsafe);
617
618int pdmacFileAioMgrAddEndpoint(PPDMACEPFILEMGR pAioMgr, PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
619
620PPDMACTASKFILE pdmacFileEpGetNewTasks(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
621PPDMACTASKFILE pdmacFileTaskAlloc(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
622void pdmacFileTaskFree(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
623 PPDMACTASKFILE pTask);
624
625int pdmacFileEpAddTask(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMACTASKFILE pTask);
626
627void pdmacFileEpTaskCompleted(PPDMACTASKFILE pTask, void *pvUser);
628
629bool pdmacFileBwMgrIsTransferAllowed(PPDMACFILEBWMGR pBwMgr, uint32_t cbTransfer);
630
631int pdmacFileCacheInit(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile, PCFGMNODE pCfgNode);
632void pdmacFileCacheDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
633int pdmacFileEpCacheInit(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
634void pdmacFileEpCacheDestroy(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
635
636int pdmacFileEpCacheRead(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
637 RTFOFF off, PCPDMDATASEG paSegments, size_t cSegments,
638 size_t cbRead);
639int pdmacFileEpCacheWrite(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
640 RTFOFF off, PCPDMDATASEG paSegments, size_t cSegments,
641 size_t cbWrite);
642int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask);
643
644RT_C_DECLS_END
645
646#endif
647
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette