00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_pfs.h"
00009
00010 void ADIOI_PFS_Open(ADIO_File fd, int *error_code)
00011 {
00012 int perm, amode, old_mask, np_comm, np_total, err, flag;
00013 char *value;
00014 struct sattr attr;
00015 static char myname[] = "ADIOI_PFS_OPEN";
00016
00017 if (fd->perm == ADIO_PERM_NULL) {
00018 old_mask = umask(022);
00019 umask(old_mask);
00020 perm = old_mask ^ 0666;
00021 }
00022 else perm = fd->perm;
00023
00024 amode = 0;
00025 if (fd->access_mode & ADIO_CREATE)
00026 amode = amode | O_CREAT;
00027 if (fd->access_mode & ADIO_RDONLY)
00028 amode = amode | O_RDONLY;
00029 if (fd->access_mode & ADIO_WRONLY)
00030 amode = amode | O_WRONLY;
00031 if (fd->access_mode & ADIO_RDWR)
00032 amode = amode | O_RDWR;
00033 if (fd->access_mode & ADIO_EXCL)
00034 amode = amode | O_EXCL;
00035
00036 MPI_Comm_size(MPI_COMM_WORLD, &np_total);
00037 MPI_Comm_size(fd->comm, &np_comm);
00038
00039 if (np_total == np_comm)
00040 fd->fd_sys = _gopen(fd->filename, amode, M_ASYNC, perm);
00041 else fd->fd_sys = open(fd->filename, amode, perm);
00042 fd->fd_direct = -1;
00043
00044 if (fd->fd_sys != -1) {
00045 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00046
00047
00048
00049
00050
00051
00052 ADIOI_Info_get(fd->info, "pfs_svr_buf", MPI_MAX_INFO_VAL,
00053 value, &flag);
00054 if (flag && (!strcmp(value, "true"))) {
00055 err = fcntl(fd->fd_sys, F_PFS_SVR_BUF, TRUE);
00056 if (err) ADIOI_Info_set(fd->info, "pfs_svr_buf", "false");
00057 }
00058
00059
00060 err = fcntl(fd->fd_sys, F_GETSATTR, &attr);
00061
00062 if (!err) {
00063 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", attr.s_sunitsize);
00064 ADIOI_Info_set(fd->info, "striping_unit", value);
00065
00066 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", attr.s_sfactor);
00067 ADIOI_Info_set(fd->info, "striping_factor", value);
00068
00069 ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", attr.s_start_sdir);
00070 ADIOI_Info_set(fd->info, "start_iodevice", value);
00071 }
00072 ADIOI_Free(value);
00073
00074 if (fd->access_mode & ADIO_APPEND)
00075 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
00076 }
00077
00078 if (fd->fd_sys == -1) {
00079 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00080 myname, __LINE__, MPI_ERR_IO,
00081 "**io",
00082 "**io %s", strerror(errno));
00083 }
00084 else *error_code = MPI_SUCCESS;
00085 }