Skip to content

Commit 1885d99

Browse files
committed
fs/ufs: set proper error codes on file_open
set proper error codes in mca_fs_ufs_file_open by mapping the errno value to the MPI error code. Fixes an issue reported on the mailing by Wei-keng Liao Fixes Issue #4443 Signed-off-by: Edgar Gabriel <[email protected]>
1 parent 3e1f771 commit 1885d99

File tree

2 files changed

+57
-9
lines changed

2 files changed

+57
-9
lines changed

ompi/mca/common/ompio/common_ompio_file_open.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ int mca_common_ompio_file_open (ompi_communicator_t *comm,
157157
ompio_fh);
158158

159159
if ( OMPI_SUCCESS != ret ) {
160-
ret = MPI_ERR_FILE;
160+
#ifdef OMPIO_DEBUG
161+
opal_output(1, "fs_file failed, error code %d\n", ret);
162+
#endif
161163
goto fn_fail;
162164
}
163165

ompi/mca/fs/ufs/fs_ufs_file_open.c

Lines changed: 54 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* University of Stuttgart. All rights reserved.
1010
* Copyright (c) 2004-2005 The Regents of the University of California.
1111
* All rights reserved.
12-
* Copyright (c) 2008-2014 University of Houston. All rights reserved.
12+
* Copyright (c) 2008-2017 University of Houston. All rights reserved.
1313
* Copyright (c) 2015 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
@@ -50,7 +50,7 @@ mca_fs_ufs_file_open (struct ompi_communicator_t *comm,
5050
{
5151
int amode;
5252
int old_mask, perm;
53-
int rank, ret;
53+
int rank, ret=OMPI_SUCCESS;
5454

5555
rank = ompi_comm_rank ( comm );
5656

@@ -72,6 +72,8 @@ mca_fs_ufs_file_open (struct ompi_communicator_t *comm,
7272
if (access_mode & MPI_MODE_RDWR)
7373
amode = amode | O_RDWR;
7474

75+
/* Reset errno */
76+
errno = 0;
7577
if ( 0 == rank ) {
7678
/* MODE_CREATE and MODE_EXCL can only be set by one process */
7779
if ( !(fh->f_flags & OMPIO_SHAREDFP_IS_SET)) {
@@ -81,19 +83,63 @@ mca_fs_ufs_file_open (struct ompi_communicator_t *comm,
8183
amode = amode | O_EXCL;
8284
}
8385
fh->fd = open (filename, amode, perm);
84-
ret = fh->fd;
86+
if ( 0 > fh->fd ) {
87+
if ( EACCES == errno ) {
88+
ret = MPI_ERR_ACCESS;
89+
}
90+
else if ( ENAMETOOLONG == errno ) {
91+
ret = MPI_ERR_BAD_FILE;
92+
}
93+
else if ( ENOENT == errno ) {
94+
ret = MPI_ERR_NO_SUCH_FILE;
95+
}
96+
else if ( EISDIR == errno ) {
97+
ret = MPI_ERR_BAD_FILE;
98+
}
99+
else if ( EROFS == errno ) {
100+
ret = MPI_ERR_READ_ONLY;
101+
}
102+
else if ( EEXIST == errno ) {
103+
ret = MPI_ERR_FILE_EXISTS;
104+
}
105+
else {
106+
ret = MPI_ERR_OTHER;
107+
}
108+
}
85109
}
86110

87111
comm->c_coll->coll_bcast ( &ret, 1, MPI_INT, 0, comm, comm->c_coll->coll_bcast_module);
88-
if ( -1 == ret ) {
89-
fh->fd = ret;
90-
return OMPI_ERROR;
112+
if ( OMPI_SUCCESS != ret ) {
113+
fh->fd = -1;
114+
return ret;
91115
}
116+
92117
if ( 0 != rank ) {
93118
fh->fd = open (filename, amode, perm);
94-
if (-1 == fh->fd) {
95-
return OMPI_ERROR;
119+
if ( 0 > fh->fd) {
120+
if ( EACCES == errno ) {
121+
ret = MPI_ERR_ACCESS;
122+
}
123+
else if ( ENAMETOOLONG == errno ) {
124+
ret = MPI_ERR_BAD_FILE;
125+
}
126+
else if ( ENOENT == errno ) {
127+
ret = MPI_ERR_NO_SUCH_FILE;
128+
}
129+
else if ( EISDIR == errno ) {
130+
ret = MPI_ERR_BAD_FILE;
131+
}
132+
else if ( EROFS == errno ) {
133+
ret = MPI_ERR_READ_ONLY;
134+
}
135+
else if ( EEXIST == errno ) {
136+
ret = MPI_ERR_FILE_EXISTS;
137+
}
138+
else {
139+
ret = MPI_ERR_OTHER;
140+
}
96141
}
142+
return ret;
97143
}
98144

99145
fh->f_stripe_size=0;

0 commit comments

Comments
 (0)