int node_attach(node_t* parent, node_t* child) { if (!parent || !child) return -1; child->isLeaf = TRUE; child->isRoot = FALSE; child->parent = parent; child->depth = parent->depth + 1; if(parent->isLeaf == TRUE) { parent->isLeaf = FALSE; } int res = node_list_add(parent->children, child); if (res == 0) { parent->count++; } return res; }
node_t *graph_add_node(graph_t *g, node_t *node, node_t *prev, int32_t use_threads) { node_t *cur = NULL; // --- SYNC ON --- if(1 == use_threads) pthread_mutex_lock(&graph_mutex); // synchronize start cur = graph_contains(g, node); if(NULL == cur) { if(node->contig != g->contig) { srma_error(__func__, "Control reached unexpected point", Exit, OutOfRange); } graph_nodes_realloc(g, node->position - g->position_start + 1); // alloc more memory if needed assert(node->position - g->position_start < g->nodes_mem); // DEBUG assert(NULL != g->nodes[node->position - g->position_start]); // DEBUG node_list_add(g->nodes[node->position - g->position_start], node); if(g->position_end < node->position) { g->position_end = node->position; } cur = node; g->is_empty = 0; } else { node_free(node); node=NULL; cur->coverage++; } if(NULL != prev) { node_add_to_prev(cur, prev); node_add_to_next(prev, cur); assert(0 < cur->prev->length); assert(0 < prev->next->length); } if(1 == use_threads) pthread_mutex_unlock(&graph_mutex); // synchronize end // --- SYNC OFF --- return cur; }
/* * Adds a node to the list. This is for iterating over the trie. */ static int add_to_list_from_trie(const char *key, void *_n, void *_headp) { struct node *n = _n; struct node_list **headp = _headp; return node_list_add(headp, n); }
int qdevice_cmap_get_nodelist(cmap_handle_t cmap_handle, struct node_list *list) { cs_error_t cs_err; cmap_iter_handle_t iter_handle; char key_name[CMAP_KEYNAME_MAXLEN + 1]; char tmp_key[CMAP_KEYNAME_MAXLEN + 1]; int res; int ret_value; unsigned int node_pos; uint32_t node_id; uint32_t data_center_id; char *tmp_str; char *addr0_str; int clear_node_high_byte; ret_value = 0; node_list_init(list); cs_err = cmap_iter_init(cmap_handle, "nodelist.node.", &iter_handle); if (cs_err != CS_OK) { return (-1); } while ((cs_err = cmap_iter_next(cmap_handle, iter_handle, key_name, NULL, NULL)) == CS_OK) { res = sscanf(key_name, "nodelist.node.%u.%s", &node_pos, tmp_key); if (res != 2) { continue; } if (strcmp(tmp_key, "ring0_addr") != 0) { continue; } snprintf(tmp_key, CMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos); cs_err = cmap_get_uint32(cmap_handle, tmp_key, &node_id); if (cs_err == CS_ERR_NOT_EXIST) { /* * Nodeid doesn't exists -> autogenerate node id */ clear_node_high_byte = 0; if (cmap_get_string(cmap_handle, "totem.clear_node_high_bit", &tmp_str) == CS_OK) { if (strcmp (tmp_str, "yes") == 0) { clear_node_high_byte = 1; } free(tmp_str); } if (cmap_get_string(cmap_handle, key_name, &addr0_str) != CS_OK) { return (-1); } node_id = qdevice_cmap_autogenerate_node_id(addr0_str, clear_node_high_byte); free(addr0_str); } else if (cs_err != CS_OK) { ret_value = -1; goto iter_finalize; } snprintf(tmp_key, CMAP_KEYNAME_MAXLEN, "nodelist.node.%u.datacenterid", node_pos); if (cmap_get_uint32(cmap_handle, tmp_key, &data_center_id) != CS_OK) { data_center_id = 0; } if (node_list_add(list, node_id, data_center_id, TLV_NODE_STATE_NOT_SET) == NULL) { ret_value = -1; goto iter_finalize; } } iter_finalize: cmap_iter_finalize(cmap_handle, iter_handle); if (ret_value != 0) { node_list_free(list); } return (ret_value); }