Skip to content

Commit 6d073a8

Browse files
committed
btl_sm: add a comment explaining why we rename(2)
Per #1230, add a comment explaining why we write to a temporary file and then rename(2) the file, just so that future code maintainers don't wonder why we do this seemingly-useless step.
1 parent 14fdf75 commit 6d073a8

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

opal/mca/btl/sm/btl_sm_component.c

+8-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* Copyright (c) 2004-2005 The Regents of the University of California.
1212
* All rights reserved.
1313
* Copyright (c) 2006-2007 Voltaire. All rights reserved.
14-
* Copyright (c) 2009-2014 Cisco Systems, Inc. All rights reserved.
14+
* Copyright (c) 2009-2016 Cisco Systems, Inc. All rights reserved.
1515
* Copyright (c) 2010-2015 Los Alamos National Security, LLC.
1616
* All rights reserved.
1717
* Copyright (c) 2011-2014 NVIDIA Corporation. All rights reserved.
@@ -664,7 +664,13 @@ create_rndv_file(mca_btl_sm_component_t *comp_ptr,
664664
* file containing all the meta info required for attach. */
665665

666666
/* now just write the contents of tmp_modp->shmem_ds to the full
667-
* sizeof(opal_shmem_ds_t), so we know where the mpool_res_size starts. */
667+
* sizeof(opal_shmem_ds_t), so we know where the mpool_res_size
668+
* starts. Note that we write into a temporary file first and
669+
* then do a rename(2) to move the full file into its final
670+
* destination. This avoids a race condition where a peer process
671+
* might open/read part of the file before this processes finishes
672+
* writing it (see
673+
* https://github.com/open-mpi/ompi/issues/1230). */
668674
asprintf(&tmpfname, "%s.tmp", fname);
669675
if (NULL == tmpfname) {
670676
rc = OPAL_ERR_OUT_OF_RESOURCE;

0 commit comments

Comments
 (0)