00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_zoidfs.h"
00009 #include "ad_zoidfs_common.h"
00010
00011
00012 struct open_status_s {
00013 int error;
00014 zoidfs_handle_t handle;
00015 };
00016 typedef struct open_status_s open_status;
00017
00018 static void fake_an_open(char *fname, int access_mode,
00019 int nr_datafiles, MPI_Offset strip_size,
00020 ADIOI_ZOIDFS_object *zoidfs_ptr,
00021 open_status *o_status)
00022 {
00023 int ret, created;
00024 zoidfs_sattr_t attribs;
00025 zoidfs_handle_t handle;
00026
00027 ADIOI_ZOIDFS_makeattribs(&attribs);
00028
00029
00030
00031
00032
00033 if (access_mode & ADIO_CREATE) {
00034 ret = zoidfs_create(NULL, NULL,
00035 fname, &attribs, &handle, &created, ZOIDFS_NO_OP_HINT);
00036 if ((ret == ZFS_OK) && !created && (access_mode & ADIO_EXCL)) {
00037
00038 o_status->error = ZFSERR_EXIST;
00039 return;
00040 }
00041 }
00042 else {
00043 ret = zoidfs_lookup(NULL, NULL, fname, &handle, ZOIDFS_NO_OP_HINT);
00044 }
00045
00046 o_status->error = ret;
00047 o_status->handle = handle;
00048 return;
00049 }
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060 void ADIOI_ZOIDFS_Open(ADIO_File fd, int *error_code)
00061 {
00062 int rank;
00063 static char myname[] = "ADIOI_ZOIDFS_OPEN";
00064 ADIOI_ZOIDFS_object *zoidfs_obj_ptr;
00065
00066
00067
00068
00069
00070 open_status o_status;
00071 MPI_Datatype open_status_type;
00072 MPI_Datatype types[2] = {MPI_INT, MPI_BYTE};
00073 int lens[2] = {1, sizeof(ADIOI_ZOIDFS_object)};
00074 MPI_Aint offsets[2];
00075
00076 memset(&o_status, 0, sizeof(o_status));
00077 zoidfs_obj_ptr = (ADIOI_ZOIDFS_object *)
00078 ADIOI_Malloc(sizeof(ADIOI_ZOIDFS_object));
00079
00080 if (zoidfs_obj_ptr == NULL) {
00081 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00082 MPIR_ERR_RECOVERABLE,
00083 myname, __LINE__,
00084 MPI_ERR_UNKNOWN,
00085 "Error allocating memory", 0);
00086 return;
00087 }
00088
00089
00090 MPI_Comm_rank(fd->comm, &rank);
00091
00092 ADIOI_ZOIDFS_Init(rank, error_code);
00093 if (*error_code != MPI_SUCCESS)
00094 {
00095
00096 ADIOI_Free(zoidfs_obj_ptr);
00097 return;
00098 }
00099
00100
00101 #ifdef ADIOI_MPE_LOGGING
00102 MPE_Log_event( ADIOI_MPE_open_a, 0, NULL );
00103 #endif
00104 if (rank == fd->hints->ranklist[0] && fd->fs_ptr == NULL) {
00105 fake_an_open(fd->filename, fd->access_mode,
00106 fd->hints->striping_factor,
00107 fd->hints->striping_unit,
00108 zoidfs_obj_ptr, &o_status);
00109
00110 *zoidfs_obj_ptr = o_status.handle;
00111 fd->fs_ptr = zoidfs_obj_ptr;
00112 }
00113 #ifdef ADIOI_MPE_LOGGING
00114 MPE_Log_event( ADIOI_MPE_open_b, 0, NULL );
00115 #endif
00116
00117
00118 MPI_Address(&o_status.error, &offsets[0]);
00119 MPI_Address(&o_status.handle, &offsets[1]);
00120
00121 MPI_Type_struct(2, lens, offsets, types, &open_status_type);
00122 MPI_Type_commit(&open_status_type);
00123
00124
00125
00126
00127
00128
00129 MPI_Bcast(MPI_BOTTOM, 1, open_status_type, fd->hints->ranklist[0],
00130 fd->comm);
00131 MPI_Type_free(&open_status_type);
00132
00133
00134 if (o_status.error != ZFS_OK)
00135 {
00136 ADIOI_Free(zoidfs_obj_ptr);
00137 fd->fs_ptr = NULL;
00138 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00139 MPIR_ERR_RECOVERABLE,
00140 myname, __LINE__,
00141 ADIOI_ZOIDFS_error_convert(o_status.error),
00142 "Unknown error", 0);
00143
00144 return;
00145 }
00146
00147
00148 *zoidfs_obj_ptr = o_status.handle;
00149 fd->fs_ptr = zoidfs_obj_ptr;
00150
00151 *error_code = MPI_SUCCESS;
00152 return;
00153 }