libfuse: remove fuse_chan_(send|receive)
authorMiklos Szeredi <mszeredi@suse.cz>
Fri, 21 Jun 2013 16:17:27 +0000 (18:17 +0200)
committerMiklos Szeredi <mszeredi@suse.cz>
Fri, 21 Jun 2013 16:17:27 +0000 (18:17 +0200)
Move the fuse_chan_ops.send and .receive implementations to fuse_lowlevel.c.  The abstraction wasn't actually useful and made the the splice implementation more difficult.

Remove fuse_chan_ops.send and fuse_chan_ops.receive.

include/fuse_lowlevel.h
lib/fuse.c
lib/fuse_i.h
lib/fuse_kern_chan.c
lib/fuse_loop.c
lib/fuse_loop_mt.c
lib/fuse_lowlevel.c
lib/fuse_session.c

index 4817747c7b16d16a776dafccdabce78041e1825f..14c4dead20c84d7dc4815185a7bb01f8b42cec86 100644 (file)
@@ -1621,11 +1621,11 @@ void fuse_session_process_buf(struct fuse_session *se,
  *
  * @param se the session
  * @param buf the fuse_buf to store the request in
- * @param chp pointer to the channel
+ * @param ch the channel
  * @return the actual size of the raw request, or -errno on error
  */
 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
-                            struct fuse_chan **chp);
+                            struct fuse_chan *ch);
 
 /**
  * Destroy a session
index f15906318803b289e46409522b9ef21f8f633b75..80479330f00bef85a0c062a4dd3e483b0f467690 100644 (file)
@@ -4037,7 +4037,6 @@ static int fuse_session_loop_remember(struct fuse *f)
        curr_time(&now);
        next_clean = now.tv_sec;
        while (!fuse_session_exited(se)) {
-               struct fuse_chan *tmpch = ch;
                struct fuse_buf fbuf = {
                        .mem = buf,
                        .size = bufsize,
@@ -4057,14 +4056,14 @@ static int fuse_session_loop_remember(struct fuse *f)
                        else
                                break;
                } else if (res > 0) {
-                       res = fuse_session_receive_buf(se, &fbuf, &tmpch);
+                       res = fuse_session_receive_buf(se, &fbuf, ch);
 
                        if (res == -EINTR)
                                continue;
                        if (res <= 0)
                                break;
 
-                       fuse_session_process_buf(se, &fbuf, tmpch);
+                       fuse_session_process_buf(se, &fbuf, ch);
                } else {
                        timeout = fuse_clean_cache(f);
                        curr_time(&now);
index 245e175f088e6279d7998f95a89275c7c8d815d7..741c3d540c6bdfef88161eb1b9b885330793b52a 100644 (file)
@@ -18,30 +18,6 @@ struct fuse_ll;
  * This is used in channel creation
  */
 struct fuse_chan_ops {
-       /**
-        * Hook for receiving a raw request
-        *
-        * @param ch pointer to the channel
-        * @param buf the buffer to store the request in
-        * @param size the size of the buffer
-        * @return the actual size of the raw request, or -1 on error
-        */
-       int (*receive)(struct fuse_chan **chp, char *buf, size_t size);
-
-       /**
-        * Hook for sending a raw reply
-        *
-        * A return value of -ENOENT means, that the request was
-        * interrupted, and the reply was discarded
-        *
-        * @param ch the channel
-        * @param iov vector of blocks
-        * @param count the number of blocks in vector
-        * @return zero on success, -errno on failure
-        */
-       int (*send)(struct fuse_chan *ch, const struct iovec iov[],
-                   size_t count);
-
        /**
         * Destroy the channel
         *
@@ -52,7 +28,7 @@ struct fuse_chan_ops {
 
 struct fuse_session {
        int (*receive_buf)(struct fuse_session *se, struct fuse_buf *buf,
-                          struct fuse_chan **chp);
+                          struct fuse_chan *ch);
 
        void (*process_buf)(void *data, const struct fuse_buf *buf,
                            struct fuse_chan *ch);
@@ -168,32 +144,6 @@ struct fuse_chan *fuse_chan_new(struct fuse_chan_ops *op, int fd,
  */
 struct fuse_session *fuse_chan_session(struct fuse_chan *ch);
 
-/**
- * Send a raw reply
- *
- * A return value of -ENOENT means, that the request was
- * interrupted, and the reply was discarded
- *
- * @param ch the channel
- * @param iov vector of blocks
- * @param count the number of blocks in vector
- * @return zero on success, -errno on failure
- */
-int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[],
-                  size_t count);
-
-/**
- * Receive a raw request
- *
- * A return value of -ENODEV means, that the filesystem was unmounted
- *
- * @param ch pointer to the channel
- * @param buf the buffer to store the request in
- * @param size the size of the buffer
- * @return the actual size of the raw request, or -errno on error
- */
-int fuse_chan_recv(struct fuse_chan **ch, char *buf, size_t size);
-
 void fuse_kern_unmount(const char *mountpoint, int fd);
 int fuse_kern_mount(const char *mountpoint, struct fuse_args *args);
 
