This source file includes following definitions.
- mca_sharedfp_lockedfile_seek
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 "sharedfp_lockedfile.h"
25
26 #include "mpi.h"
27 #include "ompi/constants.h"
28 #include "ompi/mca/sharedfp/sharedfp.h"
29 #include "ompi/mca/sharedfp/base/base.h"
30
31
32 #include <fcntl.h>
33
34 int
35 mca_sharedfp_lockedfile_seek (ompio_file_t *fh,
36 OMPI_MPI_OFFSET_TYPE off, int whence)
37 {
38 int ret = OMPI_SUCCESS;
39 struct mca_sharedfp_base_data_t *sh = NULL;
40 struct mca_sharedfp_lockedfile_data * lockedfile_data;
41 int fd_lockedfilehandle;
42
43 struct flock fl;
44 OMPI_MPI_OFFSET_TYPE offset, end_position=0;
45
46 if(fh->f_sharedfp_data==NULL){
47 opal_output(ompi_sharedfp_base_framework.framework_output,
48 "sharedfp_lockedfile_seek: module not initialized\n");
49 return OMPI_ERROR;
50 }
51
52 sh = fh->f_sharedfp_data;
53 offset = off * fh->f_etype_size;
54
55 if( 0 == fh->f_rank ){
56 if ( MPI_SEEK_SET == whence ){
57
58 if(offset < 0){
59 opal_output(0,"sharedfp_lockedfile_seek - MPI_SEEK_SET, offset must be > 0,"
60 " got offset=%lld.\n",offset);
61 return OMPI_ERROR;
62 }
63 }
64 else if ( MPI_SEEK_CUR == whence){
65 OMPI_MPI_OFFSET_TYPE current_position;
66 ret = mca_sharedfp_lockedfile_get_position(fh,¤t_position);
67 if ( OMPI_SUCCESS != ret ) {
68 return OMPI_ERROR;
69 }
70
71 offset = current_position + offset;
72 fflush(stdout);
73 if(offset < 0){
74 opal_output(0,"sharedfp_lockedfile_seek - MPI_SEEK_CUR, offset must be > 0, got offset=%lld.\n",offset);
75 return OMPI_ERROR;
76 }
77 }
78 else if( MPI_SEEK_END == whence ){
79 mca_common_ompio_file_get_size( fh,&end_position);
80 offset = end_position + offset;
81
82 if ( offset < 0){
83 opal_output(0,"sharedfp_lockedfile_seek - MPI_SEEK_CUR, offset must be > 0, got offset=%lld.\n",offset);
84 return OMPI_ERROR;
85 }
86 }else{
87 opal_output(0,"sharedfp_lockedfile_seek - whence=%i is not supported\n",whence);
88 return OMPI_ERROR;
89 }
90
91
92
93 lockedfile_data = sh->selected_module_data;
94 fd_lockedfilehandle = lockedfile_data->handle;
95
96 opal_output(ompi_sharedfp_base_framework.framework_output,
97 "sharedfp_lockedfile_seek: Aquiring lock...");
98
99
100 fl.l_type = F_WRLCK;
101 fl.l_whence = SEEK_SET;
102 fl.l_start = 0;
103 fl.l_len = 0;
104 fl.l_pid = getpid();
105
106
107 if ( fcntl(fd_lockedfilehandle, F_SETLKW, &fl) == -1) {
108 opal_output(0, "Erorr acquiring lock: fcntl(%d,F_SETLKW,&fl)\n",fd_lockedfilehandle);
109 opal_output(0,"error(%i): %s", errno, strerror(errno));
110 return OMPI_ERROR;
111 }
112 else{
113 opal_output(ompi_sharedfp_base_framework.framework_output,
114 "sharedfp_lockedfile_seek: Success! acquired lock.for fd: %d\n",fd_lockedfilehandle);
115 }
116
117
118
119
120
121 lseek ( fd_lockedfilehandle, 0, SEEK_SET);
122 write ( fd_lockedfilehandle, &offset, sizeof(OMPI_MPI_OFFSET_TYPE));
123
124
125
126
127
128 if ( mca_sharedfp_lockedfile_verbose ) {
129 opal_output(ompi_sharedfp_base_framework.framework_output,
130 "sharedfp_lockedfile_seek: Releasing lock...");
131 }
132 fl.l_type = F_UNLCK;
133 fl.l_whence = SEEK_SET;
134 fl.l_start = 0;
135 fl.l_len = 0;
136 fl.l_pid = getpid();
137
138 if (fcntl(fd_lockedfilehandle, F_SETLK, &fl) == -1) {
139 opal_output(0,"Failed to release lock for fd: %d\n",fd_lockedfilehandle);
140 opal_output(0,"error(%i): %s", errno, strerror(errno));
141 return OMPI_ERROR;
142 }
143 else{
144 opal_output(ompi_sharedfp_base_framework.framework_output,
145 "sharedfp_lockedfile_seek: released lock.for fd: %d\n",fd_lockedfilehandle);
146 }
147 }
148
149 fh->f_comm->c_coll->coll_barrier ( fh->f_comm , fh->f_comm->c_coll->coll_barrier_module );
150 return OMPI_SUCCESS;
151 }