Debian Codegraph @

src/mpi/romio/adio/ad_daos/ad_daos_common.c

raw
1 /*
2 * Copyright (C) by Argonne National Laboratory
3 * See COPYRIGHT in top-level directory
4 */
5
6 #include "ad_daos.h"
7 #include <gurt/common.h>
8 #include <daos_errno.h>
9
10 bool adio_daos_bypass_duns;
11 const char *adio_daos_path_prefix = NULL;
12 int ADIOI_DAOS_Initialized = MPI_KEYVAL_INVALID;
13
14 static int ad_daos_end(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
15 {
16 int error_code = MPI_SUCCESS;
17 int rc;
18
19 adio_daos_hash_finalize();
20 rc = daos_fini();
21
22 if (rc != 0) {
23 error_code = ADIOI_DAOS_err("ad_daos_end", "DAOS Finalize Error", __LINE__, rc);
24 return error_code;
25 }
26
27 MPI_Comm_free_keyval(&keyval);
28 return error_code;
29 }
30
31 void ADIOI_DAOS_Init(int *error_code)
32 {
33 static char myname[] = "ADIOI_DAOS_INIT";
34 int rc;
35
36 *error_code = MPI_SUCCESS;
37
38 /** nothing to do if already initialized */
39 if (ADIOI_DAOS_Initialized != MPI_KEYVAL_INVALID)
40 return;
41
42 rc = daos_init();
43 if (rc) {
44 *error_code = ADIOI_DAOS_err(myname, "DAOS Init Error", __LINE__, rc);
45 fprintf(stderr, "daos_init() failed with %d\n", rc);
46 return;
47 }
48
49 rc = adio_daos_hash_init();
50 if (rc < 0) {
51 *error_code = ADIOI_DAOS_err(myname, "DAOS Init Error", __LINE__, rc);
52 fprintf(stderr, "Failed to init daos handle hash table\n");
53 return;
54 }
55
56 d_getenv_bool("DAOS_BYPASS_DUNS", &adio_daos_bypass_duns);
57 adio_daos_path_prefix = getenv("DAOS_UNS_PREFIX");
58
59 /** attach to comm_self destroy to finalize DAOS */
60 MPI_Comm_create_keyval(MPI_NULL_COPY_FN, ad_daos_end, &ADIOI_DAOS_Initialized, (void *) 0);
61 MPI_Comm_set_attr(MPI_COMM_SELF, ADIOI_DAOS_Initialized, (void *) 0);
62 }
63
64 int ADIOI_DAOS_err(const char *myname, const char *filename, int line, int rc)
65 {
66 int error_code = MPI_SUCCESS;
67
68 if (rc == 0)
69 return MPI_SUCCESS;
70
71 switch (rc) {
72 case -DER_NO_PERM:
73 case EPERM:
74 error_code = MPIO_Err_create_code(MPI_SUCCESS,
75 MPIR_ERR_RECOVERABLE, myname,
76 line, MPI_ERR_ACCESS,
77 "**fileaccess", "**fileaccess %s", filename);
78 break;
79 case -DER_ENOENT:
80 case -DER_NONEXIST:
81 case -DER_NO_HDL:
82 case ENOENT:
83 error_code = MPIO_Err_create_code(MPI_SUCCESS,
84 MPIR_ERR_RECOVERABLE, myname,
85 line, MPI_ERR_NO_SUCH_FILE,
86 "**filenoexist", "**filenoexist %s", filename);
87 break;
88 case -DER_IO:
89 case EIO:
90 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
91 myname, line, MPI_ERR_IO, "**io",
92 "**io %s", filename);
93 break;
94 case -DER_EXIST:
95 case EEXIST:
96 error_code = MPIO_Err_create_code(MPI_SUCCESS,
97 MPIR_ERR_RECOVERABLE, myname,
98 line, MPI_ERR_FILE_EXISTS, "**fileexist", 0);
99 break;
100 case -DER_NOTDIR:
101 case ENOTDIR:
102 error_code = MPIO_Err_create_code(MPI_SUCCESS,
103 MPIR_ERR_RECOVERABLE,
104 myname, line,
105 MPI_ERR_BAD_FILE,
106 "**filenamedir", "**filenamedir %s", filename);
107 break;
108 case -DER_NOSPACE:
109 case ENOSPC:
110 error_code = MPIO_Err_create_code(MPI_SUCCESS,
111 MPIR_ERR_RECOVERABLE, myname, line,
112 MPI_ERR_NO_SPACE, "**filenospace", 0);
113 break;
114 case -DER_INVAL:
115 case EINVAL:
116 error_code = MPIO_Err_create_code(MPI_SUCCESS,
117 MPIR_ERR_RECOVERABLE, myname, line,
118 MPI_ERR_ARG, "**arg", 0);
119 break;
120 case -DER_NOSYS:
121 case ENOSYS:
122 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
123 myname, line,
124 MPI_ERR_UNSUPPORTED_OPERATION,
125 "**fileopunsupported", 0);
126 break;
127 case -DER_NOMEM:
128 case ENOMEM:
129 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
130 myname, line, MPI_ERR_NO_MEM, "**allocmem", 0);
131 break;
132 default:
133 error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
134 myname, line, MPI_ERR_IO, "**io",
135 "**io %s", filename);
136 break;
137 }
138
139 return error_code;
140 }