00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_xfs.h"
00009 #ifdef HAVE_MALLOC_H
00010 #include <malloc.h>
00011 #endif
00012
00013
00014
00015 static void ADIOI_XFS_Aligned_Mem_File_Read(ADIO_File fd, void *buf, int len,
00016 ADIO_Offset offset, int *err);
00017
00018 void ADIOI_XFS_ReadContig(ADIO_File fd, void *buf, int count,
00019 MPI_Datatype datatype, int file_ptr_type,
00020 ADIO_Offset offset, ADIO_Status *status, int *error_code)
00021 {
00022 int err=-1, datatype_size, len, diff, size, nbytes;
00023 void *newbuf;
00024 static char myname[] = "ADIOI_XFS_READCONTIG";
00025
00026 MPI_Type_size(datatype, &datatype_size);
00027 len = datatype_size * count;
00028
00029 fd->fp_sys_posn = -1;
00030
00031 if (file_ptr_type == ADIO_INDIVIDUAL) offset = fd->fp_ind;
00032
00033 if (!(fd->direct_read))
00034 err = pread(fd->fd_sys, buf, len, offset);
00035 else {
00036
00037
00038
00039
00040
00041 if (!(((long) buf) % fd->d_mem) && !(offset % fd->d_miniosz))
00042 ADIOI_XFS_Aligned_Mem_File_Read(fd, buf, len, offset, &err);
00043
00044
00045
00046
00047
00048 else if (offset % fd->d_miniosz) {
00049 diff = fd->d_miniosz - (offset % fd->d_miniosz);
00050 diff = ADIOI_MIN(diff, len);
00051 nbytes = pread(fd->fd_sys, buf, diff, offset);
00052
00053 buf = ((char *) buf) + diff;
00054 offset += diff;
00055 size = len - diff;
00056 if (!(((long) buf) % fd->d_mem)) {
00057 ADIOI_XFS_Aligned_Mem_File_Read(fd, buf, size, offset, &err);
00058 nbytes += err;
00059 }
00060 else {
00061 newbuf = (void *) memalign(XFS_MEMALIGN, size);
00062 if (newbuf) {
00063 ADIOI_XFS_Aligned_Mem_File_Read(fd, newbuf, size, offset, &err);
00064 if (err > 0) memcpy(buf, newbuf, err);
00065 nbytes += err;
00066 ADIOI_Free(newbuf);
00067 }
00068 else nbytes += pread(fd->fd_sys, buf, size, offset);
00069 }
00070 err = nbytes;
00071 }
00072
00073
00074
00075 else {
00076 newbuf = (void *) memalign(XFS_MEMALIGN, len);
00077 if (newbuf) {
00078 ADIOI_XFS_Aligned_Mem_File_Read(fd, newbuf, len, offset, &err);
00079 if (err > 0) memcpy(buf, newbuf, err);
00080 ADIOI_Free(newbuf);
00081 }
00082 else err = pread(fd->fd_sys, buf, len, offset);
00083 }
00084 }
00085
00086 if (file_ptr_type == ADIO_INDIVIDUAL) fd->fp_ind += err;
00087
00088 #ifdef HAVE_STATUS_SET_BYTES
00089 if (err != -1) MPIR_Status_set_bytes(status, datatype, err);
00090 #endif
00091
00092 if (err == -1) {
00093 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00094 myname, __LINE__, MPI_ERR_IO, "**io",
00095 "**io %s", strerror(errno));
00096 }
00097 else *error_code = MPI_SUCCESS;
00098 }
00099
00100
00101 void ADIOI_XFS_Aligned_Mem_File_Read(ADIO_File fd, void *buf, int len,
00102 ADIO_Offset offset, int *err)
00103 {
00104 int ntimes, rem, newrem, i, size, nbytes;
00105 unsigned read_chunk_sz = fd->hints->fs_hints.xfs.read_chunk_sz;
00106
00107
00108
00109
00110
00111
00112 if (!(len % fd->d_miniosz) &&
00113 (len >= fd->d_miniosz) && (len <= read_chunk_sz))
00114 *err = pread(fd->fd_direct, buf, len, offset);
00115 else if (len < fd->d_miniosz)
00116 *err = pread(fd->fd_sys, buf, len, offset);
00117 else if (len > read_chunk_sz) {
00118 ntimes = len/(read_chunk_sz);
00119 rem = len - ntimes * read_chunk_sz;
00120 nbytes = 0;
00121 for (i=0; i<ntimes; i++) {
00122 nbytes += pread(fd->fd_direct, ((char *)buf) + i * read_chunk_sz,
00123 read_chunk_sz, offset);
00124 offset += read_chunk_sz;
00125 }
00126 if (rem) {
00127 if (!(rem % fd->d_miniosz))
00128 nbytes += pread(fd->fd_direct,
00129 ((char *)buf) + ntimes * read_chunk_sz, rem, offset);
00130 else {
00131 newrem = rem % fd->d_miniosz;
00132 size = rem - newrem;
00133 if (size) {
00134 nbytes += pread(fd->fd_direct,
00135 ((char *)buf) + ntimes * read_chunk_sz, size, offset);
00136 offset += size;
00137 }
00138 nbytes += pread(fd->fd_sys,
00139 ((char *)buf) + ntimes * read_chunk_sz + size, newrem, offset);
00140 }
00141 }
00142 *err = nbytes;
00143 }
00144 else {
00145 rem = len % fd->d_miniosz;
00146 size = len - rem;
00147 nbytes = pread(fd->fd_direct, buf, size, offset);
00148 nbytes += pread(fd->fd_sys, (char *)buf + size, rem, offset+size);
00149 *err = nbytes;
00150 }
00151 }