1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
/*
* Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <crm_internal.h>
#include <sys/param.h>
#include <crm/crm.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <libgen.h>
#include <crm/msg_xml.h>
#include <crm/common/xml.h>
#include <crm/cib.h>
const char * feature_sets[] = {
"1.1",
"1.2",
"1.3",
"2.0",
};
typedef struct tag_set_s
{
int length;
const char **tags;
} tag_set_t;
const char *feature_tags_12[] = { "master_slave", };
const char *feature_tags_20[] = {
"cluster_property_set",
"meta_attributes",
"transient_attributes",
};
tag_set_t feature_tags[] = {
{ 0, NULL },
{ 1, feature_tags_12 },
{ 0, NULL },
{ 3, feature_tags_20 },
};
const char *feature_attrs_12[] = { "master_node_max", };
const char *feature_attrs_20[] = {
"start_delay",
"disabled",
"on_fail",
"prereq",
"collocated",
"globally_unique",
"from_role",
"to_role",
"node_attribute",
"score_attribute",
"hours",
"transition_key",
"op_digest",
"op_restart_digest",
"op_force_restart",
};
tag_set_t feature_attrs[] = {
{ 0, NULL },
{ 1, feature_attrs_12 },
{ 0, NULL },
{ 15, feature_attrs_20 },
};
static int
internal_update_feature_set(xmlNode *xml_obj, int current)
{
int lpc = current;
int lpc_nested = 0;
const char *value = NULL;
int num_sets = DIMOF(feature_sets);
CRM_CHECK(compare_version(
CIB_FEATURE_SET, feature_sets[num_sets-1]) == 0,
return num_sets-1);
for(;lpc < num_sets; lpc++) {
const char *tag = crm_element_name(xml_obj);
crm_debug_3("Checking set %d with %d tags", lpc,
feature_tags[lpc].length);
lpc_nested = 0;
for(; lpc_nested < feature_tags[lpc].length; lpc_nested++) {
const char *name = feature_tags[lpc].tags[lpc_nested];
crm_debug_4("Checking %s vs. %s", tag, name);
if(safe_str_eq(tag, name)) {
crm_debug_2("Found feature %s from set %s",
tag, feature_sets[lpc]);
current = lpc;
break;
}
}
if(current == lpc) {
continue;
}
lpc_nested = 0;
for(; lpc_nested < feature_attrs[lpc].length; lpc_nested++) {
const char *name = feature_attrs[lpc].tags[lpc_nested];
crm_debug_4("Checking for %s", name);
value = crm_element_value(xml_obj, name);
if(value != NULL) {
crm_info("Found feature '%s' from set %s",
name, feature_sets[lpc]);
current = lpc;
break;
}
}
}
if(current == (num_sets -1)) {
return current;
}
xml_child_iter(xml_obj, xml_child,
current = internal_update_feature_set(xml_child,current);
if(current == (num_sets -1)) {
return current;
}
);
return current;
}
const char *
feature_set(xmlNode *xml_obj)
{
int set = internal_update_feature_set(xml_obj, 0);
CRM_ASSERT(set >= 0);
CRM_ASSERT(set < DIMOF(feature_sets));
return feature_sets[set];
}
|