libfuse: remove session and chan abstractions
authorMiklos Szeredi <mszeredi@suse.cz>
Fri, 21 Jun 2013 16:20:23 +0000 (18:20 +0200)
committerMiklos Szeredi <mszeredi@suse.cz>
Fri, 21 Jun 2013 16:20:23 +0000 (18:20 +0200)
There's actually just one type of channel and session, so we don't need the
generic callback functions.

lib/Makefile.am
lib/cuse_lowlevel.c
lib/fuse_i.h
lib/fuse_kern_chan.c [deleted file]
lib/fuse_lowlevel.c
lib/fuse_session.c
lib/helper.c

index 8ec234a88410c3f875d88c8039cece34750b8489..e1dbfa2596009ee6e1adfb2312bb38d0e32d391e 100644 (file)
@@ -20,7 +20,6 @@ endif
 libfuse_la_SOURCES =           \
        fuse.c                  \
        fuse_i.h                \
-       fuse_kern_chan.c        \
        fuse_loop.c             \
        fuse_loop_mt.c          \
        fuse_lowlevel.c         \
index 0e2fe180e48e28b17605919cb5a5e8dc04addbc7..b094bd15a6375ee698691aebc141d327530ce76d 100644 (file)
@@ -174,7 +174,7 @@ struct fuse_session *cuse_lowlevel_new(struct fuse_args *args,
                free(cd);
                return NULL;
        }
-       ll = se->data;
+       ll = se->f;
        ll->cuse_data = cd;
 
        return se;
@@ -312,7 +312,7 @@ struct fuse_session *cuse_lowlevel_setup(int argc, char *argv[],
                goto err_se;
        }
 
