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

Best practices for a few scheduler functions #3779

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
d236a95
Refactor: libcrmcommon,libpe_status: best practices for get_effective…
kgaillot Nov 8, 2024
1d02191
Refactor: scheduler: add pcmk__set_scheduler_defaults()
kgaillot Nov 11, 2024
8ce7a55
Refactor: libcrmcommon,libpe_status: move deferred parameter check APIs
kgaillot Nov 12, 2024
b239fd2
Refactor: scheduler: add pcmk__free_resource()
kgaillot Nov 12, 2024
1c4baa8
Refactor: scheduler: replace pe_free_nodes()
kgaillot Nov 12, 2024
b428a36
Refactor: scheduler: replace pe__free_ordering()
kgaillot Nov 12, 2024
7140050
Refactor: scheduler: replace pe__free_location()
kgaillot Nov 12, 2024
430d020
Refactor: scheduler: replace pe_free_action()
kgaillot Nov 12, 2024
85092bb
API: libcrmcommon: add pcmk_reset_scheduler()
kgaillot Nov 11, 2024
68e79b9
API: libpe_status: deprecate pe_reset_working_set()
kgaillot Nov 12, 2024
4854118
API: libpe_status: deprecate cleanup_calculations()
kgaillot Nov 12, 2024
7413200
API: libpe_status: deprecate set_working_set_defaults()
kgaillot Nov 12, 2024
8332f4a
API: libcrmcommon: add pcmk_new_scheduler()
kgaillot Nov 12, 2024
55b0d49
API: libpe_status: deprecate pe_new_working_set()
kgaillot Nov 12, 2024
7baff2b
API: libcrmcommon: add pcmk_free_scheduler()
kgaillot Nov 12, 2024
42dbbf5
API: libpe_status: deprecate pe_free_working_set()
kgaillot Nov 12, 2024
e4414d8
Refactor: scheduler: replace last usage of "working set" terminology
kgaillot Nov 12, 2024
9822d66
Refactor: libpe_status: move pe__update_recheck_time() to libcrmcommon
kgaillot Nov 12, 2024
4e85b3e
Test: libcrmcommon: add unit tests for pcmk__update_recheck_time()
kgaillot Nov 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions daemons/execd/cts-exec-helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ generate_params(void)
}

// Calculate cluster status
scheduler = pe_new_working_set();
scheduler = pcmk_new_scheduler();
if (scheduler == NULL) {
crm_crit("Could not allocate scheduler data");
return ENOMEM;
Expand All @@ -484,7 +484,7 @@ generate_params(void)
|pcmk_rsc_match_basename);
if (rsc == NULL) {
crm_err("Resource does not exist in config");
pe_free_working_set(scheduler);
pcmk_free_scheduler(scheduler);
return EINVAL;
}

Expand All @@ -511,7 +511,7 @@ generate_params(void)
}
g_hash_table_destroy(meta);

pe_free_working_set(scheduler);
pcmk_free_scheduler(scheduler);
return rc;
}

Expand Down
6 changes: 3 additions & 3 deletions daemons/fenced/fenced_scheduler.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fenced_scheduler_init(void)
return rc;
}

scheduler = pe_new_working_set();
scheduler = pcmk_new_scheduler();
if (scheduler == NULL) {
pcmk__output_free(logger);
return ENOMEM;
Expand Down Expand Up @@ -95,7 +95,7 @@ fenced_scheduler_cleanup(void)
pcmk__output_free(logger);
scheduler->priv->out = NULL;
}
pe_free_working_set(scheduler);
pcmk_free_scheduler(scheduler);
scheduler = NULL;
}
}
Expand Down Expand Up @@ -250,5 +250,5 @@ fenced_scheduler_run(xmlNode *cib)
NULL);

scheduler->input = NULL; // Wasn't a copy, so don't let API free it
pe_reset_working_set(scheduler);
pcmk_reset_scheduler(scheduler);
}
8 changes: 4 additions & 4 deletions daemons/schedulerd/schedulerd_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
static GHashTable *schedulerd_handlers = NULL;

