Skip to content

Commit b6b9552

Browse files
authored
Merge pull request #5444 from gbossu/fix-file-delete
io/ompio: Call component-specific file_delete function instead of POSIX unlink
2 parents 4447738 + 8522ba1 commit b6b9552

File tree

5 files changed

+101
-29
lines changed

5 files changed

+101
-29
lines changed

ompi/mca/common/ompio/common_ompio.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* Copyright (c) 2008-2016 University of Houston. All rights reserved.
1414
* Copyright (c) 2018 Research Organization for Information Science
1515
* and Technology (RIST). All rights reserved.
16+
* Copyright (c) 2018 DataDirect Networks. All rights reserved.
1617
* $COPYRIGHT$
1718
*
1819
* Additional copyrights may follow
@@ -291,8 +292,10 @@ OMPI_DECLSPEC int mca_common_ompio_file_open (ompi_communicator_t *comm, const c
291292
int amode, opal_info_t *info,
292293
ompio_file_t *ompio_fh, bool use_sharedfp);
293294

294-
int mca_common_ompio_file_delete (const char *filename,
295-
struct opal_info_t *info);
295+
OMPI_DECLSPEC int mca_common_ompio_file_delete (const char *filename,
296+
struct opal_info_t *info);
297+
OMPI_DECLSPEC int mca_common_ompio_create_incomplete_file_handle (const char *filename,
298+
ompio_file_t **fh);
296299

297300
OMPI_DECLSPEC int mca_common_ompio_file_close (ompio_file_t *ompio_fh);
298301
OMPI_DECLSPEC int mca_common_ompio_file_get_size (ompio_file_t *ompio_fh, OMPI_MPI_OFFSET_TYPE *size);

