00001
00002
00003
00004
00005
00006
00007 #include "ad_pvfs2.h"
00008 #include "ad_pvfs2_common.h"
00009 #include <unistd.h>
00010 #include <sys/types.h>
00011 #include <time.h>
00012 #include <stdlib.h>
00013
00014
00015
00016
00017 int ADIOI_PVFS2_Initialized = MPI_KEYVAL_INVALID;
00018
00019 void ADIOI_PVFS2_End(int *error_code)
00020 {
00021 int ret;
00022 static char myname[] = "ADIOI_PVFS2_END";
00023
00024 ret = PVFS_sys_finalize();
00025
00026
00027 if (ret != 0 ) {
00028 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00029 MPIR_ERR_RECOVERABLE,
00030 myname, __LINE__,
00031 ADIOI_PVFS2_error_convert(ret),
00032 "Error in PVFS_sys_finalize", 0);
00033 return;
00034 }
00035
00036
00037 *error_code = MPI_SUCCESS;
00038 }
00039
00040 int ADIOI_PVFS2_End_call(MPI_Comm comm, int keyval,
00041 void *attribute_val, void *extra_state)
00042 {
00043 int error_code;
00044 ADIOI_PVFS2_End(&error_code);
00045 MPI_Keyval_free(&keyval);
00046 return error_code;
00047 }
00048
00049 void ADIOI_PVFS2_Init(int *error_code )
00050 {
00051 int ret;
00052 static char myname[] = "ADIOI_PVFS2_INIT";
00053 char * ncache_timeout;
00054
00055
00056 if (ADIOI_PVFS2_Initialized != MPI_KEYVAL_INVALID) {
00057 *error_code = MPI_SUCCESS;
00058 return;
00059 }
00060
00061
00062
00063
00064 ncache_timeout = getenv("PVFS2_NCACHE_TIMEOUT");
00065 if (ncache_timeout == NULL )
00066 setenv("PVFS2_NCACHE_TIMEOUT", "0", 1);
00067
00068 ret = PVFS_util_init_defaults();
00069 if (ret < 0 ) {
00070 *error_code = MPIO_Err_create_code(MPI_SUCCESS,
00071 MPIR_ERR_RECOVERABLE,
00072 myname, __LINE__,
00073 ADIOI_PVFS2_error_convert(ret),
00074 "Error in PVFS_util_init_defaults",
00075 0);
00076 PVFS_perror("PVFS_util_init_defaults", ret);
00077
00078 return;
00079 }
00080
00081 MPI_Keyval_create(MPI_NULL_COPY_FN, ADIOI_PVFS2_End_call,
00082 &ADIOI_PVFS2_Initialized, (void *)0);
00083
00084
00085 MPI_Attr_put(MPI_COMM_SELF, ADIOI_PVFS2_Initialized, (void *)0);
00086 }
00087
00088 void ADIOI_PVFS2_makeattribs(PVFS_sys_attr * attribs)
00089 {
00090 memset(attribs, 0, sizeof(PVFS_sys_attr));
00091
00092 attribs->owner = geteuid();
00093 attribs->group = getegid();
00094 attribs->perms = 0644;
00095 attribs->mask = PVFS_ATTR_SYS_ALL_SETABLE;
00096 attribs->atime = time(NULL);
00097 attribs->mtime = attribs->atime;
00098 attribs->ctime = attribs->atime;
00099 }
00100
00101
00102 void ADIOI_PVFS2_makecredentials(PVFS_credentials * credentials)
00103 {
00104 memset(credentials, 0, sizeof(PVFS_credentials));
00105
00106 PVFS_util_gen_credentials(credentials);
00107 }
00108
00109 int ADIOI_PVFS2_error_convert(int pvfs_error)
00110 {
00111 switch(pvfs_error)
00112 {
00113 case PVFS_EPERM:
00114 case PVFS_EACCES:
00115 return MPI_ERR_ACCESS;
00116 case PVFS_ENOENT:
00117 case PVFS_ENXIO:
00118 case PVFS_ENODEV:
00119 return MPI_ERR_NO_SUCH_FILE;
00120 case PVFS_EIO:
00121 return MPI_ERR_IO;
00122 case PVFS_EEXIST:
00123 return MPI_ERR_FILE_EXISTS;
00124 case PVFS_ENOTDIR:
00125 case PVFS_EISDIR:
00126 case PVFS_ENAMETOOLONG:
00127 return MPI_ERR_BAD_FILE;
00128 case PVFS_EINVAL:
00129 return MPI_ERR_FILE;
00130 case PVFS_EFBIG:
00131 case PVFS_ENOSPC:
00132 return MPI_ERR_NO_SPACE;
00133 case PVFS_EROFS:
00134 return MPI_ERR_READ_ONLY;
00135 case PVFS_ENOSYS:
00136 return MPI_ERR_UNSUPPORTED_OPERATION;
00137
00138 case EDQUOT:
00139 return MPI_ERR_QUOTA;
00140 case PVFS_ENOMEM:
00141 return MPI_ERR_INTERN;
00142 default:
00143 return MPI_UNDEFINED;
00144 }
00145
00146 }
00147
00148
00149
00150