Inlined fuse_chan_{send, recv}
authorNikolaus Rath <Nikolaus@rath.org>
Mon, 28 Mar 2016 20:42:08 +0000 (13:42 -0700)
committerNikolaus Rath <Nikolaus@rath.org>
Tue, 29 Mar 2016 20:18:16 +0000 (13:18 -0700)
lib/fuse_lowlevel.c

index 542d7ae35406018e462af4d85865bfeb765ffdca..3acb6638d0cb562e70a97046c9e37a295847455b 100755 (executable)
@@ -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