| 59 | } |
| 60 | |
| 61 | gint |
| 62 | sort_clone_instance(gconstpointer a, gconstpointer b, gpointer data_set) |
| 63 | { |
| 64 | int rc = 0; |
| 65 | node_t *node1 = NULL; |
| 66 | node_t *node2 = NULL; |
| 67 | |
| 68 | gboolean can1 = TRUE; |
| 69 | gboolean can2 = TRUE; |
| 70 | |
| 71 | const resource_t *resource1 = (const resource_t *)a; |
| 72 | const resource_t *resource2 = (const resource_t *)b; |
| 73 | |
| 74 | CRM_ASSERT(resource1 != NULL); |
| 75 | CRM_ASSERT(resource2 != NULL); |
| 76 | |
| 77 | /* allocation order: |
| 78 | * - active instances |
| 79 | * - instances running on nodes with the least copies |
| 80 | * - active instances on nodes that cant support them or are to be fenced |
| 81 | * - failed instances |
| 82 | * - inactive instances |
| 83 | */ |
| 84 | |
| 85 | if (resource1->running_on && resource2->running_on) { |
| 86 | if (g_list_length(resource1->running_on) < g_list_length(resource2->running_on)) { |
| 87 | crm_trace( "%s < %s: running_on", resource1->id, resource2->id); |
| 88 | return -1; |
| 89 | |
| 90 | } else if (g_list_length(resource1->running_on) > g_list_length(resource2->running_on)) { |
| 91 | crm_trace( "%s > %s: running_on", resource1->id, resource2->id); |
| 92 | return 1; |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | if (resource1->running_on) { |
| 97 | node1 = resource1->running_on->data; |
| 98 | } |
| 99 | if (resource2->running_on) { |
| 100 | node2 = resource2->running_on->data; |
| 101 | } |
| 102 | |
| 103 | if (node1) { |
| 104 | node_t *match = pe_hash_table_lookup(resource1->allowed_nodes, node1->details->id); |
| 105 | |
| 106 | if (match == NULL || match->weight < 0) { |
| 107 | crm_trace( "%s: current location is unavailable", resource1->id); |
| 108 | node1 = NULL; |
| 109 | can1 = FALSE; |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (node2) { |
| 114 | node_t *match = pe_hash_table_lookup(resource2->allowed_nodes, node2->details->id); |
| 115 | |
| 116 | if (match == NULL || match->weight < 0) { |
| 117 | crm_trace( "%s: current location is unavailable", resource2->id); |
| 118 | node2 = NULL; |
no test coverage detected