root/ompi/mca/io/romio321/romio/adio/ad_zoidfs/ad_zoidfs_open.c

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

DEFINITIONS

This source file includes following definitions.
  1. fake_an_open
  2. ADIOI_ZOIDFS_Open

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*-
   2  * vim: ts=8 sts=4 sw=4 noexpandtab
   3  *
   4  *   Copyright (C) 2007 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "ad_zoidfs.h"
   9 #include "ad_zoidfs_common.h"
  10 
  11 /* open_status is helpful for bcasting values around */
  12 struct open_status_s {
  13     int error;
  14     zoidfs_handle_t handle;
  15 };
  16 typedef struct open_status_s open_status;
  17     
  18 static void fake_an_open(char *fname, int access_mode,
  19                          int nr_datafiles, MPI_Offset strip_size,
  20                          ADIOI_ZOIDFS_object *zoidfs_ptr, 
  21                          open_status *o_status)
  22 {
  23     int ret, created;
  24     zoidfs_sattr_t attribs;
  25     zoidfs_handle_t handle;
  26 
  27     ADIOI_ZOIDFS_makeattribs(&attribs);
  28 
  29     /* zoidfs_create succeeds even if a file already exists, so we can do
  30      * our job with fewer calls than in other cases.  However, we need to
  31      * be careful with ADIO_EXCL.
  32      */
  33     if (access_mode & ADIO_CREATE) {
  34         ret = zoidfs_create(NULL, NULL, 
  35                             fname, &attribs, &handle, &created, ZOIDFS_NO_OP_HINT);
  36         if ((ret == ZFS_OK) && !created && (access_mode & ADIO_EXCL)) {
  37             /* lookup should not succeed if opened with EXCL */
  38             o_status->error = ZFSERR_EXIST;
  39             return;
  40         }
  41     }
  42     else {
  43         ret = zoidfs_lookup(NULL, NULL, fname, &handle, ZOIDFS_NO_OP_HINT);
  44     }
  45 
  46     o_status->error = ret;
  47     o_status->handle = handle;
  48     return;
  49 }
  50 
  51 
  52 /* ADIOI_ZOIDFS_Open:
  53  *  one process opens (or creates) the file, then broadcasts the result to the
  54  *  remaining processors. 
  55  *
  56  * ADIO_Open used to perform an optimization when MPI_MODE_CREATE (and before
  57  * that, MPI_MODE_EXCL) was set.  Because ZoidFS handles file lookup and
  58  * creation more scalably than traditional file systems, ADIO_Open now skips any
  59  * special handling when CREATE is set.  */
  60 void ADIOI_ZOIDFS_Open(ADIO_File fd, int *error_code)
  61 {
  62     int rank;
  63     static char myname[] = "ADIOI_ZOIDFS_OPEN";
  64     ADIOI_ZOIDFS_object *zoidfs_obj_ptr;
  65 
  66     /* since one process is doing the open, that means one process is also
  67      * doing the error checking.  define a struct for both the object reference
  68      * and the error code to broadcast to all the processors */
  69 
  70     open_status o_status;
  71     MPI_Datatype open_status_type;
  72     MPI_Datatype types[2] = {MPI_INT, MPI_BYTE};
  73     int lens[2] = {1, sizeof(ADIOI_ZOIDFS_object)};
  74     MPI_Aint offsets[2];
  75     
  76     memset(&o_status, 0, sizeof(o_status));
  77     zoidfs_obj_ptr = (ADIOI_ZOIDFS_object *) 
  78         ADIOI_Malloc(sizeof(ADIOI_ZOIDFS_object));
  79     /* --BEGIN ERROR HANDLING-- */
  80     if (zoidfs_obj_ptr == NULL) {
  81         *error_code = MPIO_Err_create_code(MPI_SUCCESS,
  82                                            MPIR_ERR_RECOVERABLE,
  83                                            myname, __LINE__,
  84                                            MPI_ERR_UNKNOWN,
  85                                            "Error allocating memory", 0);
  86         return;
  87     }
  88     /* --END ERROR HANDLING-- */
  89 
  90     MPI_Comm_rank(fd->comm, &rank);
  91 
  92     ADIOI_ZOIDFS_Init(rank, error_code);
  93     if (*error_code != MPI_SUCCESS)
  94     {
  95         /* ADIOI_ZOIDFS_INIT handles creating error codes on its own */
  96         ADIOI_Free(zoidfs_obj_ptr);
  97         return;
  98     }
  99 
 100     /* one process resolves name and will later bcast to others */
 101 #ifdef ADIOI_MPE_LOGGING
 102     MPE_Log_event( ADIOI_MPE_open_a, 0, NULL );
 103 #endif
 104     if (rank == fd->hints->ranklist[0] && fd->fs_ptr == NULL) {
 105             fake_an_open(fd->filename, fd->access_mode, 
 106                     fd->hints->striping_factor,
 107                     fd->hints->striping_unit,
 108                     zoidfs_obj_ptr, &o_status); 
 109             /* store credentials and object reference in fd */
 110             *zoidfs_obj_ptr = o_status.handle;
 111             fd->fs_ptr = zoidfs_obj_ptr;
 112     }
 113 #ifdef ADIOI_MPE_LOGGING
 114     MPE_Log_event( ADIOI_MPE_open_b, 0, NULL );
 115 #endif
 116 
 117     /* broadcast status and (possibly valid) object reference */
 118     MPI_Get_address(&o_status.error, &offsets[0]);
 119     MPI_Get_address(&o_status.handle, &offsets[1]);
 120 
 121     MPI_Type_struct(2, lens, offsets, types, &open_status_type);
 122     MPI_Type_commit(&open_status_type);
 123 
 124     /* Assertion: if we hit this Bcast, then all processes collectively
 125      *            called this open.
 126      *
 127      * That's because deferred open never happens with this fs.
 128      */
 129     MPI_Bcast(MPI_BOTTOM, 1, open_status_type, fd->hints->ranklist[0],
 130               fd->comm);
 131     MPI_Type_free(&open_status_type);
 132 
 133     /* --BEGIN ERROR HANDLING-- */
 134     if (o_status.error != ZFS_OK)
 135     { 
 136         ADIOI_Free(zoidfs_obj_ptr);
 137         fd->fs_ptr = NULL;
 138         *error_code = MPIO_Err_create_code(MPI_SUCCESS,
 139                                            MPIR_ERR_RECOVERABLE,
 140                                            myname, __LINE__,
 141                                            ADIOI_ZOIDFS_error_convert(o_status.error),
 142                                            "Unknown error", 0);
 143         /* TODO: FIX STRING */
 144         return;
 145     }
 146     /* --END ERROR HANDLING-- */
 147 
 148     *zoidfs_obj_ptr = o_status.handle;
 149     fd->fs_ptr = zoidfs_obj_ptr;
 150 
 151     *error_code = MPI_SUCCESS;
 152     return;
 153 }

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