00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_hfs.h"
00010 #include "adio_extern.h"
00011
00012 void ADIOI_HFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
00013 {
00014 MPI_Datatype copy_etype, copy_filetype;
00015 int combiner, i, j, k, filetype_is_contig, ntimes, err;
00016 ADIOI_Flatlist_node *flat_file;
00017 ADIO_Offset curr_fsize, alloc_size, size, len, done;
00018 ADIO_Status status;
00019 char *buf;
00020 #ifndef PRINT_ERR_MSG
00021 static char myname[] = "ADIOI_HFS_FCNTL";
00022 #endif
00023
00024 switch(flag) {
00025 case ADIO_FCNTL_SET_VIEW:
00026
00027
00028
00029 MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
00030 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
00031
00032 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00033 if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype);
00034
00035 MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
00036 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
00037
00038
00039 ADIO_SetInfo(fd, fcntl_struct->info, &err);
00040
00041
00042
00043 MPI_Type_get_envelope(fcntl_struct->etype, &i, &j, &k, &combiner);
00044 if (combiner == MPI_COMBINER_NAMED) fd->etype = fcntl_struct->etype;
00045 else {
00046 MPI_Type_contiguous(1, fcntl_struct->etype, ©_etype);
00047 MPI_Type_commit(©_etype);
00048 fd->etype = copy_etype;
00049 }
00050 MPI_Type_get_envelope(fcntl_struct->filetype, &i, &j, &k, &combiner);
00051 if (combiner == MPI_COMBINER_NAMED)
00052 fd->filetype = fcntl_struct->filetype;
00053 else {
00054 MPI_Type_contiguous(1, fcntl_struct->filetype, ©_filetype);
00055 MPI_Type_commit(©_filetype);
00056 fd->filetype = copy_filetype;
00057 ADIOI_Flatten_datatype(fd->filetype);
00058
00059
00060 }
00061
00062 MPI_Type_size(fd->etype, &(fd->etype_size));
00063 fd->disp = fcntl_struct->disp;
00064
00065
00066
00067
00068 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00069 if (filetype_is_contig) fd->fp_ind = fcntl_struct->disp;
00070 else {
00071 flat_file = ADIOI_Flatlist;
00072 while (flat_file->type != fd->filetype)
00073 flat_file = flat_file->next;
00074 for (i=0; i<flat_file->count; i++) {
00075 if (flat_file->blocklens[i]) {
00076 fd->fp_ind = fcntl_struct->disp + flat_file->indices[i];
00077 break;
00078 }
00079 }
00080 }
00081 *error_code = MPI_SUCCESS;
00082 break;
00083
00084 case ADIO_FCNTL_GET_FSIZE:
00085 fcntl_struct->fsize = lseek64(fd->fd_sys, 0, SEEK_END);
00086 #ifdef HPUX
00087 if (fd->fp_sys_posn != -1)
00088 lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00089
00090 #endif
00091 #ifdef PRINT_ERR_MSG
00092 *error_code = (fcntl_struct->fsize == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00093 #else
00094 if (fcntl_struct->fsize == -1) {
00095 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00096 myname, "I/O Error", "%s", strerror(errno));
00097 ADIOI_Error(fd, *error_code, myname);
00098 }
00099 else *error_code = MPI_SUCCESS;
00100 #endif
00101 break;
00102
00103 case ADIO_FCNTL_SET_DISKSPACE:
00104
00105
00106 #ifdef HPUX
00107 err = prealloc64(fd->fd_sys, fcntl_struct->diskspace);
00108
00109 if (err && (errno != ENOTEMPTY)) {
00110 #ifdef PRINT_ERR_MSG
00111 *error_code = MPI_ERR_UNKNOWN;
00112 #else
00113 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00114 myname, "I/O Error", "%s", strerror(errno));
00115 ADIOI_Error(fd, *error_code, myname);
00116 #endif
00117 return;
00118 }
00119 if (err && (errno == ENOTEMPTY)) {
00120 #endif
00121
00122 #ifdef SPPUX
00123
00124
00125 if (fcntl_struct->diskspace <= 2147483647) {
00126 err = prealloc(fd->fd_sys, (off_t) fcntl_struct->diskspace);
00127 if (err && (errno != ENOTEMPTY)) {
00128 #ifdef PRINT_ERR_MSG
00129 *error_code = MPI_ERR_UNKNOWN;
00130 #else
00131 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00132 myname, "I/O Error", "%s", strerror(errno));
00133 ADIOI_Error(fd, *error_code, myname);
00134 #endif
00135 return;
00136 }
00137 }
00138
00139 if ((fcntl_struct->diskspace > 2147483647) ||
00140 (err && (errno == ENOTEMPTY))) {
00141 #endif
00142
00143
00144
00145
00146
00147
00148
00149
00150 curr_fsize = lseek64(fd->fd_sys, 0, SEEK_END);
00151 alloc_size = fcntl_struct->diskspace;
00152
00153 size = ADIOI_MIN(curr_fsize, alloc_size);
00154
00155 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00156 buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
00157 done = 0;
00158
00159 for (i=0; i<ntimes; i++) {
00160 len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
00161 ADIO_ReadContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00162 done, &status, error_code);
00163 if (*error_code != MPI_SUCCESS) {
00164 #ifdef PRINT_ERR_MSG
00165 FPRINTF(stderr, "ADIOI_HFS_Fcntl: To preallocate disk space, ROMIO needs to read the file and write it back, but is unable to read the file. Please give the file read permission and open it with MPI_MODE_RDWR.\n");
00166 MPI_Abort(MPI_COMM_WORLD, 1);
00167 #else
00168 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_PREALLOC_PERM,
00169 myname, (char *) 0, (char *) 0);
00170 ADIOI_Error(fd, *error_code, myname);
00171 return;
00172 #endif
00173 }
00174 ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00175 done, &status, error_code);
00176 if (*error_code != MPI_SUCCESS) return;
00177 done += len;
00178 }
00179
00180 if (alloc_size > curr_fsize) {
00181 memset(buf, 0, ADIOI_PREALLOC_BUFSZ);
00182 size = alloc_size - curr_fsize;
00183 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00184 for (i=0; i<ntimes; i++) {
00185 len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
00186 ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00187 done, &status, error_code);
00188 if (*error_code != MPI_SUCCESS) return;
00189 done += len;
00190 }
00191 }
00192 ADIOI_Free(buf);
00193 #ifdef HPUX
00194 if (fd->fp_sys_posn != -1)
00195 lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00196
00197 #endif
00198 }
00199 *error_code = MPI_SUCCESS;
00200 break;
00201
00202 case ADIO_FCNTL_SET_IOMODE:
00203
00204
00205 if (fd->iomode != fcntl_struct->iomode) {
00206 fd->iomode = fcntl_struct->iomode;
00207 MPI_Barrier(MPI_COMM_WORLD);
00208 }
00209 *error_code = MPI_SUCCESS;
00210 break;
00211
00212 case ADIO_FCNTL_SET_ATOMICITY:
00213 fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
00214 *error_code = MPI_SUCCESS;
00215 break;
00216
00217 default:
00218 FPRINTF(stderr, "Unknown flag passed to ADIOI_HFS_Fcntl\n");
00219 MPI_Abort(MPI_COMM_WORLD, 1);
00220 }
00221 }