From 83c730ca8ee5d567e6a4cefa568353ab1bad0be2 Mon Sep 17 00:00:00 2001 From: Nikolaus Rath Date: Mon, 28 Mar 2016 13:42:08 -0700 Subject: [PATCH] Inlined fuse_chan_{send, recv} --- lib/fuse_lowlevel.c | 141 +++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 81 deletions(-) diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index 542d7ae..3acb663 100755 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -158,75 +158,6 @@ static struct fuse_req *fuse_ll_alloc_req(struct fuse_ll *f) return req; } -static int fuse_chan_recv(struct fuse_session *se, struct fuse_buf *buf, - struct fuse_chan *ch) -{ - struct fuse_ll *f = se->f; - int err; - ssize_t res; - - 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->mem, f->bufsize); - err = errno; - - if (fuse_session_exited(se)) - return 0; - if (res == -1) { - /* ENOENT means the operation was interrupted, it's safe - to restart */ - if (err == ENOENT) - goto restart; - - if (err == ENODEV) { - fuse_session_exit(se); - return 0; - } - /* Errors occurring during normal operation: EINTR (read - interrupted), EAGAIN (nonblocking I/O), ENODEV (filesystem - umounted) */ - if (err != EINTR && err != EAGAIN) - perror("fuse: reading device"); - return -err; - } - if ((size_t) res < sizeof(struct fuse_in_header)) { - fprintf(stderr, "short read on fuse device\n"); - return -EIO; - } - - buf->size = res; - - return res; -} - -static int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[], - size_t count) -{ - ssize_t res = writev(fuse_chan_fd(ch), iov, count); - int err = errno; - - if (res == -1) { - struct fuse_session *se = fuse_chan_session(ch); - - assert(se != NULL); - - /* ENOENT means the operation was interrupted */ - if (!fuse_session_exited(se) && err != ENOENT) - perror("fuse: writing device"); - return -err; - } - - return 0; -} - void fuse_chan_close(struct fuse_chan *ch) { int fd = fuse_chan_fd(ch); @@ -257,9 +188,24 @@ static int fuse_send_msg(struct fuse_ll *f, struct fuse_chan *ch, } } - return fuse_chan_send(ch, iov, count); + ssize_t res = writev(fuse_chan_fd(ch), iov, count); + int err = errno; + + if (res == -1) { + struct fuse_session *se = fuse_chan_session(ch); + + assert(se != NULL); + + /* ENOENT means the operation was interrupted */ + if (!fuse_session_exited(se) && err != ENOENT) + perror("fuse: writing device"); + return -err; + } + + return 0; } + int fuse_send_reply_iov_nofree(fuse_req_t req, int error, struct iovec *iov, int count) { @@ -2751,16 +2697,16 @@ static void fuse_ll_pipe_destructor(void *data) fuse_ll_pipe_free(llp); } -#ifdef HAVE_SPLICE int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf, struct fuse_chan *ch) { struct fuse_ll *f = se->f; + int err; + ssize_t res; +#ifdef HAVE_SPLICE size_t bufsize = f->bufsize; struct fuse_ll_pipe *llp; struct fuse_buf tmpbuf; - int err; - int res; if (f->conn.proto_minor < 14 || !(f->conn.want & FUSE_CAP_SPLICE_READ)) goto fallback; @@ -2855,15 +2801,48 @@ int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf, return res; fallback: - return fuse_chan_recv(se, buf, ch); -} -#else -int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf, - struct fuse_chan *ch) -{ - return fuse_chan_recv(se, buf, ch); -} #endif + 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->mem, f->bufsize); + err = errno; + + if (fuse_session_exited(se)) + return 0; + if (res == -1) { + /* ENOENT means the operation was interrupted, it's safe + to restart */ + if (err == ENOENT) + goto restart; + + if (err == ENODEV) { + fuse_session_exit(se); + return 0; + } + /* Errors occurring during normal operation: EINTR (read + interrupted), EAGAIN (nonblocking I/O), ENODEV (filesystem + umounted) */ + if (err != EINTR && err != EAGAIN) + perror("fuse: reading device"); + return -err; + } + if ((size_t) res < sizeof(struct fuse_in_header)) { + fprintf(stderr, "short read on fuse device\n"); + return -EIO; + } + + buf->size = res; + + return res; +} #define MIN_BUFSIZE 0x21000 -- 2.30.2