This source file includes following definitions.
- mca_sharedfp_lockedfile_component_init_query
- mca_sharedfp_lockedfile_component_file_query
- mca_sharedfp_lockedfile_component_file_unquery
- mca_sharedfp_lockedfile_module_init
- mca_sharedfp_lockedfile_module_finalize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28 #include "ompi_config.h"
29 #include "mpi.h"
30 #include "ompi/mca/sharedfp/sharedfp.h"
31 #include "ompi/mca/sharedfp/base/base.h"
32 #include "ompi/mca/sharedfp/lockedfile/sharedfp_lockedfile.h"
33
34
35 #include <fcntl.h>
36 #include <errno.h>
37 #include <unistd.h>
38
39
40
41
42
43
44
45 static mca_sharedfp_base_module_1_0_0_t lockedfile = {
46 mca_sharedfp_lockedfile_module_init,
47 mca_sharedfp_lockedfile_module_finalize,
48 mca_sharedfp_lockedfile_seek,
49 mca_sharedfp_lockedfile_get_position,
50 mca_sharedfp_lockedfile_read,
51 mca_sharedfp_lockedfile_read_ordered,
52 mca_sharedfp_lockedfile_read_ordered_begin,
53 mca_sharedfp_lockedfile_read_ordered_end,
54 mca_sharedfp_lockedfile_iread,
55 mca_sharedfp_lockedfile_write,
56 mca_sharedfp_lockedfile_write_ordered,
57 mca_sharedfp_lockedfile_write_ordered_begin,
58 mca_sharedfp_lockedfile_write_ordered_end,
59 mca_sharedfp_lockedfile_iwrite,
60 mca_sharedfp_lockedfile_file_open,
61 mca_sharedfp_lockedfile_file_close
62 };
63
64
65
66
67
68
69 int mca_sharedfp_lockedfile_component_init_query(bool enable_progress_threads,
70 bool enable_mpi_threads)
71 {
72
73
74 return OMPI_SUCCESS;
75 }
76
77 struct mca_sharedfp_base_module_1_0_0_t * mca_sharedfp_lockedfile_component_file_query(ompio_file_t *fh, int *priority) {
78 struct flock lock;
79 int fd, err;
80
81 char filename[256];
82 int rank;
83 bool has_file_lock_support=false;
84
85 *priority = mca_sharedfp_lockedfile_priority;
86
87
88 rank = ompi_comm_rank ( fh->f_comm);
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118 sprintf(filename,"%s%s%d",fh->f_filename,".locktest.",rank);
119
120 lock.l_type = F_WRLCK;
121 lock.l_start = 0;
122 lock.l_whence = SEEK_SET;
123 lock.l_len = 100;
124 lock.l_pid = getpid();
125
126 fd = open(filename, O_RDWR | O_CREAT, 0644);
127
128 if ( -1 == fd ){
129 opal_output(ompi_sharedfp_base_framework.framework_output,
130 "mca_sharedfp_lockedfile_component_file_query: error opening file %s %s", filename, strerror(errno));
131 has_file_lock_support=false;
132 }
133 else{
134 err = fcntl(fd, F_SETLKW, &lock);
135 opal_output(ompi_sharedfp_base_framework.framework_output,
136 "mca_sharedfp_lockedfile_component_file_query: returned err=%d, for fd=%d\n",err,fd);
137
138 if (err) {
139 opal_output(ompi_sharedfp_base_framework.framework_output,
140 "mca_sharedfp_lockedfile_component_file_query: Failed to set a file lock on %s %s\n", filename, strerror(errno) );
141 opal_output(ompi_sharedfp_base_framework.framework_output,
142 "err=%d, errno=%d, EOPNOTSUPP=%d, EINVAL=%d, ENOSYS=%d, EACCES=%d, EAGAIN=%d, EBADF=%d\n",
143 err, errno, EOPNOTSUPP, EINVAL, ENOSYS, EACCES, EAGAIN, EBADF);
144
145 if (errno == EACCES || errno == EAGAIN) {
146 opal_output(ompi_sharedfp_base_framework.framework_output,
147 "errno=EACCES || EAGAIN, Already locked by another process\n");
148 }
149
150 }
151 else {
152 opal_output(ompi_sharedfp_base_framework.framework_output,
153 "mca_sharedfp_lockedfile_component_file_query: fcntl claims success in setting a file lock on %s\n", filename );
154
155 has_file_lock_support=true;
156 }
157
158 close(fd);
159 unlink( filename );
160 }
161
162 if(has_file_lock_support){
163 return &lockedfile;
164 }
165
166 *priority = 0;
167
168
169 opal_output(ompi_sharedfp_base_framework.framework_output,
170 "mca_sharedfp_lockedfile_component_file_query: Can not run!, file locking not supported\n");
171 return NULL;
172 }
173
174 int mca_sharedfp_lockedfile_component_file_unquery (ompio_file_t *file)
175 {
176
177
178
179
180 return OMPI_SUCCESS;
181 }
182
183 int mca_sharedfp_lockedfile_module_init (ompio_file_t *file)
184 {
185 return OMPI_SUCCESS;
186 }
187
188
189 int mca_sharedfp_lockedfile_module_finalize (ompio_file_t *file)
190 {
191 return OMPI_SUCCESS;
192 }