VirtualBox

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

Last change on this file since 26600 was 26147, checked in by vboxsync, 15 years ago

AsyncCompletion: Fix incorrect count of outstanding write tasks. Fixes hangs during flush requests. Return VINF_AIO_TASK_PENDING if data needs to be read from the file

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