This source file includes following definitions.
- mca_fs_ufs_file_open
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 
  14 
  15 
  16 
  17 
  18 
  19 
  20 
  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 
  39 
  40 
  41 
  42 
  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     
  76     errno = 0;
  77     if ( 0 == rank ) {
  78         
  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     
 165 
 166 
 167 
 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                 
 184 
 185 
 186 
 187 
 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         
 207 
 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 }