Skip to content

Commit

Permalink
libfuse cleanup: remove single threaded
Browse files Browse the repository at this point in the history
  • Loading branch information
trapexit committed Aug 7, 2020
1 parent 3c761b7 commit dc1b698
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 170 deletions.
1 change: 0 additions & 1 deletion libfuse/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ SRC = \
lib/fuse_dirents.c \
lib/fuse.c \
lib/fuse_kern_chan.c \
lib/fuse_loop.c \
lib/fuse_loop_mt.c \
lib/fuse_lowlevel.c \
lib/fuse_mt.c \
Expand Down
13 changes: 1 addition & 12 deletions libfuse/include/fuse.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,17 +664,6 @@ extern "C" {
*/
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
*
Expand Down Expand Up @@ -903,7 +892,7 @@ extern "C" {
/** This is the part of fuse_main() before the event loop */
struct fuse *fuse_setup(int argc, char *argv[],
const struct fuse_operations *op, size_t op_size,
char **mountpoint, int *multithreaded,
char **mountpoint,
void *user_data);

/** This is the part of fuse_main() after the event loop */
Expand Down
7 changes: 3 additions & 4 deletions libfuse/include/fuse_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ extern "C" {
*
* '-f' foreground
* '-d' '-odebug' foreground, but keep the debug option
* '-s' single threaded
* '-h' '--help' help
* '-ho' help without header
* '-ofsname=..' file system name, if not present, then set to the program
Expand All @@ -245,12 +244,12 @@ extern "C" {
*
* @param args argument vector
* @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
* @return 0 on success, -1 on failure
*/
int fuse_parse_cmdline(struct fuse_args *args, char **mountpoint,
int *multithreaded, int *foreground);
int fuse_parse_cmdline(struct fuse_args *args,
char **mountpoint,
int *foreground);

/**
* Go into the background
Expand Down
8 changes: 0 additions & 8 deletions libfuse/include/fuse_lowlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -1698,14 +1698,6 @@ extern "C" {
*/
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
*
Expand Down
73 changes: 0 additions & 73 deletions libfuse/lib/fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -4177,79 +4177,6 @@ struct fuse_cmd *fuse_read_cmd(struct fuse *f)
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)
{
(void) f;
Expand Down
1 change: 0 additions & 1 deletion libfuse/lib/fuse_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
const struct fuse_operations *op,
size_t op_size,
char **mountpoint,
int *multithreaded,
int *fd,
void *user_data);

Expand Down
46 changes: 0 additions & 46 deletions libfuse/lib/fuse_loop.c

This file was deleted.

4 changes: 1 addition & 3 deletions libfuse/lib/fuse_mt.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ static int mt_chan_receive(struct fuse_chan **chp, char *buf, size_t size)
if (cmd == NULL)
return 0;

*(struct fuse_cmd **) buf = cmd;
*(struct fuse_cmd **)buf = cmd;

return sizeof(cmd);
}
Expand Down Expand Up @@ -121,5 +121,3 @@ int fuse_loop_mt(struct fuse *f)
fuse_stop_cleanup_thread(f);
return res;
}

FUSE_SYMVER(".symver fuse_loop_mt_proc,__fuse_loop_mt@");
34 changes: 12 additions & 22 deletions libfuse/lib/helper.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ enum {

struct helper_opts
{
int singlethread;
int foreground;
int nodefault_subtype;
char *mountpoint;
Expand All @@ -41,20 +40,19 @@ static
const
struct fuse_opt fuse_helper_opts[] =
{
FUSE_HELPER_OPT("-d", foreground),
FUSE_HELPER_OPT("-d", foreground),
FUSE_HELPER_OPT("debug", foreground),
FUSE_HELPER_OPT("-f", foreground),
FUSE_HELPER_OPT("-s", singlethread),
FUSE_HELPER_OPT("-f", foreground),
FUSE_HELPER_OPT("fsname=", nodefault_subtype),
FUSE_HELPER_OPT("subtype=", nodefault_subtype),
FUSE_OPT_KEY("-h", KEY_HELP),
FUSE_OPT_KEY("--help", KEY_HELP),
FUSE_OPT_KEY("--help", KEY_HELP),
FUSE_OPT_KEY("-ho", KEY_HELP_NOHEADER),
FUSE_OPT_KEY("-V", KEY_VERSION),
FUSE_OPT_KEY("--version", KEY_VERSION),
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
FUSE_OPT_KEY("fsname=", FUSE_OPT_KEY_KEEP),
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
FUSE_OPT_KEY("fsname=", FUSE_OPT_KEY_KEEP),
FUSE_OPT_KEY("subtype=", FUSE_OPT_KEY_KEEP),
FUSE_OPT_END
};
Expand All @@ -77,7 +75,6 @@ static void helper_help(void)
"FUSE options:\n"
" -d -o debug enable debug output (implies -f)\n"
" -f foreground operation\n"
" -s disable multi-threaded operation\n"
"\n"
);
}
Expand Down Expand Up @@ -149,7 +146,6 @@ static int add_default_subtype(const char *progname, struct fuse_args *args)
int
fuse_parse_cmdline(struct fuse_args *args_,
char **mountpoint_,
int *multithreaded_,
int *foreground_)
{
int res;
Expand All @@ -176,8 +172,6 @@ fuse_parse_cmdline(struct fuse_args *args_,
else
free(hopts.mountpoint);

if(multithreaded_)
*multithreaded_ = !hopts.singlethread;
if(foreground_)
*foreground_ = hopts.foreground;

Expand Down Expand Up @@ -296,7 +290,6 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
const struct fuse_operations *op,
size_t op_size,
char **mountpoint,
int *multithreaded,
int *fd,
void *user_data)
{
Expand All @@ -306,7 +299,7 @@ struct fuse *fuse_setup_common(int argc, char *argv[],
int foreground;
int res;

res = fuse_parse_cmdline(&args, mountpoint, multithreaded, &foreground);
res = fuse_parse_cmdline(&args, mountpoint, &foreground);
if (res == -1)
return NULL;

Expand Down Expand Up @@ -345,10 +338,10 @@ struct fuse *fuse_setup_common(int argc, char *argv[],

struct fuse *fuse_setup(int argc, char *argv[],
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,
multithreaded, NULL, user_data);
NULL, user_data);
}

static void fuse_teardown_common(struct fuse *fuse, char *mountpoint)
Expand All @@ -372,18 +365,15 @@ static int fuse_main_common(int argc, char *argv[],
{
struct fuse *fuse;
char *mountpoint;
int multithreaded;
int res;

fuse = fuse_setup_common(argc, argv, op, op_size, &mountpoint,
&multithreaded, NULL, user_data);
fuse = fuse_setup_common(argc, argv, op, op_size,
&mountpoint,
NULL, user_data);
if (fuse == NULL)
return 1;

if (multithreaded)
res = fuse_loop_mt(fuse);
else
res = fuse_loop(fuse);
res = fuse_loop_mt(fuse);

fuse_teardown_common(fuse, mountpoint);
if (res == -1)
Expand Down

0 comments on commit dc1b698

Please sign in to comment.