index c677c3e2bcf98ef77513f9dff9f945c9edce2964..d58119c725cd4dfd7cdbc5b9fa90d902767259a0 100644 (file)
 #include <unistd.h>
 #include <assert.h>
 
-static int fuse_kern_chan_receive(struct fuse_chan **chp, char *buf,
-                                 size_t size)
-{
-       struct fuse_chan *ch = *chp;
-       int err;
-       ssize_t res;
-       struct fuse_session *se = fuse_chan_session(ch);
-       assert(se != NULL);
-
-restart:
-       res = read(fuse_chan_fd(ch), buf, size);
-       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;
-       }
-       return res;
-}
-
-static int fuse_kern_chan_send(struct fuse_chan *ch, const struct iovec iov[],
-                              size_t count)
-{
-       if (iov) {
-               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;
-}
-
 static void fuse_kern_chan_destroy(struct fuse_chan *ch)
 {
        close(fuse_chan_fd(ch));
@@ -85,8 +25,6 @@ static void fuse_kern_chan_destroy(struct fuse_chan *ch)
 struct fuse_chan *fuse_kern_chan_new(int fd)
 {
        struct fuse_chan_ops op = {
-               .receive = fuse_kern_chan_receive,
-               .send = fuse_kern_chan_send,
                .destroy = fuse_kern_chan_destroy,
        };
        size_t bufsize = getpagesize() + 0x1000;
index 987a8d7a981fb562cf5cf99bb4db9776932a0e1c..91d2dd856b704db15ab7cd7eb01597b9aae0b934 100644 (file)
@@ -24,20 +24,19 @@ int fuse_session_loop(struct fuse_session *se)
        }
 
        while (!fuse_session_exited(se)) {
-               struct fuse_chan *tmpch = ch;
                struct fuse_buf fbuf = {
                        .mem = buf,
                        .size = bufsize,
                };
 
-               res = fuse_session_receive_buf(se, &fbuf, &tmpch);
+               res = fuse_session_receive_buf(se, &fbuf, ch);
 
                if (res == -EINTR)
                        continue;
                if (res <= 0)
                        break;
 
-               fuse_session_process_buf(se, &fbuf, tmpch);
+               fuse_session_process_buf(se, &fbuf, ch);
        }
 
        free(buf);
index f328fec244e50c4ceae3133886ce5e0f9a854fae..b53a86836e99c5c8aecb60d371c32bd2a233bf8b 100644 (file)
@@ -70,7 +70,6 @@ static void *fuse_do_work(void *data)
 
        while (!fuse_session_exited(mt->se)) {
                int isforget = 0;
-               struct fuse_chan *ch = mt->prevch;
                struct fuse_buf fbuf = {
                        .mem = w->buf,
                        .size = w->bufsize,
@@ -78,7 +77,7 @@ static void *fuse_do_work(void *data)
                int res;
 
                pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
-               res = fuse_session_receive_buf(mt->se, &fbuf, &ch);
+               res = fuse_session_receive_buf(mt->se, &fbuf, mt->prevch);
                pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
                if (res == -EINTR)
                        continue;
@@ -114,7 +113,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, ch);
+               fuse_session_process_buf(mt->se, &fbuf, mt->prevch);
 
                pthread_mutex_lock(&mt->lock);
                if (!isforget)
index 30877ec5f96acb1bb204a27ba5dacc38874c3630..77de5ebafa391e1caf02cd4e59839f8c8864b1d5 100644 (file)
@@ -153,6 +153,62 @@ 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)
+{
+       int err;
+       ssize_t res;
+       struct fuse_session *se = fuse_chan_session(ch);
+       assert(se != NULL);
+
+restart:
+       res = read(fuse_chan_fd(ch), buf, size);
+       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;
+       }
+       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;
+}
 
 static int fuse_send_msg(struct fuse_ll *f, struct fuse_chan *ch,
                         struct iovec *iov, int count)
@@ -301,8 +357,6 @@ int fuse_reply_err(fuse_req_t req, int err)
 
 void fuse_reply_none(fuse_req_t req)
 {
-       if (req->ch)
-               fuse_chan_send(req->ch, NULL, 0);
        fuse_free_req(req);
 }
 
@@ -2631,9 +2685,8 @@ 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 **chp)
+                              struct fuse_chan *ch)
 {
-       struct fuse_chan *ch = *chp;
        struct fuse_ll *f = fuse_session_data(se);
        size_t bufsize = buf->size;
        struct fuse_ll_pipe *llp;
@@ -2719,7 +2772,7 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
        return res;
 
 fallback:
-       res = fuse_chan_recv(chp, buf->mem, bufsize);
+       res = fuse_chan_recv(ch, buf->mem, bufsize);
        if (res <= 0)
                return res;
 
@@ -2729,11 +2782,11 @@ fallback:
 }
 #else
 static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
