00001
00002
00003
00004
00005
00006
00007
00008 #include "ad_pvfs2.h"
00009 #include "ad_pvfs2_common.h"
00010
00011
00012 struct open_status_s {
00013 int error;
00014 PVFS_object_ref object_ref;
00015 };
00016 typedef struct open_status_s open_status;
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 static void fake_an_open(PVFS_fs_id fs_id, char *pvfs_name, int access_mode,
00033 int nr_datafiles, PVFS_size strip_size,
00034 ADIOI_PVFS2_fs *pvfs2_fs,
00035 open_status *o_status)
00036 {
00037 int ret;
00038 PVFS_sysresp_lookup resp_lookup;
00039 PVFS_sysresp_getparent resp_getparent;
00040 PVFS_sysresp_create resp_create;
00041 PVFS_sys_attr attribs;
00042 PVFS_sys_dist* dist;
00043
00044 ADIOI_PVFS2_makeattribs(&attribs);
00045 if (nr_datafiles > 0 ) {
00046 attribs.dfile_count = nr_datafiles;
00047 attribs.mask |= PVFS_ATTR_SYS_DFILE_COUNT;
00048 }
00049
00050 dist = NULL;
00051
00052 memset(&resp_lookup, 0, sizeof(resp_lookup));
00053 memset(&resp_getparent, 0, sizeof(resp_getparent));
00054 memset(&resp_create, 0, sizeof(resp_create));
00055
00056
00057 ret = PVFS_sys_lookup(fs_id, pvfs_name,
00058 &(pvfs2_fs->credentials), &resp_lookup, PVFS2_LOOKUP_LINK_FOLLOW);
00059 if ( ret == (-PVFS_ENOENT)) {
00060 if (access_mode & ADIO_CREATE) {
00061 ret = PVFS_sys_getparent(fs_id, pvfs_name,
00062 &(pvfs2_fs->credentials), &resp_getparent);
00063 if (ret < 0) {
00064 FPRINTF(stderr, "pvfs_sys_getparent returns with %d\n", ret);
00065 o_status->error = ret;
00066 return;
00067 }
00068
00069
00070 if (0 < strip_size) {
00071
00072 dist = PVFS_sys_dist_lookup("simple_stripe");
00073 ret = PVFS_sys_dist_setparam(dist,
00074 "strip_size",
00075 &strip_size);
00076 if (ret < 0)
00077 {
00078 FPRINTF(stderr,
00079 "pvfs_sys_dist_setparam returns with %d\n", ret);
00080 o_status->error = ret;
00081 }
00082 }
00083
00084
00085 #ifdef HAVE_PVFS2_CREATE_WITHOUT_LAYOUT
00086 ret = PVFS_sys_create(resp_getparent.basename,
00087 resp_getparent.parent_ref, attribs,
00088 &(pvfs2_fs->credentials), dist, &resp_create);
00089 #else
00090 ret = PVFS_sys_create(resp_getparent.basename,
00091 resp_getparent.parent_ref, attribs,
00092 &(pvfs2_fs->credentials), dist, NULL, &resp_create);
00093 #endif
00094
00095
00096
00097
00098
00099
00100 if (ret == (-PVFS_EEXIST)) {
00101 ret = PVFS_sys_lookup(fs_id, pvfs_name,
00102 &(pvfs2_fs->credentials), &resp_lookup,
00103 PVFS2_LOOKUP_LINK_FOLLOW);
00104 if ( ret < 0 ) {
00105 o_status->error = ret;
00106 return;
00107 }
00108 o_status->error = ret;
00109 o_status->object_ref = resp_lookup.ref;
00110 return;
00111 }
00112 o_status->object_ref = resp_create.ref;
00113 } else {
00114 FPRINTF(stderr, "cannot create file without MPI_MODE_CREATE\n");
00115 o_status->error = ret;
00116 return;
00117 }
00118 } else if (access_mode & ADIO_EXCL) {
00119
00120 o_status->error = -PVFS_EEXIST;
00121 return;
00122 } else {
00123 o_status->object_ref = resp_lookup.ref;
00124 }
00125 o_status->error = ret;
00126 return;
00127
00128 }
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139 void ADIOI_PVFS2_Open(ADIO_File fd, int *error_code)
00140 {
00141 int rank, ret;
00142 PVFS_fs_id cur_fs;
00143 static char myname[] = "ADIOI_PVFS2_OPEN";
00144 char pvfs_path[PVFS_NAME_MAX] = {0};
00145
00146 ADIOI_PVFS2_fs *pvfs2_fs;
00147
00148
00149
00150
00151
00152 open_status o_status = {0, {0, 0}};
00153 MPI_Datatype open_status_type;
00154 MPI_Datatype types[2] = {MPI_INT, MPI_BYTE};
00155 int lens[2] = {1, sizeof(PVFS_object_ref)};
00156 MPI_Aint offsets[2];
00157
00158 pvfs2_fs = (ADIOI_PVFS2_fs *) ADIOI_Malloc(sizeof(ADIOI_PVFS2_fs));
00159
00160
00161 if (pvfs2_fs == NULL) {
00162 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00163 MPIR_ERR_RECOVERABLE,
00164 myname, __LINE__,
00165 MPI_ERR_UNKNOWN,
00166 "Error allocating memory", 0);
00167 return;
00168 }
00169
00170
00171 MPI_Comm_rank(fd->comm, &rank);
00172
00173 ADIOI_PVFS2_Init(error_code);
00174 if (*error_code != MPI_SUCCESS)
00175 {
00176
00177 return;
00178 }
00179
00180
00181 ADIOI_PVFS2_makecredentials(&(pvfs2_fs->credentials));
00182
00183
00184 #ifdef ADIOI_MPE_LOGGING
00185 MPE_Log_event( ADIOI_MPE_open_a, 0, NULL );
00186 #endif
00187 if (rank == fd->hints->ranklist[0] && fd->fs_ptr == NULL) {
00188
00189 ret = PVFS_util_resolve(fd->filename, &cur_fs,
00190 pvfs_path, PVFS_NAME_MAX);
00191 if (ret < 0 ) {
00192 PVFS_perror("PVFS_util_resolve", ret);
00193
00194 o_status.error = -1;
00195 } else {
00196 fake_an_open(cur_fs, pvfs_path,
00197 fd->access_mode, fd->hints->striping_factor,
00198 fd->hints->striping_unit,
00199 pvfs2_fs, &o_status);
00200 }
00201
00202
00203 pvfs2_fs->object_ref = o_status.object_ref;
00204 fd->fs_ptr = pvfs2_fs;
00205 }
00206 #ifdef ADIOI_MPE_LOGGING
00207 MPE_Log_event( ADIOI_MPE_open_b, 0, NULL );
00208 #endif
00209
00210
00211 MPI_Address(&o_status.error, &offsets[0]);
00212 MPI_Address(&o_status.object_ref, &offsets[1]);
00213
00214 MPI_Type_struct(2, lens, offsets, types, &open_status_type);
00215 MPI_Type_commit(&open_status_type);
00216
00217
00218
00219
00220
00221
00222 MPI_Bcast(MPI_BOTTOM, 1, open_status_type, fd->hints->ranklist[0],
00223 fd->comm);
00224 MPI_Type_free(&open_status_type);
00225
00226
00227 if (o_status.error != 0)
00228 {
00229 ADIOI_Free(pvfs2_fs);
00230 fd->fs_ptr = NULL;
00231 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00232 MPIR_ERR_RECOVERABLE,
00233 myname, __LINE__,
00234 ADIOI_PVFS2_error_convert(o_status.error),
00235 "Unknown error", 0);
00236
00237 return;
00238 }
00239
00240
00241 pvfs2_fs->object_ref = o_status.object_ref;
00242 fd->fs_ptr = pvfs2_fs;
00243
00244 *error_code = MPI_SUCCESS;
00245 return;
00246 }