VirtualBox

source: vbox/trunk/include/VBox/pdmasynccompletion.h@ 28197

Last change on this file since 28197 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 Id Revision
File size: 13.7 KB
Line 
1/* $Id: pdmasynccompletion.h 28065 2010-04-07 20:54:34Z vboxsync $ */
2/** @file
3 * PDM - Pluggable Device Manager, Async I/O Completion. (VMM)
4 */
5
6/*
7 * Copyright (C) 2007-2009 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 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 *
26 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
27 * Clara, CA 95054 USA or visit http://www.sun.com if you need
28 * additional information or have any questions.
29 */
30
31#ifndef ___VBox_pdmasynccompletion_h
32#define ___VBox_pdmasynccompletion_h
33
34#include <VBox/types.h>
35#include <VBox/err.h>
36#include <iprt/assert.h>
37#include <iprt/sg.h>
38
39RT_C_DECLS_BEGIN
40
41/** @defgroup grp_pdm_async_completion The PDM Async I/O Completion API
42 * @ingroup grp_pdm
43 * @{
44 */
45
46/** Pointer to a PDM async completion template handle. */
47typedef struct PDMASYNCCOMPLETIONTEMPLATE *PPDMASYNCCOMPLETIONTEMPLATE;
48/** Pointer to a PDM async completion template handle pointer. */
49typedef PPDMASYNCCOMPLETIONTEMPLATE *PPPDMASYNCCOMPLETIONTEMPLATE;
50
51/** Pointer to a PDM async completion task handle. */
52typedef struct PDMASYNCCOMPLETIONTASK *PPDMASYNCCOMPLETIONTASK;
53/** Pointer to a PDM async completion task handle pointer. */
54typedef PPDMASYNCCOMPLETIONTASK *PPPDMASYNCCOMPLETIONTASK;
55
56/** Pointer to a PDM async completion endpoint handle. */
57typedef struct PDMASYNCCOMPLETIONENDPOINT *PPDMASYNCCOMPLETIONENDPOINT;
58/** Pointer to a PDM async completion endpoint handle pointer. */
59typedef PPDMASYNCCOMPLETIONENDPOINT *PPPDMASYNCCOMPLETIONENDPOINT;
60
61
62/**
63 * Completion callback for devices.
64 *
65 * @param pDevIns The device instance.
66 * @param pvUser User argument.
67 * @param rc The status code of the completed request.
68 */
69typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDEV(PPDMDEVINS pDevIns, void *pvUser, int rc);
70/** Pointer to a FNPDMASYNCCOMPLETEDEV(). */
71typedef FNPDMASYNCCOMPLETEDEV *PFNPDMASYNCCOMPLETEDEV;
72
73
74/**
75 * Completion callback for drivers.
76 *
77 * @param pDrvIns The driver instance.
78 * @param pvTemplateUser User argument given when creating the template.
79 * @param pvUser User argument given during request initiation.
80 * @param rc The status code of the completed request.
81 */
82typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEDRV(PPDMDRVINS pDrvIns, void *pvTemplateUser, void *pvUser, int rc);
83/** Pointer to a FNPDMASYNCCOMPLETEDRV(). */
84typedef FNPDMASYNCCOMPLETEDRV *PFNPDMASYNCCOMPLETEDRV;
85
86
87/**
88 * Completion callback for USB devices.
89 *
90 * @param pUsbIns The USB device instance.
91 * @param pvUser User argument.
92 * @param rc The status code of the completed request.
93 */
94typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEUSB(PPDMUSBINS pUsbIns, void *pvUser, int rc);
95/** Pointer to a FNPDMASYNCCOMPLETEUSB(). */
96typedef FNPDMASYNCCOMPLETEUSB *PFNPDMASYNCCOMPLETEUSB;
97
98
99/**
100 * Completion callback for internal.
101 *
102 * @param pVM Pointer to the shared VM structure.
103 * @param pvUser User argument for the task.
104 * @param pvUser2 User argument for the template.
105 * @param rc The status code of the completed request.
106 */
107typedef DECLCALLBACK(void) FNPDMASYNCCOMPLETEINT(PVM pVM, void *pvUser, void *pvUser2, int rc);
108/** Pointer to a FNPDMASYNCCOMPLETEINT(). */
109typedef FNPDMASYNCCOMPLETEINT *PFNPDMASYNCCOMPLETEINT;
110
111
112/**
113 * Creates a async completion template for a device instance.
114 *
115 * The template is used when creating new completion tasks.
116 *
117 * @returns VBox status code.
118 * @param pVM Pointer to the shared VM structure.
119 * @param pDevIns The device instance.
120 * @param ppTemplate Where to store the template pointer on success.
121 * @param pfnCompleted The completion callback routine.
122 * @param pszDesc Description.
123 */
124VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDevice(PVM pVM, PPDMDEVINS pDevIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDEV pfnCompleted, const char *pszDesc);
125
126/**
127 * Creates a async completion template for a driver instance.
128 *
129 * The template is used when creating new completion tasks.
130 *
131 * @returns VBox status code.
132 * @param pVM Pointer to the shared VM structure.
133 * @param pDrvIns The driver instance.
134 * @param ppTemplate Where to store the template pointer on success.
135 * @param pfnCompleted The completion callback routine.
136 * @param pvTemplateUser Template user argument.
137 * @param pszDesc Description.
138 */
139VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateDriver(PVM pVM, PPDMDRVINS pDrvIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEDRV pfnCompleted, void *pvTemplateUser, const char *pszDesc);
140
141/**
142 * Creates a async completion template for a USB device instance.
143 *
144 * The template is used when creating new completion tasks.
145 *
146 * @returns VBox status code.
147 * @param pVM Pointer to the shared VM structure.
148 * @param pUsbIns The USB device instance.
149 * @param ppTemplate Where to store the template pointer on success.
150 * @param pfnCompleted The completion callback routine.
151 * @param pszDesc Description.
152 */
153VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateUsb(PVM pVM, PPDMUSBINS pUsbIns, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEUSB pfnCompleted, const char *pszDesc);
154
155/**
156 * Creates a async completion template for internally by the VMM.
157 *
158 * The template is used when creating new completion tasks.
159 *
160 * @returns VBox status code.
161 * @param pVM Pointer to the shared VM structure.
162 * @param ppTemplate Where to store the template pointer on success.
163 * @param pfnCompleted The completion callback routine.
164 * @param pvUser2 The 2nd user argument for the callback.
165 * @param pszDesc Description.
166 */
167VMMR3DECL(int) PDMR3AsyncCompletionTemplateCreateInternal(PVM pVM, PPPDMASYNCCOMPLETIONTEMPLATE ppTemplate, PFNPDMASYNCCOMPLETEINT pfnCompleted, void *pvUser2, const char *pszDesc);
168
169/**
170 * Destroys the specified async completion template.
171 *
172 * @returns VBox status codes:
173 * @retval VINF_SUCCESS on success.
174 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if the template is still in use.
175 *
176 * @param pTemplate The template in question.
177 */
178VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroy(PPDMASYNCCOMPLETIONTEMPLATE pTemplate);
179
180/**
181 * Destroys all the specified async completion templates for the given device instance.
182 *
183 * @returns VBox status codes:
184 * @retval VINF_SUCCESS on success.
185 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
186 *
187 * @param pVM Pointer to the shared VM structure.
188 * @param pDevIns The device instance.
189 */
190VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDevice(PVM pVM, PPDMDEVINS pDevIns);
191
192/**
193 * Destroys all the specified async completion templates for the given driver instance.
194 *
195 * @returns VBox status codes:
196 * @retval VINF_SUCCESS on success.
197 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
198 *
199 * @param pVM Pointer to the shared VM structure.
200 * @param pDrvIns The driver instance.
201 */
202VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyDriver(PVM pVM, PPDMDRVINS pDrvIns);
203
204/**
205 * Destroys all the specified async completion templates for the given USB device instance.
206 *
207 * @returns VBox status codes:
208 * @retval VINF_SUCCESS on success.
209 * @retval VERR_PDM_ASYNC_TEMPLATE_BUSY if one or more of the templates are still in use.
210 *
211 * @param pVM Pointer to the shared VM structure.
212 * @param pUsbIns The USB device instance.
213 */
214VMMR3DECL(int) PDMR3AsyncCompletionTemplateDestroyUsb(PVM pVM, PPDMUSBINS pUsbIns);
215
216
217/**
218 * Opens a file as a async completion endpoint.
219 *
220 * @returns VBox status code.
221 * @param ppEndpoint Where to store the opaque endpoint handle on success.
222 * @param pszFilename Path to the file which is to be opened. (UTF-8)
223 * @param fFlags Open flags, see grp_pdmacep_file_flags.
224 * @param pTemplate Handle to the completion callback template to use
225 * for this end point.
226 */
227VMMR3DECL(int) PDMR3AsyncCompletionEpCreateForFile(PPPDMASYNCCOMPLETIONENDPOINT ppEndpoint,
228 const char *pszFilename, uint32_t fFlags,
229 PPDMASYNCCOMPLETIONTEMPLATE pTemplate);
230
231/** @defgroup grp_pdmacep_file_flags Flags for PDMR3AsyncCompletionEpCreateForFile
232 * @{ */
233/** Open the file in read-only mode. */
234#define PDMACEP_FILE_FLAGS_READ_ONLY RT_BIT_32(0)
235/** whether file content should be cached by the endpoint. */
236#define PDMACEP_FILE_FLAGS_CACHING RT_BIT_32(1)
237/** @} */
238
239/**
240 * Closes a endpoint waiting for any pending tasks to finish.
241 *
242 * @returns nothing.
243 * @param pEndpoint Handle of the endpoint.
244 */
245VMMR3DECL(void) PDMR3AsyncCompletionEpClose(PPDMASYNCCOMPLETIONENDPOINT pEndpoint);
246
247/**
248 * Creates a read task on the given endpoint.
249 *
250 * @returns VBox status code.
251 * @param pEndpoint The file endpoint to read from.
252 * @param off Where to start reading from.
253 * @param paSegments Scatter gather list to store the data in.
254 * @param cSegments Number of segments in the list.
255 * @param cbRead The overall number of bytes to read.
256 * @param pvUser Opaque user data returned in the completion callback
257 * upon completion of the task.
258 * @param ppTask Where to store the task handle on success.
259 */
260VMMR3DECL(int) PDMR3AsyncCompletionEpRead(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
261 PCRTSGSEG paSegments, unsigned cSegments,
262 size_t cbRead, void *pvUser,
263 PPPDMASYNCCOMPLETIONTASK ppTask);
264
265/**
266 * Creates a write task on the given endpoint.
267 *
268 * @returns VBox status code.
269 * @param pEndpoint The file endpoint to write to.
270 * @param off Where to start writing at.
271 * @param paSegments Scatter gather list of the data to write.
272 * @param cSegments Number of segments in the list.
273 * @param cbWrite The overall number of bytes to write.
274 * @param pvUser Opaque user data returned in the completion callback
275 * upon completion of the task.
276 * @param ppTask Where to store the task handle on success.
277 */
278VMMR3DECL(int) PDMR3AsyncCompletionEpWrite(PPDMASYNCCOMPLETIONENDPOINT pEndpoint, RTFOFF off,
279 PCRTSGSEG paSegments, unsigned cSegments,
280 size_t cbWrite, void *pvUser,
281 PPPDMASYNCCOMPLETIONTASK ppTask);
282
283/**
284 * Creates a flush task on the given endpoint.
285 *
286 * Every read and write task initiated before the flush task is
287 * finished upon completion of this task.
288 *
289 * @returns VBox status code.
290 * @param pEndpoint The file endpoint to flush.
291 * @param pvUser Opaque user data returned in the completion callback
292 * upon completion of the task.
293 * @param ppTask Where to store the task handle on success.
294 */
295VMMR3DECL(int) PDMR3AsyncCompletionEpFlush(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
296 void *pvUser,
297 PPPDMASYNCCOMPLETIONTASK ppTask);
298
299/**
300 * Queries the size of an endpoint.
301 * Not that some endpoints may not support this and will return an error
302 * (sockets for example).
303 *
304 * @returns VBox status code.
305 * @retval VERR_NOT_SUPPORTED if the endpoint does not support this operation.
306 * @param pEndpoint The file endpoint.
307 * @param pcbSize Where to store the size of the endpoint.
308 */
309VMMR3DECL(int) PDMR3AsyncCompletionEpGetSize(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
310 uint64_t *pcbSize);
311
312/**
313 * Sets the size of an endpoint.
314 * Not that some endpoints may not support this and will return an error
315 * (sockets for example).
316 *
317 * @returns VBox status code.
318 * @retval VERR_NOT_SUPPORTED if the endpoint does not support this operation.
319 * @param pEndpoint The file endpoint.
320 * @param cbSize The size to set.
321 *
322 * @note PDMR3AsyncCompletionEpFlush should be called before this operation is executed.
323 */
324VMMR3DECL(int) PDMR3AsyncCompletionEpSetSize(PPDMASYNCCOMPLETIONENDPOINT pEndpoint,
325 uint64_t cbSize);
326
327/**
328 * Cancels a async completion task.
329 *
330 * If you want to use this method, you have to take great create to make sure
331 * you will never attempt cancel a task which has been completed. Since there is
332 * no reference counting or anything on the task it self, you have to serialize
333 * the cancelation and completion paths such that the aren't racing one another.
334 *
335 * @returns VBox status code
336 * @param pTask The Task to cancel.
337 */
338VMMR3DECL(int) PDMR3AsyncCompletionTaskCancel(PPDMASYNCCOMPLETIONTASK pTask);
339
340/** @} */
341
342RT_C_DECLS_END
343
344#endif
345
Note: See TracBrowser for help on using the repository browser.

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