00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 #include "ad_lustre.h"
00010 #include "adio_extern.h"
00011 
00012 void ADIOI_LUSTRE_Fcntl(ADIO_File fd, int flag, ADIO_Fcntl_t *fcntl_struct, int *error_code)
00013 {
00014     int i, ntimes;
00015     ADIO_Offset curr_fsize, alloc_size, size, len, done;
00016     ADIO_Status status;
00017     char *buf;
00018 #if defined(MPICH2) || !defined(PRINT_ERR_MSG)
00019     static char myname[] = "ADIOI_LUSTRE_FCNTL";
00020 #endif
00021 
00022     switch(flag) {
00023     case ADIO_FCNTL_GET_FSIZE:
00024     fcntl_struct->fsize = lseek(fd->fd_sys, 0, SEEK_END);
00025     if (fd->fp_sys_posn != -1) 
00026          lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00027     if (fcntl_struct->fsize == -1) {
00028         *error_code = MPIO_Err_create_code(MPI_SUCCESS, 
00029             MPIR_ERR_RECOVERABLE, myname, __LINE__, 
00030             MPI_ERR_IO, "**io", "**io %s", strerror(errno));
00031     }
00032     else *error_code = MPI_SUCCESS;
00033     break;
00034 
00035     case ADIO_FCNTL_SET_DISKSPACE:
00036     
00037     
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045     curr_fsize = lseek(fd->fd_sys, 0, SEEK_END);
00046     alloc_size = fcntl_struct->diskspace;
00047 
00048     size = ADIOI_MIN(curr_fsize, alloc_size);
00049     
00050     ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00051     buf = (char *) ADIOI_Malloc(ADIOI_PREALLOC_BUFSZ);
00052     done = 0;
00053 
00054     for (i=0; i<ntimes; i++) {
00055         len = ADIOI_MIN(size-done, ADIOI_PREALLOC_BUFSZ);
00056         ADIO_ReadContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, done,
00057                 &status, error_code);
00058         if (*error_code != MPI_SUCCESS) {
00059         *error_code = MPIO_Err_create_code(MPI_SUCCESS, 
00060             MPIR_ERR_RECOVERABLE, myname, __LINE__, 
00061             MPI_ERR_IO, "**io", "**io %s", strerror(errno));
00062                 return;  
00063         }
00064         ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
00065                              done, &status, error_code);
00066         if (*error_code != MPI_SUCCESS) return;
00067         done += len;
00068     }
00069 
00070     if (alloc_size > curr_fsize) {
00071         memset(buf, 0, ADIOI_PREALLOC_BUFSZ); 
00072         size = alloc_size - curr_fsize;
00073         ntimes = (size + ADIOI_PREALLOC_BUFSZ - 1)/ADIOI_PREALLOC_BUFSZ;
00074         for (i=0; i<ntimes; i++) {
00075         len = ADIOI_MIN(alloc_size-done, ADIOI_PREALLOC_BUFSZ);
00076         ADIO_WriteContig(fd, buf, len, MPI_BYTE, ADIO_EXPLICIT_OFFSET, 
00077                  done, &status, error_code);
00078         if (*error_code != MPI_SUCCESS) return;
00079         done += len;  
00080         }
00081     }
00082     ADIOI_Free(buf);
00083     if (fd->fp_sys_posn != -1) 
00084         lseek(fd->fd_sys, fd->fp_sys_posn, SEEK_SET);
00085     *error_code = MPI_SUCCESS;
00086     break;
00087 
00088     case ADIO_FCNTL_SET_ATOMICITY:
00089     fd->atomicity = (fcntl_struct->atomicity == 0) ? 0 : 1;
00090     *error_code = MPI_SUCCESS;
00091     break;
00092 
00093     default:
00094     FPRINTF(stderr, "Unknown flag passed to ADIOI_LUSTRE_Fcntl\n");
00095     MPI_Abort(MPI_COMM_WORLD, 1);
00096     }
00097 }