00001
00002
00003
00009
00010
00011
00012
00013
00014
00015 #include "ad_bgl.h"
00016 #include "ad_bgl_aggrs.h"
00017
00018 #include <sys/statfs.h>
00019 #include <sys/vfs.h>
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036 #ifndef PATH_MAX
00037 #define PATH_MAX 65535
00038 #endif
00039
00040
00041
00042
00043
00044 #if !defined(S_ISLNK)
00045 # if defined(S_IFLNK)
00046
00047 # define S_ISLNK(mode) ((mode) & S_IFLNK)
00048 # else
00049
00050 # define S_ISLNK(mode) 0
00051 # endif
00052 #endif
00053
00054
00055
00056
00057
00058
00059 static void ADIO_FileSysType_parentdir(char *filename, char **dirnamep)
00060 {
00061 int err;
00062 char *dir = NULL, *slash;
00063 struct stat statbuf;
00064
00065 err = lstat(filename, &statbuf);
00066
00067 if (err || (!S_ISLNK(statbuf.st_mode))) {
00068
00069
00070
00071 dir = ADIOI_Strdup(filename);
00072 }
00073 else {
00074
00075
00076
00077
00078
00079 int namelen;
00080 char *linkbuf;
00081
00082 linkbuf = ADIOI_Malloc(PATH_MAX+1);
00083 namelen = readlink(filename, linkbuf, PATH_MAX+1);
00084 if (namelen == -1) {
00085
00086
00087
00088
00089 dir = ADIOI_Strdup(filename);
00090 }
00091 else {
00092
00093 linkbuf[namelen] = '\0';
00094 dir = ADIOI_Strdup(linkbuf);
00095 ADIOI_Free(linkbuf);
00096 }
00097 }
00098
00099 slash = strrchr(dir, '/');
00100 if (!slash) ADIOI_Strncpy(dir, ".", 2);
00101 else {
00102 if (slash == dir) *(dir + 1) = '\0';
00103 else *slash = '\0';
00104 }
00105
00106 *dirnamep = dir;
00107 return;
00108 }
00109
00110 static void scaleable_stat(ADIO_File fd)
00111 {
00112 struct stat64 bgl_stat;
00113 struct statfs bgl_statfs;
00114 int rank, rc;
00115 char * dir;
00116 long buf[2];
00117 MPI_Comm_rank(fd->comm, &rank);
00118
00119 if (rank == 0) {
00120
00121 rc = stat64(fd->filename, &bgl_stat);
00122 if (rc >= 0)
00123 {
00124 buf[0] = bgl_stat.st_blksize;
00125 DBGV_FPRINTF(stderr,"Successful stat '%s'. Blocksize=%ld\n",
00126 fd->filename,bgl_stat.st_blksize);
00127 }
00128 else
00129 {
00130 DBGV_FPRINTF(stderr,"Stat '%s' failed with rc=%d, errno=%d\n",
00131 fd->filename,rc,errno);
00132 }
00133
00134
00135 rc = statfs(fd->filename,&bgl_statfs);
00136 if (rc >= 0)
00137 {
00138 DBGV_FPRINTF(stderr,"Successful statfs '%s'. Magic number=%#X\n",
00139 fd->filename,bgl_statfs.f_type);
00140 buf[1] = bgl_statfs.f_type;
00141 }
00142 else
00143 {
00144 DBGV_FPRINTF(stderr,"Statfs '%s' failed with rc=%d, errno=%d\n",
00145 fd->filename,rc,errno);
00146 ADIO_FileSysType_parentdir(fd->filename, &dir);
00147 rc = statfs(dir,&bgl_statfs);
00148 if (rc >= 0)
00149 {
00150 DBGV_FPRINTF(stderr,"Successful statfs '%s'. Magic number=%#X\n",dir,bgl_statfs.f_type);
00151 buf[1] = bgl_statfs.f_type;
00152 }
00153 else
00154 {
00155
00156
00157 buf[1] = -1;
00158 DBGV_FPRINTF(stderr,"Statfs '%s' failed with rc=%d, errno=%d\n",dir,rc,errno);
00159 }
00160 free(dir);
00161 }
00162 }
00163
00164 MPI_Bcast(buf, 2, MPI_LONG, 0, fd->comm);
00165 bgl_stat.st_blksize = buf[0];
00166 bgl_statfs.f_type = buf[1];
00167
00168
00169
00170 ((ADIOI_BGL_fs*)fd->fs_ptr)->blksize = bgl_stat.st_blksize;
00171
00172
00173 if ((bgl_statfs.f_type == GPFS_SUPER_MAGIC) ||
00174 (bgl_statfs.f_type == bglocklessmpio_f_type))
00175 {
00176 ((ADIOI_BGL_fs*)fd->fs_ptr)->fsync_aggr =
00177 ADIOI_BGL_FSYNC_AGGREGATION_ENABLED;
00178
00179
00180
00181 if (rank == 0)
00182 {
00183 ((ADIOI_BGL_fs*)fd->fs_ptr)->fsync_aggr |=
00184 ADIOI_BGL_FSYNC_AGGREGATOR;
00185 DBG_FPRINTF(stderr,"fsync aggregator %d\n",rank);
00186 }
00187 else ;
00188 }
00189 else;
00190 }
00191
00192
00193 void ADIOI_BGL_Open(ADIO_File fd, int *error_code)
00194 {
00195 int perm, old_mask, amode;
00196 static char myname[] = "ADIOI_BGL_OPEN";
00197
00198
00199 ad_bgl_get_env_vars();
00200
00201 if (fd->perm == ADIO_PERM_NULL) {
00202 old_mask = umask(022);
00203 umask(old_mask);
00204 perm = old_mask ^ 0666;
00205 }
00206 else perm = fd->perm;
00207
00208 amode = 0;
00209 if (fd->access_mode & ADIO_CREATE)
00210 amode = amode | O_CREAT;
00211 if (fd->access_mode & ADIO_RDONLY)
00212 amode = amode | O_RDONLY;
00213 if (fd->access_mode & ADIO_WRONLY)
00214 amode = amode | O_WRONLY;
00215 if (fd->access_mode & ADIO_RDWR)
00216 amode = amode | O_RDWR;
00217 if (fd->access_mode & ADIO_EXCL)
00218 amode = amode | O_EXCL;
00219 #ifdef ADIOI_MPE_LOGGING
00220 MPE_Log_event(ADIOI_MPE_open_a, 0, NULL);
00221 #endif
00222 fd->fd_sys = open(fd->filename, amode, perm);
00223 #ifdef ADIOI_MPE_LOGGING
00224 MPE_Log_event(ADIOI_MPE_open_b, 0, NULL);
00225 #endif
00226 DBG_FPRINTF(stderr,"open('%s',%#X,%#X) rc=%d, errno=%d\n",fd->filename,amode,perm,fd->fd_sys,errno);
00227 fd->fd_direct = -1;
00228
00229 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND))
00230 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
00231
00232 if(fd->fd_sys != -1)
00233 {
00234
00235 AD_BGL_assert(fd->fs_ptr == NULL);
00236 fd->fs_ptr = (ADIOI_BGL_fs*) ADIOI_Malloc(sizeof(ADIOI_BGL_fs));
00237
00238 ((ADIOI_BGL_fs*)fd->fs_ptr)->blksize = 1048576;
00239
00240
00241 ((ADIOI_BGL_fs*)fd->fs_ptr)->fsync_aggr =
00242 ADIOI_BGL_FSYNC_AGGREGATION_DISABLED;
00243
00244
00245 #ifdef ADIOI_MPE_LOGGING
00246 MPE_Log_event(ADIOI_MPE_stat_a, 0, NULL);
00247 #endif
00248 scaleable_stat(fd);
00249 #ifdef ADIOI_MPE_LOGGING
00250 MPE_Log_event(ADIOI_MPE_stat_b, 0, NULL);
00251 #endif
00252 }
00253
00254 if (fd->fd_sys == -1) {
00255 if (errno == ENAMETOOLONG)
00256 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00257 MPIR_ERR_RECOVERABLE, myname,
00258 __LINE__, MPI_ERR_BAD_FILE,
00259 "**filenamelong",
00260 "**filenamelong %s %d",
00261 fd->filename,
00262 strlen(fd->filename));
00263 else if (errno == ENOENT)
00264 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00265 MPIR_ERR_RECOVERABLE, myname,
00266 __LINE__, MPI_ERR_NO_SUCH_FILE,
00267 "**filenoexist",
00268 "**filenoexist %s",
00269 fd->filename);
00270 else if (errno == ENOTDIR || errno == ELOOP)
00271 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00272 MPIR_ERR_RECOVERABLE,
00273 myname, __LINE__,
00274 MPI_ERR_BAD_FILE,
00275 "**filenamedir",
00276 "**filenamedir %s",
00277 fd->filename);
00278 else if (errno == EACCES) {
00279 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00280 MPIR_ERR_RECOVERABLE, myname,
00281 __LINE__, MPI_ERR_ACCESS,
00282 "**fileaccess",
00283 "**fileaccess %s",
00284 fd->filename );
00285 }
00286 else if (errno == EROFS) {
00287
00288 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00289 MPIR_ERR_RECOVERABLE, myname,
00290 __LINE__, MPI_ERR_READ_ONLY,
00291 "**ioneedrd", 0 );
00292 }
00293 else {
00294 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00295 MPIR_ERR_RECOVERABLE, myname,
00296 __LINE__, MPI_ERR_IO, "**io",
00297 "**io %s", strerror(errno));
00298 }
00299 }
00300 else *error_code = MPI_SUCCESS;
00301 }
00302
00303
00304