Skip to content

Commit 5988297

Browse files
raafatfekiedgargabriel
authored andcommitted
fs/gpfs: Assign file creation to one process and management of error codes translation.
When O_CREAT and O_EXCL are set, open() shall fail if the file exists. Therefore, I assigned the file creation to the root process only. I also translated the errno codes to their corresponding MPI error codes. Signed-off-by: raafatfeki <[email protected]>
1 parent a2b1a03 commit 5988297

File tree

3 files changed

+67
-9
lines changed

3 files changed

+67
-9
lines changed

ompi/mca/fs/gpfs/fs_gpfs.c

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,43 @@ int mca_fs_gpfs_module_finalize (ompio_file_t *file)
138138
{
139139
return OMPI_SUCCESS;
140140
}
141+
142+
int
143+
mca_fs_gpfs_file_get_mpi_err (int errno_val)
144+
{
145+
int ret;
146+
switch (errno_val) {
147+
case EACCES:
148+
ret = MPI_ERR_ACCESS;
149+
break;
150+
case EISDIR:
151+
case ENAMETOOLONG:
152+
ret = MPI_ERR_BAD_FILE;
153+
break;
154+
case ENOENT:
155+
ret = MPI_ERR_NO_SUCH_FILE;
156+
break;
157+
case EROFS:
158+
ret = MPI_ERR_READ_ONLY;
159+
break;
160+
case EEXIST:
161+
ret = MPI_ERR_FILE_EXISTS;
162+
break;
163+
case ENOSPC:
164+
ret = MPI_ERR_NO_SPACE;
165+
break;
166+
case EDQUOT:
167+
ret = MPI_ERR_QUOTA;
168+
break;
169+
case ETXTBSY:
170+
ret = MPI_ERR_FILE_IN_USE;
171+
break;
172+
case EBADF:
173+
ret = MPI_ERR_FILE;
174+
break;
175+
default:
176+
ret = MPI_ERR_OTHER;
177+
break;
178+
}
179+
return ret;
180+
}

ompi/mca/fs/gpfs/fs_gpfs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ int
7474
mca_fs_gpfs_file_get_position(struct ompi_file_t *fh,
7575
OMPI_MPI_OFFSET_TYPE *offset);
7676

77+
int mca_fs_gpfs_file_get_mpi_err (int errno_val);
78+
7779
/*
7880
* ******************************************************************
7981
* ************ functions implemented in this module end ************

ompi/mca/fs/gpfs/fs_gpfs_file_open.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ mca_fs_gpfs_file_open (struct ompi_communicator_t *comm,
4848
{
4949
int amode;
5050
int old_mask, perm;
51+
int ret = OMPI_SUCCESS;
5152

5253
if (fh->f_perm == OMPIO_PERM_NULL) {
5354
old_mask = umask(022);
@@ -60,9 +61,6 @@ mca_fs_gpfs_file_open (struct ompi_communicator_t *comm,
6061

6162
amode = 0;
6263

63-
if (access_mode & MPI_MODE_CREATE) {
64-
amode = amode | O_CREAT;
65-
}
6664
if (access_mode & MPI_MODE_RDONLY) {
6765
amode = amode | O_RDONLY;
6866
}
@@ -72,15 +70,33 @@ mca_fs_gpfs_file_open (struct ompi_communicator_t *comm,
7270
if (access_mode & MPI_MODE_RDWR) {
7371
amode = amode | O_RDWR;
7472
}
75-
if (access_mode & MPI_MODE_EXCL) {
76-
amode = amode | O_EXCL;
73+
74+
if(OMPIO_ROOT == fh->f_rank) {
75+
if (access_mode & MPI_MODE_CREATE) {
76+
amode = amode | O_CREAT;
77+
}
78+
if (access_mode & MPI_MODE_EXCL) {
79+
amode = amode | O_EXCL;
80+
}
81+
82+
fh->fd = open (filename, amode, perm);
83+
84+
if ( 0 > fh->fd ) {
85+
ret = mca_fs_gpfs_file_get_mpi_err(errno);
86+
}
7787
}
7888

79-
//DEBUG: fprintf(stderr, "Opening a file using Linux open() within fs_gpfs_file_open\n");
89+
comm->c_coll->coll_bcast ( &ret, 1, MPI_INT, 0, comm, comm->c_coll->coll_bcast_module);
90+
if ( OMPI_SUCCESS != ret ) {
91+
fh->fd = -1;
92+
return ret;
93+
}
8094

81-
fh->fd = open (filename, amode, perm);
82-
if (-1 == fh->fd) {
83-
return OMPI_ERROR;
95+
if ( OMPIO_ROOT != fh->f_rank ) {
96+
fh->fd = open (filename, amode, perm);
97+
if ( 0 > fh->fd) {
98+
return mca_fs_gpfs_file_get_mpi_err(errno);
99+
}
84100
}
85101

86102
fh->f_amode=access_mode;

0 commit comments

Comments
 (0)