static void remove_edge1(HASH *hash, NODE *from, NODE *to) { HASH_ENTRY *he = find_in_hash(hash, from, sizeof(void *)); HASH *subhash; if (!he) return; subhash = he->data; remove_from_hash(subhash, to, sizeof(void *)); if (subhash->num == 0) remove_from_hash(hash, from, sizeof(void *)); }
int remove_from_double_hash(double_hash_t* hash, dc_t* cell) { if(!cell) return 0; if(!hash) return -1; /* DHASH frees the memory of cell */ remove_from_hash(hash->dhash, hash->hash_size, cell, DHASH); remove_from_hash(hash->chash, hash->hash_size, cell, CHASH); return 0; }
/* returns -1 if any error * returns 1 if does not exist in hash * returns 0 if deleted succesfully * */ int pdt_remove_from_hash_list(hash_list_t *hl, str* sdomain, str *sd) { hash_t *it; int ret; if(hl==NULL || sd==NULL || sd->s==NULL || sdomain==NULL || sdomain->s==NULL) { LM_ERR("bad parameters\n"); return -1; /* wrong parameters, error */ } lock_get(&hl->hl_lock); /* search the it position where to remove from */ it = hl->hash; while(it!=NULL && str_strcmp(&it->sdomain, sdomain)<0) it = it->next; /* sdomain not found, nothing to delete */ if(it==NULL || str_strcmp(&it->sdomain, sdomain)>0) { lock_release(&hl->hl_lock); return 1; /* nothing to delete */ } ret = remove_from_hash(it, sd); lock_release(&hl->hl_lock); return ret; }
static gboolean check_connection_cloned_mac_address (NMConnection *orig, NMConnection *candidate, GHashTable *settings) { GHashTable *props; const char *orig_mac = NULL, *cand_mac = NULL; NMSettingWired *s_wired_orig, *s_wired_cand; props = check_property_in_hash (settings, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_CLONED_MAC_ADDRESS); if (!props) return TRUE; /* If one of the MAC addresses is NULL, we accept that connection */ s_wired_orig = nm_connection_get_setting_wired (orig); if (s_wired_orig) orig_mac = nm_setting_wired_get_cloned_mac_address (s_wired_orig); s_wired_cand = nm_connection_get_setting_wired (candidate); if (s_wired_cand) cand_mac = nm_setting_wired_get_cloned_mac_address (s_wired_cand); if (!orig_mac || !cand_mac) { remove_from_hash (settings, props, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_CLONED_MAC_ADDRESS); return TRUE; } return FALSE; }
static gboolean check_connection_interface_name (NMConnection *orig, NMConnection *candidate, GHashTable *settings) { GHashTable *props; const char *orig_ifname, *cand_ifname; NMSettingConnection *s_con_orig, *s_con_cand; props = check_property_in_hash (settings, NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME); if (!props) return TRUE; /* If one of the interface names is NULL, we accept that connection */ s_con_orig = nm_connection_get_setting_connection (orig); s_con_cand = nm_connection_get_setting_connection (candidate); orig_ifname = nm_setting_connection_get_interface_name (s_con_orig); cand_ifname = nm_setting_connection_get_interface_name (s_con_cand); if (!orig_ifname || !cand_ifname) { remove_from_hash (settings, props, NM_SETTING_CONNECTION_SETTING_NAME, NM_SETTING_CONNECTION_INTERFACE_NAME); return TRUE; } return FALSE; }
static gboolean check_connection_s390_props (NMConnection *orig, NMConnection *candidate, GHashTable *settings) { GHashTable *props1, *props2, *props3; NMSettingWired *s_wired_orig, *s_wired_cand; props1 = check_property_in_hash (settings, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_SUBCHANNELS); props2 = check_property_in_hash (settings, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_NETTYPE); props3 = check_property_in_hash (settings, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_OPTIONS); if (!props1 && !props2 && !props3) return TRUE; /* If the generated connection did not contain wired setting, * allow it to match to a connection with a wired setting, * but default (empty) s390-* properties */ s_wired_orig = nm_connection_get_setting_wired (orig); s_wired_cand = nm_connection_get_setting_wired (candidate); if (!s_wired_orig && s_wired_cand) { const char * const *subchans = nm_setting_wired_get_s390_subchannels (s_wired_cand); const char *nettype = nm_setting_wired_get_s390_nettype (s_wired_cand); guint32 num_options = nm_setting_wired_get_num_s390_options (s_wired_cand); if ((!subchans || !*subchans) && !nettype && num_options == 0) { remove_from_hash (settings, props1, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_SUBCHANNELS); remove_from_hash (settings, props2, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_NETTYPE); remove_from_hash (settings, props3, NM_SETTING_WIRED_SETTING_NAME, NM_SETTING_WIRED_S390_OPTIONS); return TRUE; } } return FALSE; }
void remove_vertex(GRAPH *graph, NODE *vertex) { HASH_ENTRY *he = find_in_hash(graph->labels, vertex, sizeof(void *)); if (!he) return; int label = (int) he->data; graph->node.children->items[label] = NULL; remove_from_hash(graph->labels, vertex, sizeof(void *)); }
/* * mon_reclaim_entry - Remove an entry from the MRU list and from the * hash array, then zero-initialize it. Indirectly * decrements mru_entries. * The entry is prepared to be reused. Before return, in * remove_from_hash(), mru_entries is decremented. It is the caller's * responsibility to increment it again. */ static inline void mon_reclaim_entry( mon_entry *m ) { DEBUG_INSIST(NULL != m); UNLINK_DLIST(m, mru); remove_from_hash(m); ZERO(*m); }
static void clear_var(pgxc_ctl_var *var) { int ii; remove_from_hash(var); for (ii = 0; var->val[ii]; ii++) free(var->val[ii]); free(var->varname); free(var); }
int add_to_double_hash(double_hash_t* hash, dc_t* cell) { if(add_to_hash(hash->dhash, hash->hash_size, cell, DHASH)<0) return -1; if(add_to_hash(hash->chash, hash->hash_size, cell, CHASH)<0) { remove_from_hash(hash->dhash, hash->hash_size, cell, DHASH); return -1; } return 0; }
static gboolean check_ip_routes (NMConnection *orig, NMConnection *candidate, GHashTable *settings, gint64 default_metric, gboolean v4) { gs_free NMIPRoute **routes1 = NULL, **routes2 = NULL; NMSettingIPConfig *s_ip1, *s_ip2; const char *s_name; GHashTable *props; guint i, num; s_name = v4 ? NM_SETTING_IP4_CONFIG_SETTING_NAME : NM_SETTING_IP6_CONFIG_SETTING_NAME; props = check_property_in_hash (settings, s_name, NM_SETTING_IP_CONFIG_ROUTES); if (!props) return TRUE; s_ip1 = (NMSettingIPConfig *) nm_connection_get_setting_by_name (orig, s_name); s_ip2 = (NMSettingIPConfig *) nm_connection_get_setting_by_name (candidate, s_name); if (!s_ip1 || !s_ip2) return FALSE; num = nm_setting_ip_config_get_num_routes (s_ip1); if (num != nm_setting_ip_config_get_num_routes (s_ip2)) return FALSE; routes1 = g_new (NMIPRoute *, num); routes2 = g_new (NMIPRoute *, num); for (i = 0; i < num; i++) { routes1[i] = nm_setting_ip_config_get_route (s_ip1, i); routes2[i] = nm_setting_ip_config_get_route (s_ip2, i); } qsort (routes1, num, sizeof (NMIPRoute *), route_ptr_compare); qsort (routes2, num, sizeof (NMIPRoute *), route_ptr_compare); for (i = 0; i < num; i++) { if (route_compare (routes1[i], routes2[i], default_metric)) return FALSE; } remove_from_hash (settings, props, s_name, NM_SETTING_IP_CONFIG_ROUTES); return TRUE; }
static gboolean check_ip6_method (NMConnection *orig, NMConnection *candidate, GHashTable *settings) { GHashTable *props; const char *orig_ip6_method, *candidate_ip6_method; NMSettingIPConfig *candidate_ip6; gboolean allow = FALSE; props = check_property_in_hash (settings, NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD); if (!props) return TRUE; /* If the generated connection is 'link-local' and the candidate is both 'auto' * and may-fail=TRUE, then the candidate is OK to use. may-fail is included * in the decision because if the candidate is 'auto' but may-fail=FALSE, then * the connection could not possibly have been previously activated on the * device if the device has no non-link-local IPv6 address. */ orig_ip6_method = nm_utils_get_ip_config_method (orig, NM_TYPE_SETTING_IP6_CONFIG); candidate_ip6_method = nm_utils_get_ip_config_method (candidate, NM_TYPE_SETTING_IP6_CONFIG); candidate_ip6 = nm_connection_get_setting_ip6_config (candidate); if ( strcmp (orig_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0 && strcmp (candidate_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0 && (!candidate_ip6 || nm_setting_ip_config_get_may_fail (candidate_ip6))) { allow = TRUE; } /* If the generated connection method is 'link-local' or 'auto' and the candidate * method is 'ignore' we can take the connection, because NM didn't simply take care * of IPv6. */ if ( ( strcmp (orig_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0 || strcmp (orig_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0) && strcmp (candidate_ip6_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) { allow = TRUE; } if (allow) { remove_from_hash (settings, props, NM_SETTING_IP6_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD); } return allow; }
/* * mon_clearinterface -- remove mru entries referring to a local address * which is going away. */ void mon_clearinterface( endpt *lcladr ) { mon_entry *mon; /* iterate mon over mon_mru_list */ ITER_DLIST_BEGIN(mon_mru_list, mon, mru, mon_entry) if (mon->lcladr == lcladr) { /* remove from mru list */ UNLINK_DLIST(mon, mru); /* remove from hash list, adjust mru_entries */ remove_from_hash(mon); /* put on free list */ mon_free_entry(mon); } ITER_DLIST_END() }
static gboolean check_ip4_method (NMConnection *orig, NMConnection *candidate, GHashTable *settings, gboolean device_has_carrier) { GHashTable *props; const char *orig_ip4_method, *candidate_ip4_method; NMSettingIPConfig *candidate_ip4; props = check_property_in_hash (settings, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD); if (!props) return TRUE; /* If the generated connection is 'disabled' (device had no IP addresses) * but it has no carrier, that most likely means that IP addressing could * not complete and thus no IP addresses were assigned. In that case, allow * matching to the "auto" method. */ orig_ip4_method = nm_utils_get_ip_config_method (orig, NM_TYPE_SETTING_IP4_CONFIG); candidate_ip4_method = nm_utils_get_ip_config_method (candidate, NM_TYPE_SETTING_IP4_CONFIG); candidate_ip4 = nm_connection_get_setting_ip4_config (candidate); if ( strcmp (orig_ip4_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0 && strcmp (candidate_ip4_method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0 && (!candidate_ip4 || nm_setting_ip_config_get_may_fail (candidate_ip4)) && (device_has_carrier == FALSE)) { remove_from_hash (settings, props, NM_SETTING_IP4_CONFIG_SETTING_NAME, NM_SETTING_IP_CONFIG_METHOD); return TRUE; } return FALSE; }
void migrate_pre_process(void *data, int num_gid_entries, int num_lid_entries, int num_import, ZOLTAN_ID_PTR import_global_ids, ZOLTAN_ID_PTR import_local_ids, int *import_procs, int *import_to_part, int num_export, ZOLTAN_ID_PTR export_global_ids, ZOLTAN_ID_PTR export_local_ids, int *export_procs, int *export_to_part, int *ierr) { int i, j, k, idx, maxlen, proc, offset; int *proc_ids = NULL; /* Temp array of processor assignments for elements.*/ char *change = NULL; /* Temp array indicating whether local element's adj list must be updated due to a nbor's migration. */ int new_proc; /* New processor assignment for nbor element. */ int exp_elem; /* index of an element being exported */ int bor_elem; /* index of an element along the processor border */ int *send_vec = NULL, *recv_vec = NULL; /* Communication vecs. */ MESH_INFO_PTR mesh; ELEM_INFO_PTR elements; int lid = num_lid_entries-1; int gid = num_gid_entries-1; char msg[256]; *ierr = ZOLTAN_OK; if (data == NULL) { *ierr = ZOLTAN_FATAL; return; } mesh = (MESH_INFO_PTR) data; elements = mesh->elements; for (i=0; i < mesh->num_elems; i++) { /* don't migrate a pointer created on this process */ safe_free((void **)(void *)&(elements[i].adj_blank)); } /* * Set some flags. Assume if true for one element, true for all elements. * Note that some procs may have no elements. */ if (elements[0].edge_wgt != NULL) k = 1; else k = 0; /* Make sure all procs have the same value */ MPI_Allreduce(&k, &Use_Edge_Wgts, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); /* NOT IMPLEMENTED: blanking information is not sent along. Subsequent lb_eval may be incorrect, since imported elements may have blanked adjacencies. if (mesh->blank_count > 0) k = 1; else k = 0; MPI_Allreduce(&k, &Vertex_Blanking, 1, MPI_INT, MPI_MAX, MPI_COMM_WORLD); */ /* * For all elements, update adjacent elements' processor information. * That way, when perform migration, will be migrating updated adjacency * information. */ MPI_Comm_rank(MPI_COMM_WORLD, &proc); /* * Build New_Elem_Index array and list of processor assignments. */ New_Elem_Index_Size = mesh->num_elems + num_import - num_export; if (mesh->elem_array_len > New_Elem_Index_Size) New_Elem_Index_Size = mesh->elem_array_len; New_Elem_Index = (int *) malloc(New_Elem_Index_Size * sizeof(int)); New_Elem_Hash_Table = (int *) malloc(New_Elem_Index_Size * sizeof(int)); New_Elem_Hash_Nodes = (struct New_Elem_Hash_Node *) malloc(New_Elem_Index_Size * sizeof(struct New_Elem_Hash_Node)); if (New_Elem_Index == NULL || New_Elem_Hash_Table == NULL || New_Elem_Hash_Nodes == NULL) { Gen_Error(0, "fatal: insufficient memory"); *ierr = ZOLTAN_MEMERR; return; } for (i = 0; i < New_Elem_Index_Size; i++) New_Elem_Hash_Table[i] = -1; for (i = 0; i < New_Elem_Index_Size; i++) { New_Elem_Hash_Nodes[i].globalID = -1; New_Elem_Hash_Nodes[i].localID = -1; New_Elem_Hash_Nodes[i].next = -1; } if (mesh->num_elems > 0) { proc_ids = (int *) malloc(mesh->num_elems * sizeof(int)); change = (char *) malloc(mesh->num_elems * sizeof(char)); if (New_Elem_Index == NULL || proc_ids == NULL || change == NULL || New_Elem_Hash_Table == NULL || New_Elem_Hash_Nodes == NULL) { Gen_Error(0, "fatal: insufficient memory"); *ierr = ZOLTAN_MEMERR; return; } for (i = 0; i < mesh->num_elems; i++) { New_Elem_Index[i] = elements[i].globalID; insert_in_hash(elements[i].globalID, i); proc_ids[i] = proc; change[i] = 0; } } for (i = mesh->num_elems; i < New_Elem_Index_Size; i++) { New_Elem_Index[i] = -1; } for (i = 0; i < num_export; i++) { if (num_lid_entries) exp_elem = export_local_ids[lid+i*num_lid_entries]; else /* testing num_lid_entries == 0 */ search_by_global_id(mesh, export_global_ids[gid+i*num_gid_entries], &exp_elem); if (export_procs[i] != proc) { /* Export is moving to a new processor */ New_Elem_Index[exp_elem] = -1; remove_from_hash(export_global_ids[gid+i*num_gid_entries]); proc_ids[exp_elem] = export_procs[i]; } } j = 0; for (i = 0; i < num_import; i++) { if (import_procs[i] != proc) { /* Import is moving from a new processor, not just from a new partition */ /* search for first free location */ for ( ; j < New_Elem_Index_Size; j++) if (New_Elem_Index[j] == -1) break; New_Elem_Index[j] = import_global_ids[gid+i*num_gid_entries]; insert_in_hash((int) import_global_ids[gid+i*num_gid_entries], j); } } /* * Update local information */ /* Set change flag for elements whose adjacent elements are being exported */ for (i = 0; i < num_export; i++) { if (num_lid_entries) exp_elem = export_local_ids[lid+i*num_lid_entries]; else /* testing num_lid_entries == 0 */ search_by_global_id(mesh, export_global_ids[gid+i*num_gid_entries], &exp_elem); elements[exp_elem].my_part = export_to_part[i]; if (export_procs[i] == proc) continue; /* No adjacency changes needed if export is changing only partition, not processor. */ for (j = 0; j < elements[exp_elem].adj_len; j++) { /* Skip NULL adjacencies (sides that are not adjacent to another elem). */ if (elements[exp_elem].adj[j] == -1) continue; /* Set change flag for adjacent local elements. */ if (elements[exp_elem].adj_proc[j] == proc) { change[elements[exp_elem].adj[j]] = 1; } } } /* Change adjacency information in marked elements */ for (i = 0; i < mesh->num_elems; i++) { if (change[i] == 0) continue; /* loop over marked element's adjacencies; look for ones that are moving */ for (j = 0; j < elements[i].adj_len; j++) { /* Skip NULL adjacencies (sides that are not adjacent to another elem). */ if (elements[i].adj[j] == -1) continue; if (elements[i].adj_proc[j] == proc) { /* adjacent element is local; check whether it is moving. */ if ((new_proc = proc_ids[elements[i].adj[j]]) != proc) { /* Adjacent element is being exported; update this adjacency entry */ elements[i].adj[j] = elements[elements[i].adj[j]].globalID; elements[i].adj_proc[j] = new_proc; } } } } safe_free((void **)(void *) &change); /* * Update off-processor information */ maxlen = 0; for (i = 0; i < mesh->necmap; i++) maxlen += mesh->ecmap_cnt[i]; if (maxlen > 0) { send_vec = (int *) malloc(maxlen * sizeof(int)); if (send_vec == NULL) { Gen_Error(0, "fatal: insufficient memory"); *ierr = ZOLTAN_MEMERR; return; } /* Load send vector */ for (i = 0; i < maxlen; i++) send_vec[i] = proc_ids[mesh->ecmap_elemids[i]]; } safe_free((void **)(void *) &proc_ids); if (maxlen > 0) recv_vec = (int *) malloc(maxlen * sizeof(int)); /* Perform boundary exchange */ boundary_exchange(mesh, 1, send_vec, recv_vec); /* Unload receive vector */ offset = 0; for (i = 0; i < mesh->necmap; i++) { for (j = 0; j < mesh->ecmap_cnt[i]; j++, offset++) { if (recv_vec[offset] == mesh->ecmap_id[i]) { /* off-processor element is not changing processors. */ /* no changes are needed in the local data structure. */ continue; } /* Change processor assignment in local element's adjacency list */ bor_elem = mesh->ecmap_elemids[offset]; for (k = 0; k < elements[bor_elem].adj_len; k++) { /* Skip NULL adjacencies (sides that are not adj to another elem). */ if (elements[bor_elem].adj[k] == -1) continue; if (elements[bor_elem].adj[k] == mesh->ecmap_neighids[offset] && elements[bor_elem].adj_proc[k] == mesh->ecmap_id[i]) { elements[bor_elem].adj_proc[k] = recv_vec[offset]; if (recv_vec[offset] == proc) { /* element is moving to this processor; */ /* convert adj from global to local ID. */ idx = find_in_hash(mesh->ecmap_neighids[offset]); if (idx >= 0) idx = New_Elem_Hash_Nodes[idx].localID; else { sprintf(msg, "fatal: unable to locate element %d in " "New_Elem_Index", mesh->ecmap_neighids[offset]); Gen_Error(0, msg); *ierr = ZOLTAN_FATAL; return; } elements[bor_elem].adj[k] = idx; } break; /* from k loop */ } } } } safe_free((void **)(void *) &recv_vec); safe_free((void **)(void *) &send_vec); /* * Allocate space (if needed) for the new element data. */ if (mesh->elem_array_len < New_Elem_Index_Size) { mesh->elem_array_len = New_Elem_Index_Size; mesh->elements = (ELEM_INFO_PTR) realloc (mesh->elements, mesh->elem_array_len * sizeof(ELEM_INFO)); if (mesh->elements == NULL) { Gen_Error(0, "fatal: insufficient memory"); return; } /* initialize the new spots */ for (i = mesh->num_elems; i < mesh->elem_array_len; i++) initialize_element(&(mesh->elements[i])); } }