mirror of
https://github.com/libfuse/libfuse.git
synced 2024-12-04 01:24:18 +08:00
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.
This commit is contained in:
parent
5334a152e1
commit
561d7054d8
@ -1684,14 +1684,6 @@ int fuse_session_loop_mt(struct fuse_session *se);
|
||||
*/
|
||||
int fuse_chan_fd(struct fuse_chan *ch);
|
||||
|
||||
/**
|
||||
* Query the minimal receive buffer size
|
||||
*
|
||||
* @param ch the channel
|
||||
* @return the buffer size passed to fuse_chan_new()
|
||||
*/
|
||||
size_t fuse_chan_bufsize(struct fuse_chan *ch);
|
||||
|
||||
/**
|
||||
* Destroy a channel
|
||||
*
|
||||
|
@ -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;
|
||||
|
16
lib/fuse.c
16
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user