Skip to content

Commit 7b2d83c

Browse files
raafatfekiedgargabriel
authored andcommitted
mca/fs: Remove unused functions and prototypes & reduce recurent code through all components
I removed the implementation and/or prototypes of all unused functions defined for all components. To reduce recurrent code, I created functions under base for the management of error codes and setting of file permission and amode. Then, I replaced these recurrent code by those function for all components. Signed-off-by: raafatfeki <[email protected]> add a missing header file Signed-off-by: Edgar Gabriel <[email protected]>
1 parent 5988297 commit 7b2d83c

18 files changed

+127
-441
lines changed

ompi/mca/fs/base/base.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ OMPI_DECLSPEC int mca_fs_base_init_file (struct ompio_file_t *file);
5252
OMPI_DECLSPEC int mca_fs_base_get_param (struct ompio_file_t *file, int keyval);
5353
OMPI_DECLSPEC void mca_fs_base_get_parent_dir (char *filename, char **dirnamep);
5454
OMPI_DECLSPEC int mca_fs_base_get_fstype(char *fname);
55+
OMPI_DECLSPEC int mca_fs_base_get_mpi_err(int errno_val);
56+
OMPI_DECLSPEC int mca_fs_base_get_file_perm(ompio_file_t *fh);
57+
OMPI_DECLSPEC int mca_fs_base_get_file_amode(int rank, int access_mode);
5558

5659
OMPI_DECLSPEC int mca_fs_base_file_delete (char* file_name, struct opal_info_t *info);
5760
OMPI_DECLSPEC int mca_fs_base_file_sync (ompio_file_t *fh);

ompi/mca/fs/base/fs_base_get_parent_dir.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,3 +143,81 @@ int mca_fs_base_get_fstype(char *fname )
143143
return ompio_type;
144144
}
145145

146+
int mca_fs_base_get_mpi_err(int errno_val)
147+
{
148+
int ret;
149+
switch (errno_val) {
150+
case EACCES:
151+
ret = MPI_ERR_ACCESS;
152+
break;
153+
case ENAMETOOLONG:
154+
case EISDIR:
155+
ret = MPI_ERR_BAD_FILE;
156+
break;
157+
case ENOENT:
158+
ret = MPI_ERR_NO_SUCH_FILE;
159+
break;
160+
case EROFS:
161+
ret = MPI_ERR_READ_ONLY;
162+
break;
163+
case EEXIST:
164+
ret = MPI_ERR_FILE_EXISTS;
165+
break;
166+
case ENOSPC:
167+
ret = MPI_ERR_NO_SPACE;
168+
break;
169+
case EDQUOT:
170+
ret = MPI_ERR_QUOTA;
171+
break;
172+
case ETXTBSY:
173+
ret = MPI_ERR_FILE_IN_USE;
174+
break;
175+
case EBADF:
176+
ret = MPI_ERR_FILE;
177+
break;
178+
default:
179+
ret = MPI_ERR_OTHER;
180+
break;
181+
}
182+
return ret;
183+
}
184+
185+
int mca_fs_base_get_file_perm(ompio_file_t *fh)
186+
{
187+
int old_mask;
188+
int perm = fh->f_perm;
189+
190+
if (OMPIO_PERM_NULL == perm) {
191+
old_mask = umask(022);
192+
umask(old_mask);
193+
perm = old_mask ^ 0666;
194+
}
195+
return perm;
196+
}
197+
198+
int mca_fs_base_get_file_amode(int rank, int access_mode)
199+
{
200+
int amode = 0;
201+
202+
if (access_mode & MPI_MODE_RDONLY) {
203+
amode = amode | O_RDONLY;
204+
}
205+
if (access_mode & MPI_MODE_WRONLY) {
206+
amode = amode | O_WRONLY;
207+
}
208+
if (access_mode & MPI_MODE_RDWR) {
209+
amode = amode | O_RDWR;
210+
}
211+
212+
/* MODE_CREATE and MODE_EXCL should only be set by one process */
213+
if(OMPIO_ROOT == rank) {
214+
if (access_mode & MPI_MODE_CREATE) {
215+
amode = amode | O_CREAT;
216+
}
217+
if (access_mode & MPI_MODE_EXCL) {
218+
amode = amode | O_EXCL;
219+
}
220+
}
221+
222+
return amode;
223+
}

ompi/mca/fs/gpfs/fs_gpfs.c

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -138,43 +138,3 @@ 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: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -50,31 +50,12 @@ OMPI_MODULE_DECLSPEC extern mca_fs_base_component_2_0_0_t mca_fs_gpfs_component;
5050

