- int error;
- boolean_t funnel_state;
- vm_map_t currentmap;
- vm_map_t oldmap = VM_MAP_NULL;
- task_t oldaiotask = TASK_NULL;
-
- KERNEL_DEBUG( (BSDDBG_CODE(DBG_BSD_AIO, AIO_worker_thread)) | DBG_FUNC_START,
- (int)entryp->procp, (int)entryp->uaiocbp, entryp->flags, 0, 0 );
-
- /*
- * Assume the target's address space identity for the duration
- * of the IO.
- */
- funnel_state = thread_funnel_set( kernel_flock, TRUE );
-
- currentmap = get_task_map( (current_proc())->task );
- if ( currentmap != entryp->aio_map ) {
- oldaiotask = uthread->uu_aio_task;
- uthread->uu_aio_task = entryp->procp->task;
- oldmap = vm_map_switch( entryp->aio_map );
- }
-
- if ( (entryp->flags & AIO_READ) != 0 ) {
- error = do_aio_read( entryp );
- }
- else if ( (entryp->flags & AIO_WRITE) != 0 ) {
- error = do_aio_write( entryp );
- }
- else if ( (entryp->flags & AIO_FSYNC) != 0 ) {
- error = do_aio_fsync( entryp );
- }
- else {
- printf( "%s - unknown aio request - flags 0x%02X \n",
- __FUNCTION__, entryp->flags );
- error = EINVAL;
- }
- entryp->errorval = error;
- if ( currentmap != entryp->aio_map ) {
- (void) vm_map_switch( oldmap );
- uthread->uu_aio_task = oldaiotask;
- }
-
- /* we're done with the IO request so pop it off the active queue and */
- /* push it on the done queue */
- AIO_LOCK;
- TAILQ_REMOVE( &entryp->procp->aio_activeq, entryp, aio_workq_link );
- aio_anchor.aio_active_count--;
- entryp->procp->aio_active_count--;
- TAILQ_INSERT_TAIL( &entryp->procp->aio_doneq, entryp, aio_workq_link );
- aio_anchor.aio_done_count++;
- entryp->procp->aio_done_count++;
- entryp->flags |= AIO_COMPLETION;
-
- /* remove our reference to the user land map. */
- if ( VM_MAP_NULL != entryp->aio_map ) {
- vm_map_t my_map;
-
- my_map = entryp->aio_map;
- entryp->aio_map = VM_MAP_NULL;
- AIO_UNLOCK; /* must unlock before calling vm_map_deallocate() */
- vm_map_deallocate( my_map );
- }
- else {
- AIO_UNLOCK;
- }
-
- do_aio_completion( entryp );
- (void) thread_funnel_set( kernel_flock, funnel_state );
-
- KERNEL_DEBUG( (BSDDBG_CODE(DBG_BSD_AIO, AIO_worker_thread)) | DBG_FUNC_END,
- (int)entryp->procp, (int)entryp->uaiocbp, entryp->errorval,
- entryp->returnval, 0 );
-
- AIO_LOCK;
- entryp->flags &= ~AIO_COMPLETION;
- if ( (entryp->flags & AIO_DO_FREE) != 0 ) {
- vm_map_t my_map;
-
- my_map = entryp->aio_map;
- entryp->aio_map = VM_MAP_NULL;
- AIO_UNLOCK;
- aio_free_request( entryp, my_map );
- }
- else
- AIO_UNLOCK;