00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_ufs.h"
00010 #include "adio_extern.h"
00011 #ifdef MPISGI
00012 #include "mpisgi2.h"
00013 #endif
00014
00015 void ADIOI_UFS_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
00016 {
00017 MPI_Datatype copy_etype, copy_filetype;
00018 int combiner, i, j, k, filetype_is_contig, ntimes, err;
00019 ADIOI_Flatlist_node *flat_file;
00020 ADIO_Offset curr_fsize, alloc_size, size, len, done;
00021 ADIO_Status status;
00022 char *buf;
00023 #ifndef PRINT_ERR_MSG
00024 static char myname[] = "ADIOI_UFS_FCNTL";
00025 #endif
00026
00027 switch(flag) {
00028 case ADIO_FCNTL_SET_VIEW:
00029
00030
00031
00032 MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
00033 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
00034
00035 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00036 if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype);
00037
00038 MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
00039 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
00040
00041
00042 ADIO_SetInfo(fd, fcntl_struct->info, &err);
00043
00044
00045
00046 MPI_Type_get_envelope(fcntl_struct->etype, &i, &j, &k, &combiner);
00047 if (combiner == MPI_COMBINER_NAMED) fd->etype = fcntl_struct->etype;
00048 else {
00049 MPI_Type_contiguous(1, fcntl_struct->etype, ©_etype);
00050 MPI_Type_commit(©_etype);
00051 fd->etype = copy_etype;
00052 }
00053 MPI_Type_get_envelope(fcntl_struct->filetype, &i, &j, &k, &combiner);
00054 if (combiner == MPI_COMBINER_NAMED)
00055 fd->filetype = fcntl_struct->filetype;
00056 else {
00057 MPI_Type_contiguous(1, fcntl_struct->filetype, ©_filetype);
00058 MPI_Type_commit(©_filetype);
00059 fd->filetype = copy_filetype;
00060 ADIOI_Flatten_datatype(fd->filetype);
00061
00062
00063 }
00064
00065 MPI_Type_size(fd->etype, &(fd->etype_size));
00066 fd->disp = fcntl_struct->disp;
00067
00068
00069
00070
00071 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00072 if (filetype_is_contig) fd->fp_ind = fcntl_struct->disp;
00073 else {
00074 flat_file = ADIOI_Flatlist;
00075 while (flat_file->type != fd->filetype)
00076 flat_file = flat_file->next;
00077 for (i=0; i<flat_file->count; i++) {
00078 if (flat_file->blocklens[i]) {
00079 fd->fp_ind = fcntl_struct->disp + flat_file->indices[i];
00080 break;
00081 }
00082 }
00083 }
00084 *error_code = MPI_SUCCESS;
00085 break;
00086
00087 case ADIO_FCNTL_GET_FSIZE:
00088 fcntl_struct->fsize = lseek(fd->fd_sys, 0, SEEK_END);
00089 if (fd->fp_sys_posn != -1)
00090 lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
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
00107
00108
00109
00110
00111
00112
00113 curr_fsize = lseek(fd->fd_sys, 0, SEEK_END);
00114 alloc_size = fcntl_struct->diskspace;
00115
00116 size = ADIOI_MIN(curr_fsize, alloc_size);
00117
00118 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00119 buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
00120 done = 0;
00121
00122 for (i=0; i<ntimes; i++) {
00123 len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
00124 ADIO_ReadContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
00125 &status, error_code);
00126 if (*error_code != MPI_SUCCESS) {
00127 #ifdef PRINT_ERR_MSG
00128 FPRINTF(stderr, "ADIOI_UFS_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");
00129 MPI_Abort(MPI_COMM_WORLD, 1);
00130 #else
00131 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_PREALLOC_PERM,
00132 myname, (char *) 0, (char *) 0);
00133 ADIOI_Error(fd, *error_code, myname);
00134 return;
00135 #endif
00136 }
00137 ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00138 done, &status, error_code);
00139 if (*error_code != MPI_SUCCESS) return;
00140 done += len;
00141 }
00142
00143 if (alloc_size > curr_fsize) {
00144 memset(buf, 0, ADIOI_PREALLOC_BUFSZ);
00145 size = alloc_size - curr_fsize;
00146 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00147 for (i=0; i<ntimes; i++) {
00148 len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
00149 ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00150 done, &status, error_code);
00151 if (*error_code != MPI_SUCCESS) return;
00152 done += len;
00153 }
00154 }
00155 ADIOI_Free(buf);
00156 if (fd->fp_sys_posn != -1)
00157 lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00158 *error_code = MPI_SUCCESS;
00159 break;
00160
00161 case ADIO_FCNTL_SET_IOMODE:
00162
00163
00164 if (fd->iomode != fcntl_struct->iomode) {
00165 fd->iomode = fcntl_struct->iomode;
00166 MPI_Barrier(MPI_COMM_WORLD);
00167 }
00168 *error_code = MPI_SUCCESS;
00169 break;
00170
00171 case ADIO_FCNTL_SET_ATOMICITY:
00172 fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
00173 *error_code = MPI_SUCCESS;
00174 break;
00175
00176 default:
00177 FPRINTF(stderr, "Unknown flag passed to ADIOI_UFS_Fcntl\n");
00178 MPI_Abort(MPI_COMM_WORLD, 1);
00179 }
00180 }