-                              struct fuse_chan **chp)
+                              struct fuse_chan *ch)
 {
        (void) se;
 
-       int res = fuse_chan_recv(chp, buf->mem, buf->size);
+       int res = fuse_chan_recv(ch, buf->mem, buf->size);
        if (res <= 0)
                return res;
 
@@ -2743,7 +2796,6 @@ static int fuse_ll_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
 }
 #endif
 
-
 struct fuse_session *fuse_lowlevel_new(struct fuse_args *args,
                                       const struct fuse_lowlevel_ops *op,
                                       size_t op_size, void *userdata)
index f535720f4b9488e464bfac6d67d66ca5cec68df5..318cfeeb9002797b2a44e1562e300a092832c27b 100644 (file)
@@ -69,19 +69,9 @@ void fuse_session_process_buf(struct fuse_session *se,
 }
 
 int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf,
-                            struct fuse_chan **chp)
+                            struct fuse_chan *ch)
 {
-       int res;
-
-       if (se->receive_buf) {
-               res = se->receive_buf(se, buf, chp);
-       } else {
-               res = fuse_chan_recv(chp, buf->mem, buf->size);
-               if (res > 0)
-                       buf->size = res;
-       }
-
-       return res;
+       return se->receive_buf(se, buf, ch);
 }
 
 int fuse_chan_clearfd(struct fuse_chan *ch)
@@ -151,18 +141,6 @@ struct fuse_session *fuse_chan_session(struct fuse_chan *ch)
        return ch->se;
 }
 
-int fuse_chan_recv(struct fuse_chan **chp, char *buf, size_t size)
-{
-       struct fuse_chan *ch = *chp;
-
-       return ch->op.receive(chp, buf, size);
-}
-
-int fuse_chan_send(struct fuse_chan *ch, const struct iovec iov[], size_t count)
-{
-       return ch->op.send(ch, iov, count);
-}
-
 void fuse_chan_destroy(struct fuse_chan *ch)
 {
        fuse_session_remove_chan(ch);