00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_pvfs.h"
00009
00010 void ADIOI_PVFS_Open(ADIO_File fd, int *error_code)
00011 {
00012 int perm, amode, old_mask, flag;
00013 char *value;
00014
00015
00016 struct pvfs_filestat pstat = {-1,-1,-1};
00017 static char myname[] = "ADIOI_PVFS_OPEN";
00018
00019 if (fd->perm == ADIO_PERM_NULL) {
00020 old_mask = umask(022);
00021 umask(old_mask);
00022 perm = old_mask ^ 0666;
00023 }
00024 else perm = fd->perm;
00025
00026 amode = O_META;
00027 if (fd->access_mode & ADIO_CREATE)
00028 amode = amode | O_CREAT;
00029 if (fd->access_mode & ADIO_RDONLY)
00030 amode = amode | O_RDONLY;
00031 if (fd->access_mode & ADIO_WRONLY)
00032 amode = amode | O_WRONLY;
00033 if (fd->access_mode & ADIO_RDWR)
00034 amode = amode | O_RDWR;
00035 if (fd->access_mode & ADIO_EXCL)
00036 amode = amode | O_EXCL;
00037
00038 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00039
00040 ADIOI_Info_get(fd->info, "striping_factor", MPI_MAX_INFO_VAL,
00041 value, &flag);
00042 if (flag && (atoi(value) > 0)) pstat.pcount = atoi(value);
00043
00044 ADIOI_Info_get(fd->info, "striping_unit", MPI_MAX_INFO_VAL,
00045 value, &flag);
00046 if (flag && (atoi(value) > 0)) pstat.ssize = atoi(value);
00047
00048 ADIOI_Info_get(fd->info, "start_iodevice", MPI_MAX_INFO_VAL,
00049 value, &flag);
00050 if (flag && (atoi(value) >= 0)) pstat.base = atoi(value);
00051
00052 #ifdef ADIOI_MPE_LOGGING
00053 MPE_Log_event( ADIOI_MPE_open_a, 0, NULL );
00054 #endif
00055 fd->fd_sys = pvfs_open64(fd->filename, amode, perm, &pstat, NULL);
00056 #ifdef ADIOI_MPE_LOGGING
00057 MPE_Log_event( ADIOI_MPE_open_b, 0, NULL );
00058 #endif
00059 fd->fd_direct = -1;
00060
00061 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND)) {
00062 #ifdef ADIOI_MPE_LOGGING
00063 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
00064 #endif
00065 fd->fp_ind = fd->fp_sys_posn = pvfs_lseek64(fd->fd_sys, 0, SEEK_END);
00066 #ifdef ADIOI_MPE_LOGGING
00067 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
00068 #endif
00069 }
00070
00071 if (fd->fd_sys != -1) {
00072 pvfs_ioctl(fd->fd_sys, GETMETA, &pstat);
00073 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", pstat.pcount);
00074 ADIOI_Info_set(fd->info, "striping_factor", value);
00075 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", pstat.ssize);
00076 ADIOI_Info_set(fd->info, "striping_unit", value);
00077 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", pstat.base);
00078 ADIOI_Info_set(fd->info, "start_iodevice", value);
00079 }
00080
00081 ADIOI_Free(value);
00082
00083 if (fd->fd_sys == -1) {
00084 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00085 myname, __LINE__, MPI_ERR_IO,
00086 "**io",
00087 "**io %s", strerror(errno));
00088 }
00089 else *error_code = MPI_SUCCESS;
00090 }