int fuse_main_real(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *user_data) { struct fuse *fuse; char *mountpoint; int multithreaded; int res; fuse = fuse_setup(argc, argv, op, op_size, &mountpoint, &multithreaded, user_data); if (fuse == NULL) { rError("fuse is NULL"); return 1; } //MT loops are only supported on MSVC if (multithreaded) res = fuse_loop_mt(fuse); else res = fuse_loop(fuse); rDebug("res=%i", res); fuse_teardown(fuse, mountpoint); rDebug("res=%i", res); if (res < 0) return 1; return 0; }
static int fuse_main_common(int argc, char *argv[], const struct fuse_operations *op, size_t op_size, void *user_data, int compat) { struct fuse *fuse; char *mountpoint; int multithreaded; int res; fuse = fuse_setup_common(argc, argv, op, op_size, &mountpoint, &multithreaded, NULL, user_data, compat); if (fuse == NULL) return 1; if (multithreaded) res = fuse_loop_mt(fuse); else res = fuse_loop(fuse); fuse_teardown_common(fuse, mountpoint); if (res == -1) return 1; return 0; }
int fuse_main_real(int argc, char* argv[], const struct fuse_operations* op, size_t opSize, void* userData) { printf("fuse_main_real(%d, %p, %p, %ld, %p)\n", argc, argv, op, opSize, userData); // Note: We use the fuse_*() functions here to initialize and run the // file system, although some of them are merely dummies. struct fuse_args args = FUSE_ARGS_INIT(argc, argv); int result = 1; // create the kernel channel struct fuse_chan* channel = fuse_mount("/dummy", &args); if (channel != NULL) { // create the FUSE handle struct fuse* fuseHandle = fuse_new(channel, &args, op, opSize, userData); if (fuseHandle != NULL) { // run the main loop result = fuse_loop_mt(fuseHandle); fuse_destroy(fuseHandle); } fuse_unmount("/dummy", channel); } fuse_opt_free_args(&args); return result; }
int main(int argc, char** argv) { struct fuse_args args = FUSE_ARGS_INIT(argc, argv); char* mountpoint; int multithreaded; int foreground; if (fuse_opt_parse(&args, NULL, tfs_opts, tfs_opt_proc) == -1) return 1; if (fuse_parse_cmdline(&args, &mountpoint, &multithreaded, &foreground) == -1) return 1; struct fuse_chan *ch = fuse_mount(mountpoint, &args); if (!ch) return 1; struct fuse *fuse = fuse_new(ch, &args, &tfs_oper, sizeof(struct fuse_operations), NULL); if (!fuse) { fuse_unmount(mountpoint, ch); return 1; } if (options.debug == 1 || foreground == 1) { if (fuse_daemonize(foreground) != -1) return 1; } if (fuse_set_signal_handlers(fuse_get_session(fuse)) == -1) { fuse_unmount(mountpoint, ch); fuse_destroy(fuse); return 1; } initMultiCastListener(); if (multithreaded) return fuse_loop_mt(fuse); if (!options.debug) fprintf(stderr, "Running single threaded and we are not debugging, your performance may suffer.\n"); return fuse_loop(fuse); };
// run fskit with fuse int fskit_fuse_main( struct fskit_fuse_state* state, int argc, char** argv ) { int rc = 0; // set up FUSE struct fuse_args args = FUSE_ARGS_INIT(argc, argv); struct fuse_chan* ch = NULL; struct fuse* fs = NULL; int multithreaded = 1; int foreground = 0; char* mountpoint = NULL; // parse command-line... rc = fuse_parse_cmdline( &args, &mountpoint, &multithreaded, &foreground ); if( rc < 0 ) { fskit_error("fuse_parse_cmdline rc = %d\n", rc ); fuse_opt_free_args(&args); return rc; } if( mountpoint == NULL ) { fskit_error("%s", "No mountpoint given\n"); fuse_opt_free_args(&args); return rc; } state->mountpoint = strdup( mountpoint ); // mount ch = fuse_mount( mountpoint, &args ); if( ch == NULL ) { rc = -errno; fskit_error("fuse_mount failed, errno = %d\n", rc ); fuse_opt_free_args(&args); if( rc == 0 ) { rc = -EPERM; } return rc; } // create the filesystem fs = fuse_new( ch, &args, &state->ops, sizeof(state->ops), state ); fuse_opt_free_args(&args); if( fs == NULL ) { // failed rc = -errno; fskit_error("fuse_new failed, errno = %d\n", rc ); fuse_unmount( mountpoint, ch ); if( rc == 0 ) { rc = -EPERM; } return rc; } // daemonize if running in the background fskit_debug("FUSE daemonize: foreground=%d\n", foreground); rc = fuse_daemonize( foreground ); if( rc != 0 ) { // failed fskit_error("fuse_daemonize(%d) rc = %d\n", foreground, rc ); fuse_unmount( mountpoint, ch ); fuse_destroy( fs ); return rc; } // set up FUSE signal handlers rc = fuse_set_signal_handlers( fuse_get_session(fs) ); if( rc < 0 ) { // failed fskit_error("fuse_set_signal_handlers rc = %d\n", rc ); fuse_unmount( mountpoint, ch ); fuse_destroy( fs ); return rc; } // if we have a post-mount callback, call it now, since FUSE is ready to receive requests if( state->postmount != NULL ) { rc = (*state->postmount)( state, state->postmount_cls ); if( rc != 0 ) { fskit_error("fskit postmount callback rc = %d\n", rc ); fuse_unmount( mountpoint, ch ); fuse_destroy( fs ); return rc; } } // run the filesystem--start processing requests fskit_debug("%s", "FUSE main loop entered\n"); if( multithreaded ) { rc = fuse_loop_mt( fs ); } else { rc = fuse_loop( fs ); } fskit_debug("%s", "FUSE main loop finished\n"); fuse_teardown( fs, mountpoint ); return rc; }
void _cachefs_fuse_run(struct cachefs *fs) { fuse_loop_mt(fs->fuse); }
int main(int argc, char *argv[]) { int ret = -1; int lockfd = -1; gboolean foreground = FALSE; gboolean force_local_mode = FALSE; gboolean wrote_pidfile = FALSE; memdb_t *memdb = NULL; dfsm_t *dcdb = NULL; dfsm_t *status_fsm = NULL; qb_log_init("pmxcfs", LOG_DAEMON, LOG_DEBUG); /* remove default filter */ qb_log_filter_ctl(QB_LOG_SYSLOG, QB_LOG_FILTER_REMOVE, QB_LOG_FILTER_FILE, "*", LOG_DEBUG); qb_log_tags_stringify_fn_set(log_tags_stringify); qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_TRUE); update_qb_log_settings(); g_set_print_handler(glib_print_handler); g_set_printerr_handler(glib_print_handler); g_log_set_default_handler(glib_log_handler, NULL); GOptionContext *context; GOptionEntry entries[] = { { "debug", 'd', 0, G_OPTION_ARG_NONE, &cfs.debug, "Turn on debug messages", NULL }, { "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Do not daemonize server", NULL }, { "local", 'l', 0, G_OPTION_ARG_NONE, &force_local_mode, "Force local mode (ignore cluster.conf, force quorum)", NULL }, { NULL }, }; context = g_option_context_new (""); g_option_context_add_main_entries (context, entries, NULL); GError *err = NULL; if (!g_option_context_parse (context, &argc, &argv, &err)) { cfs_critical("option parsing failed: %s", err->message); g_error_free (err); qb_log_fini(); exit (1); } g_option_context_free(context); if (optind < argc) { cfs_critical("too many arguments"); qb_log_fini(); exit(-1); } if (cfs.debug) { update_qb_log_settings(); } struct utsname utsname; if (uname(&utsname) != 0) { cfs_critical("Unable to read local node name"); qb_log_fini(); exit (-1); } for (int i=0; i < sizeof(utsname.nodename); i++) { if (utsname.nodename[i] =='.') utsname.nodename[i] = 0; } cfs.nodename = g_strdup(utsname.nodename); if (!(cfs.ip = lookup_node_ip(cfs.nodename))) { cfs_critical("Unable to get local IP address"); qb_log_fini(); exit(-1); } struct group *www_data = getgrnam("www-data"); if (!www_data) { cfs_critical("Unable to get www-data group ID"); qb_log_fini(); exit (-1); } cfs.gid = www_data->gr_gid; g_thread_init(NULL); umask(027); mkdir(VARLIBDIR, 0755); if ((lockfd = open(LOCKFILE, O_RDWR|O_CREAT|O_APPEND)) == -1) { cfs_critical("unable to create lock '%s': %s", LOCKFILE, strerror (errno)); goto err; } for (int i = 10; i >= 0; i--) { if (flock(lockfd, LOCK_EX|LOCK_NB) != 0) { if (!i) { cfs_critical("unable to aquire pmxcfs lock: %s", strerror (errno)); goto err; } if (i == 10) cfs_message("unable to aquire pmxcfs lock - trying again"); sleep(1); } } cfs_status_init(); gboolean create = !g_file_test(DBFILENAME, G_FILE_TEST_EXISTS); if (!(memdb = memdb_open (DBFILENAME))) { cfs_critical("memdb_open failed - unable to open database '%s'", DBFILENAME); goto err; } // automatically import cluster.conf from host if (create && !force_local_mode) { char *cdata = NULL; gsize clen = 0; if (g_file_get_contents(HOST_CLUSTER_CONF_FN, &cdata, &clen, NULL)) { guint32 mtime = time(NULL); memdb_create(memdb, "/cluster.conf", 0, mtime); if (memdb_write(memdb, "/cluster.conf", 0, mtime, cdata, clen, 0, 1) < 0) { cfs_critical("memdb_write failed - unable to import cluster.conf"); goto err; } } } // does cluster.conf exist? gpointer conf_data = NULL; int len = memdb_read(memdb, "cluster.conf", &conf_data); if (len >= 0) { if (force_local_mode) { cfs_message("forcing local mode (althought cluster.conf exists)"); cfs_set_quorate(1, TRUE); } else { if (!(dcdb = dcdb_new(memdb))) goto err; dcdb_sync_cluster_conf(memdb, 1); } } else { cfs_debug("using local mode (cluster.conf does not exist)"); cfs_set_quorate(1, TRUE); } if (conf_data) g_free(conf_data); cfs_plug_memdb_t *config = cfs_plug_memdb_new("memdb", memdb, dcdb); cfs_plug_base_t *bplug = cfs_plug_base_new("", (cfs_plug_t *)config); create_symlinks(bplug, cfs.nodename); root_plug = (cfs_plug_t *)bplug; system("umount -f " CFSDIR " >/dev/null 2>&1"); char *fa[] = { "-f", "-odefault_permissions", "-oallow_other", NULL}; struct fuse_args fuse_args = FUSE_ARGS_INIT(sizeof (fa)/sizeof(gpointer) - 1, fa); struct fuse_chan *fuse_chan = fuse_mount(CFSDIR, &fuse_args); if (!fuse_chan) { cfs_critical("fuse_mount error: %s", strerror(errno)); goto err; } if (!(fuse = fuse_new(fuse_chan, &fuse_args, &fuse_ops, sizeof(fuse_ops), NULL))) { cfs_critical("fuse_new error: %s", strerror(errno)); goto err; } fuse_set_signal_handlers(fuse_get_session(fuse)); if (!foreground) { pid_t cpid = fork(); if (cpid == -1) { cfs_critical("failed to daemonize program - %s", strerror (errno)); goto err; } else if (cpid) { write_pidfile(cpid); qb_log_fini(); _exit (0); } else { int nullfd; chroot("/"); if ((nullfd = open("/dev/null", O_RDWR, 0)) != -1) { dup2(nullfd, 0); dup2(nullfd, 1); dup2(nullfd, 2); if (nullfd > 2) close (nullfd); } // do not print to the console after this point qb_log_ctl(QB_LOG_STDERR, QB_LOG_CONF_ENABLED, QB_FALSE); setsid(); } } else { write_pidfile(getpid()); } wrote_pidfile = TRUE; cfs_loop_t *corosync_loop = cfs_loop_new(fuse); cfs_service_t *service_quorum = NULL; cfs_service_t *service_confdb = NULL; cfs_service_t *service_dcdb = NULL; cfs_service_t *service_status = NULL; if (dcdb) { service_quorum = service_quorum_new(); cfs_loop_add_service(corosync_loop, service_quorum, QB_LOOP_HIGH); service_confdb = service_confdb_new(); cfs_loop_add_service(corosync_loop, service_confdb, QB_LOOP_MED); service_dcdb = service_dfsm_new(dcdb); cfs_service_set_timer(service_dcdb, DCDB_VERIFY_TIME); cfs_loop_add_service(corosync_loop, service_dcdb, QB_LOOP_MED); status_fsm = cfs_status_dfsm_new(); service_status = service_dfsm_new(status_fsm); cfs_loop_add_service(corosync_loop, service_status, QB_LOOP_LOW); } cfs_loop_start_worker(corosync_loop); server_start(memdb); ret = fuse_loop_mt(fuse); cfs_message("teardown filesystem"); server_stop(); fuse_unmount(CFSDIR, fuse_chan); fuse_destroy(fuse); cfs_debug("set stop event loop flag"); cfs_loop_stop_worker(corosync_loop); cfs_loop_destroy(corosync_loop); cfs_debug("worker finished"); if (service_dcdb) service_dfsm_destroy(service_dcdb); if (service_confdb) service_confdb_destroy(service_confdb); if (service_quorum) service_quorum_destroy(service_quorum); if (service_status) service_dfsm_destroy(service_status); sleep(1); /* do not restart too fast */ ret: if (status_fsm) dfsm_destroy(status_fsm); if (dcdb) dfsm_destroy(dcdb); if (memdb) memdb_close(memdb); if (wrote_pidfile) unlink(CFS_PID_FN); cfs_message("exit proxmox configuration filesystem (%d)", ret); cfs_status_cleanup(); qb_log_fini(); exit(ret); err: goto ret; }