summaryrefslogtreecommitdiffstats
path: root/daemons/controld/controld_cib.h
blob: dcc5a48db013c8bc72f82b37563071b680e21d19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/*
 * Copyright 2004-2023 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.
 */

#ifndef PCMK__CONTROLD_CIB__H
#define PCMK__CONTROLD_CIB__H

#include <crm_internal.h>

#include <glib.h>

#include <crm/crm.h>
#include <crm/common/xml.h>
#include <crm/cib/internal.h>   // PCMK__CIB_REQUEST_MODIFY
#include "controld_globals.h"   // controld_globals.cib_conn

static inline void
fsa_cib_anon_update(const char *section, xmlNode *data) {
    if (controld_globals.cib_conn == NULL) {
        crm_err("No CIB connection available");
    } else {
        controld_globals.cib_conn->cmds->modify(controld_globals.cib_conn,
                                                section, data,
                                                cib_scope_local|cib_can_create);
    }
}

static inline void
fsa_cib_anon_update_discard_reply(const char *section, xmlNode *data) {
    if (controld_globals.cib_conn == NULL) {
        crm_err("No CIB connection available");
    } else {
        controld_globals.cib_conn->cmds->modify(controld_globals.cib_conn,
                                                section, data,
                                                cib_scope_local
                                                |cib_can_create
                                                |cib_discard_reply);
    }
}

int controld_update_cib(const char *section, xmlNode *data, int options,
                        void (*callback)(xmlNode *, int, int, xmlNode *,
                                         void *));
unsigned int cib_op_timeout(void);

// Subsections of node_state
enum controld_section_e {
    controld_section_lrm,
    controld_section_lrm_unlocked,
    controld_section_attrs,
    controld_section_all,
    controld_section_all_unlocked
};

void controld_node_state_deletion_strings(const char *uname,
                                          enum controld_section_e section,
                                          char **xpath, char **desc);
void controld_delete_node_state(const char *uname,
                                enum controld_section_e section, int options);
int controld_delete_resource_history(const char *rsc_id, const char *node,
                                     const char *user_name, int call_options);

/* Convenience macro for registering a CIB callback
 * (assumes that data can be freed with free())
 */
#  define fsa_register_cib_callback(id, data, fn) do {                      \
    cib_t *cib_conn = controld_globals.cib_conn;                            \
                                                                            \
    CRM_ASSERT(cib_conn != NULL);                                           \
    cib_conn->cmds->register_callback_full(cib_conn, id, cib_op_timeout(),  \
                                           FALSE, data, #fn, fn, free);     \
    } while(0)

void controld_add_resource_history_xml_as(const char *func, xmlNode *parent,
                                          const lrmd_rsc_info_t *rsc,
                                          lrmd_event_data_t *op,
                                          const char *node_name);

#define controld_add_resource_history_xml(parent, rsc, op, node_name)   \
    controld_add_resource_history_xml_as(__func__, (parent), (rsc),     \
                                         (op), (node_name))

bool controld_record_pending_op(const char *node_name,
                                const lrmd_rsc_info_t *rsc,
                                lrmd_event_data_t *op);

void controld_update_resource_history(const char *node_name,
                                      const lrmd_rsc_info_t *rsc,
                                      lrmd_event_data_t *op, time_t lock_time);

void controld_delete_action_history(const lrmd_event_data_t *op);

void controld_cib_delete_last_failure(const char *rsc_id, const char *node,
                                      const char *action, guint interval_ms);

void controld_delete_action_history_by_key(const char *rsc_id, const char *node,
                                           const char *key, int call_id);

void controld_disconnect_cib_manager(void);

int crmd_cib_smart_opt(void);

/*!
 * \internal
 * \brief Check whether an action type should be recorded in the CIB
 *
 * \param[in] action  Action type
 *
 * \return true if action should be recorded, false otherwise
 */
static inline bool
controld_action_is_recordable(const char *action)
{
    return !pcmk__str_any_of(action, PCMK_ACTION_CANCEL, PCMK_ACTION_DELETE,
                             PCMK_ACTION_NOTIFY, PCMK_ACTION_META_DATA, NULL);
}

#endif // PCMK__CONTROLD_CIB__H