00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_pfs.h"
00010
00011 void ADIOI_PFS_SetInfo(ADIO_File fd, MPI_Info users_info, int *error_code)
00012 {
00013 char *value, *value_in_fd;
00014 int flag, tmp_val, str_factor=-1, str_unit=-1, start_iodev=-1;
00015 struct sattr attr;
00016 int err, myrank, fd_sys, perm, amode, old_mask;
00017
00018 if (!(fd->info)) {
00019
00020
00021 MPI_Info_create(&(fd->info));
00022
00023
00024
00025 if (users_info != MPI_INFO_NULL) {
00026 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00027
00028 MPI_Info_get(users_info, "striping_factor", MPI_MAX_INFO_VAL,
00029 value, &flag);
00030 if (flag) {
00031 str_factor=atoi(value);
00032 tmp_val = str_factor;
00033 MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
00034 if (tmp_val != str_factor) {
00035 FPRINTF(stderr, "ADIOI_PFS_SetInfo: the value for key \"striping_factor\" must be the same on all processes\n");
00036 MPI_Abort(MPI_COMM_WORLD, 1);
00037 }
00038 }
00039
00040 MPI_Info_get(users_info, "striping_unit", MPI_MAX_INFO_VAL,
00041 value, &flag);
00042 if (flag) {
00043 str_unit=atoi(value);
00044 tmp_val = str_unit;
00045 MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
00046 if (tmp_val != str_unit) {
00047 FPRINTF(stderr, "ADIOI_PFS_SetInfo: the value for key \"striping_unit\" must be the same on all processes\n");
00048 MPI_Abort(MPI_COMM_WORLD, 1);
00049 }
00050 }
00051
00052 MPI_Info_get(users_info, "start_iodevice", MPI_MAX_INFO_VAL,
00053 value, &flag);
00054 if (flag) {
00055 start_iodev=atoi(value);
00056 tmp_val = start_iodev;
00057 MPI_Bcast(&tmp_val, 1, MPI_INT, 0, fd->comm);
00058 if (tmp_val != start_iodev) {
00059 FPRINTF(stderr, "ADIOI_PFS_SetInfo: the value for key \"start_iodevice\" must be the same on all processes\n");
00060 MPI_Abort(MPI_COMM_WORLD, 1);
00061 }
00062 }
00063
00064
00065 if ((str_factor > 0) || (str_unit > 0) || (start_iodev >= 0)) {
00066 MPI_Comm_rank(fd->comm, &myrank);
00067 if (!myrank) {
00068 if (fd->perm == ADIO_PERM_NULL) {
00069 old_mask = umask(022);
00070 umask(old_mask);
00071 perm = old_mask ^ 0666;
00072 }
00073 else perm = fd->perm;
00074
00075 amode = 0;
00076 if (fd->access_mode & ADIO_CREATE)
00077 amode = amode | O_CREAT;
00078 if (fd->access_mode & ADIO_RDONLY)
00079 amode = amode | O_RDONLY;
00080 if (fd->access_mode & ADIO_WRONLY)
00081 amode = amode | O_WRONLY;
00082 if (fd->access_mode & ADIO_RDWR)
00083 amode = amode | O_RDWR;
00084 if (fd->access_mode & ADIO_EXCL)
00085 amode = amode | O_EXCL;
00086
00087 fd_sys = open(fd->filename, amode, perm);
00088 err = fcntl(fd_sys, F_GETSATTR, &attr);
00089
00090 if (!err) {
00091 if (str_unit > 0) attr.s_sunitsize = str_unit;
00092 if ((start_iodev >= 0) &&
00093 (start_iodev < attr.s_sfactor))
00094 attr.s_start_sdir = start_iodev;
00095 if ((str_factor > 0) && (str_factor < attr.s_sfactor))
00096 attr.s_sfactor = str_factor;
00097
00098 err = fcntl(fd_sys, F_SETSATTR, &attr);
00099 }
00100
00101 close(fd_sys);
00102 }
00103
00104 MPI_Barrier(fd->comm);
00105 }
00106
00107
00108
00109
00110
00111 MPI_Info_get(users_info, "pfs_svr_buf", MPI_MAX_INFO_VAL,
00112 value, &flag);
00113 if (flag && (!strcmp(value, "true")))
00114 MPI_Info_set(fd->info, "pfs_svr_buf", "true");
00115 else MPI_Info_set(fd->info, "pfs_svr_buf", "false");
00116
00117 ADIOI_Free(value);
00118 }
00119 else MPI_Info_set(fd->info, "pfs_svr_buf", "false");
00120
00121
00122 ADIOI_GEN_SetInfo(fd, users_info, error_code);
00123 }
00124
00125 else {
00126
00127
00128
00129
00130 ADIOI_GEN_SetInfo(fd, users_info, error_code);
00131
00132
00133 if (users_info != MPI_INFO_NULL) {
00134 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00135
00136 MPI_Info_get(users_info, "pfs_svr_buf", MPI_MAX_INFO_VAL,
00137 value, &flag);
00138 if (flag && (!strcmp(value, "true") || !strcmp(value, "false"))) {
00139 value_in_fd = (char *)
00140 ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00141 MPI_Info_get(fd->info, "pfs_svr_buf", MPI_MAX_INFO_VAL,
00142 value_in_fd, &flag);
00143 if (strcmp(value, value_in_fd)) {
00144 if (!strcmp(value, "true")) {
00145 err = fcntl(fd->fd_sys, F_PFS_SVR_BUF, TRUE);
00146 if (!err)
00147 MPI_Info_set(fd->info, "pfs_svr_buf", "true");
00148 }
00149 else {
00150 err = fcntl(fd->fd_sys, F_PFS_SVR_BUF, FALSE);
00151 if (!err)
00152 MPI_Info_set(fd->info, "pfs_svr_buf", "false");
00153 }
00154 }
00155 ADIOI_Free(value_in_fd);
00156 }
00157 ADIOI_Free(value);
00158 }
00159
00160 }
00161
00162 *error_code = MPI_SUCCESS;
00163 }