root/ompi/mca/fs/ime/fs_ime_file_open.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. mca_fs_ime_file_open

   1 /*
   2  * Copyright (c) 2018      DataDirect Networks. All rights reserved.
   3  * $COPYRIGHT$
   4  *
   5  * Additional copyrights may follow
   6  *
   7  * $HEADER$
   8  */
   9 
  10 #include "ime_native.h"
  11 
  12 #include "ompi_config.h"
  13 #include "fs_ime.h"
  14 
  15 #include <sys/stat.h>
  16 #include "mpi.h"
  17 #include "ompi/constants.h"
  18 #include "ompi/mca/fs/base/base.h"
  19 #include "ompi/mca/fs/fs.h"
  20 #include "ompi/communicator/communicator.h"
  21 #include "ompi/info/info.h"
  22 #include "opal/util/path.h"
  23 
  24 /*
  25  *      file_open_ime
  26  *
  27  *      Function:       - opens a new file
  28  *      Accepts:        - same arguments as MPI_File_open()
  29  *      Returns:        - Success if new file handle
  30  */
  31 int mca_fs_ime_file_open (struct ompi_communicator_t *comm,
  32                           const char* filename,
  33                           int access_mode,
  34                           struct opal_info_t *info,
  35                           ompio_file_t *fh)
  36 {
  37     int amode = 0;
  38     int old_mask, perm;
  39     int rank, ret = OMPI_SUCCESS;
  40 
  41     rank = ompi_comm_rank ( comm );
  42 
  43     if (fh->f_perm == OMPIO_PERM_NULL)  {
  44         old_mask = umask(022);
  45         umask(old_mask);
  46         perm = old_mask ^ 0666;
  47     }
  48     else {
  49         perm = fh->f_perm;
  50     }
  51 
  52     if (access_mode & MPI_MODE_RDONLY)
  53         amode = amode | O_RDONLY;
  54     if (access_mode & MPI_MODE_WRONLY)
  55         amode = amode | O_WRONLY;
  56     if (access_mode & MPI_MODE_RDWR)
  57         amode = amode | O_RDWR;
  58 
  59     /* Reset errno */
  60     errno = 0;
  61 
  62     if ( rank == OMPIO_ROOT ) {
  63         /* MODE_CREATE and MODE_EXCL should only be set by one process */
  64         if ( access_mode & MPI_MODE_CREATE )
  65             amode = amode | O_CREAT;
  66         if (access_mode & MPI_MODE_EXCL)
  67             amode = amode | O_EXCL;
  68 
  69         fh->fd = ime_native_open(filename, amode, perm);
  70         if ( fh->fd < 0 ) {
  71             ret = mca_fs_ime_get_mpi_err(errno);
  72         }
  73     }
  74 
  75     comm->c_coll->coll_bcast (&ret, 1, MPI_INT, OMPIO_ROOT, comm,
  76                               comm->c_coll->coll_bcast_module);
  77     if ( ret != OMPI_SUCCESS ) {
  78         fh->fd = -1;
  79         return ret;
  80     }
  81 
  82     if ( rank != OMPIO_ROOT ) {
  83         errno = 0;
  84         fh->fd = ime_native_open(filename, amode, perm);
  85         if ( fh->fd < 0 ) {
  86             return mca_fs_ime_get_mpi_err(errno);
  87         }
  88     }
  89 
  90     return OMPI_SUCCESS;
  91 }

/* [<][>][^][v][top][bottom][index][help] */