root/ompi/mca/fs/ufs/fs_ufs_file_open.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_fs_ufs_file_open

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2017 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2008-2018 University of Houston. All rights reserved.
  13  * Copyright (c) 2015-2018 Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * Copyright (c) 2016-2017 IBM Corporation. All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 
  23 
  24 #include "ompi_config.h"
  25 #include "fs_ufs.h"
  26 
  27 #include <fcntl.h>
  28 #include <sys/stat.h>
  29 #include "mpi.h"
  30 #include "ompi/constants.h"
  31 #include "ompi/mca/fs/base/base.h"
  32 #include "ompi/mca/fs/fs.h"
  33 #include "ompi/communicator/communicator.h"
  34 #include "ompi/info/info.h"
  35 #include "opal/util/path.h"
  36 
  37 /*
  38  *      file_open_ufs
  39  *
  40  *      Function:       - opens a new file
  41  *      Accepts:        - same arguments as MPI_File_open()
  42  *      Returns:        - Success if new file handle
  43  */
  44 int
  45 mca_fs_ufs_file_open (struct ompi_communicator_t *comm,
  46                       const char* filename,
  47                       int access_mode,
  48                       struct opal_info_t *info,
  49                       ompio_file_t *fh)
  50 {
  51     int amode;
  52     int old_mask, perm;
  53     int rank, ret=OMPI_SUCCESS;
  54 
  55     rank = ompi_comm_rank ( comm );
  56 
  57     if (fh->f_perm == OMPIO_PERM_NULL)  {
  58         old_mask = umask(022);
  59         umask(old_mask);
  60         perm = old_mask ^ 0666;
  61     }
  62     else {
  63         perm = fh->f_perm;
  64     }
  65 
  66     amode = 0;
  67 
  68     if (access_mode & MPI_MODE_RDONLY)
  69         amode = amode | O_RDONLY;
  70     if (access_mode & MPI_MODE_WRONLY)
  71         amode = amode | O_WRONLY;
  72     if (access_mode & MPI_MODE_RDWR)
  73         amode = amode | O_RDWR;
  74 
  75     /* Reset errno */
  76     errno = 0;
  77     if ( 0 == rank ) {
  78         /* MODE_CREATE and MODE_EXCL can only be set by one process */
  79         if ( access_mode & MPI_MODE_CREATE )
  80             amode = amode | O_CREAT;
  81         if (access_mode & MPI_MODE_EXCL)
  82             amode = amode | O_EXCL;
  83 
  84         fh->fd = open (filename, amode, perm);
  85         if ( 0 > fh->fd ) {
  86             if ( EACCES == errno ) {
  87                 ret = MPI_ERR_ACCESS;
  88             }
  89             else if ( ENAMETOOLONG == errno ) {
  90                 ret = MPI_ERR_BAD_FILE;
  91             }
  92             else if ( ENOENT == errno ) {
  93                 ret = MPI_ERR_NO_SUCH_FILE;
  94             }
  95             else if ( EISDIR == errno ) {
  96                 ret = MPI_ERR_BAD_FILE;
  97             }
  98             else if ( EROFS == errno ) {
  99                 ret = MPI_ERR_READ_ONLY;
 100             }
 101             else if ( EEXIST == errno ) {
 102                 ret = MPI_ERR_FILE_EXISTS;
 103             }
 104             else if ( ENOSPC == errno ) {
 105                 ret = MPI_ERR_NO_SPACE;
 106             }
 107             else if ( EDQUOT == errno ) {
 108                 ret = MPI_ERR_QUOTA;
 109             }
 110             else if ( ETXTBSY == errno ) {
 111                 ret = MPI_ERR_FILE_IN_USE;
 112             }
 113             else {
 114                 ret = MPI_ERR_OTHER;
 115             }
 116         }
 117     }
 118 
 119     comm->c_coll->coll_bcast ( &ret, 1, MPI_INT, 0, comm, comm->c_coll->coll_bcast_module);
 120     if ( OMPI_SUCCESS != ret ) {
 121         fh->fd = -1;
 122         return ret;
 123     }
 124 
 125     if ( 0 != rank ) {
 126         fh->fd = open (filename, amode, perm);
 127         if ( 0 > fh->fd) {
 128             if ( EACCES == errno ) {
 129                 ret = MPI_ERR_ACCESS;
 130             }
 131             else if ( ENAMETOOLONG == errno ) {
 132                 ret = MPI_ERR_BAD_FILE;
 133             }
 134             else if ( ENOENT == errno ) {
 135                 ret = MPI_ERR_NO_SUCH_FILE;
 136             }
 137             else if ( EISDIR == errno ) {
 138                 ret = MPI_ERR_BAD_FILE;
 139             }
 140             else if ( EROFS == errno ) {
 141                 ret = MPI_ERR_READ_ONLY;
 142             }
 143             else if ( EEXIST == errno ) {
 144                 ret = MPI_ERR_FILE_EXISTS;
 145             }
 146             else if ( ENOSPC == errno ) {
 147                 ret = MPI_ERR_NO_SPACE;
 148             }
 149             else if ( EDQUOT == errno ) {
 150                 ret = MPI_ERR_QUOTA;
 151             }
 152             else if ( ETXTBSY == errno ) {
 153                 ret = MPI_ERR_FILE_IN_USE;
 154             }
 155             else {
 156                 ret = MPI_ERR_OTHER;
 157             }
 158         }
 159     }
 160 
 161     fh->f_stripe_size=0;
 162     fh->f_stripe_count=1;
 163 
 164     /* Need to check for NFS here. If the file system is not NFS but a regular UFS file system,
 165        we do not need to enforce locking. A regular XFS or EXT4 file system can only be used 
 166        within a single node, local environment, and in this case the OS will already ensure correct
 167        handling of file system blocks;
 168     */
 169 
 170     if ( FS_UFS_LOCK_AUTO == mca_fs_ufs_lock_algorithm ) {       
 171         char *fstype=NULL;
 172         bool bret = opal_path_nfs ( (char *)filename, &fstype );
 173         
 174         if ( false == bret ) {
 175             char *dir;
 176             mca_fs_base_get_parent_dir ( (char *)filename, &dir );
 177             bret = opal_path_nfs (dir, &fstype);
 178             free(dir);
 179         }
 180         
 181         if ( true == bret ) {
 182             if ( 0 == strncasecmp(fstype, "nfs", sizeof("nfs")) ) {
 183                 /* Based on my tests, only locking the entire file for all operations
 184                    guarantueed for the entire teststuite to pass correctly. I would not
 185                    be surprised, if depending on the NFS configuration that might not always
 186                    be necessary, and the user can change that with an MCA parameter of this 
 187                    component. */
 188                 fh->f_flags |= OMPIO_LOCK_ENTIRE_FILE;
 189             }
 190             else {
 191                 fh->f_flags |= OMPIO_LOCK_NEVER;
 192             }
 193         }
 194         else {
 195             fh->f_flags |= OMPIO_LOCK_NEVER;
 196         }
 197         free (fstype);
 198     }
 199     else if ( FS_UFS_LOCK_NEVER == mca_fs_ufs_lock_algorithm ) {
 200         fh->f_flags |= OMPIO_LOCK_NEVER;
 201     }
 202     else if ( FS_UFS_LOCK_ENTIRE_FILE == mca_fs_ufs_lock_algorithm ) {
 203         fh->f_flags |= OMPIO_LOCK_ENTIRE_FILE;
 204     }
 205     else if ( FS_UFS_LOCK_RANGES == mca_fs_ufs_lock_algorithm ) {
 206         /* Nothing to be done. This is what the posix fbtl component would do
 207            anyway without additional information . */
 208     }
 209     else {
 210         opal_output ( 1, "Invalid value for mca_fs_ufs_lock_algorithm %d", mca_fs_ufs_lock_algorithm );
 211     }
 212 
 213     return OMPI_SUCCESS;
 214 }

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