This source file includes following definitions.
- mca_base_var_group_init
- mca_base_var_group_finalize
- mca_base_var_group_get_internal
- group_find_by_name
- compare_strings
- group_find_linear
- group_find
- group_register
- mca_base_var_group_register
- mca_base_var_group_component_register
- mca_base_var_group_deregister
- mca_base_var_group_find
- mca_base_var_group_find_by_name
- mca_base_var_group_add_var
- mca_base_var_group_add_pvar
- mca_base_var_group_add_enum
- mca_base_var_group_get
- mca_base_var_group_set_var_flag
- mca_base_var_group_constructor
- mca_base_var_group_destructor
- mca_base_var_group_get_count
- mca_base_var_group_get_stamp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 #include "opal_config.h"
26
27 #include <stdio.h>
28 #include <string.h>
29 #include <stdlib.h>
30 #ifdef HAVE_UNISTD_H
31 #include <unistd.h>
32 #endif
33 #ifdef HAVE_SYS_PARAM_H
34 #include <sys/param.h>
35 #endif
36 #include <errno.h>
37
38 #include "opal/include/opal_stdint.h"
39 #include "opal/util/show_help.h"
40 #include "opal/mca/mca.h"
41 #include "opal/mca/base/mca_base_vari.h"
42 #include "opal/mca/base/mca_base_pvar.h"
43 #include "opal/constants.h"
44 #include "opal/util/output.h"
45 #include "opal/util/opal_environ.h"
46 #include "opal/runtime/opal.h"
47
48 static opal_pointer_array_t mca_base_var_groups;
49 static opal_hash_table_t mca_base_var_group_index_hash;
50 static int mca_base_var_group_count = 0;
51 static int mca_base_var_groups_timestamp = 0;
52 static bool mca_base_var_group_initialized = false;
53
54 static void mca_base_var_group_constructor (mca_base_var_group_t *group);
55 static void mca_base_var_group_destructor (mca_base_var_group_t *group);
56 OBJ_CLASS_INSTANCE(mca_base_var_group_t, opal_object_t,
57 mca_base_var_group_constructor,
58 mca_base_var_group_destructor);
59
60 int mca_base_var_group_init (void)
61 {
62 int ret;
63
64 if (!mca_base_var_group_initialized) {
65 OBJ_CONSTRUCT(&mca_base_var_groups, opal_pointer_array_t);
66
67
68 ret = opal_pointer_array_init (&mca_base_var_groups, 128, 16384, 128);
69 if (OPAL_SUCCESS != ret) {
70 return ret;
71 }
72
73 OBJ_CONSTRUCT(&mca_base_var_group_index_hash, opal_hash_table_t);
74 ret = opal_hash_table_init (&mca_base_var_group_index_hash, 256);
75 if (OPAL_SUCCESS != ret) {
76 return ret;
77 }
78
79 mca_base_var_group_initialized = true;
80 mca_base_var_group_count = 0;
81 }
82
83 return OPAL_SUCCESS;
84 }
85
86 int mca_base_var_group_finalize (void)
87 {
88 opal_object_t *object;
89 int size, i;
90
91 if (mca_base_var_group_initialized) {
92 size = opal_pointer_array_get_size(&mca_base_var_groups);
93 for (i = 0 ; i < size ; ++i) {
94 object = opal_pointer_array_get_item (&mca_base_var_groups, i);
95 if (NULL != object) {
96 OBJ_RELEASE(object);
97 }
98 }
99 OBJ_DESTRUCT(&mca_base_var_groups);
100 OBJ_DESTRUCT(&mca_base_var_group_index_hash);
101 mca_base_var_group_count = 0;
102 mca_base_var_group_initialized = false;
103 }
104
105 return OPAL_SUCCESS;
106 }
107
108 int mca_base_var_group_get_internal (const int group_index, mca_base_var_group_t **group, bool invalidok)
109 {
110 if (group_index < 0) {
111 return OPAL_ERR_NOT_FOUND;
112 }
113
114 *group = (mca_base_var_group_t *) opal_pointer_array_get_item (&mca_base_var_groups,
115 group_index);
116 if (NULL == *group || (!invalidok && !(*group)->group_isvalid)) {
117 *group = NULL;
118 return OPAL_ERR_NOT_FOUND;
119 }
120
121 return OPAL_SUCCESS;
122 }
123
124 static int group_find_by_name (const char *full_name, int *index, bool invalidok)
125 {
126 mca_base_var_group_t *group;
127 void *tmp;
128 int rc;
129
130 rc = opal_hash_table_get_value_ptr (&mca_base_var_group_index_hash, full_name,
131 strlen (full_name), &tmp);
132 if (OPAL_SUCCESS != rc) {
133 return rc;
134 }
135
136 rc = mca_base_var_group_get_internal ((int)(uintptr_t) tmp, &group, invalidok);
137 if (OPAL_SUCCESS != rc) {
138 return rc;
139 }
140
141 if (invalidok || group->group_isvalid) {
142 *index = (int)(uintptr_t) tmp;
143 return OPAL_SUCCESS;
144 }
145
146 return OPAL_ERR_NOT_FOUND;
147 }
148
149 static bool compare_strings (const char *str1, const char *str2) {
150 if ((NULL != str1 && 0 == strcmp (str1, "*")) ||
151 (NULL == str1 && NULL == str2)) {
152 return true;
153 }
154
155 if (NULL != str1 && NULL != str2) {
156 return 0 == strcmp (str1, str2);
157 }
158
159 return false;
160 }
161
162 static int group_find_linear (const char *project_name, const char *framework_name,
163 const char *component_name, bool invalidok)
164 {
165 for (int i = 0 ; i < mca_base_var_group_count ; ++i) {
166 mca_base_var_group_t *group;
167
168 int rc = mca_base_var_group_get_internal (i, &group, invalidok);
169 if (OPAL_SUCCESS != rc) {
170 continue;
171 }
172
173 if (compare_strings (project_name, group->group_project) &&
174 compare_strings (framework_name, group->group_framework) &&
175 compare_strings (component_name, group->group_component)) {
176 return i;
177 }
178 }
179
180 return OPAL_ERR_NOT_FOUND;
181 }
182
183 static int group_find (const char *project_name, const char *framework_name,
184 const char *component_name, bool invalidok)
185 {
186 char *full_name;
187 int ret, index=0;
188
189 if (!mca_base_var_initialized) {
190 return OPAL_ERR_NOT_FOUND;
191 }
192
193
194 if ((project_name && '*' == project_name[0]) || (framework_name && '*' == framework_name[0]) ||
195 (component_name && '*' == component_name[0])) {
196 return group_find_linear (project_name, framework_name, component_name, invalidok);
197 }
198
199 ret = mca_base_var_generate_full_name4(project_name, framework_name, component_name,
200 NULL, &full_name);
201 if (OPAL_SUCCESS != ret) {
202 return OPAL_ERROR;
203 }
204
205 ret = group_find_by_name(full_name, &index, invalidok);
206 free (full_name);
207
208 return (0 > ret) ? ret : index;
209 }
210
211 static int group_register (const char *project_name, const char *framework_name,
212 const char *component_name, const char *description)
213 {
214 mca_base_var_group_t *group;
215 int group_id, parent_id = -1;
216 int ret;
217
218 if (NULL == project_name && NULL == framework_name && NULL == component_name) {
219
220 return -1;
221 }
222
223
224 if (NULL != project_name && NULL != framework_name &&
225 (0 == strcmp (project_name, framework_name))) {
226 project_name = NULL;
227 }
228
229 group_id = group_find (project_name, framework_name, component_name, true);
230 if (0 <= group_id) {
231 ret = mca_base_var_group_get_internal (group_id, &group, true);
232 if (OPAL_SUCCESS != ret) {
233
234 assert (NULL != group);
235 return ret;
236 }
237 group->group_isvalid = true;
238 mca_base_var_groups_timestamp++;
239
240
241 return group_id;
242 }
243
244 group = OBJ_NEW(mca_base_var_group_t);
245
246 group->group_isvalid = true;
247
248 if (NULL != project_name) {
249 group->group_project = strdup (project_name);
250 if (NULL == group->group_project) {
251 OBJ_RELEASE(group);
252 return OPAL_ERR_OUT_OF_RESOURCE;
253 }
254 }
255 if (NULL != framework_name) {
256 group->group_framework = strdup (framework_name);
257 if (NULL == group->group_framework) {
258 OBJ_RELEASE(group);
259 return OPAL_ERR_OUT_OF_RESOURCE;
260 }
261 }
262 if (NULL != component_name) {
263 group->group_component = strdup (component_name);
264 if (NULL == group->group_component) {
265 OBJ_RELEASE(group);
266 return OPAL_ERR_OUT_OF_RESOURCE;
267 }
268 }
269 if (NULL != description) {
270 group->group_description = strdup (description);
271 if (NULL == group->group_description) {
272 OBJ_RELEASE(group);
273 return OPAL_ERR_OUT_OF_RESOURCE;
274 }
275 }
276
277 if (NULL != framework_name && NULL != component_name) {
278 if (component_name) {
279 parent_id = group_register (project_name, framework_name, NULL, NULL);
280 } else if (framework_name && project_name) {
281 parent_id = group_register (project_name, NULL, NULL, NULL);
282 }
283 }
284
285
286 ret = mca_base_var_generate_full_name4 (NULL, project_name, framework_name, component_name,
287 &group->group_full_name);
288 if (OPAL_SUCCESS != ret) {
289 OBJ_RELEASE(group);
290 return ret;
291 }
292
293 group_id = opal_pointer_array_add (&mca_base_var_groups, group);
294 if (0 > group_id) {
295 OBJ_RELEASE(group);
296 return OPAL_ERROR;
297 }
298
299 opal_hash_table_set_value_ptr (&mca_base_var_group_index_hash, group->group_full_name,
300 strlen (group->group_full_name), (void *)(uintptr_t) group_id);
301
302 mca_base_var_group_count++;
303 mca_base_var_groups_timestamp++;
304
305 if (0 <= parent_id) {
306 mca_base_var_group_t *parent_group;
307
308 (void) mca_base_var_group_get_internal(parent_id, &parent_group, false);
309 opal_value_array_append_item (&parent_group->group_subgroups, &group_id);
310 }
311
312 return group_id;
313 }
314
315 int mca_base_var_group_register (const char *project_name, const char *framework_name,
316 const char *component_name, const char *description)
317 {
318 return group_register (project_name, framework_name, component_name, description);
319 }
320
321 int mca_base_var_group_component_register (const mca_base_component_t *component,
322 const char *description)
323 {
324 return group_register (component->mca_project_name, component->mca_type_name,
325 component->mca_component_name, description);
326 }
327
328
329 int mca_base_var_group_deregister (int group_index)
330 {
331 mca_base_var_group_t *group;
332 int size, ret;
333 int *params, *subgroups;
334 opal_object_t ** enums;
335
336 ret = mca_base_var_group_get_internal (group_index, &group, false);
337 if (OPAL_SUCCESS != ret) {
338 return ret;
339 }
340
341 group->group_isvalid = false;
342
343
344 size = opal_value_array_get_size(&group->group_vars);
345 params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_vars, int);
346
347 for (int i = 0 ; i < size ; ++i) {
348 const mca_base_var_t *var;
349
350 ret = mca_base_var_get (params[i], &var);
351 if (OPAL_SUCCESS != ret || !(var->mbv_flags & MCA_BASE_VAR_FLAG_DWG)) {
352 continue;
353 }
354
355 (void) mca_base_var_deregister (params[i]);
356 }
357
358
359 size = opal_value_array_get_size(&group->group_pvars);
360 params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_pvars, int);
361
362 for (int i = 0 ; i < size ; ++i) {
363 const mca_base_pvar_t *var;
364
365 ret = mca_base_pvar_get (params[i], &var);
366 if (OPAL_SUCCESS != ret || !(var->flags & MCA_BASE_PVAR_FLAG_IWG)) {
367 continue;
368 }
369
370 (void) mca_base_pvar_mark_invalid (params[i]);
371 }
372
373 size = opal_value_array_get_size(&group->group_enums);
374 enums = OPAL_VALUE_ARRAY_GET_BASE(&group->group_enums, opal_object_t *);
375 for (int i = 0 ; i < size ; ++i) {
376 OBJ_RELEASE (enums[i]);
377 }
378
379 size = opal_value_array_get_size(&group->group_subgroups);
380 subgroups = OPAL_VALUE_ARRAY_GET_BASE(&group->group_subgroups, int);
381 for (int i = 0 ; i < size ; ++i) {
382 (void) mca_base_var_group_deregister (subgroups[i]);
383 }
384
385
386
387 mca_base_var_groups_timestamp++;
388
389 return OPAL_SUCCESS;
390 }
391
392 int mca_base_var_group_find (const char *project_name,
393 const char *framework_name,
394 const char *component_name)
395 {
396 return group_find (project_name, framework_name, component_name, false);
397 }
398
399 int mca_base_var_group_find_by_name (const char *full_name, int *index)
400 {
401 return group_find_by_name (full_name, index, false);
402 }
403
404 int mca_base_var_group_add_var (const int group_index, const int param_index)
405 {
406 mca_base_var_group_t *group;
407 int size, i, ret;
408 int *params;
409
410 ret = mca_base_var_group_get_internal (group_index, &group, false);
411 if (OPAL_SUCCESS != ret) {
412 return ret;
413 }
414
415 size = opal_value_array_get_size(&group->group_vars);
416 params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_vars, int);
417 for (i = 0 ; i < size ; ++i) {
418 if (params[i] == param_index) {
419 return i;
420 }
421 }
422
423 if (OPAL_SUCCESS !=
424 (ret = opal_value_array_append_item (&group->group_vars, ¶m_index))) {
425 return ret;
426 }
427
428 mca_base_var_groups_timestamp++;
429
430
431 return (int) opal_value_array_get_size (&group->group_vars) - 1;
432 }
433
434 int mca_base_var_group_add_pvar (const int group_index, const int param_index)
435 {
436 mca_base_var_group_t *group;
437 int size, i, ret;
438 int *params;
439
440 ret = mca_base_var_group_get_internal (group_index, &group, false);
441 if (OPAL_SUCCESS != ret) {
442 return ret;
443 }
444
445 size = opal_value_array_get_size(&group->group_pvars);
446 params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_pvars, int);
447 for (i = 0 ; i < size ; ++i) {
448 if (params[i] == param_index) {
449 return i;
450 }
451 }
452
453 if (OPAL_SUCCESS !=
454 (ret = opal_value_array_append_item (&group->group_pvars, ¶m_index))) {
455 return ret;
456 }
457
458 mca_base_var_groups_timestamp++;
459
460
461 return (int) opal_value_array_get_size (&group->group_pvars) - 1;
462 }
463
464 int mca_base_var_group_add_enum (const int group_index, const void * storage)
465 {
466 mca_base_var_group_t *group;
467 int size, i, ret;
468 void **params;
469
470 ret = mca_base_var_group_get_internal (group_index, &group, false);
471 if (OPAL_SUCCESS != ret) {
472 return ret;
473 }
474
475 size = opal_value_array_get_size(&group->group_enums);
476 params = OPAL_VALUE_ARRAY_GET_BASE(&group->group_enums, void *);
477 for (i = 0 ; i < size ; ++i) {
478 if (params[i] == storage) {
479 return i;
480 }
481 }
482
483 if (OPAL_SUCCESS !=
484 (ret = opal_value_array_append_item (&group->group_enums, storage))) {
485 return ret;
486 }
487
488
489 return (int) opal_value_array_get_size (&group->group_enums) - 1;
490 }
491
492 int mca_base_var_group_get (const int group_index, const mca_base_var_group_t **group)
493 {
494 return mca_base_var_group_get_internal (group_index, (mca_base_var_group_t **) group, false);
495 }
496
497 int mca_base_var_group_set_var_flag (const int group_index, int flags, bool set)
498 {
499 mca_base_var_group_t *group;
500 int size, i, ret;
501 int *vars;
502
503 ret = mca_base_var_group_get_internal (group_index, &group, false);
504 if (OPAL_SUCCESS != ret) {
505 return ret;
506 }
507
508
509 size = opal_value_array_get_size(&group->group_vars);
510 vars = OPAL_VALUE_ARRAY_GET_BASE(&group->group_vars, int);
511
512 for (i = 0 ; i < size ; ++i) {
513 if (0 <= vars[i]) {
514 (void) mca_base_var_set_flag (vars[i], flags, set);
515 }
516 }
517
518 return OPAL_SUCCESS;
519 }
520
521
522 static void mca_base_var_group_constructor (mca_base_var_group_t *group)
523 {
524 memset ((char *) group + sizeof (group->super), 0, sizeof (*group) - sizeof (group->super));
525
526 OBJ_CONSTRUCT(&group->group_subgroups, opal_value_array_t);
527 opal_value_array_init (&group->group_subgroups, sizeof (int));
528
529 OBJ_CONSTRUCT(&group->group_vars, opal_value_array_t);
530 opal_value_array_init (&group->group_vars, sizeof (int));
531
532 OBJ_CONSTRUCT(&group->group_pvars, opal_value_array_t);
533 opal_value_array_init (&group->group_pvars, sizeof (int));
534
535 OBJ_CONSTRUCT(&group->group_enums, opal_value_array_t);
536 opal_value_array_init (&group->group_enums, sizeof(void *));
537 }
538
539 static void mca_base_var_group_destructor (mca_base_var_group_t *group)
540 {
541 free (group->group_full_name);
542 group->group_full_name = NULL;
543
544 free (group->group_description);
545 group->group_description = NULL;
546
547 free (group->group_project);
548 group->group_project = NULL;
549
550 free (group->group_framework);
551 group->group_framework = NULL;
552
553 free (group->group_component);
554 group->group_component = NULL;
555
556 OBJ_DESTRUCT(&group->group_subgroups);
557 OBJ_DESTRUCT(&group->group_vars);
558 OBJ_DESTRUCT(&group->group_pvars);
559 OBJ_DESTRUCT(&group->group_enums);
560 }
561
562 int mca_base_var_group_get_count (void)
563 {
564 return mca_base_var_group_count;
565 }
566
567 int mca_base_var_group_get_stamp (void)
568 {
569 return mca_base_var_groups_timestamp;
570 }