1 | /* $Id: PDMAsyncCompletionInternal.h 27920 2010-03-31 19:02:48Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * PDM - Pluggable Device Manager, Async I/O Completion internal header.
|
---|
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.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 | * 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 | #ifndef __PDMAsyncCompletionInternal_h
|
---|
22 | #define __PDMAsyncCompletionInternal_h
|
---|
23 |
|
---|
24 | #include "PDMInternal.h"
|
---|
25 | #include <iprt/cdefs.h>
|
---|
26 | #include <iprt/critsect.h>
|
---|
27 | #include <iprt/memcache.h>
|
---|
28 | #include <VBox/types.h>
|
---|
29 | #include <VBox/cfgm.h>
|
---|
30 | #include <VBox/stam.h>
|
---|
31 | #include <VBox/pdmasynccompletion.h>
|
---|
32 |
|
---|
33 | RT_C_DECLS_BEGIN
|
---|
34 |
|
---|
35 | /**
|
---|
36 | * Supported endpoint classes.
|
---|
37 | */
|
---|
38 | typedef enum PDMASYNCCOMPLETIONEPCLASSTYPE
|
---|
39 | {
|
---|
40 | /** File class. */
|
---|
41 | PDMASYNCCOMPLETIONEPCLASSTYPE_FILE = 0,
|
---|
42 | /** Number of supported classes. */
|
---|
43 | PDMASYNCCOMPLETIONEPCLASSTYPE_MAX,
|
---|
44 | /** 32bit hack. */
|
---|
45 | PDMASYNCCOMPLETIONEPCLASSTYPE_32BIT_HACK = 0x7fffffff
|
---|
46 | } PDMASYNCCOMPLETIONEPCLASSTYPE;
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * PDM Async completion endpoint operations.
|
---|
50 | */
|
---|
51 | typedef struct PDMASYNCCOMPLETIONEPCLASSOPS
|
---|
52 | {
|
---|
53 | /** Version identifier. */
|
---|
54 | uint32_t u32Version;
|
---|
55 | /** Name of the endpoint class. */
|
---|
56 | const char *pcszName;
|
---|
57 | /** Class type. */
|
---|
58 | PDMASYNCCOMPLETIONEPCLASSTYPE enmClassType;
|
---|
59 | /** Size of the global endpoint class data in bytes. */
|
---|
60 | size_t cbEndpointClassGlobal;
|
---|
61 | /** Size of an endpoint in bytes. */
|
---|
62 | size_t cbEndpoint;
|
---|
63 | /** size of a task in bytes. */
|
---|
64 | size_t cbTask;
|
---|
65 |
|
---|
66 | /**
|
---|
67 | * Initializes the global data for a endpoint class.
|
---|
68 | *
|
---|
69 | * @returns VBox status code.
|
---|
70 | * @param pClassGlobals Pointer to the uninitialized globals data.
|
---|
71 | * @param pCfgNode Node for querying configuration data.
|
---|
72 | */
|
---|
73 | DECLR3CALLBACKMEMBER(int, pfnInitialize, (PPDMASYNCCOMPLETIONEPCLASS pClassGlobals, PCFGMNODE pCfgNode));
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * Frees all allocated ressources which were allocated during init.
|
---|
77 | *
|
---|
78 | * @returns VBox status code.
|
---|
79 | * @param pClassGlobals Pointer to the globals data.
|
---|
80 | */
|
---|
81 | DECLR3CALLBACKMEMBER(void, pfnTerminate, (PPDMASYNCCOMPLETIONEPCLASS pClassGlobals));
|
---|
82 |
|
---|
83 | /**
|
---|
84 | * Initializes a given endpoint.
|
---|
85 | *
|
---|
86 | * @returns VBox status code.
|
---|
87 | * @param pEndpoint Pointer to the uninitialized endpoint.
|
---|
88 | * @param pszUri Pointer to the string containing the endpoint
|
---|
89 | * destination (filename, IP address, ...)
|
---|
90 | * @param fFlags Creation flags.
|
---|
91 | */
|
---|
92 | DECLR3CALLBACKMEMBER(int, pfnEpInitialize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
|
---|
93 | const char *pszUri, uint32_t fFlags));
|
---|
94 |
|
---|
95 | /**
|
---|
96 | * Closes a endpoint finishing all tasks.
|
---|
97 | *
|
---|
98 | * @returns VBox status code.
|
---|
99 | * @param pEndpoint Pointer to the endpoint to be closed.
|
---|
100 | */
|
---|
101 | DECLR3CALLBACKMEMBER(int, pfnEpClose, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint));
|
---|
102 |
|
---|
103 | /**
|
---|
104 | * Initiates a read request from the given endpoint.
|
---|
105 | *
|
---|
106 | * @returns VBox status code.
|
---|
107 | * @param pTask Pointer to the task object associated with the request.
|
---|
108 | * @param pEndpoint Endpoint the request is for.
|
---|
109 | * @param off Where to start reading from.
|
---|
110 | * @param paSegments Scatter gather list to store the data in.
|
---|
111 | * @param cSegments Number of segments in the list.
|
---|
112 | * @param cbRead The overall number of bytes to read.
|
---|
113 | */
|
---|
114 | DECLR3CALLBACKMEMBER(int, pfnEpRead, (PPDMASYNCCOMPLETIONTASK pTask,
|
---|
115 | PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
|
---|
116 | PCPDMDATASEG paSegments, size_t cSegments,
|
---|
117 | size_t cbRead));
|
---|
118 |
|
---|
119 | /**
|
---|
120 | * Initiates a write request to the given endpoint.
|
---|
121 | *
|
---|
122 | * @returns VBox status code.
|
---|
123 | * @param pTask Pointer to the task object associated with the request.
|
---|
124 | * @param pEndpoint Endpoint the request is for.
|
---|
125 | * @param off Where to start writing to.
|
---|
126 | * @param paSegments Scatter gather list to store the data in.
|
---|
127 | * @param cSegments Number of segments in the list.
|
---|
128 | * @param cbRead The overall number of bytes to write.
|
---|
129 | */
|
---|
130 | DECLR3CALLBACKMEMBER(int, pfnEpWrite, (PPDMASYNCCOMPLETIONTASK pTask,
|
---|
131 | PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
|
---|
132 | PCPDMDATASEG paSegments, size_t cSegments,
|
---|
133 | size_t cbWrite));
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * Initiates a flush request on the given endpoint.
|
---|
137 | *
|
---|
138 | * @returns VBox status code.
|
---|
139 | * @param pTask Pointer to the task object associated with the request.
|
---|
140 | * @param pEndpoint Endpoint the request is for.
|
---|
141 | */
|
---|
142 | DECLR3CALLBACKMEMBER(int, pfnEpFlush, (PPDMASYNCCOMPLETIONTASK pTask,
|
---|
143 | PPDMASYNCCOMPLETIONENDPOINT pEndpoint));
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Queries the size of the endpoint. Optional.
|
---|
147 | *
|
---|
148 | * @returns VBox status code.
|
---|
149 | * @param pEndpoint Endpoint the request is for.
|
---|
150 | * @param pcbSize Where to store the size of the endpoint.
|
---|
151 | */
|
---|
152 | DECLR3CALLBACKMEMBER(int, pfnEpGetSize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
|
---|
153 | uint64_t *pcbSize));
|
---|
154 |
|
---|
155 | /**
|
---|
156 | * Sets the size of the endpoint. Optional.
|
---|
157 | * This is a synchronous operation.
|
---|
158 | *
|
---|
159 | *
|
---|
160 | * @returns VBox status code.
|
---|
161 | * @param pEndpoint Endpoint the request is for.
|
---|
162 | * @param cbSize New size for the endpoint.
|
---|
163 | */
|
---|
164 | DECLR3CALLBACKMEMBER(int, pfnEpSetSize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
|
---|
165 | uint64_t cbSize));
|
---|
166 |
|
---|
167 | /** Initialization safety marker. */
|
---|
168 | uint32_t u32VersionEnd;
|
---|
169 | } PDMASYNCCOMPLETIONEPCLASSOPS;
|
---|
170 | /** Pointer to a async completion endpoint class operation table. */
|
---|
171 | typedef PDMASYNCCOMPLETIONEPCLASSOPS *PPDMASYNCCOMPLETIONEPCLASSOPS;
|
---|
172 | /** Const pointer to a async completion endpoint class operation table. */
|
---|
173 | typedef const PDMASYNCCOMPLETIONEPCLASSOPS *PCPDMASYNCCOMPLETIONEPCLASSOPS;
|
---|
174 |
|
---|
175 | /** Version for the endpoint class operations structure. */
|
---|
176 | #define PDMAC_EPCLASS_OPS_VERSION 0x00000001
|
---|
177 |
|
---|
178 | /**
|
---|
179 | * PDM Async completion endpoint class.
|
---|
180 | * Common data.
|
---|
181 | */
|
---|
182 | typedef struct PDMASYNCCOMPLETIONEPCLASS
|
---|
183 | {
|
---|
184 | /** Pointer to the shared VM structure. */
|
---|
185 | PVM pVM;
|
---|
186 | /** Critical section protecting the endpoint list. */
|
---|
187 | RTCRITSECT CritSect;
|
---|
188 | /** Number of endpoints in the list. */
|
---|
189 | volatile unsigned cEndpoints;
|
---|
190 | /** Head of endpoints with this class. */
|
---|
191 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pEndpointsHead;
|
---|
192 | /** Pointer to the callback table. */
|
---|
193 | R3PTRTYPE(PCPDMASYNCCOMPLETIONEPCLASSOPS) pEndpointOps;
|
---|
194 | /** Task cache. */
|
---|
195 | RTMEMCACHE hMemCacheTasks;
|
---|
196 | } PDMASYNCCOMPLETIONEPCLASS;
|
---|
197 | /** Pointer to the PDM async completion endpoint class data. */
|
---|
198 | typedef PDMASYNCCOMPLETIONEPCLASS *PPDMASYNCCOMPLETIONEPCLASS;
|
---|
199 |
|
---|
200 | /**
|
---|
201 | * A PDM Async completion endpoint.
|
---|
202 | * Common data.
|
---|
203 | */
|
---|
204 | typedef struct PDMASYNCCOMPLETIONENDPOINT
|
---|
205 | {
|
---|
206 | /** Next endpoint in the list. */
|
---|
207 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pNext;
|
---|
208 | /** Previous endpoint in the list. */
|
---|
209 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pPrev;
|
---|
210 | /** Pointer to the class this endpoint belongs to. */
|
---|
211 | R3PTRTYPE(PPDMASYNCCOMPLETIONEPCLASS) pEpClass;
|
---|
212 | /** ID of the next task to ensure consistency. */
|
---|
213 | volatile uint32_t uTaskIdNext;
|
---|
214 | /** Flag whether a wraparound occurred for the ID counter. */
|
---|
215 | bool fTaskIdWraparound;
|
---|
216 | /** Template associated with this endpoint. */
|
---|
217 | PPDMASYNCCOMPLETIONTEMPLATE pTemplate;
|
---|
218 | /** Reference count. */
|
---|
219 | unsigned cUsers;
|
---|
220 | /** URI describing the endpoint */
|
---|
221 | char *pszUri;
|
---|
222 | #ifdef VBOX_WITH_STATISTICS
|
---|
223 | STAMCOUNTER StatTaskRunTimesNs[10];
|
---|
224 | STAMCOUNTER StatTaskRunTimesMicroSec[10];
|
---|
225 | STAMCOUNTER StatTaskRunTimesMs[10];
|
---|
226 | STAMCOUNTER StatTaskRunTimesSec[10];
|
---|
227 | STAMCOUNTER StatTaskRunOver100Sec;
|
---|
228 | STAMCOUNTER StatIoOpsPerSec;
|
---|
229 | STAMCOUNTER StatIoOpsStarted;
|
---|
230 | STAMCOUNTER StatIoOpsCompleted;
|
---|
231 | uint64_t tsIntervalStartMs;
|
---|
232 | uint64_t cIoOpsCompleted;
|
---|
233 | #endif
|
---|
234 | } PDMASYNCCOMPLETIONENDPOINT;
|
---|
235 |
|
---|
236 | /**
|
---|
237 | * A PDM async completion task handle.
|
---|
238 | * Common data.
|
---|
239 | */
|
---|
240 | typedef struct PDMASYNCCOMPLETIONTASK
|
---|
241 | {
|
---|
242 | /** Next task in the list
|
---|
243 | * (for free and assigned tasks). */
|
---|
244 | R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pNext;
|
---|
245 | /** Previous task in the list
|
---|
246 | * (for free and assigned tasks). */
|
---|
247 | R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pPrev;
|
---|
248 | /** Endpoint this task is assigned to. */
|
---|
249 | R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pEndpoint;
|
---|
250 | /** Opaque user data for this task. */
|
---|
251 | void *pvUser;
|
---|
252 | /** Task id. */
|
---|
253 | uint32_t uTaskId;
|
---|
254 | #ifdef VBOX_WITH_STATISTICS
|
---|
255 | /** Start timestamp. */
|
---|
256 | uint64_t tsNsStart;
|
---|
257 | #endif
|
---|
258 | } PDMASYNCCOMPLETIONTASK;
|
---|
259 |
|
---|
260 | /**
|
---|
261 | * Called by the endpoint if a task has finished.
|
---|
262 | *
|
---|
263 | * @returns nothing
|
---|
264 | * @param pTask Pointer to the finished task.
|
---|
265 | * @param rc Status code of the completed request.
|
---|
266 | * @param fCallCompletionHandler Flag whether the completion handler should be called to
|
---|
267 | * inform the owner of the task that it has completed.
|
---|
268 | */
|
---|
269 | void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, int rc, bool fCallCompletionHandler);
|
---|
270 |
|
---|
271 | RT_C_DECLS_END
|
---|
272 |
|
---|
273 | extern const PDMASYNCCOMPLETIONEPCLASSOPS g_PDMAsyncCompletionEndpointClassFile;
|
---|
274 |
|
---|
275 | #endif /* __PDMAsyncCompletionInternal_h */
|
---|