static pcmk_scheduler_t *
init_working_set(void)
init_scheduler(void)
{
pcmk_scheduler_t *scheduler = pe_new_working_set();
pcmk_scheduler_t *scheduler = pcmk_new_scheduler();

pcmk__mem_assert(scheduler);
scheduler->priv->out = logger_out;
Expand Down Expand Up @@ -66,7 +66,7 @@ handle_pecalc_request(pcmk__request_t *request)
xmlNode *reply = NULL;
bool is_repoke = false;
bool process = true;
pcmk_scheduler_t *scheduler = init_working_set();
pcmk_scheduler_t *scheduler = init_scheduler();

pcmk__ipc_send_ack(request->ipc_client, request->ipc_id, request->ipc_flags,
PCMK__XE_ACK, NULL, CRM_EX_INDETERMINATE);
Expand Down Expand Up @@ -165,7 +165,7 @@ handle_pecalc_request(pcmk__request_t *request)

done:
pcmk__xml_free(converted);
pe_free_working_set(scheduler);
pcmk_free_scheduler(scheduler);

return reply;
}
Expand Down
3 changes: 3 additions & 0 deletions include/crm/common/action_relation_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#include <stdbool.h> // bool
#include <stdint.h> // uint32_t
#include <glib.h> // gpointer
#include <crm/common/scheduler_types.h> // pcmk_resource_t, pcmk_action_t

#ifdef __cplusplus
Expand Down Expand Up @@ -181,6 +182,8 @@ typedef struct pcmk__related_action {
#flags_to_clear); \
} while (0)

void pcmk__free_action_relation(gpointer user_data);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions include/crm/common/actions_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ struct pcmk__action {
GList *actions_after;
};

void pcmk__free_action(gpointer user_data);
char *pcmk__op_key(const char *rsc_id, const char *op_type, guint interval_ms);
char *pcmk__notify_key(const char *rsc_id, const char *notify_type,
const char *op_type);
Expand Down
4 changes: 3 additions & 1 deletion include/crm/common/location_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#ifndef PCMK__CRM_COMMON_LOCATION_INTERNAL__H
#define PCMK__CRM_COMMON_LOCATION_INTERNAL__H

#include <glib.h> // GList
#include <glib.h> // gpointer, GList

#include <crm/common/nodes_internal.h> // enum pcmk__probe_mode
#include <crm/common/resources.h> // enum rsc_role_e
Expand All @@ -29,6 +29,8 @@ typedef struct {
GList *nodes; // Copies of affected nodes, with score
} pcmk__location_t;

void pcmk__free_location(gpointer user_data);

#ifdef __cplusplus
}
#endif
Expand Down
4 changes: 3 additions & 1 deletion include/crm/common/nodes_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include <stdbool.h> // bool
#include <stdint.h> // uint32_t, UINT32_C()

#include <glib.h>
#include <glib.h> // gpointer, GList, GHashTable
#include <crm/common/nodes.h>

#ifdef __cplusplus
Expand Down Expand Up @@ -152,6 +152,8 @@ pcmk_node_t *pcmk__find_node_in_list(const GList *nodes, const char *node_name);
(node)->priv->flags, (flags_to_clear), #flags_to_clear); \
} while (0)

void pcmk__free_node(gpointer user_data);

