Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abstract controller API from crm_resource #1981

Merged
merged 10 commits into from
Feb 24, 2020
14 changes: 1 addition & 13 deletions daemons/attrd/attrd_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,6 @@ attrd_ipc_accept(qb_ipcs_connection_t *c, uid_t uid, gid_t gid)
return pcmk_ok;
}

/*!
* \internal
* \brief Callback for successful client connection
*
* \param[in] c New connection
*/
static void
attrd_ipc_created(qb_ipcs_connection_t *c)
{
crm_trace("Client connection %p accepted", c);
}

/*!
* \internal
* \brief Destroy a client IPC connection
Expand Down Expand Up @@ -179,7 +167,7 @@ attrd_init_ipc(qb_ipcs_service_t **ipcs, qb_ipcs_msg_process_fn dispatch_fn)

static struct qb_ipcs_service_handlers ipc_callbacks = {
.connection_accept = attrd_ipc_accept,
.connection_created = attrd_ipc_created,
.connection_created = NULL,
.msg_process = NULL,
.connection_closed = attrd_ipc_closed,
.connection_destroyed = attrd_ipc_destroy
Expand Down
4 changes: 1 addition & 3 deletions daemons/attrd/pacemaker-attrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ attrd_ipc_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
crm_debug("No IPC data from PID %d", pcmk__client_pid(c));
return 0;
}
xml = pcmk__client_data2xml(client, data, size, &id, &flags);
xml = pcmk__client_data2xml(client, data, &id, &flags);
if (xml == NULL) {
crm_debug("Unrecognizable IPC data from PID %d", pcmk__client_pid(c));
return 0;
Expand All @@ -261,8 +261,6 @@ attrd_ipc_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
crm_acl_get_set_user(xml, F_ATTRD_USER, client->user);
#endif

crm_log_xml_trace(xml, __FUNCTION__);

op = crm_element_value(xml, F_ATTRD_TASK);

if (client->name == NULL) {
Expand Down
15 changes: 3 additions & 12 deletions daemons/based/based_callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,6 @@ cib_ipc_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
return 0;
}

static void
cib_ipc_created(qb_ipcs_connection_t * c)
{
crm_trace("Connection %p", c);
}

static int32_t
cib_ipc_dispatch_rw(qb_ipcs_connection_t * c, void *data, size_t size)
{
Expand Down Expand Up @@ -131,15 +125,15 @@ cib_ipc_destroy(qb_ipcs_connection_t * c)

struct qb_ipcs_service_handlers ipc_ro_callbacks = {
.connection_accept = cib_ipc_accept,
.connection_created = cib_ipc_created,
.connection_created = NULL,
.msg_process = cib_ipc_dispatch_ro,
.connection_closed = cib_ipc_closed,
.connection_destroyed = cib_ipc_destroy
};

struct qb_ipcs_service_handlers ipc_rw_callbacks = {
.connection_accept = cib_ipc_accept,
.connection_created = cib_ipc_created,
.connection_created = NULL,
.msg_process = cib_ipc_dispatch_rw,
.connection_closed = cib_ipc_closed,
.connection_destroyed = cib_ipc_destroy
Expand Down Expand Up @@ -213,8 +207,7 @@ cib_common_callback(qb_ipcs_connection_t * c, void *data, size_t size, gboolean
uint32_t flags = 0;
int call_options = 0;
pcmk__client_t *cib_client = pcmk__find_client(c);
xmlNode *op_request = pcmk__client_data2xml(cib_client, data, size, &id,
&flags);
xmlNode *op_request = pcmk__client_data2xml(cib_client, data, &id, &flags);

if (op_request) {
crm_element_value_int(op_request, F_CIB_CALLOPTS, &call_options);
Expand Down Expand Up @@ -267,8 +260,6 @@ cib_common_callback(qb_ipcs_connection_t * c, void *data, size_t size, gboolean
crm_acl_get_set_user(op_request, F_CIB_USER, cib_client->user);
#endif

crm_log_xml_trace(op_request, "Client[inbound]");

cib_common_callback_worker(id, flags, op_request, cib_client, privileged);
free_xml(op_request);

Expand Down
30 changes: 11 additions & 19 deletions daemons/controld/controld_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -354,34 +354,28 @@ do_startup(long long action,
}
}

// \return libqb error code (0 on success, -errno on error)
static int32_t
crmd_ipc_accept(qb_ipcs_connection_t * c, uid_t uid, gid_t gid)
accept_controller_client(qb_ipcs_connection_t *c, uid_t uid, gid_t gid)
{
crm_trace("Connection %p", c);
crm_trace("Accepting new IPC client connection");
if (pcmk__new_client(c, uid, gid) == NULL) {
return -EIO;
}
return 0;
}

static void
crmd_ipc_created(qb_ipcs_connection_t * c)
{
crm_trace("Connection %p", c);
}

// \return libqb error code (0 on success, -errno on error)
static int32_t
crmd_ipc_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
dispatch_controller_ipc(qb_ipcs_connection_t * c, void *data, size_t size)
{
uint32_t id = 0;
uint32_t flags = 0;
pcmk__client_t *client = pcmk__find_client(c);

xmlNode *msg = pcmk__client_data2xml(client, data, size, &id, &flags);
xmlNode *msg = pcmk__client_data2xml(client, data, &id, &flags);

crm_trace("Invoked: %s", pcmk__client_name(client));
pcmk__ipc_send_ack(client, id, flags, "ack");

if (msg == NULL) {
return 0;
}
Expand All @@ -391,11 +385,9 @@ crmd_ipc_dispatch(qb_ipcs_connection_t * c, void *data, size_t size)
crm_acl_get_set_user(msg, F_CRM_USER, client->user);
#endif

crm_trace("Processing msg from %s", pcmk__client_name(client));
crm_log_xml_trace(msg, "controller[inbound]");

crm_xml_add(msg, F_CRM_SYS_FROM, client->id);
if (crmd_authorize_message(msg, client, NULL)) {
if (controld_authorize_ipc_message(msg, client, NULL)) {
crm_trace("Processing IPC message from %s", pcmk__client_name(client));
route_message(C_IPC_MESSAGE, msg);
}

Expand Down Expand Up @@ -445,9 +437,9 @@ do_started(long long action,
enum crmd_fsa_state cur_state, enum crmd_fsa_input current_input, fsa_data_t * msg_data)
{
static struct qb_ipcs_service_handlers crmd_callbacks = {
.connection_accept = crmd_ipc_accept,
.connection_created = crmd_ipc_created,
.msg_process = crmd_ipc_dispatch,
.connection_accept = accept_controller_client,
.connection_created = NULL,
.msg_process = dispatch_controller_ipc,
.connection_closed = crmd_ipc_closed,
.connection_destroyed = crmd_ipc_destroy
};
Expand Down
35 changes: 20 additions & 15 deletions daemons/controld/controld_execd.c
Original file line number Diff line number Diff line change
Expand Up @@ -954,14 +954,13 @@ delete_rsc_entry(lrm_state_t * lrm_state, ha_msg_input_t * input, const char *rs
if (rc == pcmk_ok) {
char *rsc_id_copy = strdup(rsc_id);

if (rsc_gIter)
if (rsc_gIter) {
g_hash_table_iter_remove(rsc_gIter);
else
} else {
g_hash_table_remove(lrm_state->resource_history, rsc_id_copy);
crm_debug("sync: Sending delete op for %s", rsc_id_copy);
}
controld_delete_resource_history(rsc_id_copy, lrm_state->node_name,
user_name, crmd_cib_smart_opt());

g_hash_table_foreach_remove(lrm_state->pending_ops, lrm_remove_deleted_op, rsc_id_copy);
free(rsc_id_copy);
}
Expand Down Expand Up @@ -1311,23 +1310,23 @@ delete_resource(lrm_state_t * lrm_state,
lrmd_rsc_info_t * rsc,
GHashTableIter * gIter,
const char *sys,
const char *host,
const char *user,
ha_msg_input_t * request,
gboolean unregister)
{
int rc = pcmk_ok;

crm_info("Removing resource %s for %s (%s) on %s", id, sys, user ? user : "internal", host);
crm_info("Removing resource %s from executor for %s%s%s",
id, sys, (user? " as " : ""), (user? user : ""));

if (rsc && unregister) {
rc = lrm_state_unregister_rsc(lrm_state, id, 0);
}

if (rc == pcmk_ok) {
crm_trace("Resource '%s' deleted", id);
crm_trace("Resource %s deleted from executor", id);
} else if (rc == -EINPROGRESS) {
crm_info("Deletion of resource '%s' pending", id);
crm_info("Deletion of resource '%s' from executor is pending", id);
if (request) {
struct pending_deletion_op_s *op = NULL;
char *ref = crm_element_value_copy(request->msg, XML_ATTR_REFERENCE);
Expand All @@ -1339,8 +1338,9 @@ delete_resource(lrm_state_t * lrm_state,
}
return;
} else {
crm_warn("Deletion of resource '%s' for %s (%s) on %s failed: %d",
id, sys, user ? user : "internal", host, rc);
crm_warn("Could not delete '%s' from executor for %s%s%s: %s "
CRM_XS " rc=%d", id, sys, (user? " as " : ""),
(user? user : ""), pcmk_strerror(rc), rc);
}

delete_rsc_entry(lrm_state, request, id, gIter, rc, user);
Expand Down Expand Up @@ -1406,7 +1406,7 @@ force_reprobe(lrm_state_t *lrm_state, const char *from_sys,
unregister = FALSE;
}

delete_resource(lrm_state, entry->id, &entry->rsc, &gIter, from_sys, from_host,
delete_resource(lrm_state, entry->id, &entry->rsc, &gIter, from_sys,
user_name, NULL, unregister);
}

Expand Down Expand Up @@ -1723,7 +1723,7 @@ do_lrm_delete(ha_msg_input_t *input, lrm_state_t *lrm_state,
unregister = FALSE;
}

delete_resource(lrm_state, rsc->id, rsc, NULL, from_sys, from_host,
delete_resource(lrm_state, rsc->id, rsc, NULL, from_sys,
user_name, input, unregister);
}

Expand Down Expand Up @@ -1760,15 +1760,20 @@ do_lrm_invoke(long long action,

#if ENABLE_ACL
user_name = crm_acl_get_set_user(input->msg, F_CRM_USER, NULL);
crm_trace("Executor command from user '%s'", user_name);
#endif

crm_op = crm_element_value(input->msg, F_CRM_TASK);
from_sys = crm_element_value(input->msg, F_CRM_SYS_FROM);
if (safe_str_neq(from_sys, CRM_SYSTEM_TENGINE)) {
from_host = crm_element_value(input->msg, F_CRM_HOST_FROM);
}
crm_trace("Executor %s command from %s", crm_op, from_sys);
#if ENABLE_ACL
crm_trace("Executor %s command from %s as user %s",
crm_op, from_sys, user_name);
#else
crm_trace("Executor %s command from %s",
crm_op, from_sys);
#endif

if (safe_str_eq(crm_op, CRM_OP_LRM_DELETE)) {
if (safe_str_neq(from_sys, CRM_SYSTEM_TENGINE)) {
Expand Down Expand Up @@ -2073,7 +2078,7 @@ controld_ack_event_directly(const char *to_host, const char *to_sys,
build_operation_update(iter, rsc, op, fsa_our_uname, __FUNCTION__);
reply = create_request(CRM_OP_INVOKE_LRM, update, to_host, to_sys, CRM_SYSTEM_LRMD, NULL);

crm_log_xml_trace(update, "ACK Update");
crm_log_xml_trace(update, "[direct ACK]");

crm_debug("ACK'ing resource op " CRM_OP_FMT " from %s: %s",
op->rsc_id, op->op_type, op->interval_ms, op->user_data,
Expand Down
8 changes: 3 additions & 5 deletions daemons/controld/controld_execd_state.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,12 @@ crmd_proxy_send(const char *session, xmlNode *msg)
static void
crmd_proxy_dispatch(const char *session, xmlNode *msg)
{

crm_log_xml_trace(msg, "controller-proxy[inbound]");

crm_trace("Processing proxied IPC message from session %s", session);
crm_log_xml_trace(msg, "controller[inbound]");
crm_xml_add(msg, F_CRM_SYS_FROM, session);
if (crmd_authorize_message(msg, NULL, session)) {
if (controld_authorize_ipc_message(msg, NULL, session)) {
route_message(C_IPC_MESSAGE, msg);
}

trigger_fsa(fsa_source);
}

Expand Down
Loading