00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_nfs.h"
00010
00011 void ADIOI_NFS_IwriteContig(ADIO_File fd, void *buf, int count,
00012 MPI_Datatype datatype, int file_ptr_type,
00013 ADIO_Offset offset, ADIO_Request *request, int *error_code)
00014 {
00015 int len, typesize;
00016 #ifdef NO_AIO
00017 ADIO_Status status;
00018 #else
00019 int err=-1;
00020 #ifndef PRINT_ERR_MSG
00021 static char myname[] = "ADIOI_NFS_IWRITECONTIG";
00022 #endif
00023 #endif
00024
00025 *request = ADIOI_Malloc_request();
00026 (*request)->optype = ADIOI_WRITE;
00027 (*request)->fd = fd;
00028 (*request)->datatype = datatype;
00029
00030 MPI_Type_size(datatype, &typesize);
00031 len = count * typesize;
00032
00033 #ifdef NO_AIO
00034
00035
00036
00037 ADIOI_NFS_WriteContig(fd, buf, len, MPI_BYTE, file_ptr_type, offset, &status,
00038 error_code);
00039 (*request)->queued = 0;
00040 #ifdef HAVE_STATUS_SET_BYTES
00041 if (*error_code == MPI_SUCCESS) {
00042 MPI_Get_elements(&status, MPI_BYTE, &len);
00043 (*request)->nbytes = len;
00044 }
00045 #endif
00046
00047 #else
00048 if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
00049 err = ADIOI_NFS_aio(fd, buf, len, offset, 1, &((*request)->handle));
00050 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len;
00051
00052 (*request)->queued = 1;
00053 ADIOI_Add_req_to_list(request);
00054
00055 #ifdef PRINT_ERR_MSG
00056 *error_code = (err == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00057 #else
00058 if (err == -1) {
00059 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00060 myname, "I/O Error", "%s", strerror(errno));
00061 ADIOI_Error(fd, *error_code, myname);
00062 }
00063 else *error_code = MPI_SUCCESS;
00064 #endif
00065 #endif
00066
00067 fd->fp_sys_posn = -1;
00068 fd->async_count++;
00069 }
00070
00071
00072
00073 void ADIOI_NFS_IwriteStrided(ADIO_File fd, void *buf, int count,
00074 MPI_Datatype datatype, int file_ptr_type,
00075 ADIO_Offset offset, ADIO_Request *request, int
00076 *error_code)
00077 {
00078 ADIO_Status status;
00079 #ifdef HAVE_STATUS_SET_BYTES
00080 int typesize;
00081 #endif
00082
00083 *request = ADIOI_Malloc_request();
00084 (*request)->optype = ADIOI_WRITE;
00085 (*request)->fd = fd;
00086 (*request)->datatype = datatype;
00087 (*request)->queued = 0;
00088 (*request)->handle = 0;
00089
00090
00091 ADIOI_NFS_WriteStrided(fd, buf, count, datatype, file_ptr_type,
00092 offset, &status, error_code);
00093
00094 fd->async_count++;
00095
00096 #ifdef HAVE_STATUS_SET_BYTES
00097 if (*error_code == MPI_SUCCESS) {
00098 MPI_Type_size(datatype, &typesize);
00099 (*request)->nbytes = count * typesize;
00100 }
00101 #endif
00102 }
00103
00104
00105
00106
00107
00108
00109 int ADIOI_NFS_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset,
00110 int wr, void *handle)
00111 {
00112 int err=-1, fd_sys;
00113
00114 #ifndef NO_AIO
00115 int error_code, this_errno;
00116 #ifdef AIO_SUN
00117 aio_result_t *result;
00118 #else
00119 struct aiocb *aiocbp;
00120 #endif
00121 #endif
00122
00123 fd_sys = fd->fd_sys;
00124
00125 #ifdef AIO_SUN
00126 result = (aio_result_t *) ADIOI_Malloc(sizeof(aio_result_t));
00127 result->aio_return = AIO_INPROGRESS;
00128 if (wr) {
00129 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00130 err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result);
00131 this_errno = errno;
00132 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00133 }
00134 else {
00135 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00136 err = aioread(fd_sys, buf, len, offset, SEEK_SET, result);
00137 this_errno = errno;
00138 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00139 }
00140
00141 if (err == -1) {
00142 if (this_errno == EAGAIN) {
00143
00144
00145
00146
00147
00148 ADIOI_Complete_async(&error_code);
00149 if (wr) {
00150 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00151 err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result);
00152 this_errno = errno;
00153 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00154 }
00155 else {
00156 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00157 err = aioread(fd_sys, buf, len, offset, SEEK_SET, result);
00158 this_errno = errno;
00159 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00160 }
00161
00162 while (err == -1) {
00163 if (this_errno == EAGAIN) {
00164
00165 sleep(1);
00166 if (wr) {
00167 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00168 err = aiowrite(fd_sys, buf, len, offset, SEEK_SET, result);
00169 this_errno = errno;
00170 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00171 }
00172 else {
00173 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00174 err = aioread(fd_sys, buf, len, offset, SEEK_SET, result);
00175 this_errno = errno;
00176 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00177 }
00178 }
00179 else {
00180 FPRINTF(stderr, "Unknown errno %d in ADIOI_NFS_aio\n", this_errno);
00181 MPI_Abort(MPI_COMM_WORLD, 1);
00182 }
00183 }
00184 }
00185 else {
00186 FPRINTF(stderr, "Unknown errno %d in ADIOI_NFS_aio\n", this_errno);
00187 MPI_Abort(MPI_COMM_WORLD, 1);
00188 }
00189 }
00190
00191 *((aio_result_t **) handle) = result;
00192 #endif
00193
00194 #ifdef NO_FD_IN_AIOCB
00195
00196 aiocbp = (struct aiocb *) ADIOI_Malloc(sizeof(struct aiocb));
00197 aiocbp->aio_whence = SEEK_SET;
00198 aiocbp->aio_offset = offset;
00199 aiocbp->aio_buf = buf;
00200 aiocbp->aio_nbytes = len;
00201 if (wr) {
00202 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00203 err = aio_write(fd_sys, aiocbp);
00204 this_errno = errno;
00205 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00206 }
00207 else {
00208 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00209 err = aio_read(fd_sys, aiocbp);
00210 this_errno = errno;
00211 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00212 }
00213
00214 if (err == -1) {
00215 if (this_errno == EAGAIN) {
00216
00217
00218
00219 ADIOI_Complete_async(&error_code);
00220 if (wr) {
00221 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00222 err = aio_write(fd_sys, aiocbp);
00223 this_errno = errno;
00224 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00225 }
00226 else {
00227 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00228 err = aio_read(fd_sys, aiocbp);
00229 this_errno = errno;
00230 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00231 }
00232
00233 while (err == -1) {
00234 if (this_errno == EAGAIN) {
00235
00236 sleep(1);
00237 if (wr) {
00238 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00239 err = aio_write(fd_sys, aiocbp);
00240 this_errno = errno;
00241 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00242 }
00243 else {
00244 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00245 err = aio_read(fd_sys, aiocbp);
00246 this_errno = errno;
00247 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00248 }
00249 }
00250 else {
00251 FPRINTF(stderr, "Unknown errno %d in ADIOI_NFS_aio\n", this_errno);
00252 MPI_Abort(MPI_COMM_WORLD, 1);
00253 }
00254 }
00255 }
00256 else {
00257 FPRINTF(stderr, "Unknown errno %d in ADIOI_NFS_aio\n", this_errno);
00258 MPI_Abort(MPI_COMM_WORLD, 1);
00259 }
00260 }
00261
00262 *((struct aiocb **) handle) = aiocbp;
00263
00264 #elif (!defined(NO_AIO) && !defined(AIO_SUN))
00265
00266
00267 aiocbp = (struct aiocb *) ADIOI_Calloc(sizeof(struct aiocb), 1);
00268 aiocbp->aio_fildes = fd_sys;
00269 aiocbp->aio_offset = offset;
00270 aiocbp->aio_buf = buf;
00271 aiocbp->aio_nbytes = len;
00272
00273 #ifdef AIO_PRIORITY_DEFAULT
00274
00275 aiocbp->aio_reqprio = AIO_PRIO_DFL;
00276 aiocbp->aio_sigevent.sigev_signo = 0;
00277 #else
00278 aiocbp->aio_reqprio = 0;
00279 #endif
00280
00281 #ifdef AIO_SIGNOTIFY_NONE
00282
00283 aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE;
00284 #else
00285 aiocbp->aio_sigevent.sigev_signo = 0;
00286 #endif
00287
00288 if (wr) {
00289 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00290 err = aio_write(aiocbp);
00291 this_errno = errno;
00292 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00293 }
00294 else {
00295 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00296 err = aio_read(aiocbp);
00297 this_errno = errno;
00298 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00299 }
00300
00301 if (err == -1) {
00302 if (this_errno == EAGAIN) {
00303
00304
00305
00306 ADIOI_Complete_async(&error_code);
00307 if (wr) {
00308 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00309 err = aio_write(aiocbp);
00310 this_errno = errno;
00311 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00312 }
00313 else {
00314 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00315 err = aio_read(aiocbp);
00316 this_errno = errno;
00317 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00318 }
00319
00320 while (err == -1) {
00321 if (this_errno == EAGAIN) {
00322
00323 sleep(1);
00324 if (wr) {
00325 ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00326 err = aio_write(aiocbp);
00327 this_errno = errno;
00328 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00329 }
00330 else {
00331 ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00332 err = aio_read(aiocbp);
00333 this_errno = errno;
00334 ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00335 }
00336 }
00337 else {
00338 FPRINTF(stderr, "Unknown errno %d in ADIOI_NFS_aio\n", this_errno);
00339 MPI_Abort(MPI_COMM_WORLD, 1);
00340 }
00341 }
00342 }
00343 else {
00344 FPRINTF(stderr, "Unknown errno %d in ADIOI_NFS_aio\n", this_errno);
00345 MPI_Abort(MPI_COMM_WORLD, 1);
00346 }
00347 }
00348
00349 *((struct aiocb **) handle) = aiocbp;
00350 #endif
00351
00352 return err;
00353 }