/*!
* \internal
* \brief Return a string suitable for logging as a node name
Expand Down
3 changes: 2 additions & 1 deletion include/crm/common/resources_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define PCMK__CRM_COMMON_RESOURCES_INTERNAL__H

#include <stdint.h> // uint32_t
#include <glib.h> // gboolean, guint, GHashTable, GList
#include <glib.h> // gboolean, gpointer, guint, etc.
#include <libxml/tree.h> // xmlNode

#include <crm/common/resources.h> // pcmk_resource_t
Expand Down Expand Up @@ -442,6 +442,7 @@ struct pcmk__resource_private {
const pcmk__assignment_methods_t *cmds; // Resource assignment methods
};

void pcmk__free_resource(gpointer user_data);
const char *pcmk__multiply_active_text(const pcmk_resource_t *rsc);

/*!
Expand Down
4 changes: 4 additions & 0 deletions include/crm/common/scheduler.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ struct pcmk__scheduler {
pcmk__scheduler_private_t *priv; //!< \internal For Pacemaker use only
};

pcmk_scheduler_t *pcmk_new_scheduler(void);
void pcmk_reset_scheduler(pcmk_scheduler_t *scheduler);
void pcmk_free_scheduler(pcmk_scheduler_t *scheduler);

pcmk_node_t *pcmk_get_dc(const pcmk_scheduler_t *scheduler);
enum pe_quorum_policy pcmk_get_no_quorum_policy(const pcmk_scheduler_t
*scheduler);
Expand Down
14 changes: 14 additions & 0 deletions include/crm/common/scheduler_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,20 @@ extern uint32_t pcmk__warnings;
(scheduler)->flags, (flags_to_clear), #flags_to_clear); \
} while (0)

void pcmk__set_scheduler_defaults(pcmk_scheduler_t *scheduler);
time_t pcmk__scheduler_epoch_time(pcmk_scheduler_t *scheduler);
void pcmk__update_recheck_time(time_t recheck, pcmk_scheduler_t *scheduler,
const char *reason);

void pcmk__add_param_check(const xmlNode *rsc_op, pcmk_resource_t *rsc,
pcmk_node_t *node, enum pcmk__check_parameters,
pcmk_scheduler_t *scheduler);
void pcmk__foreach_param_check(pcmk_scheduler_t *scheduler,
void (*cb)(pcmk_resource_t*, pcmk_node_t*,
const xmlNode*,
enum pcmk__check_parameters));
void pcmk__free_param_checks(pcmk_scheduler_t *scheduler);

#ifdef __cplusplus
}
#endif
Expand Down
13 changes: 0 additions & 13 deletions include/crm/pengine/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ void pe__count_bundle(pcmk_resource_t *rsc);
void common_free(pcmk_resource_t *rsc);

pcmk_node_t *pe__copy_node(const pcmk_node_t *this_node);
time_t get_effective_time(pcmk_scheduler_t *scheduler);

/* Failure handling utilities (from failcounts.c) */

