00001 
00002 
00003 
00004 
00005 
00006 
00007 #include "ad_nfs.h"
00008 
00009 #include "../../mpi-io/mpioimpl.h"
00010 #include "../../mpi-io/mpioprof.h"
00011 #include "mpiu_greq.h"
00012 
00013 #include <string.h>
00014 
00015 #ifdef ROMIO_HAVE_WORKING_AIO
00016 static MPIX_Grequest_class ADIOI_GEN_greq_class = 0;
00017 
00018 
00019 void ADIOI_NFS_IwriteContig(ADIO_File fd, void *buf, int count, 
00020                 MPI_Datatype datatype, int file_ptr_type,
00021                 ADIO_Offset offset, ADIO_Request *request, int *error_code)  
00022 {
00023     int len, typesize;
00024     int aio_errno = 0;
00025     static char myname[] = "ADIOI_NFS_IWRITECONTIG";
00026 
00027     MPI_Type_size(datatype, &typesize);
00028     len = count * typesize;
00029 
00030     if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
00031     aio_errno = ADIOI_NFS_aio(fd, buf, len, offset, 1, request);
00032     if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += len;
00033 
00034     fd->fp_sys_posn = -1;
00035 
00036     if (aio_errno != 0) {
00037     
00038     MPIO_ERR_CREATE_CODE_ERRNO(myname, aio_errno, error_code);
00039     return;
00040     
00041     }
00042     else *error_code = MPI_SUCCESS;
00043     return;
00044 }
00045 #endif
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 #ifdef ROMIO_HAVE_WORKING_AIO
00054 int ADIOI_NFS_aio(ADIO_File fd, void *buf, int len, ADIO_Offset offset,
00055           int wr, MPI_Request *request)
00056 {
00057     int err=-1, fd_sys;
00058     int error_code, this_errno;
00059 
00060     struct aiocb *aiocbp;
00061     ADIOI_AIO_Request *aio_req;
00062     MPI_Status status;
00063 
00064     fd_sys = fd->fd_sys;
00065 
00066     aio_req = (ADIOI_AIO_Request*)ADIOI_Calloc(sizeof(ADIOI_AIO_Request), 1);
00067     aiocbp = (struct aiocb *) ADIOI_Calloc(sizeof(struct aiocb), 1);
00068     aiocbp->aio_offset = offset;
00069     aiocbp->aio_buf    = buf;
00070     aiocbp->aio_nbytes = len;
00071 
00072 #ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_WHENCE
00073     aiocbp->aio_whence = SEEK_SET;
00074 #endif
00075 #ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_FILDES
00076     aiocbp->aio_fildes = fd_sys;
00077 #endif
00078 #ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_SIGEVENT
00079 # ifdef AIO_SIGNOTIFY_NONE
00080     aiocbp->aio_sigevent.sigev_notify = SIGEV_NONE;
00081 # endif
00082     aiocbp->aio_sigevent.sigev_signo = 0;
00083 #endif
00084 #ifdef ROMIO_HAVE_STRUCT_AIOCB_WITH_AIO_REQPRIO
00085 # ifdef AIO_PRIO_DFL
00086     aiocbp->aio_reqprio = AIO_PRIO_DFL;   
00087 # else
00088     aiocbp->aio_reqprio = 0;
00089 # endif
00090 #endif
00091 
00092     if (wr) ADIOI_WRITE_LOCK(fd, offset, SEEK_SET, len);
00093     else ADIOI_READ_LOCK(fd, offset, SEEK_SET, len);
00094 
00095 #ifndef ROMIO_HAVE_AIO_CALLS_NEED_FILEDES
00096     if (wr) err = aio_write(aiocbp);
00097     else err = aio_read(aiocbp);
00098 #else
00099     
00100     if (wr) err = aio_write(fd_sys, aiocbp);
00101     else err = aio_read(fd_sys, aiocbp);
00102 #endif
00103 
00104     this_errno = errno;
00105     ADIOI_UNLOCK(fd, offset, SEEK_SET, len);
00106 
00107     if (err == -1) {
00108     if (this_errno == EAGAIN) {
00109         
00110 
00111         ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00112                 offset, &status, &error_code);
00113         MPIO_Completed_request_create(&fd, len, &error_code, request);
00114         return 0;
00115     } else {
00116         return -this_errno;
00117     }
00118     }
00119     aio_req->aiocbp = aiocbp;
00120     if (ADIOI_GEN_greq_class == 0) {
00121         MPIX_Grequest_class_create(ADIOI_GEN_aio_query_fn, 
00122                 ADIOI_GEN_aio_free_fn, MPIU_Greq_cancel_fn, 
00123                 ADIOI_GEN_aio_poll_fn, ADIOI_GEN_aio_wait_fn, 
00124                 &ADIOI_GEN_greq_class);
00125     }
00126     MPIX_Grequest_class_allocate(ADIOI_GEN_greq_class, aio_req, request);
00127     memcpy(&(aio_req->req), request, sizeof(MPI_Request));
00128     return 0;
00129 }
00130 #endif