root/ompi/mca/io/romio321/romio/adio/ad_pfs/ad_pfs_open.c

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

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_PFS_Open

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "ad_pfs.h"
   9 
  10 void ADIOI_PFS_Open(ADIO_File fd, int *error_code)
  11 {
  12     int perm, amode, old_mask, np_comm, np_total, err, flag;
  13     char *value;
  14     struct sattr attr;
  15     static char myname[] = "ADIOI_PFS_OPEN";
  16 
  17     if (fd->perm == ADIO_PERM_NULL) {
  18         old_mask = umask(022);
  19         umask(old_mask);
  20         perm = old_mask ^ 0666;
  21     }
  22     else perm = fd->perm;
  23 
  24     amode = 0;
  25     if (fd->access_mode & ADIO_CREATE)
  26         amode = amode | O_CREAT;
  27     if (fd->access_mode & ADIO_RDONLY)
  28         amode = amode | O_RDONLY;
  29     if (fd->access_mode & ADIO_WRONLY)
  30         amode = amode | O_WRONLY;
  31     if (fd->access_mode & ADIO_RDWR)
  32         amode = amode | O_RDWR;
  33     if (fd->access_mode & ADIO_EXCL)
  34         amode = amode | O_EXCL;
  35 
  36     MPI_Comm_size(MPI_COMM_WORLD, &np_total);
  37     MPI_Comm_size(fd->comm, &np_comm);
  38 
  39     if (np_total == np_comm) 
  40         fd->fd_sys = _gopen(fd->filename, amode, M_ASYNC, perm);
  41     else fd->fd_sys = open(fd->filename, amode, perm);
  42     fd->fd_direct = -1;
  43 
  44     if (fd->fd_sys != -1) {
  45         value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
  46 
  47         /* if user has asked for pfs server buffering to be turned on,
  48            it will be set to true in fd->info in the earlier call
  49            to ADIOI_PFS_SetInfo. Turn it on now, since we now have a 
  50            valid file descriptor. */
  51 
  52         ADIOI_Info_get(fd->info, "pfs_svr_buf", MPI_MAX_INFO_VAL, 
  53                      value, &flag);
  54         if (flag && (!strcmp(value, "true"))) {
  55             err = fcntl(fd->fd_sys, F_PFS_SVR_BUF, TRUE);
  56             if (err) ADIOI_Info_set(fd->info, "pfs_svr_buf", "false");
  57         }
  58 
  59         /* get file striping information and set it in info */
  60         err = fcntl(fd->fd_sys, F_GETSATTR, &attr);
  61 
  62         if (!err) {
  63             ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", attr.s_sunitsize);
  64             ADIOI_Info_set(fd->info, "striping_unit", value);
  65 
  66             ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", attr.s_sfactor);
  67             ADIOI_Info_set(fd->info, "striping_factor", value);
  68 
  69             ADIOI_Snprintf(value, MPI_MAX_INFO_VAL+1, "%d", attr.s_start_sdir);
  70             ADIOI_Info_set(fd->info, "start_iodevice", value);
  71         }
  72         ADIOI_Free(value);
  73 
  74         if (fd->access_mode & ADIO_APPEND) 
  75             fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
  76     }
  77 
  78     if (fd->fd_sys == -1) {
  79         *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  80                                            myname, __LINE__, MPI_ERR_IO,
  81                                            "**io",
  82                                            "**io %s", strerror(errno));
  83     }
  84     else *error_code = MPI_SUCCESS;
  85 }

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