00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "ad_lustre.h"
00012
00013
00014
00015
00016 #define MAX_LOV_UUID_COUNT 1000
00017
00018 void ADIOI_LUSTRE_Open(ADIO_File fd, int *error_code)
00019 {
00020 int perm, old_mask, amode, amode_direct;
00021 int lumlen;
00022 struct lov_user_md *lum = NULL;
00023 char *value;
00024
00025 #if defined(MPICH2) || !defined(PRINT_ERR_MSG)
00026 static char myname[] = "ADIOI_LUSTRE_OPEN";
00027 #endif
00028
00029 if (fd->perm == ADIO_PERM_NULL) {
00030 old_mask = umask(022);
00031 umask(old_mask);
00032 perm = old_mask ^ 0666;
00033 }
00034 else perm = fd->perm;
00035
00036 amode = 0;
00037 if (fd->access_mode & ADIO_CREATE)
00038 amode = amode | O_CREAT;
00039 if (fd->access_mode & ADIO_RDONLY)
00040 amode = amode | O_RDONLY;
00041 if (fd->access_mode & ADIO_WRONLY)
00042 amode = amode | O_WRONLY;
00043 if (fd->access_mode & ADIO_RDWR)
00044 amode = amode | O_RDWR;
00045 if (fd->access_mode & ADIO_EXCL)
00046 amode = amode | O_EXCL;
00047
00048 amode_direct = amode | O_DIRECT;
00049
00050 fd->fd_sys = open(fd->filename, amode|O_CREAT, perm);
00051
00052 if (fd->fd_sys != -1) {
00053 int err;
00054
00055
00056
00057
00058 lumlen = sizeof(struct lov_user_md) +
00059 MAX_LOV_UUID_COUNT * sizeof(struct lov_user_ost_data);
00060
00061
00062
00063
00064
00065 lum = (struct lov_user_md *)ADIOI_Calloc(1,lumlen);
00066 lum->lmm_magic = LOV_USER_MAGIC;
00067 err = ioctl(fd->fd_sys, LL_IOC_LOV_GETSTRIPE, (void *)lum);
00068 if (!err) {
00069 value = (char *) ADIOI_Malloc((MPI_MAX_INFO_VAL+1)*sizeof(char));
00070
00071 fd->hints->striping_unit = lum->lmm_stripe_size;
00072 sprintf(value, "%d", lum->lmm_stripe_size);
00073 ADIOI_Info_set(fd->info, "striping_unit", value);
00074
00075 fd->hints->striping_factor = lum->lmm_stripe_count;
00076 sprintf(value, "%d", lum->lmm_stripe_count);
00077 ADIOI_Info_set(fd->info, "striping_factor", value);
00078
00079 fd->hints->fs_hints.lustre.start_iodevice = lum->lmm_stripe_offset;
00080 sprintf(value, "%d", lum->lmm_stripe_offset);
00081 ADIOI_Info_set(fd->info, "romio_lustre_start_iodevice", value);
00082
00083 ADIOI_Free(value);
00084 }
00085 ADIOI_Free(lum);
00086
00087 if (fd->access_mode & ADIO_APPEND)
00088 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
00089 }
00090
00091 if ((fd->fd_sys != -1) && (fd->access_mode & ADIO_APPEND))
00092 fd->fp_ind = fd->fp_sys_posn = lseek(fd->fd_sys, 0, SEEK_END);
00093
00094 fd->fd_direct = -1;
00095 if (fd->direct_write || fd->direct_read) {
00096 fd->fd_direct = open(fd->filename, amode_direct, perm);
00097 if (fd->fd_direct != -1) {
00098 fd->d_mem = fd->d_miniosz = (1<<12);
00099 } else {
00100 perror("cannot open file with O_Direct");
00101 fd->direct_write = fd->direct_read = 0;
00102 }
00103 }
00104
00105
00106 if (fd->fd_sys == -1 || ((fd->fd_direct == -1) &&
00107 (fd->direct_write || fd->direct_read))) {
00108 if (errno == ENAMETOOLONG)
00109 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00110 MPIR_ERR_RECOVERABLE, myname,
00111 __LINE__, MPI_ERR_BAD_FILE,
00112 "**filenamelong",
00113 "**filenamelong %s %d",
00114 fd->filename,
00115 strlen(fd->filename));
00116 else if (errno == ENOENT)
00117 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00118 MPIR_ERR_RECOVERABLE, myname,
00119 __LINE__, MPI_ERR_NO_SUCH_FILE,
00120 "**filenoexist",
00121 "**filenoexist %s",
00122 fd->filename);
00123 else if (errno == ENOTDIR || errno == ELOOP)
00124 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00125 MPIR_ERR_RECOVERABLE,
00126 myname, __LINE__,
00127 MPI_ERR_BAD_FILE,
00128 "**filenamedir",
00129 "**filenamedir %s",
00130 fd->filename);
00131 else if (errno == EACCES) {
00132 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00133 MPIR_ERR_RECOVERABLE, myname,
00134 __LINE__, MPI_ERR_ACCESS,
00135 "**fileaccess",
00136 "**fileaccess %s",
00137 fd->filename );
00138 }
00139 else if (errno == EROFS) {
00140
00141 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00142 MPIR_ERR_RECOVERABLE, myname,
00143 __LINE__, MPI_ERR_READ_ONLY,
00144 "**ioneedrd", 0 );
00145 }
00146 else {
00147 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00148 MPIR_ERR_RECOVERABLE, myname,
00149 __LINE__, MPI_ERR_IO, "**io",
00150 "**io %s", strerror(errno));
00151 }
00152 }
00153
00154 else *error_code = MPI_SUCCESS;
00155
00156 }