pacemaker 2.1.8-2.1.8
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
ipc_schedulerd.c
Go to the documentation of this file.
1/*
2 * Copyright 2021-2024 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#include <crm_internal.h>
11
12#include <stdlib.h>
13#include <time.h>
14
15#include <crm/crm.h>
16#include <crm/common/xml.h>
17#include <crm/common/ipc.h>
20#include "crmcommon_private.h"
21
22typedef struct schedulerd_api_private_s {
23 char *client_uuid;
25
26// \return Standard Pacemaker return code
27static int
28new_data(pcmk_ipc_api_t *api)
29{
30 struct schedulerd_api_private_s *private = NULL;
31
32 api->api_data = calloc(1, sizeof(struct schedulerd_api_private_s));
33
34 if (api->api_data == NULL) {
35 return errno;
36 }
37
38 private = api->api_data;
39 /* See comments in ipc_pacemakerd.c. */
40 private->client_uuid = pcmk__getpid_s();
41
42 return pcmk_rc_ok;
43}
44
45static void
46free_data(void *data)
47{
48 free(((struct schedulerd_api_private_s *) data)->client_uuid);
49 free(data);
50}
51
52// \return Standard Pacemaker return code
53static int
54post_connect(pcmk_ipc_api_t *api)
55{
56 if (api->api_data == NULL) {
57 return EINVAL;
58 }
59
60 return pcmk_rc_ok;
61}
62
63static bool
64reply_expected(pcmk_ipc_api_t *api, const xmlNode *request)
65{
66 const char *command = crm_element_value(request, PCMK__XA_CRM_TASK);
67
68 if (command == NULL) {
69 return false;
70 }
71
72 // We only need to handle commands that functions in this file can send
73 return pcmk__str_any_of(command, CRM_OP_PECALC, NULL);
74}
75
76static bool
77dispatch(pcmk_ipc_api_t *api, xmlNode *reply)
78{
79 crm_exit_t status = CRM_EX_OK;
80 xmlNode *wrapper = NULL;
81 xmlNode *msg_data = NULL;
82 pcmk_schedulerd_api_reply_t reply_data = {
84 };
85 const char *value = NULL;
86
87 if (pcmk__xe_is(reply, PCMK__XE_ACK)) {
88 return false;
89 }
90
91 value = crm_element_value(reply, PCMK__XA_SUBT);
92 if (!pcmk__str_eq(value, PCMK__VALUE_RESPONSE, pcmk__str_none)) {
93 crm_info("Unrecognizable message from schedulerd: "
94 "message type '%s' not '" PCMK__VALUE_RESPONSE "'",
95 pcmk__s(value, ""));
96 status = CRM_EX_PROTOCOL;
97 goto done;
98 }
99
100 if (pcmk__str_empty(crm_element_value(reply, PCMK_XA_REFERENCE))) {
101 crm_info("Unrecognizable message from schedulerd: no reference");
102 status = CRM_EX_PROTOCOL;
103 goto done;
104 }
105
106 // Parse useful info from reply
107 wrapper = pcmk__xe_first_child(reply, PCMK__XE_CRM_XML, NULL, NULL);
108 msg_data = pcmk__xe_first_child(wrapper, NULL, NULL, NULL);
109
110 value = crm_element_value(reply, PCMK__XA_CRM_TASK);
111
112 if (pcmk__str_eq(value, CRM_OP_PECALC, pcmk__str_none)) {
114 reply_data.data.graph.reference = crm_element_value(reply,
116 reply_data.data.graph.input = crm_element_value(reply,
118 reply_data.data.graph.tgraph = msg_data;
119 } else {
120 crm_info("Unrecognizable message from schedulerd: "
121 "unknown command '%s'", pcmk__s(value, ""));
122 status = CRM_EX_PROTOCOL;
123 goto done;
124 }
125
126done:
127 pcmk__call_ipc_callback(api, pcmk_ipc_event_reply, status, &reply_data);
128 return false;
129}
130
133{
134 pcmk__ipc_methods_t *cmds = calloc(1, sizeof(pcmk__ipc_methods_t));
135
136 if (cmds != NULL) {
137 cmds->new_data = new_data;
138 cmds->free_data = free_data;
139 cmds->post_connect = post_connect;
140 cmds->reply_expected = reply_expected;
141 cmds->dispatch = dispatch;
142 }
143 return cmds;
144}
145
146static int
147do_schedulerd_api_call(pcmk_ipc_api_t *api, const char *task, xmlNode *cib, char **ref)
148{
150 xmlNode *cmd = NULL;
151 int rc;
152
153 if (!pcmk_ipc_is_connected(api)) {
154 return ENOTCONN;
155 }
156
157 private = api->api_data;
158 CRM_ASSERT(private != NULL);
159
160 cmd = create_request(task, cib, NULL, CRM_SYSTEM_PENGINE,
162 private->client_uuid);
163
164 if (cmd) {
165 rc = pcmk__send_ipc_request(api, cmd);
166 if (rc != pcmk_rc_ok) {
167 crm_debug("Couldn't send request to schedulerd: %s rc=%d",
168 pcmk_rc_str(rc), rc);
169 }
170
171 *ref = strdup(crm_element_value(cmd, PCMK_XA_REFERENCE));
172 free_xml(cmd);
173 } else {
174 rc = ENOMSG;
175 }
176
177 return rc;
178}
179
180int
181pcmk_schedulerd_api_graph(pcmk_ipc_api_t *api, xmlNode *cib, char **ref)
182{
183 return do_schedulerd_api_call(api, CRM_OP_PECALC, cib, ref);
184}
char data[0]
Definition cpg.c:10
A dumping ground.
#define CRM_OP_PECALC
Definition crm.h:125
char * crm_system_name
Definition utils.c:50
#define CRM_SYSTEM_PENGINE
Definition crm.h:92
G_GNUC_INTERNAL int pcmk__send_ipc_request(pcmk_ipc_api_t *api, const xmlNode *request)
Definition ipc_client.c:668
G_GNUC_INTERNAL void pcmk__call_ipc_callback(pcmk_ipc_api_t *api, enum pcmk_ipc_event event_type, crm_exit_t status, void *event_data)
Definition ipc_client.c:150
IPC interface to Pacemaker daemons.
#define create_request(task, xml_data, host_to, sys_to, sys_from, uuid_from)
Definition ipc.h:49
@ pcmk_ipc_event_reply
Daemon's reply to client IPC request.
Definition ipc.h:96
bool pcmk_ipc_is_connected(pcmk_ipc_api_t *api)
Check whether an IPC API connection is active.
Definition ipc_client.c:287
int pcmk_schedulerd_api_graph(pcmk_ipc_api_t *api, xmlNode *cib, char **ref)
Make an IPC request to the scheduler for the transition graph.
struct schedulerd_api_private_s schedulerd_api_private_t
pcmk__ipc_methods_t * pcmk__schedulerd_api_methods(void)
IPC commands for Schedulerd.
@ pcmk_schedulerd_reply_graph
@ pcmk_schedulerd_reply_unknown
#define crm_info(fmt, args...)
Definition logging.h:397
#define crm_debug(fmt, args...)
Definition logging.h:400
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition nvpair.c:446
#define PCMK__VALUE_RESPONSE
#define CRM_ASSERT(expr)
Definition results.h:42
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Definition results.c:501
@ CRM_EX_PROTOCOL
Protocol violated.
Definition results.h:281
@ CRM_EX_OK
Success.
Definition results.h:255
@ pcmk_rc_ok
Definition results.h:162
enum crm_exit_e crm_exit_t
@ pcmk__str_none
bool pcmk__str_any_of(const char *s,...) G_GNUC_NULL_TERMINATED
Definition strings.c:1050
int(* new_data)(pcmk_ipc_api_t *api)
bool(* reply_expected)(pcmk_ipc_api_t *api, const xmlNode *request)
void(* free_data)(void *api_data)
bool(* dispatch)(pcmk_ipc_api_t *api, xmlNode *msg)
int(* post_connect)(pcmk_ipc_api_t *api)
enum pcmk_schedulerd_api_reply reply_type
union pcmk_schedulerd_api_reply_t::@8 data
struct pcmk_schedulerd_api_reply_t::@8::@9 graph
Wrappers for and extensions to libxml2.
void free_xml(xmlNode *child)
Definition xml.c:867
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
Definition xml.c:440
#define PCMK_XA_REFERENCE
Definition xml_names.h:367
#define PCMK__XA_CRM_TASK
#define PCMK__XA_SUBT
#define PCMK__XE_ACK
#define PCMK__XA_CRM_TGRAPH_IN
#define PCMK__XE_CRM_XML