VirtualBox

source: vbox/trunk/src/VBox/VMM/PDMAsyncCompletionInternal.h@ 28137

Last change on this file since 28137 was 28065, checked in by vboxsync, 15 years ago

Storage: Convert from PDMDATASEG to RTSGSEG to avoid casting between those two in VBoxHDD and more async I/O updates

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

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