~ubuntu-branches/ubuntu/utopic/pacemaker/utopic-proposed

« back to all changes in this revision

Viewing changes to pengine/constraints.c

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2013-08-15 11:27:07 UTC
  • mfrom: (1.1.12) (2.1.24 sid)
  • Revision ID: package-import@ubuntu.com-20130815112707-5r864ink7jme3zl5
Tags: 1.1.10+git20130802-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/control: Build-Depends on libqb-dev; Depends on libheartbeat2.
* Corosync's pacemaker plugin is disabled, hence not built:
  - debian/licrmcluster4-dev.install: Do not install plugin.h.
  - debian/pacemaker.install: Do not install pacemaker.lcrso.

Show diffs side-by-side

added added

removed removed

Lines of Context:
40
40
};
41
41
 
42
42
#define EXPAND_CONSTRAINT_IDREF(__set, __rsc, __name) do {                              \
43
 
        __rsc = pe_find_resource(data_set->resources, __name);          \
 
43
        __rsc = pe_find_constraint_resource(data_set->resources, __name);               \
44
44
        if(__rsc == NULL) {                                             \
45
45
            crm_config_err("%s: No resource found for %s", __set, __name); \
46
46
            return FALSE;                                               \
168
168
    return kind_e;
169
169
}
170
170
 
171
 
enum contains_stonith_res {
172
 
    contains_stonith_unknown = -1,
173
 
    contains_stonith_false,
174
 
    contains_stonith_true,
175
 
    contains_stonith_mixed,
176
 
};
177
 
 
178
 
static enum contains_stonith_res
179
 
contains_stonith(resource_t * rsc)
 
171
static resource_t *
 
