00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_nfs.h"
00010
00011 int ADIOI_NFS_ReadDone(ADIO_Request *request, ADIO_Status *status, int *error_code)
00012 {
00013 #ifndef NO_AIO
00014 int done=0;
00015 #ifndef PRINT_ERR_MSG
00016 static char myname[] = "ADIOI_NFS_READDONE";
00017 #endif
00018 #ifdef AIO_SUN
00019 aio_result_t *result=0, *tmp;
00020 #else
00021 int err;
00022 #endif
00023 #ifdef AIO_HANDLE_IN_AIOCB
00024 struct aiocb *tmp1;
00025 #endif
00026 #endif
00027
00028 if (*request == ADIO_REQUEST_NULL) {
00029 *error_code = MPI_SUCCESS;
00030 return 1;
00031 }
00032
00033 #ifdef NO_AIO
00034
00035 #ifdef HAVE_STATUS_SET_BYTES
00036 MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
00037 #endif
00038 (*request)->fd->async_count--;
00039 ADIOI_Free_request((ADIOI_Req_node *) (*request));
00040 *request = ADIO_REQUEST_NULL;
00041 *error_code = MPI_SUCCESS;
00042 return 1;
00043 #endif
00044
00045 #ifdef AIO_SUN
00046 if ((*request)->queued) {
00047 tmp = (aio_result_t *) (*request)->handle;
00048 if (tmp->aio_return == AIO_INPROGRESS) {
00049 done = 0;
00050 *error_code = MPI_SUCCESS;
00051 }
00052 else if (tmp->aio_return != -1) {
00053 result = (aio_result_t *) aiowait(0);
00054 done = 1;
00055 (*request)->nbytes = tmp->aio_return;
00056 *error_code = MPI_SUCCESS;
00057 }
00058 else {
00059 #ifdef PRINT_ERR_MSG
00060 *error_code = MPI_ERR_UNKNOWN;
00061 #else
00062 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00063 myname, "I/O Error", "%s", strerror(tmp->aio_errno));
00064 ADIOI_Error((*request)->fd, *error_code, myname);
00065 #endif
00066 }
00067 }
00068 else {
00069
00070
00071 done = 1;
00072 *error_code = MPI_SUCCESS;
00073 }
00074 #ifdef HAVE_STATUS_SET_BYTES
00075 if (done && ((*request)->nbytes != -1))
00076 MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
00077 #endif
00078
00079 #endif
00080
00081 #ifdef AIO_HANDLE_IN_AIOCB
00082
00083 if ((*request)->queued) {
00084 tmp1 = (struct aiocb *) (*request)->handle;
00085 errno = aio_error(tmp1->aio_handle);
00086 if (errno == EINPROG) {
00087 done = 0;
00088 *error_code = MPI_SUCCESS;
00089 }
00090 else {
00091 err = aio_return(tmp1->aio_handle);
00092 (*request)->nbytes = err;
00093 errno = aio_error(tmp1->aio_handle);
00094
00095 done = 1;
00096
00097 #ifdef PRINT_ERR_MSG
00098 *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00099 #else
00100 if (err == -1) {
00101 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00102 myname, "I/O Error", "%s", strerror(errno));
00103 ADIOI_Error((*request)->fd, *error_code, myname);
00104 }
00105 else *error_code = MPI_SUCCESS;
00106 #endif
00107 }
00108 }
00109 else {
00110 done = 1;
00111 *error_code = MPI_SUCCESS;
00112 }
00113 #ifdef HAVE_STATUS_SET_BYTES
00114 if (done && ((*request)->nbytes != -1))
00115 MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
00116 #endif
00117
00118 #elif (!defined(NO_AIO) && !defined(AIO_SUN))
00119
00120 if ((*request)->queued) {
00121 errno = aio_error((const struct aiocb *) (*request)->handle);
00122 if (errno == EINPROGRESS) {
00123 done = 0;
00124 *error_code = MPI_SUCCESS;
00125 }
00126 else {
00127 err = aio_return((struct aiocb *) (*request)->handle);
00128 (*request)->nbytes = err;
00129 errno = aio_error((struct aiocb *) (*request)->handle);
00130
00131 done = 1;
00132
00133 #ifdef PRINT_ERR_MSG
00134 *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00135 #else
00136 if (err == -1) {
00137 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00138 myname, "I/O Error", "%s", strerror(errno));
00139 ADIOI_Error((*request)->fd, *error_code, myname);
00140 }
00141 else *error_code = MPI_SUCCESS;
00142 #endif
00143 }
00144 }
00145 else {
00146 done = 1;
00147 *error_code = MPI_SUCCESS;
00148 }
00149 #ifdef HAVE_STATUS_SET_BYTES
00150 if (done && ((*request)->nbytes != -1))
00151 MPIR_Status_set_bytes(status, (*request)->datatype, (*request)->nbytes);
00152 #endif
00153
00154 #endif
00155
00156 #ifndef NO_AIO
00157 if (done) {
00158
00159
00160 if ((*request)->queued) ADIOI_Del_req_from_list(request);
00161
00162 (*request)->fd->async_count--;
00163 if ((*request)->handle) ADIOI_Free((*request)->handle);
00164 ADIOI_Free_request((ADIOI_Req_node *) (*request));
00165 *request = ADIO_REQUEST_NULL;
00166 }
00167 return done;
00168 #endif
00169
00170 }
00171
00172
00173 int ADIOI_NFS_WriteDone(ADIO_Request *request, ADIO_Status *status, int *error_code)
00174 {
00175 return ADIOI_NFS_ReadDone(request, status, error_code);
00176 }