Information about processes using cpg are now stored in objdb. Each process info is object stored in cpg object, with nodeid, pid and group name keys. --- services/cpg.c | 136 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 136 insertions(+), 0 deletions(-)
diff --git a/services/cpg.c b/services/cpg.c index ec509e0..2ac370f 100644 --- a/services/cpg.c +++ b/services/cpg.c @@ -177,6 +177,7 @@ struct process_info { uint32_t pid; mar_cpg_name_t group; struct list_head list; /* on the group_info members list */ + hdb_handle_t objdb_object_handle; }; DECLARE_LIST_INIT(process_info_list_head); @@ -580,6 +581,139 @@ static int notify_lib_totem_membership ( return CPG_OK; } +static int object_find_or_create ( + hdb_handle_t parent_object_handle, + hdb_handle_t *object_handle, + const void *object_name, + size_t object_name_len) +{ + hdb_handle_t obj_finder; + hdb_handle_t obj; + int ret = -1; + + api->object_find_create ( + parent_object_handle, + object_name, + object_name_len, + &obj_finder); + + if (api->object_find_next (obj_finder, &obj) == 0) { + /* found it */ + *object_handle = obj; + ret = 0; + } else { + ret = api->object_create (parent_object_handle, + object_handle, + object_name, object_name_len); + } + + api->object_find_destroy (obj_finder); + + return ret; +} + +static int update_confdb_info_add_process( + struct process_info *pi) +{ + hdb_handle_t cpg_handle; + hdb_handle_t pi_handle; + hdb_handle_t runtime_handle; + hdb_handle_t services_handle; + int ret; + + ret = object_find_or_create (OBJECT_PARENT_HANDLE, &runtime_handle, "runtime", strlen ("runtime")); + if (ret != 0) { + goto error_exit; + } + + ret = object_find_or_create (runtime_handle, &services_handle, "services", strlen ("services")); + if (ret != 0) { + goto error_exit; + } + + ret = object_find_or_create (services_handle, &cpg_handle, "cpg", strlen ("cpg")); + if (ret != 0) { + goto error_exit; + } + + ret = api->object_create (cpg_handle, &pi_handle, "process", strlen ("process")); + if (ret != 0) { + goto error_exit; + } + + ret = api->object_key_create_typed (pi_handle, + "nodeid", &pi->nodeid, + sizeof(pi->nodeid), + OBJDB_VALUETYPE_UINT32); + if (ret != 0) { + goto error_destroy_exit; + } + + ret = api->object_key_create_typed (pi_handle, + "pid", &pi->pid, + sizeof(pi->pid), + OBJDB_VALUETYPE_UINT32); + if (ret != 0) { + goto error_destroy_exit; + } + + ret = api->object_key_create (pi_handle, + "group", sizeof("group"), + &pi->group.value, pi->group.length); + if (ret != 0) { + goto error_destroy_exit; + } + + pi->objdb_object_handle = pi_handle; + + return 0; + +error_destroy_exit: + api->object_destroy (pi->objdb_object_handle); +error_exit: + log_printf(LOGSYS_LEVEL_WARNING, "can't update cpg membership information in objdb\n"); + return ret; +} + +static int update_confdb_info_remove_process( + struct process_info *pi) +{ + api->object_destroy (pi->objdb_object_handle); + + return 0; +} + +static int update_confdb_info( + const mar_cpg_name_t *group_name, + int joined_list_entries, + mar_cpg_address_t *joined_list, + int left_list_entries, + mar_cpg_address_t *left_list) +{ + struct list_head *iter; + int i; + + for (iter = process_info_list_head.next; iter != &process_info_list_head; iter = iter->next) { + struct process_info *pi = list_entry (iter, struct process_info, list); + + for (i = 0; i < joined_list_entries; i++) { + if (joined_list[i].nodeid == pi->nodeid && joined_list[i].pid == pi->pid && + mar_name_compare (&pi->group, group_name) == 0) { + update_confdb_info_add_process (pi); + } + } + + for (i = 0; i < left_list_entries; i++) { + if (left_list[i].nodeid == pi->nodeid && left_list[i].pid == pi->pid && + mar_name_compare (&pi->group, group_name) == 0) { + update_confdb_info_remove_process (pi); + } + } + } + + return (CPG_OK); +} + static int notify_lib_joinlist( const mar_cpg_name_t *group_name, void *conn, @@ -708,6 +842,8 @@ static int notify_lib_joinlist( } } + update_confdb_info(group_name, joined_list_entries, joined_list, left_list_entries, left_list); + return CPG_OK; } -- 1.6.2.5 _______________________________________________ Openais mailing list Openais@lists.linux-foundation.org https://lists.linux-foundation.org/mailman/listinfo/openais