5151
int mca_fs_gpfs_file_open(struct ompi_communicator_t *comm, const char *filename,
5252
int amode, struct opal_info_t *info, struct ompio_file_t *fh);
53-
int mca_fs_gpfs_file_close(struct ompio_file_t *fh);
54-
int mca_fs_gpfs_file_delete(char *filename, struct ompi_info_t *info);
55-
int mca_fs_gpfs_file_set_size(struct ompio_file_t *fh,
56-
OMPI_MPI_OFFSET_TYPE size);
57-
int mca_fs_gpfs_file_get_size(struct ompio_file_t *fh,
58-
OMPI_MPI_OFFSET_TYPE * size);
59-
int mca_fs_gpfs_file_get_amode(struct ompi_file_t *fh, int *amode);
6053
int mca_fs_gpfs_file_set_info(struct ompio_file_t *fh,
6154
struct ompi_info_t *info);
6255
int mca_fs_gpfs_file_get_info(struct ompio_file_t *fh,
6356
struct ompi_info_t **info_used);
64-
int mca_fs_gpfs_prefetch_hints(int access_mode,
65-
ompio_file_t *fh, struct ompi_info_t *info);
6657
int mca_fs_gpfs_io_selection(ompio_file_t *fh,
6758
struct ompi_info_t *info, struct ompi_info_t *info_selected);
68-
int mca_fs_gpfs_file_sync(struct ompi_file_t *fh);
69-
//CN: Is mca_fs_gpfs_file_seek needed at all. Not used anywhere!
70-
int
71-
mca_fs_gpfs_file_seek(struct ompi_file_t *fh, OMPI_MPI_OFFSET_TYPE off,
72-
int whence);
73-
int
74-
mca_fs_gpfs_file_get_position(struct ompi_file_t *fh,
75-
OMPI_MPI_OFFSET_TYPE *offset);
76-
77-
int mca_fs_gpfs_file_get_mpi_err (int errno_val);
7859

