fix
authorMiklos Szeredi <miklos@szeredi.hu>
Mon, 15 Aug 2005 13:19:07 +0000 (13:19 +0000)
committerMiklos Szeredi <miklos@szeredi.hu>
Mon, 15 Aug 2005 13:19:07 +0000 (13:19 +0000)
include/fuse.h
include/fuse_lowlevel.h
lib/Makefile.am
lib/fuse.c
lib/fuse_i.h [new file with mode: 0644]
lib/fuse_loop_mt.c
lib/fuse_mt.c
lib/fuse_session.c
lib/helper.c

index ca3797fd6cc2f502247d08fc62f43ec26b20dff0..4bb215e02cca17a63b1c9487a7305f4386e8fbe9 100644 (file)
@@ -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                                         *
  * ----------------------------------------------------------- */
index 4c1af83d80fba225e7dae66cb23b1bfd97c2714c..ffeb6f997e663b6ac3f41208fefa6697b7f7b705 100644 (file)
@@ -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);
 };
index b92a0ad48fc002a2e849fbeb8ed6623d8dbc974f..49a1b816b30e7dc898c97a6a1253163eca58f85b 100644 (file)
@@ -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          \
index 7613d38f9a0d71b8d107c3b2698320c188cbb92e..0f3da23aa713282ff60eed690fffa24397120f32 100644 (file)
@@ -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 (file)
index 0000000..281ddc4
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+    FUSE: Filesystem in Userspace
+    Copyright (C) 2001-2005  Miklos Szeredi <miklos@szeredi.hu>
+
+    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);
index ad386a2d6b6e8d2b59fd46c51c05321722925278..5adb72d2a8d2d6c177b627775fed2b0696e426ce 100644 (file)
@@ -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)
index c6a6a03fd28eb5896a9e96831d68ccbace6e0673..accd6c4cdb7b60b1af22de75677158f8beb262f7 100644 (file)
@@ -6,7 +6,7 @@
     See the file COPYING.LIB.
 */
 
-#include "fuse.h"
+#include "fuse_i.h"
 #include "fuse_lowlevel.h"
 
 #include <stdio.h>
@@ -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;
 
index a467b2fc957e9adcca8e5b831baae12334702f2b..5fd1fc7c490a301a182fff8e67d0bd075ce17818 100644 (file)
@@ -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, 
index a6c472fe06795b8e4bad80ad8a26b1bacf688b73..75959e20143977cd4dfbc94d880734678e1a39b7 100644 (file)
@@ -6,7 +6,7 @@
     See the file COPYING.LIB.
 */
 
-#include "fuse.h"
+#include "fuse_i.h"
 #include "fuse_compat.h"
 
 #include <stdio.h>
 #include <limits.h>
 #include <signal.h>
 
-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)