Expand Down Expand Up @@ -231,8 +230,6 @@ GList *find_actions_exact(GList *input, const char *key,
GList *pe__resource_actions(const pcmk_resource_t *rsc, const pcmk_node_t *node,
const char *task, bool require_node);

extern void pe_free_action(pcmk_action_t *action);

void resource_location(pcmk_resource_t *rsc, const pcmk_node_t *node, int score,
const char *tag, pcmk_scheduler_t *scheduler);

Expand Down Expand Up @@ -336,18 +333,8 @@ const char *pe__add_bundle_remote_name(pcmk_resource_t *rsc, xmlNode *xml,
const char *field);
bool pe__is_universal_clone(const pcmk_resource_t *rsc,
const pcmk_scheduler_t *scheduler);
void pe__add_param_check(const xmlNode *rsc_op, pcmk_resource_t *rsc,
pcmk_node_t *node, enum pcmk__check_parameters,
pcmk_scheduler_t *scheduler);
void pe__foreach_param_check(pcmk_scheduler_t *scheduler,
void (*cb)(pcmk_resource_t*, pcmk_node_t*,
const xmlNode*,
enum pcmk__check_parameters));
void pe__free_param_checks(pcmk_scheduler_t *scheduler);

bool pe__shutdown_requested(const pcmk_node_t *node);
void pe__update_recheck_time(time_t recheck, pcmk_scheduler_t *scheduler,
const char *reason);

/*!
* \internal
Expand Down
12 changes: 0 additions & 12 deletions include/crm/pengine/status.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ const char *rsc_printable_id(const pcmk_resource_t *rsc);
// NOTE: sbd (as of at least 1.5.2) uses this
gboolean cluster_status(pcmk_scheduler_t *scheduler);

// NOTE: sbd (as of at least 1.5.2) uses this
pcmk_scheduler_t *pe_new_working_set(void);

// NOTE: sbd (as of at least 1.5.2) uses this
void pe_free_working_set(pcmk_scheduler_t *scheduler);

void set_working_set_defaults(pcmk_scheduler_t *scheduler);
void cleanup_calculations(pcmk_scheduler_t *scheduler);

// NOTE: sbd (as of at least 1.5.2) uses this
void pe_reset_working_set(pcmk_scheduler_t *scheduler);

pcmk_resource_t *pe_find_resource(GList *rsc_list, const char *id);
pcmk_resource_t *pe_find_resource_with_flags(GList *rsc_list, const char *id,
enum pe_find flags);
Expand Down
18 changes: 18 additions & 0 deletions include/crm/pengine/status_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,24 @@ extern "C" {
* release.
*/

// NOTE: sbd (as of at least 1.5.2) uses this
//! \deprecated Use pcmk_new_scheduler() instead
pcmk_scheduler_t *pe_new_working_set(void);

// NOTE: sbd (as of at least 1.5.2) uses this
//! \deprecated Use pcmk_reset_scheduler() instead
void pe_reset_working_set(pcmk_scheduler_t *scheduler);

//! \deprecated Use pcmk_reset_scheduler() instead
void cleanup_calculations(pcmk_scheduler_t *scheduler);

//! \deprecated Use pcmk_reset_scheduler() instead
void set_working_set_defaults(pcmk_scheduler_t *scheduler);

// NOTE: sbd (as of at least 1.5.2) uses this
//! \deprecated Use pcmk_free_scheduler() instead
void pe_free_working_set(pcmk_scheduler_t *scheduler);

// NOTE: sbd (as of at least 1.5.2) uses this
//! \deprecated Use pcmk_find_node() with scheduler object instead
pcmk_node_t *pe_find_node(const GList *node_list, const char *node_name);
Expand Down
2 changes: 2 additions & 0 deletions lib/common/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ endif
## Library sources (*must* use += format for bumplibs)
libcrmcommon_la_SOURCES =
libcrmcommon_la_SOURCES += acl.c
libcrmcommon_la_SOURCES += action_relation.c
libcrmcommon_la_SOURCES += actions.c
libcrmcommon_la_SOURCES += agents.c
libcrmcommon_la_SOURCES += alerts.c
Expand All @@ -68,6 +69,7 @@ libcrmcommon_la_SOURCES += ipc_schedulerd.c
libcrmcommon_la_SOURCES += ipc_server.c
libcrmcommon_la_SOURCES += iso8601.c
libcrmcommon_la_SOURCES += lists.c
libcrmcommon_la_SOURCES += location.c
libcrmcommon_la_SOURCES += logging.c
libcrmcommon_la_SOURCES += mainloop.c
libcrmcommon_la_SOURCES += messages.c
Expand Down
31 changes: 31 additions & 0 deletions lib/common/action_relation.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/

#include <crm_internal.h>

#include <stdlib.h> // free()
#include <glib.h> // gpointer

#include <crm/common/scheduler.h>

/*!
* \internal
* \brief Free an action relation
*
* \param[in,out] user_data Action relation to free
*/
void
pcmk__free_action_relation(gpointer user_data)
{
pcmk__action_relation_t *relation = user_data;

free(relation->task1);
free(relation->task2);
free(relation);
}
30 changes: 30 additions & 0 deletions lib/common/actions.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,36 @@ pcmk__on_fail_text(enum pcmk__on_fail on_fail)
return "<unknown>";
}

/*!
* \internal
* \brief Free an action object
*
* \param[in,out] user_data Action object to free
*/
void
pcmk__free_action(gpointer user_data)
{
pcmk_action_t *action = user_data;

if (action == NULL) {
return;
}
g_list_free_full(action->actions_before, free);
g_list_free_full(action->actions_after, free);
if (action->extra != NULL) {
g_hash_table_destroy(action->extra);
}
if (action->meta != NULL) {
g_hash_table_destroy(action->meta);
}
pcmk__free_node_copy(action->node);
free(action->cancel_task);
free(action->reason);
free(action->task);
free(action->uuid);
free(action);
}

/*!
* \brief Generate an operation key (RESOURCE_ACTION_INTERVAL)
*
Expand Down
31 changes: 31 additions & 0 deletions lib/common/location.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright 2024 the Pacemaker project contributors
*
* The version control history for this file may have further details.
*
* This source code is licensed under the GNU Lesser General Public License
* version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
*/

#include <crm_internal.h>

#include <stdlib.h> // free()
#include <glib.h> // gpointer, g_list_free_full()

#include <crm/common/scheduler.h>

/*!
* \internal
* \brief Free a location constraint
*
* \param[in,out] user_data Location constraint to free
*/
void
pcmk__free_location(gpointer user_data)
{
pcmk__location_t *location = user_data;

g_list_free_full(location->nodes, pcmk__free_node_copy);
free(location->id);
free(location);
}
Loading