00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "ad_xfs.h"
00010 #include "adio_extern.h"
00011 #ifdef MPISGI
00012 #include "mpisgi2.h"
00013 #endif
00014
00015 void ADIOI_XFS_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, err;
00019 ADIOI_Flatlist_node *flat_file;
00020 struct flock64 fl;
00021 #ifndef PRINT_ERR_MSG
00022 static char myname[] = "ADIOI_XFS_FCNTL";
00023 #endif
00024
00025 switch(flag) {
00026 case ADIO_FCNTL_SET_VIEW:
00027
00028
00029
00030 MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
00031 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
00032
00033 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00034 if (!filetype_is_contig) ADIOI_Delete_flattened(fd->filetype);
00035
00036 MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
00037 if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
00038
00039
00040 ADIO_SetInfo(fd, fcntl_struct->info, &err);
00041
00042
00043
00044 MPI_Type_get_envelope(fcntl_struct->etype, &i, &j, &k, &combiner);
00045 if (combiner == MPI_COMBINER_NAMED) fd->etype = fcntl_struct->etype;
00046 else {
00047 MPI_Type_contiguous(1, fcntl_struct->etype, ©_etype);
00048 MPI_Type_commit(©_etype);
00049 fd->etype = copy_etype;
00050 }
00051 MPI_Type_get_envelope(fcntl_struct->filetype, &i, &j, &k, &combiner);
00052 if (combiner == MPI_COMBINER_NAMED)
00053 fd->filetype = fcntl_struct->filetype;
00054 else {
00055 MPI_Type_contiguous(1, fcntl_struct->filetype, ©_filetype);
00056 MPI_Type_commit(©_filetype);
00057 fd->filetype = copy_filetype;
00058 ADIOI_Flatten_datatype(fd->filetype);
00059
00060
00061 }
00062
00063 MPI_Type_size(fd->etype, &(fd->etype_size));
00064 fd->disp = fcntl_struct->disp;
00065
00066
00067
00068
00069 ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
00070 if (filetype_is_contig) fd->fp_ind = fcntl_struct->disp;
00071 else {
00072 flat_file = ADIOI_Flatlist;
00073 while (flat_file->type != fd->filetype)
00074 flat_file = flat_file->next;
00075 for (i=0; i<flat_file->count; i++) {
00076 if (flat_file->blocklens[i]) {
00077 fd->fp_ind = fcntl_struct->disp + flat_file->indices[i];
00078 break;
00079 }
00080 }
00081 }
00082 *error_code = MPI_SUCCESS;
00083 break;
00084
00085 case ADIO_FCNTL_GET_FSIZE:
00086 fcntl_struct->fsize = lseek64(fd->fd_sys, 0, SEEK_END);
00087 #ifdef PRINT_ERR_MSG
00088 *error_code = (fcntl_struct->fsize == -1) ? MPI_ERR_UNKNOWN : MPI_SUCCESS;
00089 #else
00090 if (fcntl_struct->fsize == -1) {
00091 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00092 myname, "I/O Error", "%s", strerror(errno));
00093 ADIOI_Error(fd, *error_code, myname);
00094 }
00095 else *error_code = MPI_SUCCESS;
00096 #endif
00097 break;
00098
00099 case ADIO_FCNTL_SET_DISKSPACE:
00100 i = 0;
00101 fl.l_start = 0;
00102 fl.l_whence = SEEK_SET;
00103 fl.l_len = fcntl_struct->diskspace;
00104 err = fcntl(fd->fd_sys, F_RESVSP64, &fl);
00105 if (err) i = 1;
00106 if (fcntl_struct->diskspace > lseek64(fd->fd_sys, 0, SEEK_END)) {
00107
00108 err = ftruncate64(fd->fd_sys, fcntl_struct->diskspace);
00109 if (err) i = 1;
00110 }
00111 #ifdef PRINT_ERR_MSG
00112 *error_code = (i == 0) ? MPI_SUCCESS : MPI_ERR_UNKNOWN;
00113 #else
00114 if (i == 1) {
00115 *error_code = MPIR_Err_setmsg(MPI_ERR_IO, MPIR_ADIO_ERROR,
00116 myname, "I/O Error", "%s", strerror(errno));
00117 ADIOI_Error(fd, *error_code, myname);
00118 }
00119 else *error_code = MPI_SUCCESS;
00120 #endif
00121 break;
00122
00123 case ADIO_FCNTL_SET_IOMODE:
00124
00125
00126 if (fd->iomode != fcntl_struct->iomode) {
00127 fd->iomode = fcntl_struct->iomode;
00128 MPI_Barrier(MPI_COMM_WORLD);
00129 }
00130 *error_code = MPI_SUCCESS;
00131 break;
00132
00133 case ADIO_FCNTL_SET_ATOMICITY:
00134 fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
00135 *error_code = MPI_SUCCESS;
00136 break;
00137
00138 default:
00139 FPRINTF(stderr, "Unknown flag passed to ADIOI_XFS_Fcntl\n");
00140 MPI_Abort(MPI_COMM_WORLD, 1);
00141 }
00142 }