2 Copyright (C) 2010 Proxmox Server Solutions GmbH
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.
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.
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/>.
17 Author: Dietmar Maurer <dietmar@proxmox.com>
23 #endif /* HAVE_CONFIG_H */
30 #include <sys/types.h>
32 #include <sys/mount.h>
36 #include <sys/types.h>
38 #include <sys/utsname.h>
41 #include <sys/socket.h>
42 #include <netinet/in.h>
43 #include <arpa/inet.h>
45 #include <qb/qbdefs.h>
46 #include <qb/qbutil.h>
49 #include "cfs-utils.h"
51 #include "cfs-plug-memdb.h"
59 #define DBFILENAME VARLIBDIR "/config.db"
60 #define LOCKFILE VARLIBDIR "/.pmxcfs.lockfile"
62 #define CFSDIR "/etc/pve"
68 static struct fuse
*fuse
= NULL
;
70 static cfs_plug_t
*root_plug
;
72 static void glib_print_handler(const gchar
*string
)
77 static void glib_log_handler(const gchar
*log_domain
,
78 GLogLevelFlags log_level
,
83 cfs_log(log_domain
, log_level
, NULL
, 0, NULL
, message
);
86 static gboolean
write_pidfile(pid_t pid
)
88 char *strpid
= g_strdup_printf("%d\n", pid
);
89 gboolean res
= atomic_write_file(CFS_PID_FN
, strpid
, strlen(strpid
), 0644, getgid());
95 static cfs_plug_t
*find_plug(const char *path
, char **sub
)
97 g_return_val_if_fail(root_plug
!= NULL
, NULL
);
98 g_return_val_if_fail(path
!= NULL
, NULL
);
100 while(*path
== '/') path
++;
102 cfs_debug("find_plug start %s", path
);
104 char *tmppath
= g_strdup(path
);
105 char *subpath
= tmppath
;
107 cfs_plug_t
*plug
= root_plug
->lookup_plug(root_plug
, &subpath
);
109 cfs_debug("find_plug end %s = %p (%s)", path
, plug
, subpath
);
111 if (subpath
&& subpath
[0])
112 *sub
= g_strdup(subpath
);
119 void *cfs_fuse_init(struct fuse_conn_info
*conn
)
124 static int cfs_fuse_getattr(const char *path
, struct stat
*stbuf
)
126 cfs_debug("enter cfs_fuse_getattr %s", path
);
130 char *subpath
= NULL
;
131 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
133 if (plug
&& plug
->ops
&& plug
->ops
->getattr
) {
134 ret
= plug
->ops
->getattr(plug
, subpath
? subpath
: "", stbuf
);
136 stbuf
->st_gid
= cfs
.gid
;
138 if (path_is_private(path
)) {
139 stbuf
->st_mode
&= 0777700;
141 if (S_ISDIR(stbuf
->st_mode
) || S_ISLNK(stbuf
->st_mode
)) {
142 stbuf
->st_mode
&= 0777755; // access for other users
144 if (path_is_lxc_conf(path
)) {
145 stbuf
->st_mode
&= 0777755; // access for other users
147 stbuf
->st_mode
&= 0777750; // no access for other users
153 cfs_debug("leave cfs_fuse_getattr %s (%d)", path
, ret
);
162 static int cfs_fuse_readdir(const char *path
, void *buf
, fuse_fill_dir_t filler
,
163 off_t offset
, struct fuse_file_info
*fi
)
168 cfs_debug("enter cfs_fuse_readdir %s", path
);
172 char *subpath
= NULL
;
173 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
178 if (plug
->ops
&& plug
->ops
->readdir
)
179 ret
= plug
->ops
->readdir(plug
, subpath
? subpath
: "", buf
, filler
, 0, fi
);
181 cfs_debug("leave cfs_fuse_readdir %s (%d)", path
, ret
);
189 static int cfs_fuse_mkdir(const char *path
, mode_t mode
)
191 cfs_debug("enter cfs_fuse_mkdir %s", path
);
195 char *subpath
= NULL
;
196 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
201 if (subpath
&& plug
->ops
&& plug
->ops
->mkdir
)
202 ret
= plug
->ops
->mkdir(plug
, subpath
, mode
);
205 cfs_debug("leave cfs_fuse_mkdir %s (%d)", path
, ret
);
213 static int cfs_fuse_rmdir(const char *path
)
215 cfs_debug("enter cfs_fuse_rmdir %s", path
);
219 char *subpath
= NULL
;
220 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
225 if (subpath
&& plug
->ops
&& plug
->ops
->rmdir
)
226 ret
= plug
->ops
->rmdir(plug
, subpath
);
229 cfs_debug("leave cfs_fuse_rmdir %s (%d)", path
, ret
);
237 static int cfs_fuse_rename(const char *from
, const char *to
)
239 cfs_debug("enter cfs_fuse_rename from %s to %s", from
, to
);
243 char *sub_from
= NULL
;
244 cfs_plug_t
*plug_from
= find_plug(from
, &sub_from
);
247 cfs_plug_t
*plug_to
= find_plug(to
, &sub_to
);
249 if (!plug_from
|| !plug_to
|| plug_from
!= plug_to
)
252 if (plug_from
->ops
&& plug_from
->ops
->rename
&& sub_from
&& sub_to
)
253 ret
= plug_from
->ops
->rename(plug_from
, sub_from
, sub_to
);
256 cfs_debug("leave cfs_fuse_rename from %s to %s (%d)", from
, to
, ret
);
267 static int cfs_fuse_open(const char *path
, struct fuse_file_info
*fi
)
269 cfs_debug("enter cfs_fuse_open %s", path
);
276 char *subpath
= NULL
;
277 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
279 if (plug
&& plug
->ops
) {
280 if ((subpath
|| !plug
->ops
->readdir
) && plug
->ops
->open
) {
281 ret
= plug
->ops
->open(plug
, subpath
? subpath
: "", fi
);
285 cfs_debug("leave cfs_fuse_open %s (%d)", path
, ret
);
293 static int cfs_fuse_read(const char *path
, char *buf
, size_t size
, off_t offset
,
294 struct fuse_file_info
*fi
)
298 cfs_debug("enter cfs_fuse_read %s %lu %ld", path
, size
, offset
);
302 char *subpath
= NULL
;
303 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
305 if (plug
&& plug
->ops
) {
306 if ((subpath
|| !plug
->ops
->readdir
) && plug
->ops
->read
)
307 ret
= plug
->ops
->read(plug
, subpath
? subpath
: "", buf
, size
, offset
, fi
);
310 cfs_debug("leave cfs_fuse_read %s (%d)", path
, ret
);
318 static int cfs_fuse_write(const char *path
, const char *buf
, size_t size
,
319 off_t offset
, struct fuse_file_info
*fi
)
323 cfs_debug("enter cfs_fuse_write %s %lu %ld", path
, size
, offset
);
327 char *subpath
= NULL
;
328 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
330 if (plug
&& plug
->ops
) {
331 if ((subpath
|| !plug
->ops
->readdir
) && plug
->ops
->write
)
332 ret
= plug
->ops
->write(plug
, subpath
? subpath
: "",
333 buf
, size
, offset
, fi
);
336 cfs_debug("leave cfs_fuse_write %s (%d)", path
, ret
);
344 static int cfs_fuse_truncate(const char *path
, off_t size
)
346 cfs_debug("enter cfs_fuse_truncate %s %ld", path
, size
);
350 char *subpath
= NULL
;
351 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
353 if (plug
&& plug
->ops
) {
354 if ((subpath
|| !plug
->ops
->readdir
) && plug
->ops
->truncate
)
355 ret
= plug
->ops
->truncate(plug
, subpath
? subpath
: "", size
);
358 cfs_debug("leave cfs_fuse_truncate %s (%d)", path
, ret
);
366 static int cfs_fuse_create(const char *path
, mode_t mode
, struct fuse_file_info
*fi
)
368 cfs_debug("enter cfs_fuse_create %s", path
);
372 char *subpath
= NULL
;
373 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
378 if (subpath
&& plug
->ops
&& plug
->ops
->create
)
379 ret
= plug
->ops
->create(plug
, subpath
, mode
, fi
);
382 cfs_debug("leave cfs_fuse_create %s (%d)", path
, ret
);
390 static int cfs_fuse_unlink(const char *path
)
392 cfs_debug("enter cfs_fuse_unlink %s", path
);
396 char *subpath
= NULL
;
397 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
402 if (subpath
&& plug
->ops
&& plug
->ops
->unlink
)
403 ret
= plug
->ops
->unlink(plug
, subpath
);
406 cfs_debug("leave cfs_fuse_unlink %s (%d)", path
, ret
);
414 static int cfs_fuse_readlink(const char *path
, char *buf
, size_t max
)
416 cfs_debug("enter cfs_fuse_readlink %s", path
);
420 char *subpath
= NULL
;
421 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
426 if (plug
->ops
&& plug
->ops
->readlink
)
427 ret
= plug
->ops
->readlink(plug
, subpath
? subpath
: "", buf
, max
);
430 cfs_debug("leave cfs_fuse_readlink %s (%d)", path
, ret
);
438 static int cfs_fuse_utimens(const char *path
, const struct timespec tv
[2])
440 cfs_debug("enter cfs_fuse_utimens %s", path
);
444 char *subpath
= NULL
;
445 cfs_plug_t
*plug
= find_plug(path
, &subpath
);
450 if (plug
->ops
&& plug
->ops
->utimens
)
451 ret
= plug
->ops
->utimens(plug
, subpath
? subpath
: "", tv
);
454 cfs_debug("leave cfs_fuse_utimens %s (%d)", path
, ret
);
462 static int cfs_fuse_statfs(const char *path
, struct statvfs
*stbuf
)
464 g_return_val_if_fail(root_plug
!= NULL
, PARAM_CHECK_ERRNO
);
466 cfs_debug("enter cfs_fuse_statfs %s", path
);
470 if (root_plug
&& root_plug
->ops
&& root_plug
->ops
->statfs
)
471 ret
= root_plug
->ops
->statfs(root_plug
, "", stbuf
);
476 static struct fuse_operations fuse_ops
= {
477 .getattr
= cfs_fuse_getattr
,
478 .readdir
= cfs_fuse_readdir
,
479 .mkdir
= cfs_fuse_mkdir
,
480 .rmdir
= cfs_fuse_rmdir
,
481 .rename
= cfs_fuse_rename
,
482 .open
= cfs_fuse_open
,
483 .read
= cfs_fuse_read
,
484 .write
= cfs_fuse_write
,
485 .truncate
= cfs_fuse_truncate
,
486 .create
= cfs_fuse_create
,
487 .unlink
= cfs_fuse_unlink
,
488 .readlink
= cfs_fuse_readlink
,
489 .utimens
= cfs_fuse_utimens
,
490 .statfs
= cfs_fuse_statfs
,
491 .init
= cfs_fuse_init
495 create_dot_version_cb(cfs_plug_t
*plug
)
497 GString
*outbuf
= g_string_new(NULL
);
500 if (cfs_create_version_msg(outbuf
) == 0) {
502 g_string_free(outbuf
, FALSE
);
504 g_string_free(outbuf
, TRUE
);
511 create_dot_members_cb(cfs_plug_t
*plug
)
513 GString
*outbuf
= g_string_new(NULL
);
516 if (cfs_create_memberlist_msg(outbuf
) == 0) {
518 g_string_free(outbuf
, FALSE
);
520 g_string_free(outbuf
, TRUE
);
527 create_dot_vmlist_cb(cfs_plug_t
*plug
)
529 GString
*outbuf
= g_string_new(NULL
);
532 if (cfs_create_vmlist_msg(outbuf
) == 0) {
534 g_string_free(outbuf
, FALSE
);
536 g_string_free(outbuf
, TRUE
);
543 create_dot_rrd_cb(cfs_plug_t
*plug
)
545 GString
*outbuf
= g_string_new(NULL
);
547 cfs_rrd_dump(outbuf
);
548 char *data
= outbuf
->str
;
549 g_string_free(outbuf
, FALSE
);
555 create_dot_clusterlog_cb(cfs_plug_t
*plug
)
557 GString
*outbuf
= g_string_new(NULL
);
559 cfs_cluster_log_dump(outbuf
, NULL
, 50);
560 char *data
= outbuf
->str
;
561 g_string_free(outbuf
, FALSE
);
567 read_debug_setting_cb(cfs_plug_t
*plug
)
569 return g_strdup_printf("%d\n", !!cfs
.debug
);
573 my_qb_log_filter(struct qb_log_callsite
*cs
)
575 int32_t priority
= cfs
.debug
? LOG_DEBUG
: LOG_INFO
;
577 if (qb_bit_is_set(cs
->tags
, QB_LOG_TAG_LIBQB_MSG_BIT
)) {
578 if (cs
->priority
<= (cfs
.debug
? priority
: LOG_WARNING
)) {
579 qb_bit_set(cs
->targets
, QB_LOG_SYSLOG
);
581 qb_bit_clear(cs
->targets
, QB_LOG_SYSLOG
);
583 if (cs
->priority
<= priority
) {
584 qb_bit_set(cs
->targets
, QB_LOG_STDERR
);
586 qb_bit_clear(cs
->targets
, QB_LOG_STDERR
);
589 if (cs
->priority
<= priority
) {
590 qb_bit_set(cs
->targets
, QB_LOG_SYSLOG
);
591 qb_bit_set(cs
->targets
, QB_LOG_STDERR
);
593 qb_bit_clear(cs
->targets
, QB_LOG_SYSLOG
);
594 qb_bit_clear(cs
->targets
, QB_LOG_STDERR
);
600 update_qb_log_settings(void)
602 qb_log_filter_fn_set(my_qb_log_filter
);
605 qb_log_format_set(QB_LOG_SYSLOG
, "[%g] %p: %b (%f:%l:%n)");
606 qb_log_format_set(QB_LOG_STDERR
, "[%g] %p: %b (%f:%l:%n)");
608 qb_log_format_set(QB_LOG_SYSLOG
, "[%g] %p: %b");
609 qb_log_format_set(QB_LOG_STDERR
, "[%g] %p: %b");
614 write_debug_setting_cb(
624 if (strncmp(buf
, "0\n", 2) == 0) {
626 cfs_message("disable debug mode");
628 update_qb_log_settings();
631 } else if (strncmp(buf
, "1\n", 2) == 0) {
634 update_qb_log_settings();
635 cfs_message("enable debug mode");
644 create_symlinks(cfs_plug_base_t
*bplug
, const char *nodename
)
646 g_return_if_fail(bplug
!= NULL
);
647 g_return_if_fail(nodename
!= NULL
);
649 char *lnktarget
= g_strdup_printf("nodes/%s", nodename
);
650 cfs_plug_link_t
*lnk
= cfs_plug_link_new("local", lnktarget
);
652 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)lnk
);
654 lnktarget
= g_strdup_printf("nodes/%s/qemu-server", nodename
);
655 lnk
= cfs_plug_link_new("qemu-server", lnktarget
);
657 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)lnk
);
659 lnktarget
= g_strdup_printf("nodes/%s/openvz", nodename
);
660 lnk
= cfs_plug_link_new("openvz", lnktarget
);
662 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)lnk
);
664 lnktarget
= g_strdup_printf("nodes/%s/lxc", nodename
);
665 lnk
= cfs_plug_link_new("lxc", lnktarget
);
667 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)lnk
);
669 cfs_plug_func_t
*fplug
= cfs_plug_func_new(".version", 0440, create_dot_version_cb
, NULL
);
670 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)fplug
);
672 fplug
= cfs_plug_func_new(".members", 0440, create_dot_members_cb
, NULL
);
673 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)fplug
);
675 fplug
= cfs_plug_func_new(".vmlist", 0440, create_dot_vmlist_cb
, NULL
);
676 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)fplug
);
678 fplug
= cfs_plug_func_new(".rrd", 0440, create_dot_rrd_cb
, NULL
);
679 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)fplug
);
681 fplug
= cfs_plug_func_new(".clusterlog", 0440, create_dot_clusterlog_cb
, NULL
);
682 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)fplug
);
684 fplug
= cfs_plug_func_new(".debug", 0640, read_debug_setting_cb
, write_debug_setting_cb
);
685 cfs_plug_base_insert(bplug
, (cfs_plug_t
*)fplug
);
691 lookup_node_ip(const char *nodename
)
693 char buf
[INET6_ADDRSTRLEN
];
694 struct addrinfo
*ainfo
;
695 struct addrinfo ahints
;
697 memset(&ahints
, 0, sizeof(ahints
));
699 if (getaddrinfo(nodename
, NULL
, &ahints
, &ainfo
))
702 if (ainfo
->ai_family
== AF_INET
) {
703 struct sockaddr_in
*sa
= (struct sockaddr_in
*)ainfo
->ai_addr
;
704 inet_ntop(ainfo
->ai_family
, &sa
->sin_addr
, buf
, sizeof(buf
));
705 if (strncmp(buf
, "127.", 4) != 0) {
708 } else if (ainfo
->ai_family
== AF_INET6
) {
709 struct sockaddr_in6
*sa
= (struct sockaddr_in6
*)ainfo
->ai_addr
;
710 inet_ntop(ainfo
->ai_family
, &sa
->sin6_addr
, buf
, sizeof(buf
));
711 if (strcmp(buf
, "::1") != 0) {
722 log_tags_stringify(uint32_t tags
) {
723 if (qb_bit_is_set(tags
, QB_LOG_TAG_LIBQB_MSG_BIT
)) {
727 const char *domain
= g_quark_to_string(quark
);
728 if (domain
!= NULL
) {
736 int main(int argc
, char *argv
[])
741 gboolean foreground
= FALSE
;
742 gboolean force_local_mode
= FALSE
;
743 gboolean wrote_pidfile
= FALSE
;
744 memdb_t
*memdb
= NULL
;
746 dfsm_t
*status_fsm
= NULL
;
748 qb_log_init("pmxcfs", LOG_DAEMON
, LOG_DEBUG
);
749 /* remove default filter */
750 qb_log_filter_ctl(QB_LOG_SYSLOG
, QB_LOG_FILTER_REMOVE
,
751 QB_LOG_FILTER_FILE
, "*", LOG_DEBUG
);
753 qb_log_tags_stringify_fn_set(log_tags_stringify
);
755 qb_log_ctl(QB_LOG_STDERR
, QB_LOG_CONF_ENABLED
, QB_TRUE
);
757 update_qb_log_settings();
759 g_set_print_handler(glib_print_handler
);
760 g_set_printerr_handler(glib_print_handler
);
761 g_log_set_default_handler(glib_log_handler
, NULL
);
763 GOptionContext
*context
;
765 GOptionEntry entries
[] = {
766 { "debug", 'd', 0, G_OPTION_ARG_NONE
, &cfs
.debug
, "Turn on debug messages", NULL
},
767 { "foreground", 'f', 0, G_OPTION_ARG_NONE
, &foreground
, "Do not daemonize server", NULL
},
768 { "local", 'l', 0, G_OPTION_ARG_NONE
, &force_local_mode
,
769 "Force local mode (ignore corosync.conf, force quorum)", NULL
},
773 context
= g_option_context_new ("");
774 g_option_context_add_main_entries (context
, entries
, NULL
);
777 if (!g_option_context_parse (context
, &argc
, &argv
, &err
))
779 cfs_critical("option parsing failed: %s", err
->message
);
784 g_option_context_free(context
);
787 cfs_critical("too many arguments");
793 update_qb_log_settings();
796 struct utsname utsname
;
797 if (uname(&utsname
) != 0) {
798 cfs_critical("Unable to read local node name");
803 for (int i
=0; i
< sizeof(utsname
.nodename
); i
++) {
804 if (utsname
.nodename
[i
] =='.') utsname
.nodename
[i
] = 0;
807 cfs
.nodename
= g_strdup(utsname
.nodename
);
809 if (!(cfs
.ip
= lookup_node_ip(cfs
.nodename
))) {
810 cfs_critical("Unable to get local IP address");
815 struct group
*www_data
= getgrnam("www-data");
817 cfs_critical("Unable to get www-data group ID");
821 cfs
.gid
= www_data
->gr_gid
;
825 mkdir(VARLIBDIR
, 0755);
827 if ((lockfd
= open(LOCKFILE
, O_RDWR
|O_CREAT
|O_APPEND
, 0600)) == -1) {
828 cfs_critical("unable to create lock '%s': %s", LOCKFILE
, strerror (errno
));
832 for (int i
= 10; i
>= 0; i
--) {
833 if (flock(lockfd
, LOCK_EX
|LOCK_NB
) != 0) {
835 cfs_critical("unable to aquire pmxcfs lock: %s", strerror (errno
));
839 cfs_message("unable to aquire pmxcfs lock - trying again");
847 gboolean create
= !g_file_test(DBFILENAME
, G_FILE_TEST_EXISTS
);
849 if (!(memdb
= memdb_open (DBFILENAME
))) {
850 cfs_critical("memdb_open failed - unable to open database '%s'", DBFILENAME
);
854 // automatically import corosync.conf from host
855 if (create
&& !force_local_mode
) {
858 if (g_file_get_contents(HOST_CLUSTER_CONF_FN
, &cdata
, &clen
, NULL
)) {
860 guint32 mtime
= time(NULL
);
862 memdb_create(memdb
, "/corosync.conf", 0, mtime
);
863 if (memdb_write(memdb
, "/corosync.conf", 0, mtime
, cdata
, clen
, 0, 1) < 0) {
864 cfs_critical("memdb_write failed - unable to import corosync.conf");
870 // does corosync.conf exist?
871 gpointer conf_data
= NULL
;
872 int len
= memdb_read(memdb
, "corosync.conf", &conf_data
);
874 if (force_local_mode
) {
875 cfs_message("forcing local mode (althought corosync.conf exists)");
876 cfs_set_quorate(1, TRUE
);
878 if (!(dcdb
= dcdb_new(memdb
)))
880 dcdb_sync_corosync_conf(memdb
, 1);
883 cfs_debug("using local mode (corosync.conf does not exist)");
884 cfs_set_quorate(1, TRUE
);
886 if (conf_data
) g_free(conf_data
);
888 cfs_plug_memdb_t
*config
= cfs_plug_memdb_new("memdb", memdb
, dcdb
);
890 cfs_plug_base_t
*bplug
= cfs_plug_base_new("", (cfs_plug_t
*)config
);
892 create_symlinks(bplug
, cfs
.nodename
);
894 root_plug
= (cfs_plug_t
*)bplug
;
896 umount2(CFSDIR
, MNT_FORCE
);
900 char *fa
[] = { "-f", "-odefault_permissions", "-oallow_other", NULL
};
902 struct fuse_args fuse_args
= FUSE_ARGS_INIT(sizeof (fa
)/sizeof(gpointer
) - 1, fa
);
904 struct fuse_chan
*fuse_chan
= fuse_mount(CFSDIR
, &fuse_args
);
906 cfs_critical("fuse_mount error: %s", strerror(errno
));
910 if (!(fuse
= fuse_new(fuse_chan
, &fuse_args
, &fuse_ops
, sizeof(fuse_ops
), NULL
))) {
911 cfs_critical("fuse_new error: %s", strerror(errno
));
915 fuse_set_signal_handlers(fuse_get_session(fuse
));
921 cfs_critical("failed to daemonize program - %s", strerror (errno
));
932 if ((nullfd
= open("/dev/null", O_RDWR
, 0)) != -1) {
940 // do not print to the console after this point
941 qb_log_ctl(QB_LOG_STDERR
, QB_LOG_CONF_ENABLED
, QB_FALSE
);
946 write_pidfile(getpid());
949 wrote_pidfile
= TRUE
;
951 cfs_loop_t
*corosync_loop
= cfs_loop_new(fuse
);
953 cfs_service_t
*service_quorum
= NULL
;
954 cfs_service_t
*service_confdb
= NULL
;
955 cfs_service_t
*service_dcdb
= NULL
;
956 cfs_service_t
*service_status
= NULL
;
960 service_quorum
= service_quorum_new();
962 cfs_loop_add_service(corosync_loop
, service_quorum
, QB_LOOP_HIGH
);
964 service_confdb
= service_confdb_new();
966 cfs_loop_add_service(corosync_loop
, service_confdb
, QB_LOOP_MED
);
968 service_dcdb
= service_dfsm_new(dcdb
);
969 cfs_service_set_timer(service_dcdb
, DCDB_VERIFY_TIME
);
971 cfs_loop_add_service(corosync_loop
, service_dcdb
, QB_LOOP_MED
);
973 status_fsm
= cfs_status_dfsm_new();
974 service_status
= service_dfsm_new(status_fsm
);
976 cfs_loop_add_service(corosync_loop
, service_status
, QB_LOOP_LOW
);
980 cfs_loop_start_worker(corosync_loop
);
984 ret
= fuse_loop_mt(fuse
);
986 cfs_message("teardown filesystem");
990 fuse_unmount(CFSDIR
, fuse_chan
);
994 cfs_debug("set stop event loop flag");
996 cfs_loop_stop_worker(corosync_loop
);
998 cfs_loop_destroy(corosync_loop
);
1000 cfs_debug("worker finished");
1003 service_dfsm_destroy(service_dcdb
);
1006 service_confdb_destroy(service_confdb
);
1009 service_quorum_destroy(service_quorum
);
1012 service_dfsm_destroy(service_status
);
1014 sleep(1); /* do not restart too fast */
1018 dfsm_destroy(status_fsm
);
1029 cfs_message("exit proxmox configuration filesystem (%d)", ret
);
1031 cfs_status_cleanup();