00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_nfs.h"
00009
00010
00011
00012
00013
00014
00015 void ADIOI_NFS_Get_shared_fp(ADIO_File fd, int incr, ADIO_Offset *shared_fp,
00016 int *error_code)
00017 {
00018 ADIO_Offset new_fp;
00019 int err;
00020 MPI_Comm dupcommself;
00021 static char myname[] = "ADIOI_NFS_GET_SHARED_FP";
00022
00023 if (fd->shared_fp_fd == ADIO_FILE_NULL) {
00024 MPI_Comm_dup(MPI_COMM_SELF, &dupcommself);
00025 fd->shared_fp_fd = ADIO_Open(MPI_COMM_SELF, dupcommself,
00026 fd->shared_fp_fname,
00027 fd->file_system,
00028 fd->fns,
00029 ADIO_CREATE | ADIO_RDWR | ADIO_DELETE_ON_CLOSE,
00030 0, MPI_BYTE, MPI_BYTE, MPI_INFO_NULL,
00031 ADIO_PERM_NULL, error_code);
00032 if (*error_code != MPI_SUCCESS) return;
00033 *shared_fp = 0;
00034 ADIOI_WRITE_LOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
00035 #ifdef ADIOI_MPE_LOGGING
00036 MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
00037 #endif
00038 err = read(fd->shared_fp_fd->fd_sys, shared_fp, sizeof(ADIO_Offset));
00039 #ifdef ADIOI_MPE_LOGGING
00040 MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
00041 #endif
00042
00043
00044
00045 }
00046 else {
00047 ADIOI_WRITE_LOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
00048
00049 #ifdef ADIOI_MPE_LOGGING
00050 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
00051 #endif
00052 err = lseek(fd->shared_fp_fd->fd_sys, 0, SEEK_SET);
00053 #ifdef ADIOI_MPE_LOGGING
00054 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
00055 #endif
00056 if (err == 0) {
00057 #ifdef ADIOI_MPE_LOGGING
00058 MPE_Log_event( ADIOI_MPE_read_a, 0, NULL );
00059 #endif
00060 err = read(fd->shared_fp_fd->fd_sys, shared_fp,
00061 sizeof(ADIO_Offset));
00062 #ifdef ADIOI_MPE_LOGGING
00063 MPE_Log_event( ADIOI_MPE_read_b, 0, NULL );
00064 #endif
00065 }
00066 if (err == -1) {
00067 ADIOI_UNLOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
00068 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00069 MPIR_ERR_RECOVERABLE, myname,
00070 __LINE__, MPI_ERR_IO, "**io",
00071 "**io %s", strerror(errno));
00072 return;
00073 }
00074 }
00075
00076 if (incr == 0) {goto done;}
00077
00078 new_fp = *shared_fp + incr;
00079
00080 #ifdef ADIOI_MPE_LOGGING
00081 MPE_Log_event( ADIOI_MPE_lseek_a, 0, NULL );
00082 #endif
00083 err = lseek(fd->shared_fp_fd->fd_sys, 0, SEEK_SET);
00084 #ifdef ADIOI_MPE_LOGGING
00085 MPE_Log_event( ADIOI_MPE_lseek_b, 0, NULL );
00086 #endif
00087 if (err == 0) {
00088 #ifdef ADIOI_MPE_LOGGING
00089 MPE_Log_event( ADIOI_MPE_write_a, 0, NULL );
00090 #endif
00091 err = write(fd->shared_fp_fd->fd_sys, &new_fp, sizeof(ADIO_Offset));
00092 #ifdef ADIOI_MPE_LOGGING
00093 MPE_Log_event( ADIOI_MPE_write_b, 0, NULL );
00094 #endif
00095 }
00096 done:
00097 ADIOI_UNLOCK(fd->shared_fp_fd, 0, SEEK_SET, sizeof(ADIO_Offset));
00098 if (err == -1) {
00099 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
00100 myname, __LINE__, MPI_ERR_IO,
00101 "**io",
00102 "**io %s", strerror(errno));
00103 }
00104 else *error_code = MPI_SUCCESS;
00105 }