172
pe_find_constraint_resource(GListPtr rsc_list, const char *id)
180
173
{
181
 
    enum contains_stonith_res res = contains_stonith_unknown;
182
 
    GListPtr gIter = rsc->children;
183
 
 
184
 
    if (gIter == FALSE) {
185
 
        const char *class = crm_element_value(rsc->xml, XML_AGENT_ATTR_CLASS);
186
 
 
187
 
        if (safe_str_eq(class, "stonith")) {
188
 
            return contains_stonith_true;
189
 
        }
190
 
        return contains_stonith_false;
191
 
    }
192
 
 
193
 
    for (; gIter != NULL; gIter = gIter->next) {
194
 
        resource_t *child = (resource_t *) gIter->data;
195
 
        enum contains_stonith_res tmp = contains_stonith(child);
196
 
 
197
 
        if (tmp != contains_stonith_unknown) {
198
 
            switch (res) {
199
 
                case contains_stonith_unknown:
200
 
                    res = tmp;
201
 
                    break;
202
 
                case contains_stonith_false:
203
 
                case contains_stonith_true:
204
 
                    if (tmp != res) {
205
 
                        return contains_stonith_mixed;
206
 
                    }
207
 
                    break;
208
 
                case contains_stonith_mixed:
209
 
                    return contains_stonith_mixed;
 
174
    GListPtr rIter = NULL;
 
175
 
 
176
    for (rIter = rsc_list; id && rIter; rIter = rIter->next) {
 
177
        resource_t *parent = rIter->data;
 
178
 
 
179
        resource_t *match =
 
180
            parent->fns->find_rsc(parent, id, NULL, pe_find_renamed | pe_find_current);
 
181
 
 
182
        if (match != NULL) {
 
183
            if(safe_str_neq(match->id, id)) {
 
184
                /* We found an instance of a clone instead */
 
185
                match = uber_parent(match);
 
186
                crm_debug("Found %s for %s", match->id, id);
210
187
            }
 
188
            return match;
211
189
        }
212
190
    }
213
 
 
214
 
    return res;
 
191
    crm_trace("No match for %s", id);
 
192
    return NULL;
215
193
}
216
194
 
217
195
static gboolean
267
245
        return FALSE;
268
246
    }
269
247
 
270
 
    rsc_then = pe_find_resource(data_set->resources, id_then);
271
 
    rsc_first = pe_find_resource(data_set->resources, id_first);
 
248
    rsc_then = pe_find_constraint_resource(data_set->resources, id_then);
 
249
    rsc_first = pe_find_constraint_resource(data_set->resources, id_first);
272
250
 
273
251
    if (rsc_then == NULL) {
274
252
        crm_config_err("Constraint %s: no resource found for name '%s'", id, id_then);
366
344
{
367
345
    gboolean empty = TRUE;
368
346
    rsc_to_node_t *location = NULL;
369
 
    const char *id_lh = crm_element_value(xml_obj, "rsc");
 
347
    const char *id_lh = crm_element_value(xml_obj, XML_COLOC_ATTR_SOURCE);
370
348
    const char *id = crm_element_value(xml_obj, XML_ATTR_ID);
371
 
    resource_t *rsc_lh = pe_find_resource(data_set->resources, id_lh);
372
 
    const char *node = crm_element_value(xml_obj, "node");
 
349
    resource_t *rsc_lh = pe_find_constraint_resource(data_set->resources, id_lh);
 
350
    const char *node = crm_element_value(xml_obj, XML_CIB_TAG_NODE);
373
351
    const char *score = crm_element_value(xml_obj, XML_RULE_ATTR_SCORE);
374
352
    const char *domain = crm_element_value(xml_obj, XML_CIB_TAG_DOMAIN);
375
353
    const char *role = crm_element_value(xml_obj, XML_RULE_ATTR_ROLE);
710
688
    return TRUE;
711
689
}
712
690
 
713
 
static int
714
 
validate_order_resources(resource_t * lh_rsc, resource_t * rh_rsc)
715
 
{
716
 
    enum contains_stonith_res lh_flag = contains_stonith(lh_rsc);
717
 
    enum contains_stonith_res rh_flag = contains_stonith(rh_rsc);
718
 
 
719
 
    if (lh_flag == contains_stonith_mixed) {
720
 
        crm_config_err
721
 
            ("Order constraint, LH (%s) then RH (%s), can not be applied.  LH contains stonith resources mixed with other resource classes.",
722
 
             lh_rsc->id, rh_rsc->id);
723
 
        return -1;
724
 
    } else if (rh_flag == contains_stonith_mixed) {
725
 
        crm_config_err
726
 
            ("Order constraint, LH (%s) then RH (%s), can not be applied.  RH contains stonith resources mixed with other resource classes.",
727
 
             lh_rsc->id, rh_rsc->id);
728
 
        return -1;
729
 
    } else if (lh_flag == contains_stonith_true && (lh_flag != rh_flag)) {
730
 
        crm_config_err
731
 
            ("Order constraint, LH (%s) then RH (%s), can not be applied. LH is of class stonith and RH is not.",
732
 
             lh_rsc->id, rh_rsc->id);
733
 
        return -1;
734
 
    } else if (rh_flag == contains_stonith_true && (rh_flag != lh_flag)) {
735
 
        crm_config_err
736
 
            ("Order constraint, LH (%s) then RH (%s), can not be applied. RH is of class stonith and LH is not.",
737
 
             lh_rsc->id, rh_rsc->id);
738
 
        return -1;
739
 
    }
740
 
 
741
 
    return 0;
742
 
}
743
 
 
744
691
/* LHS before RHS */
745
692
int
746
693
new_rsc_order(resource_t * lh_rsc, const char *lh_task,
755
702
    CRM_CHECK(rh_rsc != NULL, return -1);
756
703
    CRM_CHECK(rh_task != NULL, return -1);
757
704
 
758
 
    if (validate_order_resources(lh_rsc, rh_rsc)) {
 
705
    /* We no longer need to test if these reference stonith resources
 
706
     * now that stonithd has access to them even when they're not "running"
 
707
     *
 
708
    if (validate_order_resources(lh_rsc, lh_task, rh_rsc, rh_task)) {
759
709
        return -1;
760
710
    }
 
711
    */
761
712
 
762
713
    lh_key = generate_op_key(lh_rsc->id, lh_task, 0);
763
714
    rh_key = generate_op_key(rh_rsc->id, rh_task, 0);
1347
1298
        return TRUE;
1348
1299
    }
1349
1300
 
1350
 
    rsc = pe_find_resource(data_set->resources, id);
 
1301
    rsc = pe_find_constraint_resource(data_set->resources, id);
1351
1302
    if (rsc == NULL) {
1352
1303
        xmlNode *template_rsc_set = g_hash_table_lookup(data_set->template_rsc_sets, id);
1353
1304
 
1432
1383
        return TRUE;
1433
1384
    }
1434
1385
 
1435
 
    rsc_first = pe_find_resource(data_set->resources, id_first);
1436
 
    rsc_then = pe_find_resource(data_set->resources, id_then);
 
1386
    rsc_first = pe_find_constraint_resource(data_set->resources, id_first);
 
1387
    rsc_then = pe_find_constraint_resource(data_set->resources, id_then);
1437
1388
    if (rsc_first && rsc_then) {
1438
1389
        /* Neither side references any template. */
1439
1390
        return TRUE;
1816
1767
 
1817
1768
    const char *symmetrical = crm_element_value(xml_obj, XML_CONS_ATTR_SYMMETRICAL);
1818
1769
 
1819
 
    resource_t *rsc_lh = pe_find_resource(data_set->resources, id_lh);
1820
 
    resource_t *rsc_rh = pe_find_resource(data_set->resources, id_rh);
 
1770
    resource_t *rsc_lh = pe_find_constraint_resource(data_set->resources, id_lh);
 
1771
    resource_t *rsc_rh = pe_find_constraint_resource(data_set->resources, id_rh);
1821
1772
 
1822
1773
    if (rsc_lh == NULL) {
1823
1774
        crm_config_err("Invalid constraint '%s': No resource named '%s'", id, id_lh);
1919
1870
        return TRUE;
1920
1871
    }
1921
1872
 
1922
 
    rsc_lh = pe_find_resource(data_set->resources, id_lh);
1923
 
    rsc_rh = pe_find_resource(data_set->resources, id_rh);
 
1873
    rsc_lh = pe_find_constraint_resource(data_set->resources, id_lh);
 
1874
    rsc_rh = pe_find_constraint_resource(data_set->resources, id_rh);
1924
1875
    if (rsc_lh && rsc_rh) {
1925
1876
        /* Neither side references any template. */
1926
1877
        return TRUE;
2222
2173
        crm_config_err("Invalid constraint '%s': No resource specified", id);
2223
2174
        return FALSE;
2224
2175
    } else {
2225
 
        rsc_lh = pe_find_resource(data_set->resources, id_lh);
 
2176
        rsc_lh = pe_find_constraint_resource(data_set->resources, id_lh);
2226
2177
    }
2227
2178
 
2228
2179
    if (rsc_lh == NULL) {
2291
2242
        return TRUE;
2292
2243
    }
2293
2244
 
2294
 
    rsc_lh = pe_find_resource(data_set->resources, id_lh);
 
2245
    rsc_lh = pe_find_constraint_resource(data_set->resources, id_lh);
2295
2246
    if (rsc_lh) {
2296
2247
        /* No template is referenced. */
2297
2248
        return TRUE;
2364
2315
        return FALSE;
2365
2316
    }
2366
2317
 
 
2318
    if (data_set->tickets == NULL) {                                                                  
 
2319
        data_set->tickets =                                                                           
 
2320
            g_hash_table_new_full(crm_str_hash, g_str_equal, g_hash_destroy_str, destroy_ticket);
 
2321
    }  
 
2322
 
2367
2323
    if (ticket_str == NULL) {
2368
2324
        crm_config_err("Invalid constraint '%s': No ticket specified", id);
2369
2325
        return FALSE;