9
9
* University of Stuttgart. All rights reserved.
10
10
* Copyright (c) 2004-2005 The Regents of the University of California.
11
11
* 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.
13
13
* Copyright (c) 2015 Research Organization for Information Science
14
14
* and Technology (RIST). All rights reserved.
15
15
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
@@ -50,7 +50,7 @@ mca_fs_ufs_file_open (struct ompi_communicator_t *comm,
50
50
{
51
51
int amode ;
52
52
int old_mask , perm ;
53
- int rank , ret ;
53
+ int rank , ret = OMPI_SUCCESS ;
54
54
55
55
rank = ompi_comm_rank ( comm );
56
56
@@ -72,6 +72,8 @@ mca_fs_ufs_file_open (struct ompi_communicator_t *comm,
72
72
if (access_mode & MPI_MODE_RDWR )
73
73
amode = amode | O_RDWR ;
74
74
75
+ /* Reset errno */
76
+ errno = 0 ;
75
77
if ( 0 == rank ) {
76
78
/* MODE_CREATE and MODE_EXCL can only be set by one process */
77
79
if ( !(fh -> f_flags & OMPIO_SHAREDFP_IS_SET )) {
@@ -81,19 +83,63 @@ mca_fs_ufs_file_open (struct ompi_communicator_t *comm,
81
83
amode = amode | O_EXCL ;
82
84
}
83
85
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
+ }
85
109
}
86
110
87
111
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 ;
91
115
}
116
+
92
117
if ( 0 != rank ) {
93
118
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
+ }
96
141
}
142
+ return ret ;
97
143
}
98
144
99
145
fh -> f_stripe_size = 0 ;
0 commit comments