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 if (client != NULL) {
32 return crm_strdup_printf("client %s (%s)%s%s",
33 pcmk__client_name(client),
34 pcmk__s(client->id, "unidentified"),
35 ((origin != NULL)? " on " : ""),
36 pcmk__s(origin, ""));
37 } else {
38 return pcmk__str_copy(pcmk__s(origin, "unknown source"));
39 }
40 }
41
42
43
44
45
46
47
48
49
50
51
52
53
54 static int
55 process_transaction_requests(xmlNodePtr transaction,
56 const pcmk__client_t *client, const char *source)
57 {
58 for (xmlNode *request = pcmk__xe_first_child(transaction,
59 PCMK__XE_CIB_COMMAND, NULL,
60 NULL);
61 request != NULL; request = pcmk__xe_next_same(request)) {
62
63 const char *op = crm_element_value(request, PCMK__XA_CIB_OP);
64 const char *host = crm_element_value(request, PCMK__XA_CIB_HOST);
65 const cib__operation_t *operation = NULL;
66 int rc = cib__get_operation(op, &operation);
67
68 if (rc == pcmk_rc_ok) {
69 if (!pcmk_is_set(operation->flags, cib__op_attr_transaction)
70 || (host != NULL)) {
71
72 rc = EOPNOTSUPP;
73 } else {
74
75
76
77 rc = cib_process_request(request, TRUE, client);
78 rc = pcmk_legacy2rc(rc);
79 }
80 }
81
82 if (rc != pcmk_rc_ok) {
83 crm_err("Aborting CIB transaction for %s due to failed %s request: "
84 "%s",
85 source, op, pcmk_rc_str(rc));
86 crm_log_xml_info(request, "Failed request");
87 return rc;
88 }
89
90 crm_trace("Applied %s request to transaction working CIB for %s",
91 op, source);
92 crm_log_xml_trace(request, "Successful request");
93 }
94
95 return pcmk_rc_ok;
96 }
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116 int
117 based_commit_transaction(xmlNodePtr transaction, const pcmk__client_t *client,
118 const char *origin, xmlNodePtr *result_cib)
119 {
120 xmlNodePtr saved_cib = the_cib;
121 int rc = pcmk_rc_ok;
122 char *source = NULL;
123
124 CRM_ASSERT(result_cib != NULL);
125
126 CRM_CHECK(pcmk__xe_is(transaction, PCMK__XE_CIB_TRANSACTION),
127 return pcmk_rc_no_transaction);
128
129
130
131
132
133
134
135
136 CRM_CHECK((*result_cib != NULL) && (*result_cib != the_cib),
137 *result_cib = pcmk__xml_copy(NULL, the_cib));
138
139 source = based_transaction_source_str(client, origin);
140 crm_trace("Committing transaction for %s to working CIB", source);
141
142
143 the_cib = *result_cib;
144
145 rc = process_transaction_requests(transaction, client, origin);
146
147 crm_trace("Transaction commit %s for %s",
148 ((rc == pcmk_rc_ok)? "succeeded" : "failed"), source);
149
150
151
152
153
154
155
156 *result_cib = the_cib;
157
158
159 the_cib = saved_cib;
160
161 free(source);
162 return rc;
163 }