00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_pvfs.h"
00010 #include "adio_extern.h"
00011
00012 void ADIOI_PVFS_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_PVFS_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 = pvfs_lseek64(fd->fd_sys, 0, SEEK_END);
00086 if (fd->fp_sys_posn != -1)
00087 pvfs_lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00088 #ifdef PRINT_ERR_MSG
00089 *error_code = (fcntl_struct->fsize == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00090 #else
00091 if (fcntl_struct->fsize == -1) {
00092 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00093 myname, "I/O Error", "%s", strerror(errno));
00094 ADIOI_Error(fd, *error_code, myname);
00095 }
00096 else *error_code = MPI_SUCCESS;
00097 #endif
00098 break;
00099
00100 case ADIO_FCNTL_SET_DISKSPACE:
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110 curr_fsize = pvfs_lseek64(fd->fd_sys, 0, SEEK_END);
00111 alloc_size = fcntl_struct->diskspace;
00112
00113 size = ADIOI_MIN(curr_fsize, alloc_size);
00114
00115 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00116 buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
00117 done = 0;
00118
00119 for (i=0; i<ntimes; i++) {
00120 len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
00121 ADIO_ReadContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
00122 &status, error_code);
00123 if (*error_code != MPI_SUCCESS) {
00124 #ifdef PRINT_ERR_MSG
00125 FPRINTF(stderr, "ADIOI_PVFS_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");
00126 MPI_Abort(MPI_COMM_WORLD, 1);
00127 #else
00128 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_PREALLOC_PERM,
00129 myname, (char *) 0, (char *) 0);
00130 ADIOI_Error(fd, *error_code, myname);
00131 return;
00132 #endif
00133 }
00134 ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
00135 &status, error_code);
00136 if (*error_code != MPI_SUCCESS) return;
00137 done += len;
00138 }
00139
00140 if (alloc_size > curr_fsize) {
00141 memset(buf, 0, ADIOI_PREALLOC_BUFSZ);
00142 size = alloc_size - curr_fsize;
00143 ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00144 for (i=0; i<ntimes; i++) {
00145 len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
00146 ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET,
00147 done, &status, error_code);
00148 if (*error_code != MPI_SUCCESS) return;
00149 done += len;
00150 }
00151 }
00152 ADIOI_Free(buf);
00153 if (fd->fp_sys_posn != -1)
00154 pvfs_lseek64(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00155 *error_code = MPI_SUCCESS;
00156 break;
00157
00158 case ADIO_FCNTL_SET_IOMODE:
00159
00160
00161 if (fd->iomode != fcntl_struct->iomode) {
00162 fd->iomode = fcntl_struct->iomode;
00163 MPI_Barrier(MPI_COMM_WORLD);
00164 }
00165 *error_code = MPI_SUCCESS;
00166 break;
00167
00168 case ADIO_FCNTL_SET_ATOMICITY:
00169 *error_code = MPI_ERR_UNKNOWN;
00170 break;
00171
00172 default:
00173 FPRINTF(stderr, "Unknown flag passed to ADIOI_PVFS_Fcntl\n");
00174 MPI_Abort(MPI_COMM_WORLD, 1);
00175 }
00176 }