summaryrefslogtreecommitdiffstats
path: root/include/crm/common/ipc_attrd_internal.h
blob: b1b7584bd0e5e31dc6a6d6a839ce34120704b0d3 (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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 * Copyright 2022-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__CRM_COMMON_IPC_ATTRD_INTERNAL__H
#  define PCMK__CRM_COMMON_IPC_ATTRD_INTERNAL__H

#include <glib.h>            // GList
#include <crm/common/ipc.h>  // pcmk_ipc_api_t

#ifdef __cplusplus
extern "C" {
#endif

//! Possible types of attribute manager replies
enum pcmk__attrd_api_reply {
    pcmk__attrd_reply_unknown,
    pcmk__attrd_reply_query,
};

// Information passed with pcmk__attrd_reply_query
typedef struct {
    const char *node;
    const char *name;
    const char *value;
} pcmk__attrd_query_pair_t;

/*!
 * Attribute manager reply passed to event callback
 *
 * \note The pointers in the reply are only guaranteed to be meaningful for the
 *       execution of the callback; if the values are needed for later, the
 *       callback should copy them.
 */
typedef struct {
    enum pcmk__attrd_api_reply reply_type;

    union {
        // pcmk__attrd_reply_query
        GList *pairs;
    } data;
} pcmk__attrd_api_reply_t;

/*!
 * \internal
 * \brief Send a request to pacemaker-attrd to clear resource failure
 *
 * \param[in,out] api           pacemaker-attrd IPC object
 * \param[in]     node          Affect only this node (or NULL for all nodes)
 * \param[in]     resource      Name of resource to clear (or NULL for all)
 * \param[in]     operation     Name of operation to clear (or NULL for all)
 * \param[in]     interval_spec If operation is not NULL, its interval
 * \param[in]     user_name     ACL user to pass to pacemaker-attrd
 * \param[in]     options       Bitmask of pcmk__node_attr_opts
 *
 * \note If \p api is NULL, a new temporary connection will be created
 *       just for this operation and destroyed afterwards.  If \p api is
 *       not NULL but is not yet connected to pacemaker-attrd, the object
 *       will be connected for this operation and left connected afterwards.
 *       This allows for reusing an IPC connection.
 *
 * \return Standard Pacemaker return code
 */
int pcmk__attrd_api_clear_failures(pcmk_ipc_api_t *api, const char *node,
                                   const char *resource, const char *operation,
                                   const char *interval_spec, const char *user_name,
                                   uint32_t options);

/*!
 * \internal
 *
 * \brief Delete a previously set attribute by setting its value to NULL
 *
 * \param[in,out] api      Connection to pacemaker-attrd (or NULL to use
 *                         a temporary new connection)
 * \param[in]     node     Delete attribute for this node (or NULL for local)
 * \param[in]     name     Attribute name
 * \param[in]     options  Bitmask of pcmk__node_attr_opts
 *
 * \return Standard Pacemaker return code
 */
int pcmk__attrd_api_delete(pcmk_ipc_api_t *api, const char *node, const char *name,
                           uint32_t options);

/*!
 * \internal
 * \brief Purge a node from pacemaker-attrd
 *
 * \param[in,out] api           pacemaker-attrd IPC object
 * \param[in]     node          Node to remove
 *
 * \note If \p api is NULL, a new temporary connection will be created
 *       just for this operation and destroyed afterwards.  If \p api is
 *       not NULL but is not yet connected to pacemaker-attrd, the object
 *       will be connected for this operation and left connected afterwards.
 *       This allows for reusing an IPC connection.
 *
 * \return Standard Pacemaker return code
 */
int pcmk__attrd_api_purge(pcmk_ipc_api_t *api, const char *node);

/*!
 * \internal
 * \brief Get the value of an attribute from pacemaker-attrd
 *
 * \param[in,out] api           Connection to pacemaker-attrd
 * \param[in]     node          Look up the attribute for this node
 *                              (or NULL for the local node)
 * \param[in]     name          Attribute name
 * \param[in]     options       Bitmask of pcmk__node_attr_opts
 *
 * \note Passing pcmk__node_attr_query_all will cause the function to query
 *       the value of \p name on all nodes, regardless of the value of \p node.
 *
 * \return Standard Pacemaker return code
 */
int pcmk__attrd_api_query(pcmk_ipc_api_t *api, const char *node, const char *name,
                          uint32_t options);

/*!
 * \internal
 * \brief Tell pacemaker-attrd to update the CIB with current values
 *
 * \param[in,out] api   pacemaker-attrd IPC object
 * \param[in]     node  Affect only this node (or NULL for all nodes)
 *
 * \note If \p api is NULL, a new temporary connection will be created
 *       just for this operation and destroyed afterwards.  If \p api is
 *       not NULL but is not yet connected to pacemaker-attrd, the object
 *       will be connected for this operation and left connected afterwards.
 *       This allows for reusing an IPC connection.
 *
 * \return Standard Pacemaker return code
 */
int pcmk__attrd_api_refresh(pcmk_ipc_api_t *api, const char *node);

/*!
 * \internal
 * \brief Update an attribute's value, time to wait, or both
 *
 * \param[in,out] api        pacemaker-attrd IPC object
 * \param[in]     node       Affect only this node (or NULL for current node)
 * \param[in]     name       Attribute name
 * \param[in]     value      The attribute's new value, or NULL to unset
 * \param[in]     dampen     The new time to wait value, or NULL to unset
 * \param[in]     set        ID of attribute set to use (or NULL for first)
 * \param[in]     user_name  ACL user to pass to pacemaker-attrd
 * \param[in]     options    Bitmask of pcmk__node_attr_opts
 *
 * \note If \p api is NULL, a new temporary connection will be created
 *       just for this operation and destroyed afterwards.  If \p api is
 *       not NULL but is not yet connected to pacemaker-attrd, the object
 *       will be connected for this operation and left connected afterwards.
 *       This allows for reusing an IPC connection.
 *
 * \return Standard Pacemaker return code
 */
int pcmk__attrd_api_update(pcmk_ipc_api_t *api, const char *node, const char *name,
                           const char *value, const char *dampen, const char *set,
                           const char *user_name, uint32_t options);

/*!
 * \internal
 * \brief Like pcmk__attrd_api_update, but for multiple attributes at once
 *
 * \param[in,out] api        pacemaker-attrd IPC object
 * \param[in,out] attrs      A list of pcmk__attr_query_pair_t structs
 * \param[in]     dampen     The new time to wait value, or NULL to unset
 * \param[in]     set        ID of attribute set to use (or NULL for first)
 * \param[in]     user_name  ACL user to pass to pacemaker-attrd
 * \param[in]     options    Bitmask of pcmk__node_attr_opts
 *
 * \note If \p api is NULL, a new temporary connection will be created
 *       just for this operation and destroyed afterwards.  If \p api is
 *       not NULL but is not yet connected to pacemaker-attrd, the object
 *       will be connected for this operation and left connected afterwards.
 *       This allows for reusing an IPC connection.
 *
 * \note Not all attrd versions support setting multiple attributes at once.
 *       For those servers that do not, this function will fall back to just
 *       sending a separate IPC request for each attribute.
 *
 * \return Standard Pacemaker return code
 */
int pcmk__attrd_api_update_list(pcmk_ipc_api_t *api, GList *attrs,
                                const char *dampen, const char *set,
                                const char *user_name, uint32_t options);

#ifdef __cplusplus
}
#endif

#endif // PCMK__CRM_COMMON_IPC_ATTRD_INTERNAL__H