| 115 | } |
| 116 | |
| 117 | static gboolean |
| 118 | native_choose_node(resource_t * rsc, node_t * prefer, pe_working_set_t * data_set) |
| 119 | { |
| 120 | /* |
| 121 | 1. Sort by weight |
| 122 | 2. color.chosen_node = the node (of those with the highest wieght) |
| 123 | with the fewest resources |
| 124 | 3. remove color.chosen_node from all other colors |
| 125 | */ |
| 126 | int alloc_details = scores_log_level + 1; |
| 127 | |
| 128 | GListPtr nodes = NULL; |
| 129 | node_t *chosen = NULL; |
| 130 | |
| 131 | int lpc = 0; |
| 132 | int multiple = 0; |
| 133 | int length = 0; |
| 134 | gboolean result = FALSE; |
| 135 | |
| 136 | if (safe_str_neq(data_set->placement_strategy, "default")) { |
| 137 | GListPtr gIter = NULL; |
| 138 | |
| 139 | for (gIter = data_set->nodes; gIter != NULL; gIter = gIter->next) { |
| 140 | node_t *node = (node_t *) gIter->data; |
| 141 | |
| 142 | if (have_enough_capacity(node, rsc) == FALSE) { |
| 143 | pe_rsc_debug(rsc, "Resource %s cannot be allocated to node %s: none of enough capacity", |
| 144 | rsc->id, node->details->uname); |
| 145 | resource_location(rsc, node, -INFINITY, "__limit_utilization_", data_set); |
| 146 | } |
| 147 | } |
| 148 | dump_node_scores(alloc_details, rsc, "Post-utilization", rsc->allowed_nodes); |
| 149 | } |
| 150 | |
| 151 | length = g_hash_table_size(rsc->allowed_nodes); |
| 152 | |
| 153 | if (is_not_set(rsc->flags, pe_rsc_provisional)) { |
| 154 | return rsc->allocated_to ? TRUE : FALSE; |
| 155 | } |
| 156 | |
| 157 | if (prefer) { |
| 158 | chosen = g_hash_table_lookup(rsc->allowed_nodes, prefer->details->id); |
| 159 | if (chosen && chosen->weight >= 0 && can_run_resources(chosen)) { |
| 160 | pe_rsc_trace(rsc, "Using preferred node %s for %s instead of choosing from %d candidates", |
| 161 | chosen->details->uname, rsc->id, length); |
| 162 | } else if (chosen && chosen->weight < 0) { |
| 163 | pe_rsc_trace(rsc, "Preferred node %s for %s was unavailable", chosen->details->uname, rsc->id); |
| 164 | chosen = NULL; |
| 165 | } else if (chosen && can_run_resources(chosen)) { |
| 166 | pe_rsc_trace(rsc, "Preferred node %s for %s was unsuitable", chosen->details->uname, rsc->id); |
| 167 | chosen = NULL; |
| 168 | } else { |
| 169 | pe_rsc_trace(rsc, "Preferred node %s for %s was unknown", prefer->details->uname, rsc->id); |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | if (chosen == NULL && rsc->allowed_nodes) { |
| 174 | nodes = g_hash_table_get_values(rsc->allowed_nodes); |
no test coverage detected