This source file includes following definitions.
- mca_fbtl_posix_preadv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
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
119 break;
120 }
121 iov_count = 0;
122 }
123
124 free (iov);
125
126 return bytes_read;
127 }