This source file includes following definitions.
- mca_fbtl_posix_pwritev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 #include "ompi_config.h"
24 #include "fbtl_posix.h"
25
26 #include "mpi.h"
27 #include <unistd.h>
28 #include <sys/uio.h>
29 #include <limits.h>
30 #include "ompi/constants.h"
31 #include "ompi/mca/fbtl/fbtl.h"
32
33 ssize_t mca_fbtl_posix_pwritev(ompio_file_t *fh )
34 {
35
36 int i, block = 1, ret;
37 struct iovec *iov = NULL;
38 int iov_count = 0;
39 OMPI_MPI_OFFSET_TYPE iov_offset = 0;
40 ssize_t ret_code=0, bytes_written=0;
41 struct flock lock;
42 off_t total_length, end_offset=0;
43
44 if (NULL == fh->f_io_array) {
45 return OMPI_ERROR;
46 }
47
48 iov = (struct iovec *) malloc
49 (OMPIO_IOVEC_INITIAL_SIZE * sizeof (struct iovec));
50 if (NULL == iov) {
51 opal_output(1, "OUT OF MEMORY\n");
52 return OMPI_ERR_OUT_OF_RESOURCE;
53 }
54
55 for (i=0 ; i<fh->f_num_of_io_entries ; i++) {
56 if (0 == iov_count) {
57 iov[iov_count].iov_base = fh->f_io_array[i].memory_address;
58 iov[iov_count].iov_len = fh->f_io_array[i].length;
59 iov_offset = (OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i].offset;
60 end_offset = (off_t)fh->f_io_array[i].offset + (off_t)fh->f_io_array[i].length;
61 iov_count ++;
62 }
63
64 if (OMPIO_IOVEC_INITIAL_SIZE*block <= iov_count) {
65 block ++;
66 iov = (struct iovec *)realloc
67 (iov, OMPIO_IOVEC_INITIAL_SIZE * block *
68 sizeof(struct iovec));
69 if (NULL == iov) {
70 opal_output(1, "OUT OF MEMORY\n");
71 return OMPI_ERR_OUT_OF_RESOURCE;
72 }
73 }
74
75 if (fh->f_num_of_io_entries != i+1) {
76 if ( (((OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i].offset +
77 (ptrdiff_t)fh->f_io_array[i].length) ==
78 (OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i+1].offset) &&
79 (iov_count < IOV_MAX )) {
80 iov[iov_count].iov_base = fh->f_io_array[i+1].memory_address;
81 iov[iov_count].iov_len = fh->f_io_array[i+1].length;
82 end_offset = (off_t)fh->f_io_array[i].offset + (off_t)fh->f_io_array[i].length;
83 iov_count ++;
84 continue;
85 }
86 }
87
88
89
90
91
92
93
94
95
96
97
98
99
100 total_length = (end_offset - (off_t)iov_offset);
101 ret = mca_fbtl_posix_lock ( &lock, fh, F_WRLCK, iov_offset, total_length, OMPIO_LOCK_SELECTIVE );
102 if ( 0 < ret ) {
103 opal_output(1, "mca_fbtl_posix_pwritev: error in mca_fbtl_posix_lock() error ret=%d %s", ret, strerror(errno));
104 free (iov);
105
106 mca_fbtl_posix_unlock ( &lock, fh );
107 return OMPI_ERROR;
108 }
109 #if defined (HAVE_PWRITEV)
110 ret_code = pwritev (fh->fd, iov, iov_count, iov_offset);
111 #else
112 if (-1 == lseek (fh->fd, iov_offset, SEEK_SET)) {
113 opal_output(1, "mca_fbtl_posix_pwritev: error in lseek:%s", strerror(errno));
114 free(iov);
115 mca_fbtl_posix_unlock ( &lock, fh );
116 return OMPI_ERROR;
117 }
118 ret_code = writev (fh->fd, iov, iov_count);
119 #endif
120 mca_fbtl_posix_unlock ( &lock, fh );
121 if ( 0 < ret_code ) {
122 bytes_written += ret_code;
123 }
124 else if (-1 == ret_code ) {
125 opal_output(1, "mca_fbtl_posix_pwritev: error in writev:%s", strerror(errno));
126 free (iov);
127 return OMPI_ERROR;
128 }
129 iov_count = 0;
130 }
131
132 free (iov);
133
134 return bytes_written;
135 }