fileaio-solaris.cpp revision b79e4344bf4eb8033fd06d560cd864192728bd0b
/* $Id$ */
/** @file
* IPRT - File async I/O, native implementation for the Solaris host platform.
*/
/*
* Copyright (C) 2006-2010 Sun Microsystems, Inc.
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL) only, as it comes in the "COPYING.CDDL" file of the
* VirtualBox OSE distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
/*******************************************************************************
* Header Files *
*******************************************************************************/
#define LOG_GROUP RTLOGGROUP_FILE
#include <port.h>
#include <aio.h>
#include <errno.h>
#include <unistd.h>
/*******************************************************************************
* Structures and Typedefs *
*******************************************************************************/
/**
* Async I/O completion context state.
*/
typedef struct RTFILEAIOCTXINTERNAL
{
/** Handle to the port. */
int iPort;
/** Current number of requests active on this context. */
/** Magic value (RTFILEAIOCTX_MAGIC). */
/** Pointer to an internal context structure. */
typedef RTFILEAIOCTXINTERNAL *PRTFILEAIOCTXINTERNAL;
/**
* Async I/O request state.
*/
typedef struct RTFILEAIOREQINTERNAL
{
/** The aio control block. Must be the FIRST
* element. */
/** Current state the request is in. */
/** Flag whether this is a flush request. */
bool fFlush;
/** Port notifier object to associate a request to a port. */
/** Opaque user data. */
void *pvUser;
/** Completion context we are assigned to. */
/** Magic value (RTFILEAIOREQ_MAGIC). */
/** Pointer to an internal request structure. */
typedef RTFILEAIOREQINTERNAL *PRTFILEAIOREQINTERNAL;
/*******************************************************************************
* Defined Constants And Macros *
*******************************************************************************/
/** The max number of events to get in one call. */
#define AIO_MAXIMUM_REQUESTS_PER_CONTEXT 64
/** Id for the wakeup event. */
#define AIO_CONTEXT_WAKEUP_EVENT 1
{
int rcBSD = 0;
/* No limits known. */
pAioLimits->cbBufferAlignment = 0;
return VINF_SUCCESS;
}
{
if (RT_UNLIKELY(!pReqInt))
return VERR_NO_MEMORY;
/* Ininitialize static parts. */
return VINF_SUCCESS;
}
{
/*
* Validate the handle and ignore nil.
*/
if (hReq == NIL_RTFILEAIOREQ)
return VINF_SUCCESS;
/*
* Trash the magic and free it.
*/
return VINF_SUCCESS;
}
/**
* Worker setting up the request.
*/
unsigned uTransferDirection,
void *pvUser)
{
/*
* Validate the input.
*/
Assert(cbTransfer > 0);
return VINF_SUCCESS;
}
{
}
{
}
{
return VINF_SUCCESS;
}
{
}
{
if (rcSolaris == AIO_CANCELED)
{
/*
* Decrement request count because the request will never arrive at the
* completion port.
*/
("Invalid state. Request was canceled but wasn't submitted\n"));
return VINF_SUCCESS;
}
else if (rcSolaris == AIO_ALLDONE)
return VERR_FILE_AIO_COMPLETED;
else if (rcSolaris == AIO_NOTCANCELED)
return VERR_FILE_AIO_IN_PROGRESS;
else
return RTErrConvertFromErrno(errno);
}
{
if (rcSol == 0)
{
if (pcbTransfered)
return VINF_SUCCESS;
}
/* An error occurred. */
return RTErrConvertFromErrno(rcSol);
}
{
int rc = VINF_SUCCESS;
if (RT_UNLIKELY(!pCtxInt))
return VERR_NO_MEMORY;
/* Init the event handle. */
{
}
else
{
}
return rc;
}
{
/* Validate the handle and ignore nil. */
if (hAioCtx == NIL_RTFILEAIOCTX)
return VINF_SUCCESS;
/* Cannot destroy a busy context. */
return VERR_FILE_AIO_BUSY;
return VINF_SUCCESS;
}
{
return RTFILEAIO_UNLIMITED_REQS;
}
{
return VINF_SUCCESS;
}
{
/*
* Parameter validation.
*/
int rc = VINF_SUCCESS;
do
{
int rcSol = 0;
size_t cReqsSubmit = 0;
while(i-- > 0)
{
{
/* Undo everything and stop submitting. */
{
}
break;
}
break;
cReqsSubmit++;
}
if (cReqsSubmit)
{
if (RT_UNLIKELY(rcSol < 0))
{
else
/* Check which requests got actually submitted and which not. */
for (i = 0; i < cReqs; i++)
{
{
/* Was not submitted. */
}
else if (rcSol != EINPROGRESS)
{
/* The request encountered an error. */
}
}
break;
}
cReqs -= cReqsSubmit;
pahReqs += cReqsSubmit;
}
if (cReqs)
{
/*
* If there are still requests left we have a flush request.
* lio_listio does not work with this requests so
* we have to use aio_fsync directly.
*/
if (RT_UNLIKELY(rcSol < 0))
{
break;
}
cReqs--;
pahReqs++;
}
} while (cReqs);
return rc;
}
{
int rc = VINF_SUCCESS;
int cRequestsCompleted = 0;
/*
* Validate the parameters, making sure to always set pcReqs.
*/
*pcReqs = 0; /* always set */
return VERR_FILE_AIO_NO_REQUEST;
/*
* Convert the timeout if specified.
*/
uint64_t StartNanoTS = 0;
if (cMillies != RT_INDEFINITE_WAIT)
{
StartNanoTS = RTTimeNanoTS();
}
/* Wait for at least one. */
if (!cMinReqs)
cMinReqs = 1;
while ( cMinReqs
&& RT_SUCCESS_NP(rc))
{
int cRequestsToWait = cMinReqs < AIO_MAXIMUM_REQUESTS_PER_CONTEXT ? cReqs : AIO_MAXIMUM_REQUESTS_PER_CONTEXT;
int rcSol;
if (RT_UNLIKELY(rcSol < 0))
/* Process received events. */
{
{
/* Reset the port. */
}
else
{
/* A request has finished. */
/* Mark the request as finished. */
}
}
/*
* Done Yet? If not advance and try again.
*/
break;
if (cMillies != RT_INDEFINITE_WAIT)
{
/* The syscall supposedly updates it, but we're paranoid. :-) */
if (cMilliesElapsed < cMillies)
{
}
else
{
}
}
}
/*
* Update the context state and set the return value.
*/
return rc;
}
{
int rc = VINF_SUCCESS;
return RTErrConvertFromErrno(errno);
return VINF_SUCCESS;
}