This source file includes following definitions.
- best_op
- pcmk__resource_digests
- pcmk_resource_digests
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <errno.h>
13 #include <glib.h>
14 #include <libxml/tree.h>
15
16 #include <crm/common/mainloop.h>
17 #include <crm/common/results.h>
18 #include <crm/common/output_internal.h>
19 #include <crm/pengine/internal.h>
20
21 #include <pacemaker.h>
22 #include <pacemaker-internal.h>
23
24
25 #define XPATH_OP_HISTORY "//" XML_CIB_TAG_STATUS \
26 "/" XML_CIB_TAG_STATE "[@" XML_ATTR_UNAME "='%s']" \
27 "/" XML_CIB_TAG_LRM "/" XML_LRM_TAG_RESOURCES \
28 "/" XML_LRM_TAG_RESOURCE "[@" XML_ATTR_ID "='%s']"
29
30 static xmlNode *
31 best_op(pe_resource_t *rsc, pe_node_t *node, pe_working_set_t *data_set)
32 {
33 char *xpath = NULL;
34 xmlNode *history = NULL;
35 xmlNode *best = NULL;
36 bool best_effective_op = false;
37 guint best_interval = 0;
38 bool best_failure = false;
39 const char *best_digest = NULL;
40
41
42 xpath = crm_strdup_printf(XPATH_OP_HISTORY, node->details->uname, rsc->id);
43 history = get_xpath_object(xpath, data_set->input, LOG_NEVER);
44 free(xpath);
45
46
47 for (xmlNode *lrm_rsc_op = first_named_child(history, XML_LRM_TAG_RSC_OP);
48 lrm_rsc_op != NULL; lrm_rsc_op = crm_next_same_xml(lrm_rsc_op)) {
49
50 const char *digest = crm_element_value(lrm_rsc_op,
51 XML_LRM_ATTR_RESTART_DIGEST);
52 guint interval_ms = 0;
53 const char *task = crm_element_value(lrm_rsc_op, XML_LRM_ATTR_TASK);
54 bool effective_op = false;
55 bool failure = pcmk__ends_with(ID(lrm_rsc_op), "_last_failure_0");
56
57
58 crm_element_value_ms(lrm_rsc_op, XML_LRM_ATTR_INTERVAL, &interval_ms);
59 effective_op = interval_ms == 0
60 && pcmk__strcase_any_of(task, RSC_STATUS,
61 RSC_START, RSC_PROMOTE,
62 RSC_MIGRATED, NULL);
63
64 if (best == NULL) {
65 goto is_best;
66 }
67
68 if (best_effective_op) {
69
70 if (!effective_op) {
71 continue;
72 }
73
74 } else if (best_interval != 0
75 && !effective_op
76 && interval_ms == 0) {
77 continue;
78 }
79
80
81 if (!best_failure && failure) {
82 continue;
83 }
84
85
86 if (best_digest != NULL && digest == NULL) {
87 continue;
88 }
89
90
91 if (pe__is_newer_op(best, lrm_rsc_op, true) > 0) {
92 continue;
93 }
94
95 is_best:
96 best = lrm_rsc_op;
97 best_effective_op = effective_op;
98 best_interval = interval_ms;
99 best_failure = failure;
100 best_digest = digest;
101 }
102 return best;
103 }
104
105
106
107
108
109
110
111
112
113
114
115
116 int
117 pcmk__resource_digests(pcmk__output_t *out, pe_resource_t *rsc,
118 pe_node_t *node, GHashTable *overrides)
119 {
120 const char *task = NULL;
121 xmlNode *xml_op = NULL;
122 op_digest_cache_t *digests = NULL;
123 guint interval_ms = 0;
124 int rc = pcmk_rc_ok;
125
126 if ((out == NULL) || (rsc == NULL) || (node == NULL)) {
127 return EINVAL;
128 }
129 if (rsc->variant != pe_native) {
130
131 return EOPNOTSUPP;
132 }
133
134
135 xml_op = best_op(rsc, node, rsc->cluster);
136
137
138 if (xml_op != NULL) {
139 task = crm_element_value(xml_op, XML_LRM_ATTR_TASK);
140 crm_element_value_ms(xml_op, XML_LRM_ATTR_INTERVAL_MS, &interval_ms);
141 }
142 if (task == NULL) {
143 task = RSC_START;
144 interval_ms = 0;
145 }
146
147
148 digests = pe__calculate_digests(rsc, task, &interval_ms, node, xml_op,
149 overrides, true, rsc->cluster);
150 rc = out->message(out, "digests", rsc, node, task, interval_ms, digests);
151
152 pe__free_digests(digests);
153 return rc;
154 }
155
156 int
157 pcmk_resource_digests(xmlNodePtr *xml, pe_resource_t *rsc,
158 pe_node_t *node, GHashTable *overrides,
159 pe_working_set_t *data_set)
160 {
161 pcmk__output_t *out = NULL;
162 int rc = pcmk_rc_ok;
163
164 rc = pcmk__xml_output_new(&out, xml);
165 if (rc != pcmk_rc_ok) {
166 return rc;
167 }
168 pcmk__register_lib_messages(out);
169 rc = pcmk__resource_digests(out, rsc, node, overrides);
170 pcmk__xml_output_finish(out, xml);
171 return rc;
172 }