|
22 | 22 | #define IFACE_NAME_LEN_MAX \ |
23 | 23 | (UCC_MAX_FRAMEWORK_NAME_LEN + UCC_MAX_COMPONENT_NAME_LEN + 32) |
24 | 24 |
|
| 25 | +/* Check if a module name from the allow list matches the given component. |
| 26 | + Entries with a framework prefix are matched as <framework>_<component> |
| 27 | + (e.g. "tl_cuda"), entries without a known framework prefix are matched |
| 28 | + against the component name only (e.g. "cuda" matches cuda in any |
| 29 | + framework). */ |
| 30 | +static int ucc_modules_list_search(const ucc_config_names_array_t *names, |
| 31 | + const char *framework_name, |
| 32 | + const char *component_name) |
| 33 | +{ |
| 34 | + char qualified[UCC_MAX_FRAMEWORK_NAME_LEN + |
| 35 | + UCC_MAX_COMPONENT_NAME_LEN + 2]; |
| 36 | + unsigned i; |
| 37 | + |
| 38 | + ucc_snprintf_safe(qualified, sizeof(qualified), "%s_%s", |
| 39 | + framework_name, component_name); |
| 40 | + |
| 41 | + for (i = 0; i < names->count; i++) { |
| 42 | + if ((strcmp(names->names[i], qualified) == 0) || |
| 43 | + (strcmp(names->names[i], component_name) == 0)) { |
| 44 | + return i; |
| 45 | + } |
| 46 | + } |
| 47 | + return -1; |
| 48 | +} |
| 49 | + |
| 50 | +static int ucc_component_is_enabled(const char *framework_name, |
| 51 | + const char *component_name) |
| 52 | +{ |
| 53 | + ucc_config_allow_list_t *modules = &ucc_global_config.modules; |
| 54 | + int found; |
| 55 | + |
| 56 | + if (modules->mode == UCC_CONFIG_ALLOW_LIST_ALLOW_ALL) { |
| 57 | + return 1; |
| 58 | + } |
| 59 | + |
| 60 | + found = ucc_modules_list_search(&modules->array, framework_name, |
| 61 | + component_name) >= 0; |
| 62 | + return ((modules->mode == UCC_CONFIG_ALLOW_LIST_ALLOW) && found) || |
| 63 | + ((modules->mode == UCC_CONFIG_ALLOW_LIST_NEGATE) && !found); |
| 64 | +} |
| 65 | + |
25 | 66 | static ucc_status_t ucc_component_load_one(const char *so_path, |
26 | 67 | const char *framework_name, |
27 | 68 | ucc_component_iface_t **c_iface) |
@@ -50,6 +91,14 @@ static ucc_status_t ucc_component_load_one(const char *so_path, |
50 | 91 | ucc_strncpy_safe(iface_struct, so_path + basename_start, |
51 | 92 | iface_struct_name_len + 1); |
52 | 93 |
|
| 94 | + if (!ucc_component_is_enabled(framework_name, |
| 95 | + iface_struct + strlen(framework_pattern))) { |
| 96 | + ucc_debug("component '%s_%s' is disabled by UCC_MODULES configuration", |
| 97 | + framework_name, iface_struct + strlen(framework_pattern)); |
| 98 | + *c_iface = NULL; |
| 99 | + return UCC_ERR_NO_MESSAGE; |
| 100 | + } |
| 101 | + |
53 | 102 | handle = dlopen(so_path, RTLD_LAZY); |
54 | 103 | if (!handle) { |
55 | 104 | error = dlerror(); |
|
0 commit comments