1 | /* $Id: PDMAsyncCompletionFileInternal.h 39034 2011-10-19 11:43:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM Async I/O - Transport data asynchronous in R3 using EMT.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2008 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.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 |
|
---|
18 | #ifndef ___PDMAsyncCompletionFileInternal_h
|
---|
19 | #define ___PDMAsyncCompletionFileInternal_h
|
---|
20 |
|
---|
21 | #include <VBox/vmm/cfgm.h>
|
---|
22 | #include <VBox/vmm/stam.h>
|
---|
23 | #include <VBox/vmm/tm.h>
|
---|
24 | #include <iprt/types.h>
|
---|
25 | #include <iprt/file.h>
|
---|
26 | #include <iprt/thread.h>
|
---|
27 | #include <iprt/semaphore.h>
|
---|
28 | #include <iprt/critsect.h>
|
---|
29 | #include <iprt/avl.h>
|
---|
30 | #include <iprt/list.h>
|
---|
31 | #include <iprt/spinlock.h>
|
---|
32 | #include <iprt/memcache.h>
|
---|
33 |
|
---|
34 | #include "PDMAsyncCompletionInternal.h"
|
---|
35 |
|
---|
36 | /** @todo: Revise the caching of tasks. We have currently four caches:
|
---|
37 | * Per endpoint task cache
|
---|
38 | * Per class cache
|
---|
39 | * Per endpoint task segment cache
|
---|
40 | * Per class task segment cache
|
---|
41 | *
|
---|
42 | * We could use the RT heap for this probably or extend MMR3Heap (uses RTMemAlloc
|
---|
43 | * instead of managing larger blocks) to have this global for the whole VM.
|
---|
44 | */
|
---|
45 |
|
---|
46 | /** Enable for delay injection from the debugger. */
|
---|
47 | #if 0
|
---|
48 | # define PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | RT_C_DECLS_BEGIN
|
---|
52 |
|
---|
53 | /**
|
---|
54 | * A few forward declarations.
|
---|
55 | */
|
---|
56 | typedef struct PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
57 | /** Pointer to a request segment. */
|
---|
58 | typedef struct PDMACTASKFILE *PPDMACTASKFILE;
|
---|
59 | /** Pointer to the endpoint class data. */
|
---|
60 | typedef struct PDMASYNCCOMPLETIONTASKFILE *PPDMASYNCCOMPLETIONTASKFILE;
|
---|
61 | /** Pointer to a cache LRU list. */
|
---|
62 | typedef struct PDMACFILELRULIST *PPDMACFILELRULIST;
|
---|
63 | /** Pointer to the global cache structure. */
|
---|
64 | typedef struct PDMACFILECACHEGLOBAL *PPDMACFILECACHEGLOBAL;
|
---|
65 | /** Pointer to a task segment. */
|
---|
66 | typedef struct PDMACFILETASKSEG *PPDMACFILETASKSEG;
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * Blocking event types.
|
---|
70 | */
|
---|
71 | typedef enum PDMACEPFILEAIOMGRBLOCKINGEVENT
|
---|
72 | {
|
---|
73 | /** Invalid tye */
|
---|
74 | PDMACEPFILEAIOMGRBLOCKINGEVENT_INVALID = 0,
|
---|
75 | /** An endpoint is added to the manager. */
|
---|
76 | PDMACEPFILEAIOMGRBLOCKINGEVENT_ADD_ENDPOINT,
|
---|
77 | /** An endpoint is removed from the manager. */
|
---|
78 | PDMACEPFILEAIOMGRBLOCKINGEVENT_REMOVE_ENDPOINT,
|
---|
79 | /** An endpoint is about to be closed. */
|
---|
80 | PDMACEPFILEAIOMGRBLOCKINGEVENT_CLOSE_ENDPOINT,
|
---|
81 | /** The manager is requested to terminate */
|
---|
82 | PDMACEPFILEAIOMGRBLOCKINGEVENT_SHUTDOWN,
|
---|
83 | /** The manager is requested to suspend */
|
---|
84 | PDMACEPFILEAIOMGRBLOCKINGEVENT_SUSPEND,
|
---|
85 | /** The manager is requested to resume */
|
---|
86 | PDMACEPFILEAIOMGRBLOCKINGEVENT_RESUME,
|
---|
87 | /** 32bit hack */
|
---|
88 | PDMACEPFILEAIOMGRBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
|
---|
89 | } PDMACEPFILEAIOMGRBLOCKINGEVENT;
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * I/O manager type.
|
---|
93 | */
|
---|
94 | typedef enum PDMACEPFILEMGRTYPE
|
---|
95 | {
|
---|
96 | /** Simple aka failsafe */
|
---|
97 | PDMACEPFILEMGRTYPE_SIMPLE = 0,
|
---|
98 | /** Async I/O with host cache enabled. */
|
---|
99 | PDMACEPFILEMGRTYPE_ASYNC,
|
---|
100 | /** 32bit hack */
|
---|
101 | PDMACEPFILEMGRTYPE_32BIT_HACK = 0x7fffffff
|
---|
102 | } PDMACEPFILEMGRTYPE;
|
---|
103 | /** Pointer to a I/O manager type */
|
---|
104 | typedef PDMACEPFILEMGRTYPE *PPDMACEPFILEMGRTYPE;
|
---|
105 |
|
---|
106 | /**
|
---|
107 | * States of the I/O manager.
|
---|
108 | */
|
---|
109 | typedef enum PDMACEPFILEMGRSTATE
|
---|
110 | {
|
---|
111 | /** Invalid state. */
|
---|
112 | PDMACEPFILEMGRSTATE_INVALID = 0,
|
---|
113 | /** Normal running state accepting new requests
|
---|
114 | * and processing them.
|
---|
115 | */
|
---|
116 | PDMACEPFILEMGRSTATE_RUNNING,
|
---|
117 | /** Fault state - not accepting new tasks for endpoints but waiting for
|
---|
118 | * remaining ones to finish.
|
---|
119 | */
|
---|
120 | PDMACEPFILEMGRSTATE_FAULT,
|
---|
121 | /** Suspending state - not accepting new tasks for endpoints but waiting
|
---|
122 | * for remaining ones to finish.
|
---|
123 | */
|
---|
124 | PDMACEPFILEMGRSTATE_SUSPENDING,
|
---|
125 | /** Shutdown state - not accepting new tasks for endpoints but waiting
|
---|
126 | * for remaining ones to finish.
|
---|
127 | */
|
---|
128 | PDMACEPFILEMGRSTATE_SHUTDOWN,
|
---|
129 | /** The I/O manager waits for all active requests to complete and doesn't queue
|
---|
130 | * new ones because it needs to grow to handle more requests.
|
---|
131 | */
|
---|
132 | PDMACEPFILEMGRSTATE_GROWING,
|
---|
133 | /** 32bit hack */
|
---|
134 | PDMACEPFILEMGRSTATE_32BIT_HACK = 0x7fffffff
|
---|
135 | } PDMACEPFILEMGRSTATE;
|
---|
136 |
|
---|
137 | /**
|
---|
138 | * State of a async I/O manager.
|
---|
139 | */
|
---|
140 | typedef struct PDMACEPFILEMGR
|
---|
141 | {
|
---|
142 | /** Next Aio manager in the list. */
|
---|
143 | R3PTRTYPE(struct PDMACEPFILEMGR *) pNext;
|
---|
144 | /** Previous Aio manager in the list. */
|
---|
145 | R3PTRTYPE(struct PDMACEPFILEMGR *) pPrev;
|
---|
146 | /** Manager type */
|
---|
147 | PDMACEPFILEMGRTYPE enmMgrType;
|
---|
148 | /** Current state of the manager. */
|
---|
149 | PDMACEPFILEMGRSTATE enmState;
|
---|
150 | /** Event semaphore the manager sleeps on when waiting for new requests. */
|
---|
151 | RTSEMEVENT EventSem;
|
---|
152 | /** Flag whether the thread waits in the event semaphore. */
|
---|
153 | volatile bool fWaitingEventSem;
|
---|
154 | /** Thread data */
|
---|
155 | RTTHREAD Thread;
|
---|
156 | /** The async I/O context for this manager. */
|
---|
157 | RTFILEAIOCTX hAioCtx;
|
---|
158 | /** Flag whether the I/O manager was woken up. */
|
---|
159 | volatile bool fWokenUp;
|
---|
160 | /** List of endpoints assigned to this manager. */
|
---|
161 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointsHead;
|
---|
162 | /** Number of endpoints assigned to the manager. */
|
---|
163 | unsigned cEndpoints;
|
---|
164 | /** Number of requests active currently. */
|
---|
165 | unsigned cRequestsActive;
|
---|
166 | /** Number of maximum requests active. */
|
---|
167 | uint32_t cRequestsActiveMax;
|
---|
168 | /** Pointer to an array of free async I/O request handles. */
|
---|
169 | RTFILEAIOREQ *pahReqsFree;
|
---|
170 | /** Index of the next free entry in the cache. */
|
---|
171 | uint32_t iFreeEntry;
|
---|
172 | /** Size of the array. */
|
---|
173 | unsigned cReqEntries;
|
---|
174 | /** Memory cache for file range locks. */
|
---|
175 | RTMEMCACHE hMemCacheRangeLocks;
|
---|
176 | /** Number of milliseconds to wait until the bandwidth is refreshed for at least
|
---|
177 | * one endpoint and it is possible to process more requests. */
|
---|
178 | RTMSINTERVAL msBwLimitExpired;
|
---|
179 | /** Critical section protecting the blocking event handling. */
|
---|
180 | RTCRITSECT CritSectBlockingEvent;
|
---|
181 | /** Event semaphore for blocking external events.
|
---|
182 | * The caller waits on it until the async I/O manager
|
---|
183 | * finished processing the event. */
|
---|
184 | RTSEMEVENT EventSemBlock;
|
---|
185 | /** Flag whether a blocking event is pending and needs
|
---|
186 | * processing by the I/O manager. */
|
---|
187 | volatile bool fBlockingEventPending;
|
---|
188 | /** Blocking event type */
|
---|
189 | volatile PDMACEPFILEAIOMGRBLOCKINGEVENT enmBlockingEvent;
|
---|
190 | /** Event type data */
|
---|
191 | union
|
---|
192 | {
|
---|
193 | /** Add endpoint event. */
|
---|
194 | struct
|
---|
195 | {
|
---|
196 | /** The endpoint to be added */
|
---|
197 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
198 | } AddEndpoint;
|
---|
199 | /** Remove endpoint event. */
|
---|
200 | struct
|
---|
201 | {
|
---|
202 | /** The endpoint to be removed */
|
---|
203 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
204 | } RemoveEndpoint;
|
---|
205 | /** Close endpoint event. */
|
---|
206 | struct
|
---|
207 | {
|
---|
208 | /** The endpoint to be closed */
|
---|
209 | volatile PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
210 | } CloseEndpoint;
|
---|
211 | } BlockingEventData;
|
---|
212 | } PDMACEPFILEMGR;
|
---|
213 | /** Pointer to a async I/O manager state. */
|
---|
214 | typedef PDMACEPFILEMGR *PPDMACEPFILEMGR;
|
---|
215 | /** Pointer to a async I/O manager state pointer. */
|
---|
216 | typedef PPDMACEPFILEMGR *PPPDMACEPFILEMGR;
|
---|
217 |
|
---|
218 | /**
|
---|
219 | * A file access range lock.
|
---|
220 | */
|
---|
221 | typedef 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 | * Backend type for the endpoint.
|
---|
237 | */
|
---|
238 | typedef enum PDMACFILEEPBACKEND
|
---|
239 | {
|
---|
240 | /** Non buffered. */
|
---|
241 | PDMACFILEEPBACKEND_NON_BUFFERED = 0,
|
---|
242 | /** Buffered (i.e host cache enabled) */
|
---|
243 | PDMACFILEEPBACKEND_BUFFERED,
|
---|
244 | /** 32bit hack */
|
---|
245 | PDMACFILEEPBACKEND_32BIT_HACK = 0x7fffffff
|
---|
246 | } PDMACFILEEPBACKEND;
|
---|
247 | /** Pointer to a backend type. */
|
---|
248 | typedef PDMACFILEEPBACKEND *PPDMACFILEEPBACKEND;
|
---|
249 |
|
---|
250 | /**
|
---|
251 | * Global data for the file endpoint class.
|
---|
252 | */
|
---|
253 | typedef struct PDMASYNCCOMPLETIONEPCLASSFILE
|
---|
254 | {
|
---|
255 | /** Common data. */
|
---|
256 | PDMASYNCCOMPLETIONEPCLASS Core;
|
---|
257 | /** Override I/O manager type - set to SIMPLE after failure. */
|
---|
258 | PDMACEPFILEMGRTYPE enmMgrTypeOverride;
|
---|
259 | /** Default backend type for the endpoint. */
|
---|
260 | PDMACFILEEPBACKEND enmEpBackendDefault;
|
---|
261 | RTCRITSECT CritSect;
|
---|
262 | /** Pointer to the head of the async I/O managers. */
|
---|
263 | R3PTRTYPE(PPDMACEPFILEMGR) pAioMgrHead;
|
---|
264 | /** Number of async I/O managers currently running. */
|
---|
265 | unsigned cAioMgrs;
|
---|
266 | /** Maximum number of segments to cache per endpoint */
|
---|
267 | unsigned cTasksCacheMax;
|
---|
268 | /** Maximum number of simultaneous outstandingrequests. */
|
---|
269 | uint32_t cReqsOutstandingMax;
|
---|
270 | /** Bitmask for checking the alignment of a buffer. */
|
---|
271 | RTR3UINTPTR uBitmaskAlignment;
|
---|
272 | /** Flag whether the out of resources warning was printed already. */
|
---|
273 | bool fOutOfResourcesWarningPrinted;
|
---|
274 | } PDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
275 | /** Pointer to the endpoint class data. */
|
---|
276 | typedef PDMASYNCCOMPLETIONEPCLASSFILE *PPDMASYNCCOMPLETIONEPCLASSFILE;
|
---|
277 |
|
---|
278 | typedef enum PDMACEPFILEBLOCKINGEVENT
|
---|
279 | {
|
---|
280 | /** The invalid event type */
|
---|
281 | PDMACEPFILEBLOCKINGEVENT_INVALID = 0,
|
---|
282 | /** A task is about to be canceled */
|
---|
283 | PDMACEPFILEBLOCKINGEVENT_CANCEL,
|
---|
284 | /** Usual 32bit hack */
|
---|
285 | PDMACEPFILEBLOCKINGEVENT_32BIT_HACK = 0x7fffffff
|
---|
286 | } PDMACEPFILEBLOCKINGEVENT;
|
---|
287 |
|
---|
288 | /**
|
---|
289 | * States of the endpoint.
|
---|
290 | */
|
---|
291 | typedef enum PDMASYNCCOMPLETIONENDPOINTFILESTATE
|
---|
292 | {
|
---|
293 | /** Invalid state. */
|
---|
294 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_INVALID = 0,
|
---|
295 | /** Normal running state accepting new requests
|
---|
296 | * and processing them.
|
---|
297 | */
|
---|
298 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_ACTIVE,
|
---|
299 | /** The endpoint is about to be closed - not accepting new tasks for endpoints but waiting for
|
---|
300 | * remaining ones to finish.
|
---|
301 | */
|
---|
302 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_CLOSING,
|
---|
303 | /** Removing from current I/O manager state - not processing new tasks for endpoints but waiting
|
---|
304 | * for remaining ones to finish.
|
---|
305 | */
|
---|
306 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_REMOVING,
|
---|
307 | /** The current endpoint will be migrated to another I/O manager. */
|
---|
308 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_MIGRATING,
|
---|
309 | /** 32bit hack */
|
---|
310 | PDMASYNCCOMPLETIONENDPOINTFILESTATE_32BIT_HACK = 0x7fffffff
|
---|
311 | } PDMASYNCCOMPLETIONENDPOINTFILESTATE;
|
---|
312 |
|
---|
313 | /**
|
---|
314 | * Data for the file endpoint.
|
---|
315 | */
|
---|
316 | typedef struct PDMASYNCCOMPLETIONENDPOINTFILE
|
---|
317 | {
|
---|
318 | /** Common data. */
|
---|
319 | PDMASYNCCOMPLETIONENDPOINT Core;
|
---|
320 | /** Current state of the endpoint. */
|
---|
321 | PDMASYNCCOMPLETIONENDPOINTFILESTATE enmState;
|
---|
322 | /** The backend to use for this endpoint. */
|
---|
323 | PDMACFILEEPBACKEND enmBackendType;
|
---|
324 | /** async I/O manager this endpoint is assigned to. */
|
---|
325 | R3PTRTYPE(volatile PPDMACEPFILEMGR) pAioMgr;
|
---|
326 | /** Flags for opening the file. */
|
---|
327 | unsigned fFlags;
|
---|
328 | /** File handle. */
|
---|
329 | RTFILE hFile;
|
---|
330 | /** Real size of the file. Only updated if data is appended. */
|
---|
331 | volatile uint64_t cbFile;
|
---|
332 | /** List of new tasks. */
|
---|
333 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksNewHead;
|
---|
334 |
|
---|
335 | /** Head of the small cache for allocated task segments for exclusive
|
---|
336 | * use by this endpoint. */
|
---|
337 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeHead;
|
---|
338 | /** Tail of the small cache for allocated task segments for exclusive
|
---|
339 | * use by this endpoint. */
|
---|
340 | R3PTRTYPE(volatile PPDMACTASKFILE) pTasksFreeTail;
|
---|
341 | /** Number of elements in the cache. */
|
---|
342 | volatile uint32_t cTasksCached;
|
---|
343 |
|
---|
344 | /** Flag whether a flush request is currently active */
|
---|
345 | PPDMACTASKFILE pFlushReq;
|
---|
346 |
|
---|
347 | #ifdef VBOX_WITH_STATISTICS
|
---|
348 | /** Time spend in a read. */
|
---|
349 | STAMPROFILEADV StatRead;
|
---|
350 | /** Time spend in a write. */
|
---|
351 | STAMPROFILEADV StatWrite;
|
---|
352 | #endif
|
---|
353 |
|
---|
354 | /** Event semaphore for blocking external events.
|
---|
355 | * The caller waits on it until the async I/O manager
|
---|
356 | * finished processing the event. */
|
---|
357 | RTSEMEVENT EventSemBlock;
|
---|
358 | /** Flag whether caching is enabled for this file. */
|
---|
359 | bool fCaching;
|
---|
360 | /** Flag whether the file was opened readonly. */
|
---|
361 | bool fReadonly;
|
---|
362 | /** Flag whether the host supports the async flush API. */
|
---|
363 | bool fAsyncFlushSupported;
|
---|
364 | #ifdef VBOX_WITH_DEBUGGER
|
---|
365 | /** Status code to inject for the next complete read. */
|
---|
366 | volatile int rcReqRead;
|
---|
367 | /** Status code to inject for the next complete write. */
|
---|
368 | volatile int rcReqWrite;
|
---|
369 | #endif
|
---|
370 | #ifdef PDM_ASYNC_COMPLETION_FILE_WITH_DELAY
|
---|
371 | /** Request delay. */
|
---|
372 | volatile uint32_t msDelay;
|
---|
373 | /** The current task which gets delayed. */
|
---|
374 | PPDMASYNCCOMPLETIONTASKFILE pReqDelayed;
|
---|
375 | /** Timestamp when the delay expires. */
|
---|
376 | uint64_t tsDelayEnd;
|
---|
377 | #endif
|
---|
378 | /** Flag whether a blocking event is pending and needs
|
---|
379 | * processing by the I/O manager. */
|
---|
380 | bool fBlockingEventPending;
|
---|
381 | /** Blocking event type */
|
---|
382 | PDMACEPFILEBLOCKINGEVENT enmBlockingEvent;
|
---|
383 |
|
---|
384 | /** Additional data needed for the event types. */
|
---|
385 | union
|
---|
386 | {
|
---|
387 | /** Cancelation event. */
|
---|
388 | struct
|
---|
389 | {
|
---|
390 | /** The task to cancel. */
|
---|
391 | PPDMACTASKFILE pTask;
|
---|
392 | } Cancel;
|
---|
393 | } BlockingEventData;
|
---|
394 | /** Data for exclusive use by the assigned async I/O manager. */
|
---|
395 | struct
|
---|
396 | {
|
---|
397 | /** Pointer to the next endpoint assigned to the manager. */
|
---|
398 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointNext;
|
---|
399 | /** Pointer to the previous endpoint assigned to the manager. */
|
---|
400 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINTFILE) pEndpointPrev;
|
---|
401 | /** List of pending requests (not submitted due to usage restrictions
|
---|
402 | * or a pending flush request) */
|
---|
403 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingHead;
|
---|
404 | /** Tail of pending requests. */
|
---|
405 | R3PTRTYPE(PPDMACTASKFILE) pReqsPendingTail;
|
---|
406 | /** Tree of currently locked ranges.
|
---|
407 | * If a write task is enqueued the range gets locked and any other
|
---|
408 | * task writing to that range has to wait until the task completes.
|
---|
409 | */
|
---|
410 | PAVLRFOFFTREE pTreeRangesLocked;
|
---|
411 | /** Number of requests currently being processed for this endpoint
|
---|
412 | * (excluded flush requests). */
|
---|
413 | unsigned cRequestsActive;
|
---|
414 | /** Number of requests processed during the last second. */
|
---|
415 | unsigned cReqsPerSec;
|
---|
416 | /** Current number of processed requests for the current update period. */
|
---|
417 | unsigned cReqsProcessed;
|
---|
418 | /** Flag whether the endpoint is about to be moved to another manager. */
|
---|
419 | bool fMoving;
|
---|
420 | /** Destination I/O manager. */
|
---|
421 | PPDMACEPFILEMGR pAioMgrDst;
|
---|
422 | } AioMgr;
|
---|
423 | } PDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
424 | /** Pointer to the endpoint class data. */
|
---|
425 | typedef PDMASYNCCOMPLETIONENDPOINTFILE *PPDMASYNCCOMPLETIONENDPOINTFILE;
|
---|
426 | #ifdef VBOX_WITH_STATISTICS
|
---|
427 | AssertCompileMemberAlignment(PDMASYNCCOMPLETIONENDPOINTFILE, StatRead, sizeof(uint64_t));
|
---|
428 | #endif
|
---|
429 |
|
---|
430 | /** Request completion function */
|
---|
431 | typedef DECLCALLBACK(void) FNPDMACTASKCOMPLETED(PPDMACTASKFILE pTask, void *pvUser, int rc);
|
---|
432 | /** Pointer to a request completion function. */
|
---|
433 | typedef FNPDMACTASKCOMPLETED *PFNPDMACTASKCOMPLETED;
|
---|
434 |
|
---|
435 | /**
|
---|
436 | * Transfer type.
|
---|
437 | */
|
---|
438 | typedef enum PDMACTASKFILETRANSFER
|
---|
439 | {
|
---|
440 | /** Invalid. */
|
---|
441 | PDMACTASKFILETRANSFER_INVALID = 0,
|
---|
442 | /** Read transfer. */
|
---|
443 | PDMACTASKFILETRANSFER_READ,
|
---|
444 | /** Write transfer. */
|
---|
445 | PDMACTASKFILETRANSFER_WRITE,
|
---|
446 | /** Flush transfer. */
|
---|
447 | PDMACTASKFILETRANSFER_FLUSH
|
---|
448 | } PDMACTASKFILETRANSFER;
|
---|
449 |
|
---|
450 | /**
|
---|
451 | * Data of a request.
|
---|
452 | */
|
---|
453 | typedef struct PDMACTASKFILE
|
---|
454 | {
|
---|
455 | /** Pointer to the range lock we are waiting for */
|
---|
456 | PPDMACFILERANGELOCK pRangeLock;
|
---|
457 | /** Next task in the list. (Depending on the state) */
|
---|
458 | struct PDMACTASKFILE *pNext;
|
---|
459 | /** Endpoint */
|
---|
460 | PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint;
|
---|
461 | /** Transfer type. */
|
---|
462 | PDMACTASKFILETRANSFER enmTransferType;
|
---|
463 | /** Start offset */
|
---|
464 | RTFOFF Off;
|
---|
465 | /** Data segment. */
|
---|
466 | RTSGSEG DataSeg;
|
---|
467 | /** When non-zero the segment uses a bounce buffer because the provided buffer
|
---|
468 | * doesn't meet host requirements. */
|
---|
469 | size_t cbBounceBuffer;
|
---|
470 | /** Pointer to the used bounce buffer if any. */
|
---|
471 | void *pvBounceBuffer;
|
---|
472 | /** Start offset in the bounce buffer to copy from. */
|
---|
473 | uint32_t offBounceBuffer;
|
---|
474 | /** Flag whether this is a prefetch request. */
|
---|
475 | bool fPrefetch;
|
---|
476 | /** Already prepared native I/O request.
|
---|
477 | * Used if the request is prepared already but
|
---|
478 | * was not queued because the host has not enough
|
---|
479 | * resources. */
|
---|
480 | RTFILEAIOREQ hReq;
|
---|
481 | /** Completion function to call on completion. */
|
---|
482 | PFNPDMACTASKCOMPLETED pfnCompleted;
|
---|
483 | /** User data */
|
---|
484 | void *pvUser;
|
---|
485 | } PDMACTASKFILE;
|
---|
486 |
|
---|
487 | /**
|
---|
488 | * Per task data.
|
---|
489 | */
|
---|
490 | typedef struct PDMASYNCCOMPLETIONTASKFILE
|
---|
491 | {
|
---|
492 | /** Common data. */
|
---|
493 | PDMASYNCCOMPLETIONTASK Core;
|
---|
494 | /** Number of bytes to transfer until this task completes. */
|
---|
495 | volatile int32_t cbTransferLeft;
|
---|
496 | /** Flag whether the task completed. */
|
---|
497 | volatile bool fCompleted;
|
---|
498 | /** Return code. */
|
---|
499 | volatile int rc;
|
---|
500 | } PDMASYNCCOMPLETIONTASKFILE;
|
---|
501 |
|
---|
502 | int pdmacFileAioMgrFailsafe(RTTHREAD ThreadSelf, void *pvUser);
|
---|
503 | int pdmacFileAioMgrNormal(RTTHREAD ThreadSelf, void *pvUser);
|
---|
504 |
|
---|
505 | int pdmacFileAioMgrNormalInit(PPDMACEPFILEMGR pAioMgr);
|
---|
506 | void pdmacFileAioMgrNormalDestroy(PPDMACEPFILEMGR pAioMgr);
|
---|
507 |
|
---|
508 | int pdmacFileAioMgrCreate(PPDMASYNCCOMPLETIONEPCLASSFILE pEpClass, PPPDMACEPFILEMGR ppAioMgr, PDMACEPFILEMGRTYPE enmMgrType);
|
---|
509 |
|
---|
510 | int pdmacFileAioMgrAddEndpoint(PPDMACEPFILEMGR pAioMgr, PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
511 |
|
---|
512 | PPDMACTASKFILE pdmacFileEpGetNewTasks(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
513 | PPDMACTASKFILE pdmacFileTaskAlloc(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
514 | void pdmacFileTaskFree(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint,
|
---|
515 | PPDMACTASKFILE pTask);
|
---|
516 |
|
---|
517 | int pdmacFileEpAddTask(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMACTASKFILE pTask);
|
---|
518 |
|
---|
519 | void pdmacFileEpTaskCompleted(PPDMACTASKFILE pTask, void *pvUser, int rc);
|
---|
520 |
|
---|
521 | int pdmacFileCacheInit(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile, PCFGMNODE pCfgNode);
|
---|
522 | void pdmacFileCacheDestroy(PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
523 | int pdmacFileEpCacheInit(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONEPCLASSFILE pClassFile);
|
---|
524 | void pdmacFileEpCacheDestroy(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
525 |
|
---|
526 | int pdmacFileEpCacheRead(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
527 | RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
|
---|
528 | size_t cbRead);
|
---|
529 | int pdmacFileEpCacheWrite(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint, PPDMASYNCCOMPLETIONTASKFILE pTask,
|
---|
530 | RTFOFF off, PCRTSGSEG paSegments, size_t cSegments,
|
---|
531 | size_t cbWrite);
|
---|
532 | int pdmacFileEpCacheFlush(PPDMASYNCCOMPLETIONENDPOINTFILE pEndpoint);
|
---|
533 |
|
---|
534 | RT_C_DECLS_END
|
---|
535 |
|
---|
536 | #endif
|
---|
537 |
|
---|