Skip to content

Fix singleton tmp files cleanup #13261

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions ompi/runtime/ompi_rte.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ opal_process_name_t pmix_name_invalid = {UINT32_MAX, UINT32_MAX};
* infrastructure that manages its structure (e.g., OpenPMIx). If we setup this
* session directory structure, then we shall cleanup after ourselves.
*/
static bool destroy_top_session_dir = false;
static bool destroy_job_session_dir = false;
static bool destroy_proc_session_dir = false;

Expand Down Expand Up @@ -983,22 +984,25 @@ int ompi_rte_finalize(void)
{

/* cleanup the session directory we created */
if (NULL != opal_process_info.top_session_dir && destroy_top_session_dir) {
opal_os_dirpath_destroy(opal_process_info.top_session_dir,
true, check_file);
free(opal_process_info.top_session_dir);
opal_process_info.top_session_dir = NULL;
destroy_top_session_dir = false;
}

if (NULL != opal_process_info.job_session_dir && destroy_job_session_dir) {
opal_os_dirpath_destroy(opal_process_info.job_session_dir,
false, check_file);
true, check_file);
free(opal_process_info.job_session_dir);
opal_process_info.job_session_dir = NULL;
destroy_job_session_dir = false;
}

if (NULL != opal_process_info.top_session_dir) {
free(opal_process_info.top_session_dir);
opal_process_info.top_session_dir = NULL;
}

if (NULL != opal_process_info.proc_session_dir && destroy_proc_session_dir) {
opal_os_dirpath_destroy(opal_process_info.proc_session_dir,
false, check_file);
true, check_file);
free(opal_process_info.proc_session_dir);
opal_process_info.proc_session_dir = NULL;
destroy_proc_session_dir = false;
Expand Down Expand Up @@ -1165,27 +1169,45 @@ void ompi_rte_wait_for_debugger(void)

static int _setup_top_session_dir(char **sdir)
{
/*
* Use a session directory structure similar to prrte (create only one
* directory for the top session) so that it can be cleaned up correctly
* when terminated.
*/
char *tmpdir;
int rc;
uid_t uid = geteuid();
pid_t pid = getpid();

if( NULL == (tmpdir = getenv("TMPDIR")) )
if( NULL == (tmpdir = getenv("TEMP")) )
if( NULL == (tmpdir = getenv("TMP")) )
tmpdir = "/tmp";

*sdir = strdup(tmpdir);
if (0 > opal_asprintf(sdir, "%s/%s.%s.%lu.%lu",
tmpdir, "ompi",
opal_process_info.nodename,
(unsigned long)pid, (unsigned long) uid)) {
opal_process_info.top_session_dir = NULL;
return OPAL_ERR_OUT_OF_RESOURCE;
}
rc = opal_os_dirpath_create(opal_process_info.top_session_dir, 0755);
if (OPAL_SUCCESS != rc) {
// could not create top session dir
free(opal_process_info.top_session_dir);
opal_process_info.top_session_dir = NULL;
return rc;
}
destroy_top_session_dir = true;
return OPAL_SUCCESS;
}

static int _setup_job_session_dir(char **sdir)
{
int rc;
/* get the effective uid */
uid_t uid = geteuid();

if (0 > opal_asprintf(sdir, "%s/ompi.%s.%lu/jf.0/%u",
if (0 > opal_asprintf(sdir, "%s/%u",
opal_process_info.top_session_dir,
opal_process_info.nodename,
(unsigned long)uid,
opal_process_info.my_name.jobid)) {
opal_process_info.job_session_dir = NULL;
return OPAL_ERR_OUT_OF_RESOURCE;
Expand Down
11 changes: 11 additions & 0 deletions opal/mca/btl/sm/btl_sm_component.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@ static int mca_btl_sm_deregister_mem_knem(struct mca_btl_base_module_t *btl,
return OPAL_SUCCESS;
}

static void mca_btl_sm_component_finalize(void *data /*data unused*/) {
opal_shmem_unlink(&mca_btl_sm_component.seg_ds);
opal_shmem_segment_detach(&mca_btl_sm_component.seg_ds);
}

/*
* SM component initialization
*/
Expand Down Expand Up @@ -419,6 +424,12 @@ mca_btl_sm_component_init(int *num_btls, bool enable_progress_threads, bool enab
/* set flag indicating btl not inited */
mca_btl_sm.btl_inited = false;

/*
* Use a method similar to `mca_btl_smcuda_component_init` to register segment finalize
* to opal and release it before shmem is closed.
*/
opal_finalize_register_cleanup(mca_btl_sm_component_finalize);

return btls;
failed:
opal_shmem_unlink(&component->seg_ds);
Expand Down
3 changes: 0 additions & 3 deletions opal/mca/btl/sm/btl_sm_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,9 +347,6 @@ static int sm_finalize(struct mca_btl_base_module_t *btl)
free(component->fbox_in_endpoints);
component->fbox_in_endpoints = NULL;

opal_shmem_unlink(&mca_btl_sm_component.seg_ds);
opal_shmem_segment_detach(&mca_btl_sm_component.seg_ds);

return OPAL_SUCCESS;
}

Expand Down