ompi/mca/common/ompio/common_ompio_file_open.c

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* and Technology (RIST). All rights reserved.
1515
* Copyright (c) 2016 Cisco Systems, Inc. All rights reserved.
1616
* Copyright (c) 2017 IBM Corporation. All rights reserved.
17+
* Copyright (c) 2018 DataDirect Networks. All rights reserved.
1718
* $COPYRIGHT$
1819
*
1920
* Additional copyrights may follow
@@ -480,23 +481,74 @@ int mca_common_ompio_file_delete (const char *filename,
480481
struct opal_info_t *info)
481482
{
482483
int ret = OMPI_SUCCESS;
484+
ompio_file_t *fh = NULL;
483485

484486
/* No locking required for file_delete according to my understanding.
485487
One thread will succeed, the other ones silently ignore the
486488
error that the file is already deleted.
487489
*/
488-
ret = unlink(filename);
489-
490-
if (0 > ret ) {
491-
if ( ENOENT == errno ) {
492-
return MPI_ERR_NO_SUCH_FILE;
493-
} else {
494-
opal_output (0, "mca_common_ompio_file_delete: Could not remove file %s errno = %d %s\n", filename,
495-
errno, strerror(errno));
496-
return MPI_ERR_ACCESS;
497-
}
490+
491+
/* Create an incomplete file handle, it will basically only
492+
contain the filename. It is needed to select the correct
493+
component in the fs framework and call the file_remove
494+
function corresponding to the file type.
495+
*/
496+
ret = mca_common_ompio_create_incomplete_file_handle(filename, &fh);
497+
if (OMPI_SUCCESS != ret) {
498+
return ret;
499+
}
500+
501+
ret = mca_fs_base_file_select (fh, NULL);
502+
if (OMPI_SUCCESS != ret) {
503+
opal_output(1, "error in mca_common_ompio_file_delete: "
504+
"mca_fs_base_file_select() failed\n");
505+
free(fh);
506+
return ret;
507+
}
508+
509+
ret = fh->f_fs->fs_file_delete (filename, NULL);
510+
free(fh);
511+
512+
if (OMPI_SUCCESS != ret) {
513+
return ret;
514+
}
515+
return OMPI_SUCCESS;
516+
}
517+
518+
int mca_common_ompio_create_incomplete_file_handle (const char *filename,
519+
ompio_file_t **fh)
520+
{
521+
ompio_file_t *file;
522+
523+
if (NULL == filename) {
524+
opal_output(1, "error in mca_common_ompio_create_incomplete_file_handle"
525+
", filename is NULL.\n");
526+
return OMPI_ERROR;
498527
}
499528

529+
file = calloc(1, sizeof(ompio_file_t));
530+
if (NULL == file) {
531+
opal_output(1, "Out of memory.\n");
532+
return OMPI_ERR_OUT_OF_RESOURCE;
533+
}
534+
535+
536+
/* Do not use communicator */
537+
file->f_comm = MPI_COMM_NULL;
538+
file->f_rank = OMPIO_ROOT;
539+
540+
/* TODO:
541+
- Maybe copy the info for the info layer
542+
- Maybe do the same as a file open: first create an ompi_file_t,
543+
then allocate f_io_selected_data,
544+
then use the ompio_file_t stored in this data structure
545+
*/
546+
547+
/* We don't need to create a copy of the filename,
548+
this file handle is only temporary. */
549+
file->f_filename = filename;
550+
551+
*fh = file;
500552
return OMPI_SUCCESS;
501553
}
502554

ompi/mca/fs/base/fs_base_file_delete.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
* All rights reserved.
1212
* Copyright (c) 2008-2018 University of Houston. All rights reserved.
1313
* Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
14+
* Copyright (c) 2018 DataDirect Networks. All rights reserved.
1415
* $COPYRIGHT$
1516
*
1617
* Additional copyrights may follow
@@ -41,8 +42,16 @@ int mca_fs_base_file_delete (char* file_name,
4142
int ret;
4243

4344
ret = unlink(file_name);
44-
if (0 > ret) {
45-
return OMPI_ERROR;
45+
46+
if (0 > ret ) {
47+
if ( ENOENT == errno ) {
48+
return MPI_ERR_NO_SUCH_FILE;
49+
} else {
50+
opal_output (0, "mca_fs_base_file_delete: Could not remove file "
51+
"%s errno = %d %s\n",
52+
file_name, errno, strerror(errno));
53+
return MPI_ERR_ACCESS;
54+
}
4655
}
4756

4857
return OMPI_SUCCESS;

ompi/mca/fs/lustre/fs_lustre.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Copyright (c) 2008-2018 University of Houston. All rights reserved.
1313
* Copyright (c) 2018 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2018 DataDirect Networks. All rights reserved.
1516
* $COPYRIGHT$
1617
*
1718
* Additional copyrights may follow
@@ -89,15 +90,18 @@ mca_fs_lustre_component_file_query (ompio_file_t *fh, int *priority)
8990

9091
tmp = strchr (fh->f_filename, ':');
9192
if (!tmp) {
92-
if (OMPIO_ROOT == fh->f_rank) {
93+
/* The communicator might be NULL if we only want to delete the file */
94+
if (OMPIO_ROOT == fh->f_rank || MPI_COMM_NULL == fh->f_comm) {
9395
fh->f_fstype = mca_fs_base_get_fstype ( fh->f_filename );
9496
}
95-
fh->f_comm->c_coll->coll_bcast (&(fh->f_fstype),
96-
1,
97-
MPI_INT,
98-
OMPIO_ROOT,
99-
fh->f_comm,
100-
fh->f_comm->c_coll->coll_bcast_module);
97+
if (fh->f_comm != MPI_COMM_NULL) {
98+
fh->f_comm->c_coll->coll_bcast (&(fh->f_fstype),
99+
1,
100+
MPI_INT,
101+
OMPIO_ROOT,
102+
fh->f_comm,
103+
fh->f_comm->c_coll->coll_bcast_module);
104+
}
101105
}
102106
else {
103107
if (!strncmp(fh->f_filename, "lustre:", 7) ||

ompi/mca/fs/pvfs2/fs_pvfs2.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* Copyright (c) 2008-2016 University of Houston. All rights reserved.
1313
* Copyright (c) 2018 Research Organization for Information Science
1414
* and Technology (RIST). All rights reserved.
15+
* Copyright (c) 2018 DataDirect Networks. All rights reserved.
1516
* $COPYRIGHT$
1617
*
1718
* Additional copyrights may follow
@@ -94,15 +95,18 @@ mca_fs_pvfs2_component_file_query (ompio_file_t *fh, int *priority)
9495

9596
tmp = strchr (fh->f_filename, ':');
9697
if (!tmp) {
97-
if (OMPIO_ROOT == fh->f_rank) {
98+
/* The communicator might be NULL if we only want to delete the file */
99+
if (OMPIO_ROOT == fh->f_rank || MPI_COMM_NULL == fh->f_comm) {
98100
fh->f_fstype = mca_fs_base_get_fstype ( fh->f_filename );
99-
}
100-
fh->f_comm->c_coll->coll_bcast (&(fh->f_fstype),
101-
1,
102-
MPI_INT,
103-
OMPIO_ROOT,
104-
fh->f_comm,
105-
fh->f_comm->c_coll->coll_bcast_module);
101+
}
102+
if (fh->f_comm != MPI_COMM_NULL) {
103+
fh->f_comm->c_coll->coll_bcast (&(fh->f_fstype),
104+
1,
105+
MPI_INT,
106+
OMPIO_ROOT,
107+
fh->f_comm,
108+
fh->f_comm->c_coll->coll_bcast_module);
109+
}
106110
}
107111
else {
108112
if (!strncmp(fh->f_filename, "pvfs2:", 6) ||

0 commit comments

Comments
 (0)