diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cuse_lowlevel.c | 16 | ||||
-rw-r--r-- | lib/fuse.c | 9 | ||||
-rwxr-xr-x | lib/fuse_loop_mt.c | 2 | ||||
-rwxr-xr-x | lib/fuse_lowlevel.c | 157 | ||||
-rw-r--r-- | lib/fuse_session.c | 5 | ||||
-rwxr-xr-x | lib/fuse_signals.c | 1 | ||||
-rw-r--r-- | lib/mount.c | 14 | ||||
-rw-r--r-- | lib/mount_bsd.c | 2 |
8 files changed, 90 insertions, 116 deletions
diff --git a/lib/cuse_lowlevel.c b/lib/cuse_lowlevel.c index fbaa873..cef14c6 100644 --- a/lib/cuse_lowlevel.c +++ b/lib/cuse_lowlevel.c @@ -281,12 +281,16 @@ struct fuse_session *cuse_lowlevel_setup(int argc, char *argv[], int res; res = fuse_parse_cmdline(&args, NULL, multithreaded, &foreground); - if (res == -1) - goto err_args; + if (res == -1) { + fuse_opt_free_args(&args); + return NULL; + } res = fuse_opt_parse(&args, NULL, kill_subtype_opts, NULL); - if (res == -1) - goto err_args; + if (res == -1) { + fuse_opt_free_args(&args); + return NULL; + } /* * Make sure file descriptors 0, 1 and 2 are open, otherwise chaos @@ -301,7 +305,7 @@ struct fuse_session *cuse_lowlevel_setup(int argc, char *argv[], se = cuse_lowlevel_new(&args, ci, clop, userdata); fuse_opt_free_args(&args); if (se == NULL) - goto err_args; + return NULL; fd = open(devname, O_RDWR); if (fd == -1) { @@ -335,8 +339,6 @@ err_sig: fuse_remove_signal_handlers(se); err_se: fuse_session_destroy(se); -err_args: - fuse_opt_free_args(&args); return NULL; } @@ -118,11 +118,11 @@ struct node_table { }; #define container_of(ptr, type, member) ({ \ - const typeof( ((type *)0)->member ) *__mptr = (ptr); \ - (type *)( (char *)__mptr - offsetof(type,member) );}) + const typeof( ((type *)0)->member ) *__mptr = (ptr); \ + (type *)( (char *)__mptr - offsetof(type,member) );}) #define list_entry(ptr, type, member) \ - container_of(ptr, type, member) + container_of(ptr, type, member) struct list_head { struct list_head *next; @@ -4320,7 +4320,7 @@ static int fuse_session_loop_remember(struct fuse *f) time_t next_clean; struct fuse_chan *ch = fuse_session_chan(se); struct pollfd fds = { - .fd = fuse_chan_fd(ch), + .fd = ch->fd, .events = POLLIN }; struct fuse_buf fbuf = { @@ -4831,4 +4831,3 @@ void fuse_destroy(struct fuse *f) free(f); fuse_delete_context_key(); } - diff --git a/lib/fuse_loop_mt.c b/lib/fuse_loop_mt.c index 6d7f051..036f75c 100755 --- a/lib/fuse_loop_mt.c +++ b/lib/fuse_loop_mt.c @@ -193,7 +193,7 @@ static struct fuse_chan *fuse_clone_chan(struct fuse_mt *mt) } fcntl(clonefd, F_SETFD, FD_CLOEXEC); - masterfd = fuse_chan_fd(mt->prevch); + masterfd = mt->prevch->fd; res = ioctl(clonefd, FUSE_DEV_IOC_CLONE, &masterfd); if (res == -1) { fprintf(stderr, "fuse: failed to clone device fd: %s\n", diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c index eff820f..a28ff47 100755 --- a/lib/fuse_lowlevel.c +++ b/lib/fuse_lowlevel.c @@ -158,80 +158,11 @@ 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); + int fd = ch->fd; if (fd != -1) - close(fd); + close(fd); } @@ -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(ch->fd, 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) { @@ -868,7 +814,7 @@ static int fuse_send_data_iov(struct fuse_ll *f, struct fuse_chan *ch, splice_flags |= SPLICE_F_MOVE; res = splice(llp->pipe[0], NULL, - fuse_chan_fd(ch), NULL, out->len, splice_flags); + ch->fd, NULL, out->len, splice_flags); if (res == -1) { res = -errno; perror("fuse: splice from pipe"); @@ -2088,7 +2034,7 @@ static void do_init(fuse_req_t req, fuse_ino_t nodeid, const void *inarg) fprintf(stderr, " max_background=%i\n", outarg.max_background); fprintf(stderr, " congestion_threshold=%i\n", - outarg.congestion_threshold); + outarg.congestion_threshold); fprintf(stderr, " time_gran=%u\n", outarg.time_gran); } @@ -2193,7 +2139,7 @@ int fuse_lowlevel_notify_poll(struct fuse_pollhandle *ph) } int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino, - off_t off, off_t len) + off_t off, off_t len) { struct fuse_notify_inval_inode_out outarg; struct fuse_ll *f; @@ -2217,7 +2163,7 @@ int fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, fuse_ino_t ino, } int fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, fuse_ino_t parent, - const char *name, size_t namelen) + const char *name, size_t namelen) { struct fuse_notify_inval_entry_out outarg; struct fuse_ll *f; @@ -2723,7 +2669,7 @@ static void fuse_ll_help(void) " -o big_writes enable larger than 4kB writes\n" " -o no_remote_lock disable remote file locking\n" " -o no_remote_flock disable remote file locking (BSD)\n" -" -o no_remote_posix_lock disable remove file locking (POSIX)\n" +" -o no_remote_posix_lock disable remote file locking (POSIX)\n" " -o [no_]splice_write use splice to write to the fuse device\n" " -o [no_]splice_move move data while splicing to the fuse device\n" " -o [no_]splice_read use splice to read from the fuse device\n" @@ -2788,16 +2734,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; @@ -2819,7 +2765,7 @@ int fuse_session_receive_buf(struct fuse_session *se, struct fuse_buf *buf, goto fallback; } - res = splice(fuse_chan_fd(ch), NULL, llp->pipe[1], NULL, bufsize, 0); + res = splice(ch->fd, NULL, llp->pipe[1], NULL, bufsize, 0); err = errno; if (fuse_session_exited(se)) @@ -2892,15 +2838,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(ch->fd, 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 diff --git a/lib/fuse_session.c b/lib/fuse_session.c index 42fe5c3..6b54e43 100644 --- a/lib/fuse_session.c +++ b/lib/fuse_session.c @@ -90,11 +90,6 @@ struct fuse_chan *fuse_chan_new(int fd) return ch; } -int fuse_chan_fd(struct fuse_chan *ch) -{ - return ch->fd; -} - struct fuse_session *fuse_chan_session(struct fuse_chan *ch) { return ch->se; diff --git a/lib/fuse_signals.c b/lib/fuse_signals.c index b992b71..9fa787c 100755 --- a/lib/fuse_signals.c +++ b/lib/fuse_signals.c @@ -72,4 +72,3 @@ void fuse_remove_signal_handlers(struct fuse_session *se) set_one_signal_handler(SIGTERM, exit_handler, 1); set_one_signal_handler(SIGPIPE, SIG_IGN, 1); } - diff --git a/lib/mount.c b/lib/mount.c index de4ae74..7be7b25 100644 --- a/lib/mount.c +++ b/lib/mount.c @@ -28,12 +28,12 @@ #ifdef __NetBSD__ #include <perfuse.h> -#define MS_RDONLY MNT_RDONLY -#define MS_NOSUID MNT_NOSUID -#define MS_NODEV MNT_NODEV -#define MS_NOEXEC MNT_NOEXEC -#define MS_SYNCHRONOUS MNT_SYNCHRONOUS -#define MS_NOATIME MNT_NOATIME +#define MS_RDONLY MNT_RDONLY +#define MS_NOSUID MNT_NOSUID +#define MS_NODEV MNT_NODEV +#define MS_NOEXEC MNT_NOEXEC +#define MS_SYNCHRONOUS MNT_SYNCHRONOUS +#define MS_NOATIME MNT_NOATIME #define umount2(mnt, flags) unmount(mnt, (flags == 2) ? MNT_FORCE : 0) #endif @@ -398,7 +398,7 @@ static int fuse_mount_fusermount(const char *mountpoint, struct mount_opts *mo, rv = receive_fd(fds[1]); if (!mo->auto_unmount) { - /* with auto_unmount option fusermount will not exit until + /* with auto_unmount option fusermount will not exit until this socket is closed */ close(fds[1]); waitpid(pid, NULL, 0); /* bury zombie */ diff --git a/lib/mount_bsd.c b/lib/mount_bsd.c index 8f3acf0..6a7c958 100644 --- a/lib/mount_bsd.c +++ b/lib/mount_bsd.c @@ -43,7 +43,7 @@ struct mount_opts { char *kernel_opts; }; -#define FUSE_DUAL_OPT_KEY(templ, key) \ +#define FUSE_DUAL_OPT_KEY(templ, key) \ FUSE_OPT_KEY(templ, key), FUSE_OPT_KEY("no" templ, key) static const struct fuse_opt fuse_mount_opts[] = { |