pacemaker  2.0.2-debe490
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2015-2019 the Pacemaker project contributors
3  *
4  * The version control history for this file may have further details.
5  *
6  * This source code is licensed under the GNU Lesser General Public License
7  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8  */
9 
10 #ifndef CRM_COMMON_INTERNAL__H
11 #define CRM_COMMON_INTERNAL__H
12 
13 #include <glib.h> /* for gboolean */
14 #include <dirent.h> /* for struct dirent */
15 #include <unistd.h> /* for getpid() */
16 #include <sys/types.h> /* for uid_t and gid_t */
17 
18 #include <crm/common/logging.h>
19 
20 /* internal I/O utilities (from io.c) */
21 
22 char *generate_series_filename(const char *directory, const char *series, int sequence,
23  gboolean bzip);
24 int get_last_sequence(const char *directory, const char *series);
25 void write_last_sequence(const char *directory, const char *series, int sequence, int max);
26 int crm_chown_last_sequence(const char *directory, const char *series, uid_t uid, gid_t gid);
27 
28 bool pcmk__daemon_can_write(const char *dir, const char *file);
29 void crm_sync_directory(const char *name);
30 
31 char *crm_read_contents(const char *filename);
32 int crm_write_sync(int fd, const char *contents);
33 int crm_set_nonblocking(int fd);
34 const char *crm_get_tmpdir(void);
35 
36 
37 /* internal procfs utilities (from procfs.c) */
38 
39 int crm_procfs_process_info(struct dirent *entry, char *name, int *pid);
40 int crm_procfs_pid_of(const char *name);
41 unsigned int crm_procfs_num_cores(void);
42 
43 
44 /* internal XML schema functions (from xml.c) */
45 
46 void crm_schema_init(void);
47 void crm_schema_cleanup(void);
48 
49 
50 /* internal functions related to process IDs (from pid.c) */
51 
72 int crm_pid_active(long pid, const char *daemon);
73 
74 long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon);
75 long crm_read_pidfile(const char *filename);
76 int crm_lock_pidfile(const char *filename, const char *name);
77 
78 
79 /* interal functions related to resource operations (from operations.c) */
80 
81 char *generate_op_key(const char *rsc_id, const char *op_type,
82  guint interval_ms);
83 char *generate_notify_key(const char *rsc_id, const char *notify_type,
84  const char *op_type);
85 char *generate_transition_key(int action, int transition_id, int target_rc,
86  const char *node);
87 void filter_action_parameters(xmlNode *param_set, const char *version);
88 xmlNode *create_operation_update(xmlNode *parent, lrmd_event_data_t *event,
89  const char *caller_version, int target_rc,
90  const char *node, const char *origin,
91  int level);
92 
93 
94 // miscellaneous utilities (from utils.c)
95 
96 const char *pcmk_message_name(const char *name);
97 
98 
99 /* internal generic string functions (from strings.c) */
100 
101 long long crm_int_helper(const char *text, char **end_text);
102 guint crm_parse_ms(const char *text);
103 bool crm_starts_with(const char *str, const char *prefix);
104 gboolean crm_ends_with(const char *s, const char *match);
105 gboolean crm_ends_with_ext(const char *s, const char *match);
106 char *add_list_element(char *list, const char *value);
107 bool crm_compress_string(const char *data, int length, int max, char **result,
108  unsigned int *result_len);
109 gint crm_alpha_sort(gconstpointer a, gconstpointer b);
110 
111 static inline char *
112 crm_concat(const char *prefix, const char *suffix, char join)
113 {
114  CRM_ASSERT(prefix && suffix);
115  return crm_strdup_printf("%s%c%s", prefix, join, suffix);
116 }
117 
118 static inline int
119 crm_strlen_zero(const char *s)
120 {
121  return !s || *s == '\0';
122 }
123 
124 static inline char *
125 crm_getpid_s()
126 {
127  return crm_strdup_printf("%lu", (unsigned long) getpid());
128 }
129 
130 /* convenience functions for failure-related node attributes */
131 
132 #define CRM_FAIL_COUNT_PREFIX "fail-count"
133 #define CRM_LAST_FAILURE_PREFIX "last-failure"
134 
152 static inline char *
153 crm_fail_attr_name(const char *prefix, const char *rsc_id, const char *op,
154  guint interval_ms)
155 {
156  CRM_CHECK(prefix && rsc_id && op, return NULL);
157  return crm_strdup_printf("%s-%s#%s_%u", prefix, rsc_id, op, interval_ms);
158 }
159 
160 static inline char *
161 crm_failcount_name(const char *rsc_id, const char *op, guint interval_ms)
162 {
163  return crm_fail_attr_name(CRM_FAIL_COUNT_PREFIX, rsc_id, op, interval_ms);
164 }
165 
166 static inline char *
167 crm_lastfailure_name(const char *rsc_id, const char *op, guint interval_ms)
168 {
169  return crm_fail_attr_name(CRM_LAST_FAILURE_PREFIX, rsc_id, op, interval_ms);
170 }
171 
172 #endif /* CRM_COMMON_INTERNAL__H */
#define CRM_CHECK(expr, failure_action)
Definition: logging.h:156
const char * crm_get_tmpdir(void)
Definition: io.c:500
void crm_schema_init(void)
Definition: schemas.c:374
int crm_lock_pidfile(const char *filename, const char *name)
Definition: pid.c:168
int get_last_sequence(const char *directory, const char *series)
Definition: io.c:102
#define CRM_LAST_FAILURE_PREFIX
Definition: internal.h:133
long long crm_int_helper(const char *text, char **end_text)
Definition: strings.c:34
void crm_schema_cleanup(void)
Definition: schemas.c:546
uint32_t pid
Definition: internal.h:83
char * generate_series_filename(const char *directory, const char *series, int sequence, gboolean bzip)
Definition: io.c:75
bool crm_starts_with(const char *str, const char *prefix)
Check whether a string starts with a certain sequence.
Definition: strings.c:259
Wrappers for and extensions to libqb logging.
char * crm_read_contents(const char *filename)
Definition: io.c:410
char * generate_transition_key(int action, int transition_id, int target_rc, const char *node)
Definition: operations.c:201
int daemon(int nochdir, int noclose)
#define CRM_FAIL_COUNT_PREFIX
Definition: internal.h:132
char * add_list_element(char *list, const char *value)
Definition: strings.c:408
const char * pcmk_message_name(const char *name)
Get name to be used as identifier for cluster messages.
Definition: utils.c:1100
gint crm_alpha_sort(gconstpointer a, gconstpointer b)
Compare two strings alphabetically (case-insensitive)
Definition: strings.c:489
xmlNode * create_operation_update(xmlNode *parent, lrmd_event_data_t *event, const char *caller_version, int target_rc, const char *node, const char *origin, int level)
Definition: operations.c:440
int crm_set_nonblocking(int fd)
Definition: io.c:486
bool pcmk__daemon_can_write(const char *dir, const char *file)
Definition: io.c:305
char * generate_notify_key(const char *rsc_id, const char *notify_type, const char *op_type)
Definition: operations.c:128
long crm_pidfile_inuse(const char *filename, long mypid, const char *daemon)
Definition: pid.c:141
gboolean crm_ends_with_ext(const char *s, const char *match)
Definition: strings.c:338
gboolean crm_ends_with(const char *s, const char *match)
Definition: strings.c:309
int crm_procfs_process_info(struct dirent *entry, char *name, int *pid)
Definition: procfs.c:39
int crm_pid_active(long pid, const char *daemon)
Definition: pid.c:23
void write_last_sequence(const char *directory, const char *series, int sequence, int max)
Definition: io.c:168
bool crm_compress_string(const char *data, int length, int max, char **result, unsigned int *result_len)
Definition: strings.c:427
guint crm_parse_ms(const char *text)
Definition: strings.c:143
unsigned int crm_procfs_num_cores(void)
Definition: procfs.c:144
#define CRM_ASSERT(expr)
Definition: results.h:42
int crm_write_sync(int fd, const char *contents)
Definition: io.c:456
char data[0]
Definition: internal.h:92
int crm_chown_last_sequence(const char *directory, const char *series, uid_t uid, gid_t gid)
Definition: io.c:217
void filter_action_parameters(xmlNode *param_set, const char *version)
Definition: operations.c:270
void crm_sync_directory(const char *name)
Definition: io.c:373
int crm_procfs_pid_of(const char *name)
Definition: procfs.c:110
char * crm_strdup_printf(char const *format,...) __attribute__((__format__(__printf__
char * generate_op_key(const char *rsc_id, const char *op_type, guint interval_ms)
Generate an operation key.
Definition: operations.c:39
uint32_t version
Definition: remote.c:146
long crm_read_pidfile(const char *filename)
Definition: pid.c:103