Skip to content

Commit 05d2538

Browse files
committed
common/ompio: return correct error code for improper access
return MPI_ERR_ACCESS if the user tries to read from a file that was opened using MPI_MODE_WRONLY return MPI_ERR_READ_ONLY if the user tries to write a file that was opened using MPI_MODE_RDONLY Signed-off-by: Edgar Gabriel <egabriel@central.uh.edu>
1 parent c0d7b57 commit 05d2538

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

ompi/mca/common/ompio/common_ompio_file_read.c

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,19 @@ int mca_common_ompio_file_read (ompio_file_t *fh,
7777
int i = 0; /* index into the decoded iovec of the buffer */
7878
int j = 0; /* index into the file vie iovec */
7979

80+
if (fh->f_amode & MPI_MODE_WRONLY){
81+
// opal_output(10, "Improper use of FILE Mode, Using WRONLY for Read!\n");
82+
ret = MPI_ERR_ACCESS;
83+
return ret;
84+
}
85+
8086
if ( 0 == count ) {
8187
if ( MPI_STATUS_IGNORE != status ) {
8288
status->_ucount = 0;
8389
}
8490
return ret;
8591
}
8692

87-
if (fh->f_amode & MPI_MODE_WRONLY){
88-
printf("Improper use of FILE Mode, Using WRONLY for Read!\n");
89-
ret = OMPI_ERROR;
90-
return ret;
91-
}
9293

9394
#if OPAL_CUDA_SUPPORT
9495
int is_gpu, is_managed;
@@ -226,6 +227,12 @@ int mca_common_ompio_file_iread (ompio_file_t *fh,
226227
mca_ompio_request_t *ompio_req=NULL;
227228
size_t spc=0;
228229

230+
if (fh->f_amode & MPI_MODE_WRONLY){
231+
// opal_output(10, "Improper use of FILE Mode, Using WRONLY for Read!\n");
232+
ret = MPI_ERR_ACCESS;
233+
return ret;
234+
}
235+
229236
mca_common_ompio_request_alloc ( &ompio_req, MCA_OMPIO_REQUEST_READ);
230237

231238
if ( 0 == count ) {

ompi/mca/common/ompio/common_ompio_file_write.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ int mca_common_ompio_file_write (ompio_file_t *fh,
5858
int i = 0; /* index into the decoded iovec of the buffer */
5959
int j = 0; /* index into the file view iovec */
6060

61+
if (fh->f_amode & MPI_MODE_RDONLY){
62+
// opal_output(10, "Improper use of FILE Mode, Using RDONLY for write!\n");
63+
ret = MPI_ERR_READ_ONLY;
64+
return ret;
65+
}
66+
67+
6168
if ( 0 == count ) {
6269
if ( MPI_STATUS_IGNORE != status ) {
6370
status->_ucount = 0;
@@ -194,6 +201,12 @@ int mca_common_ompio_file_iwrite (ompio_file_t *fh,
194201
mca_ompio_request_t *ompio_req=NULL;
195202
size_t spc=0;
196203

204+
if (fh->f_amode & MPI_MODE_RDONLY){
205+
// opal_output(10, "Improper use of FILE Mode, Using RDONLY for write!\n");
206+
ret = MPI_ERR_READ_ONLY;
207+
return ret;
208+
}
209+
197210
mca_common_ompio_request_alloc ( &ompio_req, MCA_OMPIO_REQUEST_WRITE);
198211

199212
if ( 0 == count ) {

0 commit comments

Comments
 (0)