aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGravatar Miklos Szeredi <mszeredi@suse.cz>2013-06-21 18:17:27 +0200
committerGravatar Miklos Szeredi <mszeredi@suse.cz>2013-06-21 18:17:27 +0200
commit561d7054d856eea6c2d634093546d6af773dada9 (patch)
tree834081dc3e406f37af0f2c00d3d6ca515f217738 /lib
parent5334a152e1272a072339fb4519de04ed4269d3ca (diff)
libfuse: remove fuse_chan_bufsize()
Remove fuse_chan_bufsize() from the lowlevel API. fuse_session_receive_buf() is now responsible for allocating memory for the buffer.
Diffstat (limited to 'lib')
-rw-r--r--lib/cuse_lowlevel.c2
-rw-r--r--lib/fuse.c16
-rw-r--r--lib/fuse_i.h5
-rw-r--r--lib/fuse_kern_chan.c6
-rw-r--r--lib/fuse_loop.c16
-rw-r--r--lib/fuse_loop_mt.c27
-rw-r--r--lib/fuse_lowlevel.c47
-rw-r--r--lib/fuse_session.c11
-rw-r--r--lib/fuse_versionscript1
9 files changed, 46 insertions, 85 deletions
diff --git a/lib/cuse_lowlevel.c b/lib/cuse_lowlevel.c
index c51a78e..0e2fe18 100644
--- a/lib/cuse_lowlevel.c
+++ b/lib/cuse_lowlevel.c
@@ -199,7 +199,7 @@ void cuse_lowlevel_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
struct cuse_init_out outarg;
struct fuse_ll *f = req->f;
struct cuse_data *cd = f->cuse_data;
- size_t bufsize = fuse_chan_bufsize(req->ch);
+ size_t bufsize = f->bufsize;
struct cuse_lowlevel_ops *clop = req_clop(req);
(void) nodeid;
diff --git a/lib/fuse.c b/lib/fuse.c
index 8047933..d859482 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -4022,25 +4022,17 @@ static int fuse_session_loop_remember(struct fuse *f)
struct timespec now;
time_t next_clean;
struct fuse_chan *ch = fuse_session_chan(se);
- 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;
- }
+ struct fuse_buf fbuf = {
+ .mem = NULL,
+ };
curr_time(&now);
next_clean = now.tv_sec;
while (!fuse_session_exited(se)) {
- struct fuse_buf fbuf = {
- .mem = buf,
- .size = bufsize,
- };
unsigned timeout;
curr_time(&now);
@@ -4071,7 +4063,7 @@ static int fuse_session_loop_remember(struct fuse *f)
}
}
- free(buf);
+ free(fbuf.mem);
fuse_session_reset(se);
return res < 0 ? -1 : 0;
}
diff --git a/lib/fuse_i.h b/lib/fuse_i.h
index 741c3d5..15834c7 100644
--- a/lib/fuse_i.h
+++ b/lib/fuse_i.h
@@ -103,6 +103,7 @@ struct fuse_ll {
int broken_splice_nonblock;
uint64_t notify_ctr;
struct fuse_notify_req notify_list;
+ size_t bufsize;
};
struct fuse_chan *fuse_kern_chan_new(int fd);
@@ -130,11 +131,9 @@ void *fuse_session_data(struct fuse_session *se);
*
* @param op channel operations
* @param fd file descriptor of the channel
- * @param bufsize the minimal receive buffer size
* @return the new channel object, or NULL on failure
*/
-struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
- size_t bufsize);
+struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, 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
index d58119c..ecb8f9d 100644
--- a/lib/fuse_kern_chan.c
+++ b/lib/fuse_kern_chan.c
@@ -20,14 +20,10 @@ static void fuse_kern_chan_destroy(struct fuse_chan *ch)
close(fuse_chan_fd(ch));
}
-#define MIN_BUFSIZE 0x21000
-
struct fuse_chan *fuse_kern_chan_new(int fd)
{
struct fuse_chan_ops op = {
.destroy = fuse_kern_chan_destroy,
};
- size_t bufsize = getpagesize() + 0x1000;
- bufsize = bufsize < MIN_BUFSIZE ? MIN_BUFSIZE : bufsize;
- return fuse_chan_new(&op, fd, bufsize);
+ return fuse_chan_new(&op, fd);
}
diff --git a/lib/fuse_loop.c b/lib/fuse_loop.c
index 91d2dd8..7ddf2f9 100644
--- a/lib/fuse_loop.c
+++ b/lib/fuse_loop.c
@@ -16,19 +16,11 @@ int fuse_session_loop(struct fuse_session *se)
{
int res = 0;
struct fuse_chan *ch = fuse_session_chan(se);
- size_t bufsize = fuse_chan_bufsize(ch);
- char *buf = (char *) malloc(bufsize);
- if (!buf) {
- fprintf(stderr, "fuse: failed to allocate read buffer\n");
- return -1;
- }
+ struct fuse_buf fbuf = {
+ .mem = NULL,
+ };
while (!fuse_session_exited(se)) {
- struct fuse_buf fbuf = {
- .mem = buf,
- .size = bufsize,
- };
-
res = fuse_session_receive_buf(se, &fbuf, ch);
if (res == -EINTR)
@@ -39,7 +31,7 @@ int fuse_session_loop(struct fuse_session *se)
fuse_session_process_buf(se, &fbuf, ch);
}
- free(buf);
+ free(fbuf.mem);
fuse_session_reset(se);
return res < 0 ? -1 : 0;
}
diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c
index b53a868..b146d73 100644
--- a/lib/fuse_loop_mt.c
+++ b/lib/fuse_loop_mt.c
@@ -28,7 +28,7 @@ struct fuse_worker {
struct fuse_worker *next;
pthread_t thread_id;
size_t bufsize;
- char *buf;
+ struct fuse_buf fbuf;
struct fuse_mt *mt;
};
@@ -70,14 +70,10 @@ static void *fuse_do_work(void *data)
while (!fuse_session_exited(mt->se)) {
int isforget = 0;
- struct fuse_buf fbuf = {
- .mem = w->buf,
- .size = w->bufsize,
- };
int res;
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
- res = fuse_session_receive_buf(mt->se, &fbuf, mt->prevch);
+ res = fuse_session_receive_buf(mt->se, &w->fbuf, mt->prevch);
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
if (res == -EINTR)
continue;
@@ -99,8 +95,8 @@ static void *fuse_do_work(void *data)
* This disgusting hack is needed so that zillions of threads
* are not created on a burst of FORGET messages
*/
- if (!(fbuf.flags & FUSE_BUF_IS_FD)) {
- struct fuse_in_header *in = fbuf.mem;
+ if (!(w->fbuf.flags & FUSE_BUF_IS_FD)) {
+ struct fuse_in_header *in = w->fbuf.mem;
if (in->opcode == FUSE_FORGET ||
in->opcode == FUSE_BATCH_FORGET)
@@ -113,7 +109,7 @@ static void *fuse_do_work(void *data)
fuse_loop_start_thread(mt);
pthread_mutex_unlock(&mt->lock);
- fuse_session_process_buf(mt->se, &fbuf, mt->prevch);
+ fuse_session_process_buf(mt->se, &w->fbuf, mt->prevch);
pthread_mutex_lock(&mt->lock);
if (!isforget)
@@ -129,7 +125,7 @@ static void *fuse_do_work(void *data)
pthread_mutex_unlock(&mt->lock);
pthread_detach(w->thread_id);
- free(w->buf);
+ free(w->fbuf.mem);
free(w);
return NULL;
}
@@ -183,18 +179,11 @@ static int fuse_loop_start_thread(struct fuse_mt *mt)
return -1;
}
memset(w, 0, sizeof(struct fuse_worker));
- w->bufsize = fuse_chan_bufsize(mt->prevch);
- w->buf = malloc(w->bufsize);
+ w->fbuf.mem = NULL;
w->mt = mt;
- if (!w->buf) {
- fprintf(stderr, "fuse: failed to allocate read buffer\n");
- free(w);
- return -1;
- }
res = fuse_start_thread(&w->thread_id, fuse_do_work, w);
if (res == -1) {
- free(w->buf);
free(w);
return -1;
}
@@ -211,7 +200,7 @@ static void fuse_join_worker(struct fuse_mt *mt, struct fuse_worker *w)
pthread_mutex_lock(&mt->lock);
list_del_worker(w);
pthread_mutex_unlock(&mt->lock);
- free(w->buf);
+ free(w->fbuf.mem);
free(w);
}
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 77de5eb..7c0871e 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -153,15 +153,24 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_ll *f)
return req;
}
-static int fuse_chan_recv(struct fuse_chan *ch, char *buf, size_t size)
+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);
int err;
ssize_t res;
- struct fuse_session *se = fuse_chan_session(ch);
- assert(se != NULL);
+
+ if (!buf->mem) {
+ buf->mem = malloc(f->bufsize);
+ if (!buf->mem) {
+ fprintf(stderr,
+ "fuse: failed to allocate read buffer\n");
+ return -ENOMEM;
+ }
+ }
restart:
- res = read(fuse_chan_fd(ch), buf, size);
+ res = read(fuse_chan_fd(ch), buf->mem, f->bufsize);
err = errno;
if (fuse_session_exited(se))
@@ -187,6 +196,9 @@ restart:
fprintf(stderr, "short read on fuse device\n");
return -EIO;
}
+
+ buf->size = res;
+
return res;
}
@@ -1841,7 +1853,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg)
struct fuse_init_in *arg = (struct fuse_init_in *) inarg;
struct fuse_init_out outarg;
struct fuse_ll *f = req->f;
- size_t bufsize = fuse_chan_bufsize(req->ch);
+ size_t bufsize = f->bufsize;
(void) nodeid;
if (f->debug) {
@@ -2688,7 +2700,7 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
struct fuse_chan *ch)
{
struct fuse_ll *f = fuse_session_data(se);
- size_t bufsize = buf->size;
+ size_t bufsize = buf->size = f->bufsize;
struct fuse_ll_pipe *llp;
struct fuse_buf tmpbuf;
int err;
@@ -2772,30 +2784,18 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
return res;
fallback:
- res = fuse_chan_recv(ch, buf->mem, bufsize);
- if (res <= 0)
- return res;
-
- buf->size = res;
-
- return res;
+ 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)
{
- (void) se;
-
- int res = fuse_chan_recv(ch, buf->mem, buf->size);
- if (res <= 0)
- return res;
-
- buf->size = res;
-
- return res;
+ return fuse_chan_recv(se, buf, ch);
}
#endif
+#define MIN_BUFSIZE 0x21000
+
struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
const struct fuse_lowlevel_ops *op,
size_t op_size, void *userdata)
@@ -2819,6 +2819,9 @@ struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
f->conn.max_write = UINT_MAX;
f->conn.max_readahead = UINT_MAX;
f->atomic_o_trunc = 0;
+ f->bufsize = getpagesize() + 0x1000;
+ f->bufsize = f->bufsize < MIN_BUFSIZE ? MIN_BUFSIZE : f->bufsize;
+
list_init_req(&f->list);
list_init_req(&f->interrupts);
list_init_nreq(&f->notify_list);
diff --git a/lib/fuse_session.c b/lib/fuse_session.c
index 318cfee..b8687a4 100644
--- a/lib/fuse_session.c
+++ b/lib/fuse_session.c
@@ -21,8 +21,6 @@ struct fuse_chan {
struct fuse_session *se;
int fd;
-
- size_t bufsize;
};
struct fuse_session *fuse_session_new(void *data)
@@ -109,8 +107,7 @@ void *fuse_session_data(struct fuse_session *se)
return se->data;
}
-struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
- size_t bufsize)
+struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd)
{
struct fuse_chan *ch = (struct fuse_chan *) malloc(sizeof(*ch));
if (ch == NULL) {
@@ -121,7 +118,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;
- ch->bufsize = bufsize;
return ch;
}
@@ -131,11 +127,6 @@ int fuse_chan_fd(struct fuse_chan *ch)
return ch->fd;
}
-size_t fuse_chan_bufsize(struct fuse_chan *ch)
-{
- return ch->bufsize;
-}
-
struct fuse_session *fuse_chan_session(struct fuse_chan *ch)
{
return ch->se;
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 39be9f4..08dafbd 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -4,7 +4,6 @@ FUSE_3.0 {
fuse_exit;
fuse_loop;
fuse_loop_mt;
- fuse_chan_bufsize;
fuse_chan_destroy;
fuse_chan_fd;
fuse_reply_attr;