root/ompi/mca/fbtl/posix/fbtl_posix_preadv.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_fbtl_posix_preadv

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2008-2017 University of Houston. All rights reserved.
  13  * Copyright (c) 2015-2018 Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 #include "ompi_config.h"
  23 #include "fbtl_posix.h"
  24 
  25 #include "mpi.h"
  26 #include <unistd.h>
  27 #include <limits.h>
  28 #include "ompi/constants.h"
  29 #include "ompi/mca/fbtl/fbtl.h"
  30 
  31 ssize_t mca_fbtl_posix_preadv (ompio_file_t *fh )
  32 {
  33     /*int *fp = NULL;*/
  34     int i, block=1, ret;
  35     struct iovec *iov = NULL;
  36     int iov_count = 0;
  37     OMPI_MPI_OFFSET_TYPE iov_offset = 0;
  38     ssize_t bytes_read=0, ret_code=0;
  39     struct flock lock;
  40     off_t total_length, end_offset=0;
  41 
  42     if (NULL == fh->f_io_array) {
  43         return OMPI_ERROR;
  44     }
  45 
  46     iov = (struct iovec *) malloc
  47         (OMPIO_IOVEC_INITIAL_SIZE * sizeof (struct iovec));
  48     if (NULL == iov) {
  49         opal_output(1, "OUT OF MEMORY\n");
  50         return OMPI_ERR_OUT_OF_RESOURCE;
  51     }
  52 
  53     for (i=0 ; i<fh->f_num_of_io_entries ; i++) {
  54         if (0 == iov_count) {
  55             iov[iov_count].iov_base = fh->f_io_array[i].memory_address;
  56             iov[iov_count].iov_len = fh->f_io_array[i].length;
  57             iov_offset = (OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i].offset;
  58             end_offset = (off_t)fh->f_io_array[i].offset + (off_t)fh->f_io_array[i].length;
  59             iov_count ++;
  60         }
  61 
  62         if (OMPIO_IOVEC_INITIAL_SIZE*block <= iov_count) {
  63             block ++;
  64             iov = (struct iovec *)realloc
  65                 (iov, OMPIO_IOVEC_INITIAL_SIZE * block *
  66                  sizeof(struct iovec));
  67             if (NULL == iov) {
  68                 opal_output(1, "OUT OF MEMORY\n");
  69                 return OMPI_ERR_OUT_OF_RESOURCE;
  70             }
  71         }
  72 
  73         if (fh->f_num_of_io_entries != i+1) {
  74             if (((((OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i].offset +
  75                    (ptrdiff_t)fh->f_io_array[i].length) ==
  76                   (OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i+1].offset)) &&
  77                 (iov_count < IOV_MAX ) ){
  78                     iov[iov_count].iov_base =
  79                         fh->f_io_array[i+1].memory_address;
  80                     iov[iov_count].iov_len = fh->f_io_array[i+1].length;
  81                     end_offset = (off_t)fh->f_io_array[i].offset + (off_t)fh->f_io_array[i].length;
  82                     iov_count ++;
  83                     continue;
  84             }
  85         }
  86 
  87         total_length = (end_offset - (off_t)iov_offset );
  88 
  89         ret = mca_fbtl_posix_lock ( &lock, fh, F_RDLCK, iov_offset, total_length, OMPIO_LOCK_SELECTIVE ); 
  90         if ( 0 < ret ) {
  91             opal_output(1, "mca_fbtl_posix_preadv: error in mca_fbtl_posix_lock() ret=%d: %s", ret, strerror(errno));
  92             free (iov);
  93             /* Just in case some part of the lock worked */
  94             mca_fbtl_posix_unlock ( &lock, fh);
  95             return OMPI_ERROR;
  96         }
  97 #if defined(HAVE_PREADV)
  98         ret_code = preadv (fh->fd, iov, iov_count, iov_offset);
  99 #else
 100         if (-1 == lseek (fh->fd, iov_offset, SEEK_SET)) {
 101             opal_output(1, "mca_fbtl_posix_preadv: error in lseek:%s", strerror(errno));
 102             free(iov);
 103             mca_fbtl_posix_unlock ( &lock, fh );
 104             return OMPI_ERROR;
 105         }
 106         ret_code = readv (fh->fd, iov, iov_count);
 107 #endif
 108         mca_fbtl_posix_unlock ( &lock, fh );
 109         if ( 0 < ret_code ) {
 110             bytes_read+=ret_code;
 111         }
 112         else if ( ret_code == -1 ) {
 113             opal_output(1, "mca_fbtl_posix_preadv: error in (p)readv:%s", strerror(errno));
 114             free(iov);
 115             return OMPI_ERROR;
 116         }
 117         else if ( 0 == ret_code ){
 118             /* end of file reached, no point in continue reading; */
 119             break;
 120         }
 121         iov_count = 0;
 122     }
 123 
 124     free (iov);
 125 
 126     return bytes_read;
 127 }

/* [<][>][^][v][top][bottom][index][help] */