summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiklos Szeredi <mszeredi@suse.cz>2013-06-21 18:20:23 +0200
committerMiklos Szeredi <mszeredi@suse.cz>2013-06-21 18:20:23 +0200
commitf9a7c2b1135beeacbdcecab9065eddd2f7e68dbd (patch)
tree386480447871aa2473691c49f8253163b7ace914
parent561d7054d856eea6c2d634093546d6af773dada9 (diff)
downloadfuse-f9a7c2b1135beeacbdcecab9065eddd2f7e68dbd.tar.gz
libfuse: remove session and chan abstractions
There's actually just one type of channel and session, so we don't need the generic callback functions.
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/cuse_lowlevel.c4
-rw-r--r--lib/fuse_i.h47
-rw-r--r--lib/fuse_kern_chan.c29
-rw-r--r--lib/fuse_lowlevel.c52
-rw-r--r--lib/fuse_session.c42
-rw-r--r--lib/helper.c2
7 files changed, 49 insertions, 128 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 8ec234a..e1dbfa2 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -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 \
diff --git a/lib/cuse_lowlevel.c b/lib/cuse_lowlevel.c
index 0e2fe18..b094bd1 100644
--- a/lib/cuse_lowlevel.c
+++ b/lib/cuse_lowlevel.c
@@ -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;
diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index 15834c7..5823743 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -12,36 +12,21 @@
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
index ecb8f9d..0000000
--- a/lib/fuse_kern_chan.c
+++ /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);
-}
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 7c0871e..76cb7b7 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -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;
diff --git a/lib/fuse_session.c b/lib/fuse_session.c
index b8687a4..c030d68 100644
--- a/lib/fuse_session.c
+++ b/lib/fuse_session.c
@@ -15,24 +15,15 @@
#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);
}
diff --git a/lib/helper.c b/lib/helper.c
index 139e1ae..204bb22 100644
--- a/lib/helper.c
+++ b/lib/helper.c
@@ -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);