]> git.proxmox.com Git - pve-cluster.git/blob - data/src/cfs-utils.h
add pmxcfs restart detection heuristic for IPCC
[pve-cluster.git] / data / src / cfs-utils.h
1 /*
2 Copyright (C) 2010 Proxmox Server Solutions GmbH
3
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU Affero General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Affero General Public License for more details.
13
14 You should have received a copy of the GNU Affero General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 Author: Dietmar Maurer <dietmar@proxmox.com>
18
19 */
20
21 #ifndef _PVE_CFS_UTILS_H_
22 #define _PVE_CFS_UTILS_H_
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif /* HAVE_CONFIG_H */
27
28 #include <stdint.h>
29 #include <glib.h>
30 #include <fcntl.h>
31
32 #define HOST_CLUSTER_CONF_FN "/etc/corosync/corosync.conf"
33 #define CFS_PID_FN "/var/run/pve-cluster.pid"
34 #define VARLIBDIR "/var/lib/pve-cluster"
35 #define RUNDIR "/run/pve-cluster"
36
37 #define CFS_MAX(a, b) (((a) > (b)) ? (a) : (b))
38 #define CFS_MIN(a, b) (((a) < (b)) ? (a) : (b))
39
40 typedef struct {
41 char *nodename;
42 char *ip;
43 gid_t gid;
44 int debug;
45 } cfs_t;
46
47 extern cfs_t cfs;
48
49 void
50 utf8_to_ascii(
51 char *buf,
52 int bufsize,
53 const char *msg,
54 gboolean quotequote);
55
56 void
57 cfs_log(
58 const gchar *log_domain,
59 GLogLevelFlags log_level,
60 const char *file,
61 int line,
62 const char *func,
63 const gchar *format,
64 ...) G_GNUC_PRINTF (6, 7);
65
66 void ipc_log_fn(
67 const char *file,
68 int32_t line,
69 int32_t severity,
70 const char *msg);
71
72
73 #define cfs_debug(...) G_STMT_START { \
74 if (cfs.debug) \
75 cfs_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__); \
76 } G_STMT_END
77
78 #define cfs_dom_debug(domain, ...) G_STMT_START { \
79 if (cfs.debug) \
80 cfs_log(domain, G_LOG_LEVEL_DEBUG, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__); \
81 } G_STMT_END
82
83 #define cfs_critical(...) cfs_log(G_LOG_DOMAIN, G_LOG_LEVEL_CRITICAL, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
84 #define cfs_dom_critical(domain, ...) cfs_log(domain, G_LOG_LEVEL_CRITICAL, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
85 #define cfs_message(...) cfs_log(G_LOG_DOMAIN, G_LOG_LEVEL_MESSAGE, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
86 #define cfs_dom_message(domain, ...) cfs_log(domain, G_LOG_LEVEL_MESSAGE, __FILE__, __LINE__, G_STRFUNC, __VA_ARGS__)
87
88 guint64
89 cluster_config_version(
90 const gpointer config_data,
91 gsize config_length);
92
93 ssize_t
94 safe_read(
95 int fd,
96 char *buf,
97 size_t count);
98
99 gboolean
100 full_write(
101 int fd,
102 const char *buf,
103 size_t len);
104
105 gboolean
106 atomic_write_file(
107 const char *filename,
108 gconstpointer data,
109 size_t len,
110 mode_t mode,
111 gid_t gid);
112
113 gboolean
114 path_is_private(const char *path);
115
116 gboolean
117 path_is_lxc_conf(const char *path);
118
119 gboolean
120 path_is_lockdir(const char *path);
121
122 #endif /* _PVE_CFS_UTILS_H_ */