7960
/*
8061
* ******************************************************************

ompi/mca/fs/gpfs/fs_gpfs_file_open.c

Lines changed: 6 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -46,43 +46,16 @@ mca_fs_gpfs_file_open (struct ompi_communicator_t *comm,
4646
struct opal_info_t *info,
4747
ompio_file_t *fh)
4848
{
49-
int amode;
50-
int old_mask, perm;
49+
int perm, amode;
5150
int ret = OMPI_SUCCESS;
5251

53-
if (fh->f_perm == OMPIO_PERM_NULL) {
54-
old_mask = umask(022);
55-
umask(old_mask);
56-
perm = old_mask ^ 0666;
57-
}
58-
else {
59-
perm = fh->f_perm;
60-
}
61-
62-
amode = 0;
63-
64-
if (access_mode & MPI_MODE_RDONLY) {
65-
amode = amode | O_RDONLY;
66-
}
67-
if (access_mode & MPI_MODE_WRONLY) {
68-
amode = amode | O_WRONLY;
69-
}
70-
if (access_mode & MPI_MODE_RDWR) {
71-
amode = amode | O_RDWR;
72-
}
52+
perm = mca_fs_base_get_file_perm(fh);
53+
amode = mca_fs_base_get_file_amode(fh->f_rank, access_mode);
7354

7455
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-
8256
fh->fd = open (filename, amode, perm);
83-
8457
if ( 0 > fh->fd ) {
85-
ret = mca_fs_gpfs_file_get_mpi_err(errno);
58+
ret = mca_fs_base_get_mpi_err(errno);
8659
}
8760
}
8861

@@ -92,10 +65,10 @@ mca_fs_gpfs_file_open (struct ompi_communicator_t *comm,
9265
return ret;
9366
}
9467

95-
if ( OMPIO_ROOT != fh->f_rank ) {
68+
if (OMPIO_ROOT != fh->f_rank) {
9669
fh->fd = open (filename, amode, perm);
9770
if ( 0 > fh->fd) {
98-
return mca_fs_gpfs_file_get_mpi_err(errno);
71+
return mca_fs_base_get_mpi_err(errno);
9972
}
10073
}
10174

@@ -104,69 +77,3 @@ mca_fs_gpfs_file_open (struct ompi_communicator_t *comm,
10477

10578
return OMPI_SUCCESS;
10679
}
107-
108-
int
109-
mca_fs_gpfs_file_get_amode (ompi_file_t *fh,
110-
int *amode)
111-
{
112-
mca_common_ompio_data_t *data;
113-
114-
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
115-
116-
*amode = data->ompio_fh.f_amode;
117-
118-
return OMPI_SUCCESS;
119-
}
120-
121-
//CN: Is mca_fs_gpfs_file_seek needed at all. Not used anywhere!
122-
int
123-
mca_fs_gpfs_file_seek(ompi_file_t *fh, OMPI_MPI_OFFSET_TYPE off, int whence) {
124-
//DEBUG: fprintf(stderr, "GPFS FILE SEEK!");
125-
int ret = OMPI_SUCCESS;
126-
mca_common_ompio_data_t *data;
127-
OMPI_MPI_OFFSET_TYPE offset, temp_offset;
128-
129-
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
130-
131-
offset = off * data->ompio_fh.f_etype_size;
132-
133-
switch (whence) {
134-
case MPI_SEEK_SET:
135-
if (offset < 0) {
136-
return OMPI_ERROR;
137-
}
138-
break;
139-
case MPI_SEEK_CUR:
140-
offset += data->ompio_fh.f_position_in_file_view;
141-
offset += data->ompio_fh.f_disp;
142-
if (offset < 0) {
143-
return OMPI_ERROR;
144-
}
145-
break;
146-
case MPI_SEEK_END:
147-
ret = data->ompio_fh.f_fs->fs_file_get_size(&data->ompio_fh,
148-
&temp_offset);
149-
offset += temp_offset;
150-
if (offset < 0 || OMPI_SUCCESS != ret) {
151-
return OMPI_ERROR;
152-
}
153-
break;
154-
default:
155-
return OMPI_ERROR;
156-
}
157-
158-
ret = mca_common_ompio_set_explicit_offset(&data->ompio_fh, offset
159-
/ data->ompio_fh.f_etype_size);
160-
return ret;
161-
}
162-
163-
int mca_fs_gpfs_file_get_position(ompi_file_t *fh, OMPI_MPI_OFFSET_TYPE *offset) {
164-
mca_common_ompio_data_t *data;
165-
166-
data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
167-
168-
*offset = data->ompio_fh.f_position_in_file_view
169-
/ data->ompio_fh.f_etype_size;
170-
171-
return OMPI_SUCCESS;
172-
}

ompi/mca/fs/ime/fs_ime.c

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -133,44 +133,6 @@ int mca_fs_ime_module_finalize (ompio_file_t *file)
133133
return OMPI_SUCCESS;
134134
}
135135

136-
int mca_fs_ime_get_mpi_err(int errno_val)
137-
{
138-
switch (errno_val) {
139-
case EACCES:
140-
return MPI_ERR_ACCESS;
141-
142-
case ENAMETOOLONG:
143-
return MPI_ERR_BAD_FILE;
144-
145-
case ENOENT:
146-
return MPI_ERR_NO_SUCH_FILE;
147-
148-
case EISDIR:
149-
return MPI_ERR_BAD_FILE;
150-
151-
case EROFS:
152-
return MPI_ERR_READ_ONLY;
153-
154-
case EEXIST:
155-
return MPI_ERR_FILE_EXISTS;
156-
157-
case ENOSPC:
158-
return MPI_ERR_NO_SPACE;
159-
160-
case EDQUOT:
161-
return MPI_ERR_QUOTA;
162-
163-
case ETXTBSY:
164-
return MPI_ERR_FILE_IN_USE;
165-
166-
case EBADF:
167-
return MPI_ERR_FILE;
168-
169-
default:
170-
return MPI_ERR_OTHER;
171-
}
172-
}
173-
174136
int mca_fs_ime_native_fini()
175137
{
176138
int ret;

ompi/mca/fs/ime/fs_ime.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ int mca_fs_ime_component_file_unquery (ompio_file_t *file);
3333
int mca_fs_ime_module_init (ompio_file_t *file);
3434
int mca_fs_ime_module_finalize (ompio_file_t *file);
3535

36-
int mca_fs_ime_get_mpi_err(int errno_val);
3736
int mca_fs_ime_native_fini();
3837

3938
OMPI_MODULE_DECLSPEC extern mca_fs_base_component_2_0_0_t mca_fs_ime_component;
@@ -62,9 +61,6 @@ int mca_fs_ime_file_get_size (ompio_file_t *fh,
6261

6362
int mca_fs_ime_file_sync (ompio_file_t *fh);
6463

65-
int mca_fs_ime_file_seek (ompio_file_t *fh,
66-
OMPI_MPI_OFFSET_TYPE offset,
67-
int whence);
6864
/*
6965
* ******************************************************************
7066
* ************ functions implemented in this module end ************

ompi/mca/fs/ime/fs_ime_file_close.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int mca_fs_ime_file_close (ompio_file_t *fh)
3434

3535
ret = ime_native_close(fh->fd);
3636
if (ret != 0) {
37-
return mca_fs_ime_get_mpi_err(errno);
37+
return mca_fs_base_get_mpi_err(errno);
3838
}
3939

4040
return OMPI_SUCCESS;

ompi/mca/fs/ime/fs_ime_file_delete.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ int mca_fs_ime_file_delete (char* file_name,
3333

3434
ret = ime_native_unlink(file_name);
3535
if (ret != 0) {
36-
return mca_fs_ime_get_mpi_err(errno);
36+
return mca_fs_base_get_mpi_err(errno);
3737
}
3838

3939
return OMPI_SUCCESS;

ompi/mca/fs/ime/fs_ime_file_get_size.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ int mca_fs_ime_file_get_size (ompio_file_t *fh,
3131

3232
*size = ime_native_lseek(fh->fd, 0, SEEK_END);
3333
if (*size < 0) {
34-
return mca_fs_ime_get_mpi_err(errno);
34+
return mca_fs_base_get_mpi_err(errno);
3535
}
3636

3737
errno = 0;
3838
if ((ime_native_lseek(fh->fd, fh->f_offset, SEEK_SET)) < 0) {
39-
return mca_fs_ime_get_mpi_err(errno);
39+
return mca_fs_base_get_mpi_err(errno);
4040
}
4141

4242
return OMPI_SUCCESS;

0 commit comments

Comments
 (0)