Skip to content

Commit f64c53d

Browse files
committed
Refactor: controller: Light cleanup of lrm_state_unregister_rsc()
Signed-off-by: Reid Wahl <nrwahl@protonmail.com>
1 parent 578bb1e commit f64c53d

3 files changed

Lines changed: 37 additions & 17 deletions

File tree

daemons/controld/controld_execd.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -835,18 +835,19 @@ delete_resource(lrm_state_t *lrm_state, const char *id, lrmd_rsc_info_t *rsc,
835835
GHashTableIter *iter, const char *sys, const char *user,
836836
ha_msg_input_t *request, bool unregister, bool from_cib)
837837
{
838-
int rc = pcmk_ok;
838+
int rc = pcmk_rc_ok;
839839

840840
pcmk__info("Removing resource %s from executor for %s%s%s", id, sys,
841841
((user != NULL)? " as " : ""), pcmk__s(user, ""));
842842

843843
if (rsc && unregister) {
844-
rc = lrm_state_unregister_rsc(lrm_state, id);
844+
rc = controld_execd_state_unregister_rsc(lrm_state, id);
845845
}
846846

847-
if (rc == pcmk_ok) {
847+
if (rc == pcmk_rc_ok) {
848848
pcmk__trace("Resource %s deleted from executor", id);
849-
} else if (rc == -EINPROGRESS) {
849+
850+
} else if (rc == EINPROGRESS) {
850851
pcmk__info("Deletion of resource '%s' from executor is pending", id);
851852
if (request) {
852853
struct pending_deletion_op_s *op = NULL;
@@ -857,15 +858,16 @@ delete_resource(lrm_state_t *lrm_state, const char *id, lrmd_rsc_info_t *rsc,
857858
op->input = copy_ha_msg_input(request);
858859
g_hash_table_insert(lrm_state->deletion_ops, ref, op);
859860
}
861+
860862
return;
863+
861864
} else {
862865
pcmk__warn("Could not delete '%s' from executor for %s%s%s: %s "
863866
QB_XS " rc=%d",
864867
id, sys, ((user != NULL)? " as " : ""), pcmk__s(user, ""),
865-
pcmk_strerror(rc), rc);
868+
pcmk_rc_str(rc), rc);
866869
}
867870

868-
rc = pcmk_legacy2rc(rc);
869871
delete_rsc_entry(lrm_state, request, id, iter, rc, user, from_cib);
870872
}
871873

daemons/controld/controld_execd.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,8 @@ lrmd_rsc_info_t *controld_execd_state_get_rsc_info(lrm_state_t *lrm_state,
151151
int controld_execd_state_register_rsc(lrm_state_t *lrm_state,
152152
const char *rsc_id, const char *class,
153153
const char *provider, const char *agent);
154-
int lrm_state_unregister_rsc(lrm_state_t *lrm_state, const char *rsc_id);
154+
int controld_execd_state_unregister_rsc(lrm_state_t *lrm_state,
155+
const char *rsc_id);
155156

156157
// Functions used to manage remote executor connection resources
157158
void remote_lrm_op_callback(lrmd_event_data_t * op);

daemons/controld/controld_execd_state.c

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,27 +1007,44 @@ controld_execd_state_register_rsc(lrm_state_t *lrm_state, const char *rsc_id,
10071007
return pcmk_legacy2rc(rc);
10081008
}
10091009

1010+
/*!
1011+
* \internal
1012+
* \brief Unegister a resource with the executor via a given state object
1013+
*
1014+
* If \p rsc_id is the name of a remote connection resource, remove the executor
1015+
* state object for node \p rsc_id from the state table.
1016+
*
1017+
* Otherwise, remove the \p lrm_state resource info cache entry for \p rsc_id,
1018+
* and send an unregister request to the executor for \p rsc_id.
1019+
*
1020+
* \param[in,out] lrm_state Executor state
1021+
* \param[in] rsc_id Resource ID
1022+
*
1023+
* \return Standard Pacemaker return code
1024+
*
1025+
* \todo This function probably shouldn't handle remote connection resources,
1026+
* since it doesn't unregister a resource in that case.
1027+
*/
10101028
int
1011-
lrm_state_unregister_rsc(lrm_state_t *lrm_state, const char *rsc_id)
1029+
controld_execd_state_unregister_rsc(lrm_state_t *lrm_state, const char *rsc_id)
10121030
{
1031+
int rc = pcmk_rc_ok;
1032+
10131033
pcmk__assert(lrm_state != NULL);
10141034

10151035
if (lrm_state->conn == NULL) {
1016-
return -ENOTCONN;
1036+
return ENOTCONN;
10171037
}
10181038

10191039
if (is_remote_lrmd_ra(rsc_id)) {
10201040
g_hash_table_remove(lrm_state_table, rsc_id);
1021-
return pcmk_ok;
1041+
return pcmk_rc_ok;
10221042
}
10231043

10241044
g_hash_table_remove(lrm_state->rsc_info_cache, rsc_id);
10251045

1026-
/* @TODO Optimize this ... this function is a blocking round trip from
1027-
* client to daemon. The controld_execd_state.c code path that uses this
1028-
* function should always treat it as an async operation. The executor API
1029-
* should make an async version available.
1030-
*/
1031-
return lrm_state->conn->cmds->unregister_rsc(lrm_state->conn, rsc_id,
1032-
lrmd_opt_none);
1046+
// @TODO Implement an asynchronous version of this
1047+
rc = lrm_state->conn->cmds->unregister_rsc(lrm_state->conn, rsc_id,
1048+
lrmd_opt_none);
1049+
return pcmk_legacy2rc(rc);
10331050
}

0 commit comments

Comments
 (0)