This source file includes following definitions.
- based_transaction_source_str
- process_transaction_requests
- based_commit_transaction
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <glib.h>
13 #include <libxml/tree.h>
14
15 #include "pacemaker-based.h"
16
17
18
19
20
21
22
23
24
25
26
27
28 char *
29 based_transaction_source_str(const pcmk__client_t *client, const char *origin)
30 {
31 char *source = NULL;
32
33 if (client != NULL) {
34 source = crm_strdup_printf("client %s (%s)%s%s",
35 pcmk__client_name(client),
36 pcmk__s(client->id, "unidentified"),
37 ((origin != NULL)? " on " : ""),
38 pcmk__s(origin, ""));
39
40 } else {
41 source = strdup((origin != NULL)? origin : "unknown source");
42 }
43
44 CRM_ASSERT(source != NULL);
45 return source;
46 }
47
48
49
50
51
52
53
54
55
56
57
58
59
60 static int
61 process_transaction_requests(xmlNodePtr transaction,
62 const pcmk__client_t *client, const char *source)
63 {
64 for (xmlNodePtr request = first_named_child(transaction, T_CIB_COMMAND);
65 request != NULL; request = crm_next_same_xml(request)) {
66
67 const char *op = crm_element_value(request, F_CIB_OPERATION);
68 const char *host = crm_element_value(request, F_CIB_HOST);
69 const cib__operation_t *operation = NULL;
70 int rc = cib__get_operation(op, &operation);
71
72 if (rc == pcmk_rc_ok) {
73 if (!pcmk_is_set(operation->flags, cib__op_attr_transaction)
74 || (host != NULL)) {
75
76 rc = EOPNOTSUPP;
77 } else {
78
79
80
81 rc = cib_process_request(request, TRUE, client);
82 rc = pcmk_legacy2rc(rc);
83 }
84 }
85
86 if (rc != pcmk_rc_ok) {
87 crm_err("Aborting CIB transaction for %s due to failed %s request: "
88 "%s",
89 source, op, pcmk_rc_str(rc));
90 crm_log_xml_info(request, "Failed request");
91 return rc;
92 }
93
94 crm_trace("Applied %s request to transaction working CIB for %s",
95 op, source);
96 crm_log_xml_trace(request, "Successful request");
97 }
98
99 return pcmk_rc_ok;
100 }
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120 int
121 based_commit_transaction(xmlNodePtr transaction, const pcmk__client_t *client,
122 const char *origin, xmlNodePtr *result_cib)
123 {
124 xmlNodePtr saved_cib = the_cib;
125 int rc = pcmk_rc_ok;
126 char *source = NULL;
127
128 CRM_ASSERT(result_cib != NULL);
129
130 CRM_CHECK(pcmk__xe_is(transaction, T_CIB_TRANSACTION),
131 return pcmk_rc_no_transaction);
132
133
134
135
136
137
138
139
140 CRM_CHECK((*result_cib != NULL) && (*result_cib != the_cib),
141 *result_cib = copy_xml(the_cib));
142
143 source = based_transaction_source_str(client, origin);
144 crm_trace("Committing transaction for %s to working CIB", source);
145
146
147 the_cib = *result_cib;
148
149 rc = process_transaction_requests(transaction, client, origin);
150
151 crm_trace("Transaction commit %s for %s",
152 ((rc == pcmk_rc_ok)? "succeeded" : "failed"), source);
153
154
155
156
157
158
159
160 *result_cib = the_cib;
161
162
163 the_cib = saved_cib;
164
165 free(source);
166 return rc;
167 }