From 178451d6f063c1054e7960fd628692d6d394f4cd Mon Sep 17 00:00:00 2001 From: Miklos Szeredi Date: Mon, 15 Aug 2005 13:19:07 +0000 Subject: [PATCH] fix --- include/fuse.h | 6 ------ include/fuse_lowlevel.h | 4 ++++ lib/Makefile.am | 1 + lib/fuse.c | 11 +++-------- lib/fuse_i.h | 24 ++++++++++++++++++++++++ lib/fuse_loop_mt.c | 1 - lib/fuse_mt.c | 40 ++++++++++++++++++++++++++++++++++++---- lib/fuse_session.c | 9 ++++++++- lib/helper.c | 6 +----- 9 files changed, 77 insertions(+), 25 deletions(-) create mode 100644 lib/fuse_i.h diff --git a/include/fuse.h b/include/fuse.h index ca3797f..4bb215e 100644 --- a/include/fuse.h +++ b/include/fuse.h @@ -37,9 +37,6 @@ struct fuse; /** Structure containing a raw command */ struct fuse_cmd; -/** The lowlevel FUSE session */ -struct fuse_session; - /** Function to add an entry in a readdir() operation * * @param buf the buffer passed to the readdir() operation @@ -510,9 +507,6 @@ int fuse_exited(struct fuse *f); /** Set function which can be used to get the current context */ void fuse_set_getcontext_func(struct fuse_context *(*func)(void)); -/** Returns the lowlevel FUSE session */ -struct fuse_session *fuse_get_session(struct fuse *f); - /* ----------------------------------------------------------- * * Compatibility stuff * * ----------------------------------------------------------- */ diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h index 4c1af83..ffeb6f9 100644 --- a/include/fuse_lowlevel.h +++ b/include/fuse_lowlevel.h @@ -190,6 +190,10 @@ struct fuse_chan *fuse_kern_chan_new(int fd); struct fuse_session_ops { void (*process) (void *data, const char *buf, size_t len, struct fuse_chan *ch); + + void (*exit) (void *data, int val); + + int (*exited) (void *data); void (*destroy) (void *data); }; diff --git a/lib/Makefile.am b/lib/Makefile.am index b92a0ad..49a1b81 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,6 +4,7 @@ lib_LTLIBRARIES = libfuse.la libfuse_la_SOURCES = \ fuse.c \ + fuse_i.h \ fuse_kern_chan.c \ fuse_loop.c \ fuse_loop_mt.c \ diff --git a/lib/fuse.c b/lib/fuse.c index 7613d38..0f3da23 100644 --- a/lib/fuse.c +++ b/lib/fuse.c @@ -10,7 +10,7 @@ /* For pthread_rwlock_t */ #define _GNU_SOURCE -#include "fuse.h" +#include "fuse_i.h" #include "fuse_lowlevel.h" #include "fuse_compat.h" @@ -110,11 +110,6 @@ struct fuse_dirhandle { fuse_ino_t nodeid; }; -struct fuse_cmd { - char *buf; - size_t buflen; -}; - static struct fuse_context *(*fuse_getcontext)(void) = NULL; #ifndef USE_UCLIBC @@ -1643,8 +1638,7 @@ static void free_cmd(struct fuse_cmd *cmd) void fuse_process_cmd(struct fuse *f, struct fuse_cmd *cmd) { - struct fuse_chan *ch = fuse_session_next_chan(f->se, NULL); - fuse_session_process(f->se, cmd->buf, cmd->buflen, ch); + fuse_session_process(f->se, cmd->buf, cmd->buflen, cmd->ch); } int fuse_exited(struct fuse *f) @@ -1685,6 +1679,7 @@ struct fuse_cmd *fuse_read_cmd(struct fuse *f) return NULL; } cmd->buflen = res; + cmd->ch = ch; } return cmd; } diff --git a/lib/fuse_i.h b/lib/fuse_i.h new file mode 100644 index 0000000..281ddc4 --- /dev/null +++ b/lib/fuse_i.h @@ -0,0 +1,24 @@ +/* + FUSE: Filesystem in Userspace + Copyright (C) 2001-2005 Miklos Szeredi + + This program can be distributed under the terms of the GNU LGPL. + See the file COPYING.LIB +*/ + +#include "fuse.h" + +struct fuse_session; +struct fuse_chan; + +struct fuse_cmd { + char *buf; + size_t buflen; + struct fuse_chan *ch; +}; + +struct fuse_session *fuse_get_session(struct fuse *f); + +struct fuse *fuse_new_common(int fd, const char *opts, + const struct fuse_operations *op, + size_t op_size, int compat); diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index ad386a2..5adb72d 100644 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -53,7 +53,6 @@ static int fuse_loop_mt_send(struct fuse_chan *ch, const struct iovec iov[], return fuse_chan_send(w->prevch, iov, count); } - static int start_thread(struct fuse_worker *w, pthread_t *thread_id); static void *do_work(void *data) diff --git a/lib/fuse_mt.c b/lib/fuse_mt.c index c6a6a03..accd6c4 100644 --- a/lib/fuse_mt.c +++ b/lib/fuse_mt.c @@ -6,7 +6,7 @@ See the file COPYING.LIB. */ -#include "fuse.h" +#include "fuse_i.h" #include "fuse_lowlevel.h" #include @@ -71,6 +71,8 @@ static void mt_delete_context_key(void) struct procdata { struct fuse *f; + struct fuse_chan *prevch; + struct fuse_session *prevse; fuse_processor_t proc; void *data; }; @@ -82,10 +84,25 @@ static void mt_session_proc(void *data, const char *buf, size_t len, struct fuse_cmd *cmd = *(struct fuse_cmd **) buf; (void) len; - (void) ch; + cmd->ch = ch; pd->proc(pd->f, cmd, pd->data); } +static void mt_session_exit(void *data, int val) +{ + struct procdata *pd = (struct procdata *) data; + if (val) + fuse_session_exit(pd->prevse); + else + fuse_session_reset(pd->prevse); +} + +static int mt_session_exited(void *data) +{ + struct procdata *pd = (struct procdata *) data; + return fuse_session_exited(pd->prevse); +} + static int mt_chan_receive(struct fuse_chan *ch, char *buf, size_t size) { struct fuse_cmd *cmd; @@ -95,11 +112,18 @@ static int mt_chan_receive(struct fuse_chan *ch, char *buf, size_t size) cmd = fuse_read_cmd(pd->f); if (cmd == NULL) - return -1; + return 0; *(struct fuse_cmd **) buf = cmd; - return 0; + return sizeof(cmd); +} + +static int mt_chan_send(struct fuse_chan *ch, const struct iovec iov[], + size_t count) +{ + struct procdata *pd = (struct procdata *) fuse_chan_data(ch); + return fuse_chan_send(pd->prevch, iov, count); } int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data) @@ -111,13 +135,18 @@ int fuse_loop_mt_proc(struct fuse *f, fuse_processor_t proc, void *data) struct fuse_chan *prevch = fuse_session_next_chan(prevse, NULL); struct fuse_chan *ch; struct fuse_session_ops sop = { + .exit = mt_session_exit, + .exited = mt_session_exited, .process = mt_session_proc, }; struct fuse_chan_ops cop = { .receive = mt_chan_receive, + .send = mt_chan_send, }; pd.f = f; + pd.prevch = prevch; + pd.prevse = prevse; pd.proc = proc; pd.data = data; @@ -149,6 +178,9 @@ int fuse_loop_mt(struct fuse *f) { int res; + if (f == NULL) + return -1; + if (mt_create_context_key() != 0) return -1; diff --git a/lib/fuse_session.c b/lib/fuse_session.c index a467b2f..5fd1fc7 100644 --- a/lib/fuse_session.c +++ b/lib/fuse_session.c @@ -85,17 +85,24 @@ void fuse_session_destroy(struct fuse_session *se) void fuse_session_exit(struct fuse_session *se) { + if (se->op.exit) + se->op.exit(se->data, 1); se->exited = 1; } void fuse_session_reset(struct fuse_session *se) { + if (se->op.exit) + se->op.exit(se->data, 0); se->exited = 0; } int fuse_session_exited(struct fuse_session *se) { - return se->exited; + if (se->op.exited) + return se->op.exited(se->data); + else + return se->exited; } struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd, diff --git a/lib/helper.c b/lib/helper.c index a6c472f..75959e2 100644 --- a/lib/helper.c +++ b/lib/helper.c @@ -6,7 +6,7 @@ See the file COPYING.LIB. */ -#include "fuse.h" +#include "fuse_i.h" #include "fuse_compat.h" #include @@ -16,10 +16,6 @@ #include #include -struct fuse *fuse_new_common(int fd, const char *opts, - const struct fuse_operations *op, - size_t op_size, int compat); - static struct fuse *fuse_instance; static void usage(const char *progname) -- 2.30.2