root/ompi/mca/fs/lustre/fs_lustre_file_open.c

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

DEFINITIONS

This source file includes following definitions.
  1. alloc_lum
  2. mca_fs_lustre_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_lustre.h"
  26 
  27 #include <fcntl.h>
  28 #include <unistd.h>
  29 #include "mpi.h"
  30 #include "ompi/constants.h"
  31 #include "ompi/mca/fs/fs.h"
  32 #include "ompi/communicator/communicator.h"
  33 #include "ompi/info/info.h"
  34 
  35 #include <sys/ioctl.h>
  36 
  37 static void *alloc_lum();
  38 
  39 static void *alloc_lum()
  40 {
  41   int v1, v3, join;
  42 
  43   v1 = sizeof(struct lov_user_md_v1) +
  44     LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
  45   v3 = sizeof(struct lov_user_md_v3) +
  46     LOV_MAX_STRIPE_COUNT * sizeof(struct lov_user_ost_data_v1);
  47 
  48   return malloc(MAX(v1, v3));
  49 }
  50 
  51 /*
  52  *      file_open_lustre
  53  *
  54  *      Function:       - opens a new file
  55  *      Accepts:        - same arguments as MPI_File_open()
  56  *      Returns:        - Success if new file handle
  57  */
  58 
  59 int
  60 mca_fs_lustre_file_open (struct ompi_communicator_t *comm,
  61                      const char* filename,
  62                      int access_mode,
  63                      struct opal_info_t *info,
  64                      ompio_file_t *fh)
  65 {
  66     int amode, rank;
  67     int old_mask, perm;
  68     int rc, ret=OMPI_SUCCESS;
  69     int flag;
  70     int fs_lustre_stripe_size = -1;
  71     int fs_lustre_stripe_width = -1;
  72     char char_stripe[MPI_MAX_INFO_KEY];
  73 
  74     struct lov_user_md *lump=NULL;
  75 
  76     if (fh->f_perm == OMPIO_PERM_NULL) {
  77         old_mask = umask(022);
  78         umask(old_mask);
  79         perm = old_mask ^ 0666;
  80     }
  81     else {
  82         perm = fh->f_perm;
  83     }
  84     
  85     rank = fh->f_rank;
  86 
  87     amode = 0;
  88     if (access_mode & MPI_MODE_RDONLY)
  89         amode = amode | O_RDONLY;
  90     if (access_mode & MPI_MODE_WRONLY)
  91         amode = amode | O_WRONLY;
  92     if (access_mode & MPI_MODE_RDWR)
  93         amode = amode | O_RDWR;
  94 
  95     opal_info_get (info, "stripe_size", MPI_MAX_INFO_VAL, char_stripe, &flag);
  96     if ( flag ) {
  97         sscanf ( char_stripe, "%d", &fs_lustre_stripe_size );
  98     }
  99 
 100     opal_info_get (info, "stripe_width", MPI_MAX_INFO_VAL, char_stripe, &flag);
 101     if ( flag ) {
 102         sscanf ( char_stripe, "%d", &fs_lustre_stripe_width );
 103     }
 104 
 105     if (fs_lustre_stripe_size < 0) {
 106         fs_lustre_stripe_size = mca_fs_lustre_stripe_size;
 107     }   
 108 
 109     if (fs_lustre_stripe_width < 0) {
 110         fs_lustre_stripe_width = mca_fs_lustre_stripe_width;
 111     }
 112 
 113     
 114     /* Reset errno */
 115     errno = 0;
 116     if (0 == fh->f_rank) {
 117        /* MODE_CREATE and MODE_EXCL can only be set by one process */
 118         if ( access_mode & MPI_MODE_CREATE )
 119             amode = amode | O_CREAT;
 120         if (access_mode & MPI_MODE_EXCL)
 121             amode = amode | O_EXCL;
 122 
 123         if ( (fs_lustre_stripe_size>0 || fs_lustre_stripe_width>0) &&
 124              ( amode&O_CREAT)                                      && 
 125              ( (amode&O_RDWR)|| amode&O_WRONLY) ) {
 126             llapi_file_create(filename,
 127                               fs_lustre_stripe_size,
 128                               -1, /* MSC need to change that */
 129                               fs_lustre_stripe_width,
 130                               0); /* MSC need to change that */
 131             
 132             fh->fd = open(filename, amode | O_LOV_DELAY_CREATE, perm);
 133         }
 134         else {
 135             fh->fd = open (filename, amode, perm);
 136         }
 137         if ( 0 > fh->fd ) {
 138             if ( EACCES == errno ) {
 139                 ret = MPI_ERR_ACCESS;
 140             }
 141             else if ( ENAMETOOLONG == errno ) {
 142                 ret = MPI_ERR_BAD_FILE;
 143             }
 144             else if ( ENOENT == errno ) {
 145                 ret = MPI_ERR_NO_SUCH_FILE;
 146             }
 147             else if ( EISDIR == errno ) {
 148                 ret = MPI_ERR_BAD_FILE;
 149             }
 150             else if ( EROFS == errno ) {
 151                 ret = MPI_ERR_READ_ONLY;
 152             }
 153             else if ( EEXIST == errno ) {
 154                 ret = MPI_ERR_FILE_EXISTS;
 155             }
 156             else {
 157                 ret = MPI_ERR_OTHER;
 158             }
 159         }
 160     }
 161 
 162    comm->c_coll->coll_bcast ( &ret, 1, MPI_INT, 0, comm, comm->c_coll->coll_bcast_module);
 163     if ( OMPI_SUCCESS != ret ) {
 164         fh->fd = -1;
 165         return ret;
 166     }
 167 
 168     if ( 0 != rank ) {
 169         fh->fd = open (filename, amode, perm);
 170         if ( 0 > fh->fd) {
 171             if ( EACCES == errno ) {
 172                 ret = MPI_ERR_ACCESS;
 173             }
 174             else if ( ENAMETOOLONG == errno ) {
 175                 ret = MPI_ERR_BAD_FILE;
 176             }
 177             else if ( ENOENT == errno ) {
 178                 ret = MPI_ERR_NO_SUCH_FILE;
 179             }
 180             else if ( EISDIR == errno ) {
 181                 ret = MPI_ERR_BAD_FILE;
 182             }
 183             else if ( EROFS == errno ) {
 184                 ret = MPI_ERR_READ_ONLY;
 185             }
 186             else if ( EEXIST == errno ) {
 187                 ret = MPI_ERR_FILE_EXISTS;
 188             }
 189             else {
 190                 ret = MPI_ERR_OTHER;
 191             }
 192         }
 193     }
 194 
 195 
 196 
 197     lump = alloc_lum();
 198     if (NULL == lump ){
 199         fprintf(stderr,"Cannot allocate memory for extracting stripe size\n");
 200         return OMPI_ERROR;
 201     }
 202     rc = llapi_file_get_stripe(filename, lump);
 203     if (rc != 0) {
 204         opal_output(1, "get_stripe failed: %d (%s)\n", errno, strerror(errno));
 205         return OMPI_ERROR;
 206     }
 207     fh->f_stripe_size   = lump->lmm_stripe_size;
 208     fh->f_stripe_count  = lump->lmm_stripe_count;
 209     fh->f_fs_block_size = lump->lmm_stripe_size;
 210     
 211     return OMPI_SUCCESS;
 212 }

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