-       ch = fuse_kern_chan_new(fd);
+       ch = fuse_chan_new(fd);
        if (!ch) {
                close(fd);
                goto err_se;
index 15834c774f30baaa286a8976e97f25e65e9272c2..582374371905ec518ffd4112feb4fd3d0f523fe5 100644 (file)
 struct fuse_chan;
 struct fuse_ll;
 
-/**
- * Channel operations
- *
- * This is used in channel creation
- */
-struct fuse_chan_ops {
-       /**
-        * Destroy the channel
-        *
-        * @param ch the channel
-        */
-       void (*destroy)(struct fuse_chan *ch);
-};
-
 struct fuse_session {
-       int (*receive_buf)(struct fuse_session *se, struct fuse_buf *buf,
-                          struct fuse_chan *ch);
-
-       void (*process_buf)(void *data, const struct fuse_buf *buf,
-                           struct fuse_chan *ch);
-
-       void (*destroy) (void *data);
-
-       void *data;
+       struct fuse_ll *f;
 
        volatile int exited;
 
        struct fuse_chan *ch;
 };
 
+struct fuse_chan {
+       struct fuse_session *se;
+
+       int fd;
+};
+
+
 struct fuse_req {
        struct fuse_ll *f;
        uint64_t unique;
@@ -106,25 +91,15 @@ struct fuse_ll {
        size_t bufsize;
 };
 
-struct fuse_chan *fuse_kern_chan_new(int fd);
-
 int fuse_chan_clearfd(struct fuse_chan *ch);
+void fuse_chan_close(struct fuse_chan *ch);
 
 /**
  * Create a new session
  *
- * @param data user data
  * @return new session object, or NULL on failure
  */
-struct fuse_session *fuse_session_new(void *data);
-
-/**
- * Get the user data provided to the session
- *
- * @param se the session
- * @return the user data
- */
-void *fuse_session_data(struct fuse_session *se);
+struct fuse_session *fuse_session_new(void);
 
 /**
  * Create a new channel
@@ -133,7 +108,7 @@ void *fuse_session_data(struct fuse_session *se);
  * @param fd file descriptor of the channel
  * @return the new channel object, or NULL on failure
  */
-struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd);
+struct fuse_chan *fuse_chan_new(int fd);
 
 /**
  * Query the session to which this channel is assigned
diff --git a/lib/fuse_kern_chan.c b/lib/fuse_kern_chan.c
deleted file mode 100644 (file)
index ecb8f9d..0000000
+++ /dev/null
@@ -1,29 +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 "fuse_kernel.h"
-#include "fuse_i.h"
-
-#include <stdio.h>
-#include <errno.h>
-#include <unistd.h>
-#include <assert.h>
-
-static void fuse_kern_chan_destroy(struct fuse_chan *ch)
-{
-       close(fuse_chan_fd(ch));
-}
-
-struct fuse_chan *fuse_kern_chan_new(int fd)
-{
-       struct fuse_chan_ops op = {
-               .destroy = fuse_kern_chan_destroy,
-       };
-       return fuse_chan_new(&op, fd);
-}
index 7c0871e76d0dfa28c107c6df80f6c0b46fffb049..76cb7b7947269d53199d95b4a44203c6a8009b39 100644 (file)
@@ -156,7 +156,7 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_ll *f)
 static int fuse_chan_recv(struct fuse_session *se, struct fuse_buf *buf,
                          struct fuse_chan *ch)
 {
-       struct fuse_ll *f = fuse_session_data(se);
+       struct fuse_ll *f = se->f;
        int err;
        ssize_t res;
 
@@ -222,6 +222,12 @@ static int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[],
        return 0;
 }
 
+void fuse_chan_close(struct fuse_chan *ch)
+{
+       close(fuse_chan_fd(ch));
+}
+
+
 static int fuse_send_msg(struct fuse_ll *f, struct fuse_chan *ch,
                         struct iovec *iov, int count)
 {
@@ -2128,7 +2134,7 @@ int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino,
        if (!ch)
                return -EINVAL;
 
-       f = (struct fuse_ll *)fuse_session_data(fuse_chan_session(ch));
+       f = fuse_chan_session(ch)->f;
        if (!f)
                return -ENODEV;
 
@@ -2152,7 +2158,7 @@ int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent,
        if (!ch)
                return -EINVAL;
 
-       f = (struct fuse_ll *)fuse_session_data(fuse_chan_session(ch));
+       f = fuse_chan_session(ch)->f;
        if (!f)
                return -ENODEV;
 
@@ -2179,7 +2185,7 @@ int fuse_lowlevel_notify_delete(struct fuse_chan *ch,
        if (!ch)
                return -EINVAL;
 
-       f = (struct fuse_ll *)fuse_session_data(fuse_chan_session(ch));
+       f = fuse_chan_session(ch)->f;
        if (!f)
                return -ENODEV;
 
@@ -2213,7 +2219,7 @@ int fuse_lowlevel_notify_store(struct fuse_chan *ch, fuse_ino_t ino,
        if (!ch)
                return -EINVAL;
 
-       f = (struct fuse_ll *)fuse_session_data(fuse_chan_session(ch));
+       f = fuse_chan_session(ch)->f;
        if (!f)
                return -ENODEV;
 
@@ -2295,7 +2301,7 @@ int fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, fuse_ino_t ino,
        if (!ch)
                return -EINVAL;
 
-       f = (struct fuse_ll *)fuse_session_data(fuse_chan_session(ch));
+       f = fuse_chan_session(ch)->f;
        if (!f)
                return -ENODEV;
 
@@ -2440,10 +2446,10 @@ static int fuse_ll_copy_from_pipe(struct fuse_bufvec *dst,
        return 0;
 }
 
-static void fuse_ll_process_buf(void *data, const struct fuse_buf *buf,
-                               struct fuse_chan *ch)
+void fuse_session_process_buf(struct fuse_session *se,
+                             const struct fuse_buf *buf, struct fuse_chan *ch)
 {
-       struct fuse_ll *f = (struct fuse_ll *) data;
+       struct fuse_ll *f = se->f;
        const size_t write_header_size = sizeof(struct fuse_in_header) +
                sizeof(struct fuse_write_in);
        struct fuse_bufvec bufv = { .buf[0] = *buf, .count = 1 };
@@ -2671,9 +2677,8 @@ static int fuse_ll_opt_proc(void *data, const char *arg, int key,
        return -1;
 }
 
-static void fuse_ll_destroy(void *data)
+static void fuse_ll_destroy(struct fuse_ll *f)
 {
-       struct fuse_ll *f = (struct fuse_ll *) data;
        struct fuse_ll_pipe *llp;
 
        if (f->got_init && !f->got_destroy) {
@@ -2689,6 +2694,15 @@ static void fuse_ll_destroy(void *data)
        free(f);
 }
 
+void fuse_session_destroy(struct fuse_session *se)
+{
+       fuse_ll_destroy(se->f);
+       if (se->ch != NULL)
+               fuse_chan_destroy(se->ch);
+       free(se);
+}
+
+
 static void fuse_ll_pipe_destructor(void *data)
 {
        struct fuse_ll_pipe *llp = data;
@@ -2696,10 +2710,10 @@ static void fuse_ll_pipe_destructor(void *data)
 }
 
 #ifdef HAVE_SPLICE
-static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
-                              struct fuse_chan *ch)
+int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
+                            struct fuse_chan *ch)
 {
-       struct fuse_ll *f = fuse_session_data(se);
+       struct fuse_ll *f = se->f;
        size_t bufsize = buf->size = f->bufsize;
        struct fuse_ll_pipe *llp;
        struct fuse_buf tmpbuf;
@@ -2787,8 +2801,8 @@ fallback:
        return fuse_chan_recv(se, buf, ch);
 }
 #else
-static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
-                              struct fuse_chan *ch)
+int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
+                            struct fuse_chan *ch)
 {
        return fuse_chan_recv(se, buf, ch);
 }
@@ -2845,13 +2859,11 @@ struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
        f->owner = getuid();
        f->userdata = userdata;
 
-       se = fuse_session_new(f);
+       se = fuse_session_new();
        if (!se)
                goto out_key_destroy;
 
-       se->receive_buf = fuse_ll_receive_buf;
-       se->process_buf = fuse_ll_process_buf;
-       se->destroy = fuse_ll_destroy;
+       se->f = f;
 
        return se;
 
index b8687a4e12f03657fa009bb7344e43bab2c23115..c030d68399b29bccc96a6e45bdb323d434532649 100644 (file)
 #include <assert.h>
 #include <errno.h>
 
-struct fuse_chan {
-       struct fuse_chan_ops op;
 
-       struct fuse_session *se;
-
-       int fd;
-};
-
-struct fuse_session *fuse_session_new(void *data)
+struct fuse_session *fuse_session_new(void)
 {
        struct fuse_session *se = (struct fuse_session *) malloc(sizeof(*se));
        if (se == NULL) {
                fprintf(stderr, "fuse: failed to allocate session\n");
                return NULL;
        }
-
        memset(se, 0, sizeof(*se));
-       se->data = data;
 
        return se;
 }
@@ -60,18 +51,6 @@ struct fuse_chan *fuse_session_chan(struct fuse_session *se)
        return se->ch;
 }
 
-void fuse_session_process_buf(struct fuse_session *se,
-                             const struct fuse_buf *buf, struct fuse_chan *ch)
-{
-       se->process_buf(se->data, buf, ch);
-}
-
-int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
-                            struct fuse_chan *ch)
-{
-       return se->receive_buf(se, buf, ch);
-}
-
 int fuse_chan_clearfd(struct fuse_chan *ch)
 {
        int fd = ch->fd;
@@ -79,14 +58,6 @@ int fuse_chan_clearfd(struct fuse_chan *ch)
        return fd;
 }
 
-void fuse_session_destroy(struct fuse_session *se)
-{
-       se->destroy(se->data);
-       if (se->ch != NULL)
-               fuse_chan_destroy(se->ch);
-       free(se);
-}
-
 void fuse_session_exit(struct fuse_session *se)
 {
        se->exited = 1;
@@ -102,12 +73,7 @@ int fuse_session_exited(struct fuse_session *se)
        return se->exited;
 }
 
-void *fuse_session_data(struct fuse_session *se)
-{
-       return se->data;
-}
-
-struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd)
+struct fuse_chan *fuse_chan_new(int fd)
 {
        struct fuse_chan *ch = (struct fuse_chan *) malloc(sizeof(*ch));
        if (ch == NULL) {
@@ -116,7 +82,6 @@ struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd)
        }
 
        memset(ch, 0, sizeof(*ch));
-       ch->op = *op;
        ch->fd = fd;
 
        return ch;
@@ -135,7 +100,6 @@ struct fuse_session *fuse_chan_session(struct fuse_chan *ch)
 void fuse_chan_destroy(struct fuse_chan *ch)
 {
        fuse_session_remove_chan(ch);
-       if (ch->op.destroy)
-               ch->op.destroy(ch);
+       fuse_chan_close(ch);
        free(ch);
 }
index 139e1aee41124a4a953e8f105ab4ee5e3bb381fa..204bb2263b8a6d774284dee5a56561548e30f250 100644 (file)
@@ -235,7 +235,7 @@ struct fuse_chan *fuse_mount(const char *mountpoint, struct fuse_args *args)
        if (fd == -1)
                return NULL;
 
-       ch = fuse_kern_chan_new(fd);
+       ch = fuse_chan_new(fd);
        if (!ch)
                fuse_kern_unmount(mountpoint, fd);