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