This source file includes following definitions.
- mca_sharedfp_lockedfile_request_position
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  21 #include "ompi_config.h"
  22 #include "sharedfp_lockedfile.h"
  23 
  24 #include "mpi.h"
  25 #include "ompi/constants.h"
  26 #include "ompi/mca/sharedfp/sharedfp.h"
  27 #include "ompi/mca/sharedfp/base/base.h"
  28 
  29 
  30 #include <fcntl.h>
  31 #include <unistd.h>
  32 
  33 int mca_sharedfp_lockedfile_request_position(struct mca_sharedfp_base_data_t * sh,
  34                                              int bytes_requested,
  35                                              OMPI_MPI_OFFSET_TYPE *offset)
  36 {
  37     int ret = OMPI_SUCCESS;
  38     
  39     int fd;
  40     
  41     struct flock fl;
  42     OMPI_MPI_OFFSET_TYPE position = 0;
  43     
  44     OMPI_MPI_OFFSET_TYPE buf;
  45     
  46 
  47     struct mca_sharedfp_lockedfile_data * lockedfile_data = sh->selected_module_data;
  48     int handle = lockedfile_data->handle;
  49 
  50     *offset = 0;
  51 
  52     
  53 
  54     fd = handle;
  55 
  56     
  57     fl.l_type   = F_WRLCK;
  58     fl.l_whence = SEEK_SET;
  59     fl.l_start  = 0;
  60     fl.l_len    = 0;
  61     fl.l_pid    = getpid();
  62 
  63 
  64     
  65     if (fcntl(fd, F_SETLKW, &fl) == -1) {
  66         opal_output(0,"sharedfp_lockedfile_request_position: errorr acquiring lock: fcntl(%d,F_SETLKW,&fl)\n",fd);
  67         opal_output(0,"sharedfp_lockedfile_request_position: error(%i): %s", errno, strerror(errno));
  68         return OMPI_ERROR;
  69     }
  70     else{
  71         if ( mca_sharedfp_lockedfile_verbose ) {
  72             opal_output(ompi_sharedfp_base_framework.framework_output,
  73                         "sharedfp_lockedfile_request_position: Success: acquired lock.for fd: %d\n",fd);
  74         }
  75     }
  76 
  77     
  78     lseek ( fd, 0, SEEK_SET );
  79     read ( fd, &buf, sizeof(OMPI_MPI_OFFSET_TYPE));
  80     if ( mca_sharedfp_lockedfile_verbose ) {
  81         opal_output(ompi_sharedfp_base_framework.framework_output,
  82                     "sharedfp_lockedfile_request_position: Read last_offset=%lld! ret=%d\n",buf, ret);
  83     }
  84 
  85     
  86     position = buf + bytes_requested;
  87     if ( mca_sharedfp_lockedfile_verbose ) {
  88         opal_output(ompi_sharedfp_base_framework.framework_output,
  89                     "sharedfp_lockedfile_request_position: old_offset=%lld, bytes_requested=%d, new offset=%lld!\n",
  90                     buf,bytes_requested,position);
  91     }
  92 
  93     
  94     lseek ( fd, 0, SEEK_SET );
  95     write ( fd, &position, sizeof(OMPI_MPI_OFFSET_TYPE));
  96 
  97     
  98     if ( mca_sharedfp_lockedfile_verbose ) {
  99         opal_output(ompi_sharedfp_base_framework.framework_output,
 100                     "sharedfp_lockedfile_request_position: Releasing lock...");
 101     }
 102 
 103     
 104 
 105 
 106 
 107 
 108 
 109     fl.l_type   = F_UNLCK;  
 110     fl.l_whence = SEEK_SET;
 111     fl.l_start  = 0;
 112     fl.l_len    = 0;
 113     fl.l_pid    = getpid();
 114 
 115     if (fcntl(fd, F_SETLK, &fl) == -1) {
 116         opal_output(0,"sharedfp_lockedfile_request_position:failed to release lock for fd: %d\n",fd);
 117         opal_output(0,"error(%i): %s", errno, strerror(errno));
 118         return OMPI_ERROR;
 119     }
 120     else {
 121         if ( mca_sharedfp_lockedfile_verbose ) {
 122             opal_output(ompi_sharedfp_base_framework.framework_output,
 123                         "sharedfp_lockedfile_request_position: released lock.for fd: %d\n",fd);
 124         }
 125     }
 126 
 127     
 128     *offset = buf;
 129 
 130     return ret;
 131 }