1
/* $Id: PDMAsyncCompletionInternal.h $ */
3
* PDM - Pluggable Device Manager, Async I/O Completion internal header.
7
* Copyright (C) 2006-2010 Oracle Corporation
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.
18
#ifndef ___PDMAsyncCompletionInternal_h
19
#define ___PDMAsyncCompletionInternal_h
21
#include <iprt/critsect.h>
22
#include <iprt/memcache.h>
24
#include <VBox/types.h>
25
#include <VBox/cfgm.h>
26
#include <VBox/stam.h>
27
#include <VBox/pdmasynccompletion.h>
28
#include "PDMInternal.h"
34
* PDM Async completion endpoint operations.
36
typedef struct PDMASYNCCOMPLETIONEPCLASSOPS
38
/** Version identifier. */
40
/** Name of the endpoint class. */
43
PDMASYNCCOMPLETIONEPCLASSTYPE enmClassType;
44
/** Size of the global endpoint class data in bytes. */
45
size_t cbEndpointClassGlobal;
46
/** Size of an endpoint in bytes. */
48
/** size of a task in bytes. */
52
* Initializes the global data for a endpoint class.
54
* @returns VBox status code.
55
* @param pClassGlobals Pointer to the uninitialized globals data.
56
* @param pCfgNode Node for querying configuration data.
58
DECLR3CALLBACKMEMBER(int, pfnInitialize, (PPDMASYNCCOMPLETIONEPCLASS pClassGlobals, PCFGMNODE pCfgNode));
61
* Frees all allocated ressources which were allocated during init.
63
* @returns VBox status code.
64
* @param pClassGlobals Pointer to the globals data.
66
DECLR3CALLBACKMEMBER(void, pfnTerminate, (PPDMASYNCCOMPLETIONEPCLASS pClassGlobals));
69
* Initializes a given endpoint.
71
* @returns VBox status code.
72
* @param pEndpoint Pointer to the uninitialized endpoint.
73
* @param pszUri Pointer to the string containing the endpoint
74
* destination (filename, IP address, ...)
75
* @param fFlags Creation flags.
77
DECLR3CALLBACKMEMBER(int, pfnEpInitialize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
78
const char *pszUri, uint32_t fFlags));
81
* Closes a endpoint finishing all tasks.
83
* @returns VBox status code.
84
* @param pEndpoint Pointer to the endpoint to be closed.
86
DECLR3CALLBACKMEMBER(int, pfnEpClose, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint));
89
* Initiates a read request from the given endpoint.
91
* @returns VBox status code.
92
* @param pTask Pointer to the task object associated with the request.
93
* @param pEndpoint Endpoint the request is for.
94
* @param off Where to start reading from.
95
* @param paSegments Scatter gather list to store the data in.
96
* @param cSegments Number of segments in the list.
97
* @param cbRead The overall number of bytes to read.
99
DECLR3CALLBACKMEMBER(int, pfnEpRead, (PPDMASYNCCOMPLETIONTASK pTask,
100
PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
101
PCRTSGSEG paSegments, size_t cSegments,
105
* Initiates a write request to the given endpoint.
107
* @returns VBox status code.
108
* @param pTask Pointer to the task object associated with the request.
109
* @param pEndpoint Endpoint the request is for.
110
* @param off Where to start writing to.
111
* @param paSegments Scatter gather list to store the data in.
112
* @param cSegments Number of segments in the list.
113
* @param cbRead The overall number of bytes to write.
115
DECLR3CALLBACKMEMBER(int, pfnEpWrite, (PPDMASYNCCOMPLETIONTASK pTask,
116
PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
117
PCRTSGSEG paSegments, size_t cSegments,
121
* Initiates a flush request on the given endpoint.
123
* @returns VBox status code.
124
* @param pTask Pointer to the task object associated with the request.
125
* @param pEndpoint Endpoint the request is for.
127
DECLR3CALLBACKMEMBER(int, pfnEpFlush, (PPDMASYNCCOMPLETIONTASK pTask,
128
PPDMASYNCCOMPLETIONENDPOINT pEndpoint));
131
* Queries the size of the endpoint. Optional.
133
* @returns VBox status code.
134
* @param pEndpoint Endpoint the request is for.
135
* @param pcbSize Where to store the size of the endpoint.
137
DECLR3CALLBACKMEMBER(int, pfnEpGetSize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
141
* Sets the size of the endpoint. Optional.
142
* This is a synchronous operation.
145
* @returns VBox status code.
146
* @param pEndpoint Endpoint the request is for.
147
* @param cbSize New size for the endpoint.
149
DECLR3CALLBACKMEMBER(int, pfnEpSetSize, (PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
152
/** Initialization safety marker. */
153
uint32_t u32VersionEnd;
154
} PDMASYNCCOMPLETIONEPCLASSOPS;
155
/** Pointer to a async completion endpoint class operation table. */
156
typedef PDMASYNCCOMPLETIONEPCLASSOPS *PPDMASYNCCOMPLETIONEPCLASSOPS;
157
/** Const pointer to a async completion endpoint class operation table. */
158
typedef const PDMASYNCCOMPLETIONEPCLASSOPS *PCPDMASYNCCOMPLETIONEPCLASSOPS;
160
/** Version for the endpoint class operations structure. */
161
#define PDMAC_EPCLASS_OPS_VERSION 0x00000001
164
* PDM Async completion endpoint class.
167
typedef struct PDMASYNCCOMPLETIONEPCLASS
169
/** Pointer to the shared VM structure. */
171
/** Critical section protecting the endpoint list. */
173
/** Number of endpoints in the list. */
174
volatile unsigned cEndpoints;
175
/** Head of endpoints with this class. */
176
R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pEndpointsHead;
177
/** Pointer to the callback table. */
178
R3PTRTYPE(PCPDMASYNCCOMPLETIONEPCLASSOPS) pEndpointOps;
180
RTMEMCACHE hMemCacheTasks;
181
} PDMASYNCCOMPLETIONEPCLASS;
182
/** Pointer to the PDM async completion endpoint class data. */
183
typedef PDMASYNCCOMPLETIONEPCLASS *PPDMASYNCCOMPLETIONEPCLASS;
186
* A PDM Async completion endpoint.
189
typedef struct PDMASYNCCOMPLETIONENDPOINT
191
/** Next endpoint in the list. */
192
R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pNext;
193
/** Previous endpoint in the list. */
194
R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pPrev;
195
/** Pointer to the class this endpoint belongs to. */
196
R3PTRTYPE(PPDMASYNCCOMPLETIONEPCLASS) pEpClass;
197
/** ID of the next task to ensure consistency. */
198
volatile uint32_t uTaskIdNext;
199
/** Flag whether a wraparound occurred for the ID counter. */
200
bool fTaskIdWraparound;
201
/** Template associated with this endpoint. */
202
PPDMASYNCCOMPLETIONTEMPLATE pTemplate;
203
/** Reference count. */
205
/** URI describing the endpoint */
207
#ifdef VBOX_WITH_STATISTICS
208
STAMCOUNTER StatTaskRunTimesNs[10];
209
STAMCOUNTER StatTaskRunTimesMicroSec[10];
210
STAMCOUNTER StatTaskRunTimesMs[10];
211
STAMCOUNTER StatTaskRunTimesSec[10];
212
STAMCOUNTER StatTaskRunOver100Sec;
213
STAMCOUNTER StatIoOpsPerSec;
214
STAMCOUNTER StatIoOpsStarted;
215
STAMCOUNTER StatIoOpsCompleted;
216
uint64_t tsIntervalStartMs;
217
uint64_t cIoOpsCompleted;
219
} PDMASYNCCOMPLETIONENDPOINT;
222
* A PDM async completion task handle.
225
typedef struct PDMASYNCCOMPLETIONTASK
227
/** Next task in the list
228
* (for free and assigned tasks). */
229
R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pNext;
230
/** Previous task in the list
231
* (for free and assigned tasks). */
232
R3PTRTYPE(PPDMASYNCCOMPLETIONTASK) pPrev;
233
/** Endpoint this task is assigned to. */
234
R3PTRTYPE(PPDMASYNCCOMPLETIONENDPOINT) pEndpoint;
235
/** Opaque user data for this task. */
239
/** Start timestamp. */
241
} PDMASYNCCOMPLETIONTASK;
244
* Called by the endpoint if a task has finished.
247
* @param pTask Pointer to the finished task.
248
* @param rc Status code of the completed request.
249
* @param fCallCompletionHandler Flag whether the completion handler should be called to
250
* inform the owner of the task that it has completed.
252
void pdmR3AsyncCompletionCompleteTask(PPDMASYNCCOMPLETIONTASK pTask, int rc, bool fCallCompletionHandler);
256
extern const PDMASYNCCOMPLETIONEPCLASSOPS g_PDMAsyncCompletionEndpointClassFile;
258
#endif /* !___PDMAsyncCompletionInternal_h */