mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-02-08 23:01:45 +08:00
libfuse cleanup: remove single threaded
This commit is contained in:
parent
3c761b708b
commit
dc1b698847
|
@ -34,7 +34,6 @@ SRC = \
|
||||||
lib/fuse_dirents.c \
|
lib/fuse_dirents.c \
|
||||||
lib/fuse.c \
|
lib/fuse.c \
|
||||||
lib/fuse_kern_chan.c \
|
lib/fuse_kern_chan.c \
|
||||||
lib/fuse_loop.c \
|
|
||||||
lib/fuse_loop_mt.c \
|
lib/fuse_loop_mt.c \
|
||||||
lib/fuse_lowlevel.c \
|
lib/fuse_lowlevel.c \
|
||||||
lib/fuse_mt.c \
|
lib/fuse_mt.c \
|
||||||
|
|
|
@ -664,17 +664,6 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
void fuse_destroy(struct fuse *f);
|
void fuse_destroy(struct fuse *f);
|
||||||
|
|
||||||
/**
|
|
||||||
* FUSE event loop.
|
|
||||||
*
|
|
||||||
* Requests from the kernel are processed, and the appropriate
|
|
||||||
* operations are called.
|
|
||||||
*
|
|
||||||
* @param f the FUSE handle
|
|
||||||
* @return 0 if no error occurred, -1 otherwise
|
|
||||||
*/
|
|
||||||
int fuse_loop(struct fuse *f);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Exit from event loop
|
* Exit from event loop
|
||||||
*
|
*
|
||||||
|
@ -903,7 +892,7 @@ extern "C" {
|
||||||
/** This is the part of fuse_main() before the event loop */
|
/** This is the part of fuse_main() before the event loop */
|
||||||
struct fuse *fuse_setup(int argc, char *argv[],
|
struct fuse *fuse_setup(int argc, char *argv[],
|
||||||
const struct fuse_operations *op, size_t op_size,
|
const struct fuse_operations *op, size_t op_size,
|
||||||
char **mountpoint, int *multithreaded,
|
char **mountpoint,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
/** This is the part of fuse_main() after the event loop */
|
/** This is the part of fuse_main() after the event loop */
|
||||||
|
|
|
@ -235,7 +235,6 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* '-f' foreground
|
* '-f' foreground
|
||||||
* '-d' '-odebug' foreground, but keep the debug option
|
* '-d' '-odebug' foreground, but keep the debug option
|
||||||
* '-s' single threaded
|
|
||||||
* '-h' '--help' help
|
* '-h' '--help' help
|
||||||
* '-ho' help without header
|
* '-ho' help without header
|
||||||
* '-ofsname=..' file system name, if not present, then set to the program
|
* '-ofsname=..' file system name, if not present, then set to the program
|
||||||
|
@ -245,12 +244,12 @@ extern "C" {
|
||||||
*
|
*
|
||||||
* @param args argument vector
|
* @param args argument vector
|
||||||
* @param mountpoint the returned mountpoint, should be freed after use
|
* @param mountpoint the returned mountpoint, should be freed after use
|
||||||
* @param multithreaded set to 1 unless the '-s' option is present
|
|
||||||
* @param foreground set to 1 if one of the relevant options is present
|
* @param foreground set to 1 if one of the relevant options is present
|
||||||
* @return 0 on success, -1 on failure
|
* @return 0 on success, -1 on failure
|
||||||
*/
|
*/
|
||||||
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
|
int fuse_parse_cmdline(struct fuse_args *args,
|
||||||
int *multithreaded, int *foreground);
|
char **mountpoint,
|
||||||
|
int *foreground);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Go into the background
|
* Go into the background
|
||||||
|
|
|
@ -1698,14 +1698,6 @@ extern "C" {
|
||||||
*/
|
*/
|
||||||
void *fuse_session_data(struct fuse_session *se);
|
void *fuse_session_data(struct fuse_session *se);
|
||||||
|
|
||||||
/**
|
|
||||||
* Enter a single threaded event loop
|
|
||||||
*
|
|
||||||
* @param se the session
|
|
||||||
* @return 0 on success, -1 on error
|
|
||||||
*/
|
|
||||||
int fuse_session_loop(struct fuse_session *se);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enter a multi-threaded event loop
|
* Enter a multi-threaded event loop
|
||||||
*
|
*
|
||||||
|
|
|
@ -4177,79 +4177,6 @@ struct fuse_cmd *fuse_read_cmd(struct fuse *f)
|
||||||
return cmd;
|
return cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fuse_session_loop_remember(struct fuse *f)
|
|
||||||
{
|
|
||||||
struct fuse_session *se = f->se;
|
|
||||||
int res = 0;
|
|
||||||
struct timespec now;
|
|
||||||
time_t next_clean;
|
|
||||||
struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
|
|
||||||
size_t bufsize = fuse_chan_bufsize(ch);
|
|
||||||
char *buf = (char *) malloc(bufsize);
|
|
||||||
struct pollfd fds = {
|
|
||||||
.fd = fuse_chan_fd(ch),
|
|
||||||
.events = POLLIN
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!buf) {
|
|
||||||
fprintf(stderr, "fuse: failed to allocate read buffer\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
curr_time(&now);
|
|
||||||
next_clean = now.tv_sec;
|
|
||||||
while (!fuse_session_exited(se)) {
|
|
||||||
struct fuse_chan *tmpch = ch;
|
|
||||||
struct fuse_buf fbuf = {
|
|
||||||
.mem = buf,
|
|
||||||
.size = bufsize,
|
|
||||||
};
|
|
||||||
unsigned timeout;
|
|
||||||
|
|
||||||
curr_time(&now);
|
|
||||||
if (now.tv_sec < next_clean)
|
|
||||||
timeout = next_clean - now.tv_sec;
|
|
||||||
else
|
|
||||||
timeout = 0;
|
|
||||||
|
|
||||||
res = poll(&fds, 1, timeout * 1000);
|
|
||||||
if (res == -1) {
|
|
||||||
if (errno == -EINTR)
|
|
||||||
continue;
|
|
||||||
else
|
|
||||||
break;
|
|
||||||
} else if (res > 0) {
|
|
||||||
res = fuse_session_receive_buf(se, &fbuf, &tmpch);
|
|
||||||
|
|
||||||
if (res == -EINTR)
|
|
||||||
continue;
|
|
||||||
if (res <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
fuse_session_process_buf(se, &fbuf, tmpch);
|
|
||||||
} else {
|
|
||||||
timeout = fuse_clean_cache(f);
|
|
||||||
curr_time(&now);
|
|
||||||
next_clean = now.tv_sec + timeout;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
fuse_session_reset(se);
|
|
||||||
return res < 0 ? -1 : 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
int fuse_loop(struct fuse *f)
|
|
||||||
{
|
|
||||||
if (!f)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
if (lru_enabled(f))
|
|
||||||
return fuse_session_loop_remember(f);
|
|
||||||
|
|
||||||
return fuse_session_loop(f->se);
|
|
||||||
}
|
|
||||||
|
|
||||||
int fuse_invalidate(struct fuse *f, const char *path)
|
int fuse_invalidate(struct fuse *f, const char *path)
|
||||||
{
|
{
|
||||||
(void) f;
|
(void) f;
|
||||||
|
|
|
@ -120,7 +120,6 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
|
||||||
const struct fuse_operations *op,
|
const struct fuse_operations *op,
|
||||||
size_t op_size,
|
size_t op_size,
|
||||||
char **mountpoint,
|
char **mountpoint,
|
||||||
int *multithreaded,
|
|
||||||
int *fd,
|
int *fd,
|
||||||
void *user_data);
|
void *user_data);
|
||||||
|
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
/*
|
|
||||||
FUSE: Filesystem in Userspace
|
|
||||||
Copyright (C) 2001-2007 Miklos Szeredi <miklos@szeredi.hu>
|
|
||||||
|
|
||||||
This program can be distributed under the terms of the GNU LGPLv2.
|
|
||||||
See the file COPYING.LIB
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "fuse_lowlevel.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <errno.h>
|
|
||||||
|
|
||||||
int fuse_session_loop(struct fuse_session *se)
|
|
||||||
{
|
|
||||||
int res = 0;
|
|
||||||
struct fuse_chan *ch = fuse_session_next_chan(se, NULL);
|
|
||||||
size_t bufsize = fuse_chan_bufsize(ch);
|
|
||||||
char *buf = (char*)calloc(bufsize,1);
|
|
||||||
if (!buf) {
|
|
||||||
fprintf(stderr, "fuse: failed to allocate read buffer\n");
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (!fuse_session_exited(se)) {
|
|
||||||
struct fuse_chan *tmpch = ch;
|
|
||||||
struct fuse_buf fbuf = {
|
|
||||||
.mem = buf,
|
|
||||||
.size = bufsize,
|
|
||||||
};
|
|
||||||
|
|
||||||
res = fuse_session_receive_buf(se, &fbuf, &tmpch);
|
|
||||||
|
|
||||||
if (res == -EINTR)
|
|
||||||
continue;
|
|
||||||
if (res <= 0)
|
|
||||||
break;
|
|
||||||
|
|
||||||
fuse_session_process_buf(se, &fbuf, tmpch);
|
|
||||||
}
|
|
||||||
|
|
||||||
free(buf);
|
|
||||||
fuse_session_reset(se);
|
|
||||||
return res < 0 ? -1 : 0;
|
|
||||||
}
|
|
|
@ -62,7 +62,7 @@ static int mt_chan_receive(struct fuse_chan **chp, char *buf, size_t size)
|
||||||
if (cmd == NULL)
|
if (cmd == NULL)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
*(struct fuse_cmd **) buf = cmd;
|
*(struct fuse_cmd **)buf = cmd;
|
||||||
|
|
||||||
return sizeof(cmd);
|
return sizeof(cmd);
|
||||||
}
|
}
|
||||||
|
@ -121,5 +121,3 @@ int fuse_loop_mt(struct fuse *f)
|
||||||
fuse_stop_cleanup_thread(f);
|
fuse_stop_cleanup_thread(f);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
FUSE_SYMVER(".symver fuse_loop_mt_proc,__fuse_loop_mt@");
|
|
||||||
|
|
|
@ -29,7 +29,6 @@ enum {
|
||||||
|
|
||||||
struct helper_opts
|
struct helper_opts
|
||||||
{
|
{
|
||||||
int singlethread;
|
|
||||||
int foreground;
|
int foreground;
|
||||||
int nodefault_subtype;
|
int nodefault_subtype;
|
||||||
char *mountpoint;
|
char *mountpoint;
|
||||||
|
@ -44,7 +43,6 @@ struct fuse_opt fuse_helper_opts[] =
|
||||||
FUSE_HELPER_OPT("-d", foreground),
|
FUSE_HELPER_OPT("-d", foreground),
|
||||||
FUSE_HELPER_OPT("debug", foreground),
|
FUSE_HELPER_OPT("debug", foreground),
|
||||||
FUSE_HELPER_OPT("-f", foreground),
|
FUSE_HELPER_OPT("-f", foreground),
|
||||||
FUSE_HELPER_OPT("-s", singlethread),
|
|
||||||
FUSE_HELPER_OPT("fsname=", nodefault_subtype),
|
FUSE_HELPER_OPT("fsname=", nodefault_subtype),
|
||||||
FUSE_HELPER_OPT("subtype=", nodefault_subtype),
|
FUSE_HELPER_OPT("subtype=", nodefault_subtype),
|
||||||
FUSE_OPT_KEY("-h", KEY_HELP),
|
FUSE_OPT_KEY("-h", KEY_HELP),
|
||||||
|
@ -77,7 +75,6 @@ static void helper_help(void)
|
||||||
"FUSE options:\n"
|
"FUSE options:\n"
|
||||||
" -d -o debug enable debug output (implies -f)\n"
|
" -d -o debug enable debug output (implies -f)\n"
|
||||||
" -f foreground operation\n"
|
" -f foreground operation\n"
|
||||||
" -s disable multi-threaded operation\n"
|
|
||||||
"\n"
|
"\n"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -149,7 +146,6 @@ static int add_default_subtype(const char *progname, struct fuse_args *args)
|
||||||
int
|
int
|
||||||
fuse_parse_cmdline(struct fuse_args *args_,
|
fuse_parse_cmdline(struct fuse_args *args_,
|
||||||
char **mountpoint_,
|
char **mountpoint_,
|
||||||
int *multithreaded_,
|
|
||||||
int *foreground_)
|
int *foreground_)
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
@ -176,8 +172,6 @@ fuse_parse_cmdline(struct fuse_args *args_,
|
||||||
else
|
else
|
||||||
free(hopts.mountpoint);
|
free(hopts.mountpoint);
|
||||||
|
|
||||||
if(multithreaded_)
|
|
||||||
*multithreaded_ = !hopts.singlethread;
|
|
||||||
if(foreground_)
|
if(foreground_)
|
||||||
*foreground_ = hopts.foreground;
|
*foreground_ = hopts.foreground;
|
||||||
|
|
||||||
|
@ -296,7 +290,6 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
|
||||||
const struct fuse_operations *op,
|
const struct fuse_operations *op,
|
||||||
size_t op_size,
|
size_t op_size,
|
||||||
char **mountpoint,
|
char **mountpoint,
|
||||||
int *multithreaded,
|
|
||||||
int *fd,
|
int *fd,
|
||||||
void *user_data)
|
void *user_data)
|
||||||
{
|
{
|
||||||
|
@ -306,7 +299,7 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
|
||||||
int foreground;
|
int foreground;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
res = fuse_parse_cmdline(&args, mountpoint, multithreaded, &foreground);
|
res = fuse_parse_cmdline(&args, mountpoint, &foreground);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -345,10 +338,10 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
|
||||||
|
|
||||||
struct fuse *fuse_setup(int argc, char *argv[],
|
struct fuse *fuse_setup(int argc, char *argv[],
|
||||||
const struct fuse_operations *op, size_t op_size,
|
const struct fuse_operations *op, size_t op_size,
|
||||||
char **mountpoint, int *multithreaded, void *user_data)
|
char **mountpoint, void *user_data)
|
||||||
{
|
{
|
||||||
return fuse_setup_common(argc, argv, op, op_size, mountpoint,
|
return fuse_setup_common(argc, argv, op, op_size, mountpoint,
|
||||||
multithreaded, NULL, user_data);
|
NULL, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fuse_teardown_common(struct fuse *fuse, char *mountpoint)
|
static void fuse_teardown_common(struct fuse *fuse, char *mountpoint)
|
||||||
|
@ -372,18 +365,15 @@ static int fuse_main_common(int argc, char *argv[],
|
||||||
{
|
{
|
||||||
struct fuse *fuse;
|
struct fuse *fuse;
|
||||||
char *mountpoint;
|
char *mountpoint;
|
||||||
int multithreaded;
|
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
fuse = fuse_setup_common(argc, argv, op, op_size, &mountpoint,
|
fuse = fuse_setup_common(argc, argv, op, op_size,
|
||||||
&multithreaded, NULL, user_data);
|
&mountpoint,
|
||||||
|
NULL, user_data);
|
||||||
if (fuse == NULL)
|
if (fuse == NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
if (multithreaded)
|
|
||||||
res = fuse_loop_mt(fuse);
|
res = fuse_loop_mt(fuse);
|
||||||
else
|
|
||||||
res = fuse_loop(fuse);
|
|
||||||
|
|
||||||
fuse_teardown_common(fuse, mountpoint);
|
fuse_teardown_common(fuse, mountpoint);
|
||||||
if (res == -1)
|
if (res == -1)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user