static int updn_set_min_hop_table(IN updn_t * p_updn) { osm_subn_t *p_subn = &p_updn->p_osm->subn; osm_log_t *p_log = &p_updn->p_osm->log; osm_switch_t *p_sw; cl_map_item_t *item; OSM_LOG_ENTER(p_log); /* Go over all the switches in the subnet - for each init their Min Hop Table */ OSM_LOG(p_log, OSM_LOG_VERBOSE, "Init Min Hop Table of all switches [\n"); for (item = cl_qmap_head(&p_updn->p_osm->subn.sw_guid_tbl); item != cl_qmap_end(&p_updn->p_osm->subn.sw_guid_tbl); item = cl_qmap_next(item)) { p_sw = (osm_switch_t *)item; /* Clear Min Hop Table */ if (p_subn->opt.connect_roots) updn_clear_non_root_hops(p_updn, p_sw); else osm_switch_clear_hops(p_sw); } OSM_LOG(p_log, OSM_LOG_VERBOSE, "Init Min Hop Table of all switches ]\n"); /* Now do the BFS for each port in the subnet */ OSM_LOG(p_log, OSM_LOG_VERBOSE, "BFS through all port guids in the subnet [\n"); for (item = cl_qmap_head(&p_updn->p_osm->subn.sw_guid_tbl); item != cl_qmap_end(&p_updn->p_osm->subn.sw_guid_tbl); item = cl_qmap_next(item)) { p_sw = (osm_switch_t *)item; updn_bfs_by_node(p_log, p_subn, p_sw); } OSM_LOG(p_log, OSM_LOG_VERBOSE, "BFS through all port guids in the subnet ]\n"); /* Cleanup */ OSM_LOG_EXIT(p_log); return 0; }
int osm_switch_prepare_path_rebuild(IN osm_switch_t * p_sw, IN uint16_t max_lids) { uint8_t **hops; unsigned i; for (i = 0; i < p_sw->num_ports; i++) osm_port_prof_construct(&p_sw->p_prof[i]); osm_switch_clear_hops(p_sw); if (!p_sw->new_lft && !(p_sw->new_lft = malloc(IB_LID_UCAST_END_HO + 1))) return IB_INSUFFICIENT_MEMORY; memset(p_sw->new_lft, OSM_NO_PATH, IB_LID_UCAST_END_HO + 1); if (!p_sw->hops) { hops = malloc((max_lids + 1) * sizeof(hops[0])); if (!hops) return -1; memset(hops, 0, (max_lids + 1) * sizeof(hops[0])); p_sw->hops = hops; p_sw->num_hops = max_lids + 1; } else if (max_lids + 1 > p_sw->num_hops) { uint8_t **old_hops; hops = malloc((max_lids + 1) * sizeof(hops[0])); if (!hops) return -1; memcpy(hops, p_sw->hops, p_sw->num_hops * sizeof(hops[0])); memset(hops + p_sw->num_hops, 0, (max_lids + 1 - p_sw->num_hops) * sizeof(hops[0])); old_hops = p_sw->hops; p_sw->hops = hops; p_sw->num_hops = max_lids + 1; free(old_hops); } p_sw->max_lid_ho = max_lids; return 0; }
int osm_switch_prepare_path_rebuild(IN osm_switch_t * p_sw, IN uint16_t max_lids) { uint8_t **hops; unsigned i; if (alloc_lft(p_sw, max_lids)) return -1; for (i = 0; i < p_sw->num_ports; i++) osm_port_prof_construct(&p_sw->p_prof[i]); osm_switch_clear_hops(p_sw); if (!(p_sw->new_lft = realloc(p_sw->new_lft, p_sw->lft_size))) return -1; memset(p_sw->new_lft, OSM_NO_PATH, p_sw->lft_size); if (!p_sw->hops) { hops = malloc((max_lids + 1) * sizeof(hops[0])); if (!hops) return -1; memset(hops, 0, (max_lids + 1) * sizeof(hops[0])); p_sw->hops = hops; p_sw->num_hops = max_lids + 1; } else if (max_lids + 1 > p_sw->num_hops) { hops = realloc(p_sw->hops, (max_lids + 1) * sizeof(hops[0])); if (!hops) return -1; memset(hops + p_sw->num_hops, 0, (max_lids + 1 - p_sw->num_hops) * sizeof(hops[0])); p_sw->hops = hops; p_sw->num_hops = max_lids + 1; } p_sw->max_lid_ho = max_lids; return 0; }