diff --git a/libfuse/include/fuse.h b/libfuse/include/fuse.h index 909227b0..767532d6 100644 --- a/libfuse/include/fuse.h +++ b/libfuse/include/fuse.h @@ -13,6 +13,7 @@ #include "fuse_common.h" #include "fuse_kernel.h" #include "fuse_req_ctx.h" +#include "fuse_conn_info.hpp" #include #include @@ -150,7 +151,7 @@ struct fuse_operations int (*fsyncdir)(const fuse_req_ctx_t *, const fuse_file_info_t *, int); - void *(*init)(struct fuse_conn_info *conn); + void *(*init)(struct fuse_conn_info_t *conn); void (*destroy)(void); int (*access)(const fuse_req_ctx_t *, const char *, @@ -187,10 +188,6 @@ struct fuse_operations unsigned int flags, void *data, uint32_t *out_bufsz); - int (*poll)(const fuse_req_ctx_t *, - const fuse_file_info_t *ffi, - fuse_pollhandle_t *ph, - unsigned *reventsp); int (*write)(const fuse_req_ctx_t *, const fuse_file_info_t *ffi, const char *data, @@ -387,8 +384,6 @@ int fuse_clean_cache(struct fuse *fuse); * fuse_fs_releasedir and fuse_fs_statfs, which return 0. */ -int fuse_notify_poll(fuse_pollhandle_t *ph); - /* ----------------------------------------------------------- * * Advanced API for event handling, don't worry about this... * * ----------------------------------------------------------- */ diff --git a/libfuse/include/fuse_common.h b/libfuse/include/fuse_common.h index 78cbbce1..37094e48 100644 --- a/libfuse/include/fuse_common.h +++ b/libfuse/include/fuse_common.h @@ -128,25 +128,8 @@ struct fuse_file_info_t #define FUSE_IOCTL_MAX_IOV 256 -/** - * Connection information, passed to the ->init() method - * - * Some of the elements are read-write, these can be changed to - * indicate the value requested by the filesystem. The requested - * value must usually be smaller than the indicated value. - */ -struct fuse_conn_info -{ - unsigned proto_major; - unsigned proto_minor; - uint64_t capable; - uint64_t want; -}; - struct fuse_session; struct fuse_chan; -struct fuse_pollhandle_t; -typedef struct fuse_pollhandle_t fuse_pollhandle_t; /** * Create a FUSE mountpoint @@ -207,13 +190,6 @@ int fuse_daemonize(int foreground); */ int fuse_version(void); -/** - * Destroy poll handle - * - * @param ph the poll handle - */ -void fuse_pollhandle_destroy(fuse_pollhandle_t *ph); - /* ----------------------------------------------------------- * * Data buffer * * ----------------------------------------------------------- */ diff --git a/libfuse/include/fuse_conn_info.hpp b/libfuse/include/fuse_conn_info.hpp new file mode 100644 index 00000000..bb971307 --- /dev/null +++ b/libfuse/include/fuse_conn_info.hpp @@ -0,0 +1,12 @@ +#pragma once + +#include "int_types.h" + +typedef struct fuse_conn_info_t fuse_conn_info_t; +struct fuse_conn_info_t +{ + u32 proto_major; + u32 proto_minor; + u64 capable; + u64 want; +}; diff --git a/libfuse/include/fuse_lowlevel.hpp b/libfuse/include/fuse_lowlevel.hpp index 340d8f3a..ad666d14 100644 --- a/libfuse/include/fuse_lowlevel.hpp +++ b/libfuse/include/fuse_lowlevel.hpp @@ -119,7 +119,7 @@ struct fuse_lowlevel_ops void (*getattr)(fuse_req_t *req, struct fuse_in_header *hdr); void (*getlk)(fuse_req_t *req, const struct fuse_in_header *hdr); void (*getxattr)(fuse_req_t *req, struct fuse_in_header *hdr); - void (*init)(void *userdata, struct fuse_conn_info *conn); + void (*init)(void *userdata, fuse_conn_info_t *conn); void (*ioctl)(fuse_req_t *req, const struct fuse_in_header *hdr); void (*link)(fuse_req_t *req, struct fuse_in_header *hdr); void (*listxattr)(fuse_req_t *req, struct fuse_in_header *hdr); @@ -401,27 +401,10 @@ int fuse_reply_ioctl(fuse_req_t *req, int result, const void *buf, uint32_t size int fuse_reply_ioctl_iov(fuse_req_t *req, int result, const struct iovec *iov, int count); -/** - * Reply with poll result event mask - * - * @param req request handle - * @param revents poll result event mask - */ -int fuse_reply_poll(fuse_req_t *req, unsigned revents); - /* ----------------------------------------------------------- * * Notification * * ----------------------------------------------------------- */ -/** - * Notify IO readiness event - * - * For more information, please read comment for poll operation. - * - * @param ph poll handle to notify IO readiness event for - */ -int fuse_lowlevel_notify_poll(fuse_pollhandle_t *ph); - /** * Notify to invalidate cache for an inode * @@ -574,8 +557,7 @@ struct fuse_session *fuse_lowlevel_new(struct fuse_args *args, * Session interface * * ----------------------------------------------------------- */ -struct fuse_session *fuse_session_new(void *data, - void *receive_buf, +struct fuse_session *fuse_session_new(void *receive_buf, void *process_buf, void *destroy); void fuse_session_add_chan(struct fuse_session *se, struct fuse_chan *ch); diff --git a/libfuse/include/fuse_pollhandle.h b/libfuse/include/fuse_pollhandle.h deleted file mode 100644 index 76a62610..00000000 --- a/libfuse/include/fuse_pollhandle.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include - -struct fuse_chan; -struct fuse_ll; - -typedef struct fuse_pollhandle_t fuse_pollhandle_t; -struct fuse_pollhandle_t -{ - uint64_t kh; - struct fuse_chan *ch; - struct fuse_ll *f; -}; diff --git a/libfuse/include/fuse_req.hpp b/libfuse/include/fuse_req.hpp index 3f16c85c..07f0cab5 100644 --- a/libfuse/include/fuse_req.hpp +++ b/libfuse/include/fuse_req.hpp @@ -1,17 +1,17 @@ #pragma once #include "fuse_req_ctx.h" +#include "fuse_conn_info.hpp" -struct fuse_ll; struct fuse_chan; typedef struct fuse_req_t fuse_req_t; struct fuse_req_t { fuse_req_ctx_t ctx; - struct fuse_ll *f; struct fuse_chan *ch; unsigned int ioctl_64bit : 1; + fuse_conn_info_t conn; }; fuse_req_t* fuse_req_alloc(); diff --git a/libfuse/lib/fuse.cpp b/libfuse/lib/fuse.cpp index b0ab7c87..5e61fcc4 100644 --- a/libfuse/lib/fuse.cpp +++ b/libfuse/lib/fuse.cpp @@ -26,7 +26,6 @@ #include "fuse_kernel.h" #include "fuse_lowlevel.hpp" #include "fuse_opt.h" -#include "fuse_pollhandle.h" #include "fuse_msgbuf.hpp" #include "maintenance_thread.hpp" @@ -40,7 +39,6 @@ #include #include #include -#include #include #include #include @@ -69,10 +67,6 @@ static int g_LOG_METRICS = 0; -struct fuse_config -{ -}; - struct lock_queue_element { struct lock_queue_element *next; @@ -125,7 +119,6 @@ struct fuse nodeid_gen_t nodeid_gen; unsigned int hidectr; pthread_mutex_t lock; - struct fuse_config conf; fuse_operations ops; struct lock_queue_element *lockq; @@ -1366,8 +1359,8 @@ reply_entry(fuse_req_t *req_, static void -fuse_lib_init(void *data, - struct fuse_conn_info *conn) +fuse_lib_init(void *data, + fuse_conn_info_t *conn) { f.ops.init(conn); } @@ -1790,7 +1783,7 @@ fuse_lib_mknod(fuse_req_t *req_, arg = (fuse_mknod_in*)fuse_hdr_arg(hdr_); name = (const char*)PARAM(arg); - if(req_->f->conn.proto_minor >= 12) + if(req_->conn.proto_minor >= 12) req_->ctx.umask = arg->umask; else name = (char*)arg + FUSE_COMPAT_MKNOD_IN_SIZE; @@ -1846,7 +1839,7 @@ fuse_lib_mkdir(fuse_req_t *req_, arg = (fuse_mkdir_in*)fuse_hdr_arg(hdr_); name = (const char*)PARAM(arg); - if(req_->f->conn.proto_minor >= 12) + if(req_->conn.proto_minor >= 12) req_->ctx.umask = arg->umask; err = get_path_name(hdr_->nodeid,name,&fusepath); @@ -2083,7 +2076,7 @@ fuse_lib_create(fuse_req_t *req_, ffi.flags = arg->flags; - if(req_->f->conn.proto_minor >= 12) + if(req_->conn.proto_minor >= 12) req_->ctx.umask = arg->umask; else name = ((char*)arg + sizeof(struct fuse_open_in)); @@ -2237,7 +2230,7 @@ fuse_lib_read(fuse_req_t *req_, arg = (fuse_read_in*)fuse_hdr_arg(hdr_); ffi.fh = arg->fh; - if(req_->f->conn.proto_minor >= 9) + if(req_->conn.proto_minor >= 9) { ffi.flags = arg->flags; ffi.lock_owner = arg->lock_owner; @@ -2272,7 +2265,7 @@ fuse_lib_write(fuse_req_t *req_, arg = (fuse_write_in*)fuse_hdr_arg(hdr_); ffi.fh = arg->fh; ffi.writepage = !!(arg->write_flags & 1); - if(req_->f->conn.proto_minor < 9) + if(req_->conn.proto_minor < 9) { data = ((char*)arg) + FUSE_COMPAT_WRITE_IN_SIZE; } @@ -2592,8 +2585,8 @@ fuse_lib_setxattr(fuse_req_t *req_, struct fuse_setxattr_in *arg; arg = (fuse_setxattr_in*)fuse_hdr_arg(hdr_); - if((req_->f->conn.capable & FUSE_SETXATTR_EXT) && - (req_->f->conn.want & FUSE_SETXATTR_EXT)) + if((req_->conn.capable & FUSE_SETXATTR_EXT) && + (req_->conn.want & FUSE_SETXATTR_EXT)) name = (const char*)PARAM(arg); else name = (((char*)arg) + FUSE_COMPAT_SETXATTR_IN_SIZE); @@ -2834,7 +2827,7 @@ fuse_lib_tmpfile(fuse_req_t *req_, ffi.flags = arg->flags; - if(req_->f->conn.proto_minor >= 12) + if(req_->conn.proto_minor >= 12) req_->ctx.umask = arg->umask; else name = (char*)arg + sizeof(struct fuse_open_in); @@ -3078,7 +3071,7 @@ fuse_lib_release(fuse_req_t *req_, arg = (fuse_release_in*)fuse_hdr_arg(hdr_); ffi.fh = arg->fh; ffi.flags = arg->flags; - if(req_->f->conn.proto_minor >= 8) + if(req_->conn.proto_minor >= 8) { ffi.flush = !!(arg->release_flags & FUSE_RELEASE_FLUSH); ffi.lock_owner = arg->lock_owner; @@ -3116,7 +3109,7 @@ fuse_lib_flush(fuse_req_t *req_, ffi.fh = arg->fh; ffi.flush = 1; - if(req_->f->conn.proto_minor >= 7) + if(req_->conn.proto_minor >= 7) ffi.lock_owner = arg->lock_owner; err = fuse_flush_common(req_,hdr_->nodeid,&ffi); @@ -3276,14 +3269,15 @@ fuse_lib_ioctl(fuse_req_t *req_, const struct fuse_ioctl_in *arg; arg = (fuse_ioctl_in*)fuse_hdr_arg(hdr_); - if((arg->flags & FUSE_IOCTL_DIR) && !(req_->f->conn.want & FUSE_CAP_IOCTL_DIR)) + if((arg->flags & FUSE_IOCTL_DIR) && + !(req_->conn.want & FUSE_CAP_IOCTL_DIR)) { fuse_reply_err(req_,ENOTTY); return; } if((sizeof(void*) == 4) && - (req_->f->conn.proto_minor >= 16) && + (req_->conn.proto_minor >= 16) && !(arg->flags & FUSE_IOCTL_32BIT)) { req_->ioctl_64bit = 1; @@ -3337,38 +3331,7 @@ void fuse_lib_poll(fuse_req_t *req_, const struct fuse_in_header *hdr_) { - int err; - unsigned revents = 0; - fuse_file_info_t ffi = {0}; - fuse_pollhandle_t *ph = NULL; - const struct fuse_poll_in *arg; - - arg = (fuse_poll_in*)fuse_hdr_arg(hdr_); - ffi.fh = arg->fh; - - if(arg->flags & FUSE_POLL_SCHEDULE_NOTIFY) - { - ph = (fuse_pollhandle_t*)malloc(sizeof(fuse_pollhandle_t)); - if(ph == NULL) - { - fuse_reply_err(req_,ENOMEM); - return; - } - - ph->kh = arg->kh; - ph->ch = req_->ch; - ph->f = req_->f; - } - - err = f.ops.poll(&req_->ctx, - &ffi, - ph, - &revents); - - if(!err) - fuse_reply_poll(req_,revents); - else - fuse_reply_err(req_,err); + fuse_reply_err(req_,-ENOSYS); } static @@ -3555,12 +3518,6 @@ static struct fuse_lowlevel_ops fuse_path_ops = .write = fuse_lib_write, }; -int -fuse_notify_poll(fuse_pollhandle_t *ph) -{ - return fuse_lowlevel_notify_poll(ph); -} - int fuse_exited() { @@ -3584,8 +3541,6 @@ enum KEY_HELP, }; -#define FUSE_LIB_OPT(t,p,v) { t,offsetof(struct fuse_config,p),v } - static const struct fuse_opt fuse_lib_opts[] = { FUSE_OPT_END @@ -3805,7 +3760,7 @@ fuse_new(struct fuse_chan *ch, llop.setlk = NULL; } - if(fuse_opt_parse(args,&f.conf,fuse_lib_opts,fuse_lib_opt_proc) == -1) + if(fuse_opt_parse(args,NULL,fuse_lib_opts,fuse_lib_opt_proc) == -1) goto out_free_fs; g_LOG_METRICS = fuse_cfg.debug; diff --git a/libfuse/lib/fuse_i.h b/libfuse/lib/fuse_i.h index 78b6d1b6..97e4c914 100644 --- a/libfuse/lib/fuse_i.h +++ b/libfuse/lib/fuse_i.h @@ -27,7 +27,6 @@ struct fuse_session void (*destroy)(void *data); - struct fuse_ll *f; volatile int exited; struct fuse_chan *ch; }; @@ -43,27 +42,6 @@ struct fuse_notify_req struct fuse_notify_req *prev; }; -struct fuse_ll -{ - struct fuse_lowlevel_ops op; - void *userdata; - uid_t owner; - struct fuse_conn_info conn; - pthread_mutex_t lock; - int got_init; - int got_destroy; - int broken_splice_nonblock; - uint64_t notify_ctr; - struct fuse_notify_req notify_list; -}; - -struct fuse_cmd -{ - char *buf; - size_t buflen; - struct fuse_chan *ch; -}; - EXTERN_C_BEGIN struct fuse *fuse_new_common(struct fuse_chan *ch, diff --git a/libfuse/lib/fuse_loop.cpp b/libfuse/lib/fuse_loop.cpp index 92986caa..a816f823 100644 --- a/libfuse/lib/fuse_loop.cpp +++ b/libfuse/lib/fuse_loop.cpp @@ -16,7 +16,6 @@ #include "fuse_cfg.hpp" #include "fuse_msgbuf.hpp" -#include "fuse_ll.hpp" #include #include diff --git a/libfuse/lib/fuse_lowlevel.cpp b/libfuse/lib/fuse_lowlevel.cpp index d78d232a..9e3f68bd 100644 --- a/libfuse/lib/fuse_lowlevel.cpp +++ b/libfuse/lib/fuse_lowlevel.cpp @@ -11,7 +11,6 @@ #endif #include "mutex.hpp" -#include "lfmp.h" #include "debug.hpp" #include "fuse_cfg.hpp" @@ -19,7 +18,6 @@ #include "fuse_kernel.h" #include "fuse_msgbuf.hpp" #include "fuse_opt.h" -#include "fuse_pollhandle.h" #include "stat_utils.h" #include "fmt/core.h" @@ -48,26 +46,19 @@ const decltype( ((type*)0)->member ) *__mptr = (ptr); \ (type *)( (char*)__mptr - offsetof(type,member) );}) -static size_t pagesize; -static lfmp_t g_FMP_fuse_req; - -static -__attribute__((constructor)) -void -fuse_ll_constructor(void) +struct fuse_ll { - pagesize = sysconf(_SC_PAGESIZE); - lfmp_init(&g_FMP_fuse_req,sizeof(struct fuse_req_t),1); -} - -static -__attribute__((destructor)) -void -fuse_ll_destructor(void) -{ - lfmp_destroy(&g_FMP_fuse_req); -} + struct fuse_lowlevel_ops op; + void *userdata; + fuse_conn_info_t conn; + pthread_mutex_t lock; + int got_init; + int got_destroy; + uint64_t notify_ctr; + struct fuse_notify_req notify_list; +}; +static fuse_ll f = {0}; static void @@ -104,37 +95,9 @@ iov_length(const struct iovec *iov, return ret; } -static -void -destroy_req(fuse_req_t *req) -{ - lfmp_free(&g_FMP_fuse_req,req); -} - -static -fuse_req_t* -fuse_ll_alloc_req(struct fuse_ll *f) -{ - fuse_req_t *req; - - req = (fuse_req_t*)lfmp_calloc(&g_FMP_fuse_req); - if(req == NULL) - { - fprintf(stderr, "fuse: failed to allocate request\n"); - } - else - { - req->f = f; - } - - return req; -} - - static int -fuse_send_msg(struct fuse_ll *f, - struct fuse_chan *ch, +fuse_send_msg(struct fuse_chan *ch, struct iovec *iov, int count) { @@ -175,22 +138,22 @@ fuse_send_reply_iov_nofree(fuse_req_t *req, iov[0].iov_base = &out; iov[0].iov_len = sizeof(struct fuse_out_header); - return fuse_send_msg(req->f, req->ch, iov, count); + return fuse_send_msg(req->ch, iov, count); } static int -send_reply_iov(fuse_req_t *req, - int error, - struct iovec *iov, - int count) +send_reply_iov(fuse_req_t *req_, + int error_, + struct iovec *iov_, + int count_) { - int res; + int rv; - res = fuse_send_reply_iov_nofree(req, error, iov, count); - destroy_req(req); + rv = fuse_send_reply_iov_nofree(req_, error_, iov_, count_); + fuse_req_free(req_); - return res; + return rv; } static @@ -244,9 +207,9 @@ fuse_reply_err(fuse_req_t *req_, } void -fuse_reply_none(fuse_req_t *req) +fuse_reply_none(fuse_req_t *req_) { - destroy_req(req); + fuse_req_free(req_); } static @@ -293,12 +256,12 @@ fuse_reply_entry(fuse_req_t *req, const struct fuse_entry_param *e) { struct fuse_entry_out arg = {0}; - size_t size = req->f->conn.proto_minor < 9 ? + size_t size = f.conn.proto_minor < 9 ? FUSE_COMPAT_ENTRY_OUT_SIZE : sizeof(arg); /* before ABI 7.4 e->ino == 0 was invalid, only ENOENT meant negative entry */ - if(!e->ino && req->f->conn.proto_minor < 4) + if(!e->ino && f.conn.proto_minor < 4) return fuse_reply_err(req, ENOENT); fill_entry(&arg, e); @@ -318,20 +281,20 @@ struct fuse_create_out }; int -fuse_reply_create(fuse_req_t *req, - const struct fuse_entry_param *e, - const fuse_file_info_t *f) +fuse_reply_create(fuse_req_t *req_, + const struct fuse_entry_param *e_, + const fuse_file_info_t *ffi_) { struct fuse_create_out buf = {0}; - size_t entrysize = req->f->conn.proto_minor < 9 ? + size_t entrysize = (f.conn.proto_minor < 9) ? FUSE_COMPAT_ENTRY_OUT_SIZE : sizeof(struct fuse_entry_out); struct fuse_entry_out *earg = (struct fuse_entry_out*)&buf.e; struct fuse_open_out *oarg = (struct fuse_open_out*)(((char*)&buf)+entrysize); - fill_entry(earg, e); - fill_open(oarg, f); + fill_entry(earg, e_); + fill_open(oarg, ffi_); - return send_reply_ok(req, &buf, entrysize + sizeof(struct fuse_open_out)); + return send_reply_ok(req_, &buf, entrysize + sizeof(struct fuse_open_out)); } int @@ -340,7 +303,7 @@ fuse_reply_attr(fuse_req_t *req, const uint64_t timeout) { struct fuse_attr_out arg = {0}; - size_t size = req->f->conn.proto_minor < 9 ? + size_t size = f.conn.proto_minor < 9 ? FUSE_COMPAT_ATTR_OUT_SIZE : sizeof(arg); arg.attr_valid = timeout; @@ -405,8 +368,7 @@ fuse_reply_buf(fuse_req_t *req, static int -fuse_send_data_iov_fallback(struct fuse_ll *f, - struct fuse_chan *ch, +fuse_send_data_iov_fallback(struct fuse_chan *ch, struct iovec *iov, int iov_count, struct fuse_bufvec *buf, @@ -426,7 +388,7 @@ fuse_send_data_iov_fallback(struct fuse_ll *f, iov[iov_count].iov_len = len; iov_count++; - return fuse_send_msg(f, ch, iov, iov_count); + return fuse_send_msg(ch, iov, iov_count); } fuse_msgbuf_t *msgbuf; @@ -446,7 +408,7 @@ fuse_send_data_iov_fallback(struct fuse_ll *f, iov[iov_count].iov_base = msgbuf->mem; iov[iov_count].iov_len = len; iov_count++; - res = fuse_send_msg(f, ch, iov, iov_count); + res = fuse_send_msg(ch, iov, iov_count); msgbuf_free(msgbuf); return res; @@ -454,8 +416,7 @@ fuse_send_data_iov_fallback(struct fuse_ll *f, static int -fuse_send_data_iov(struct fuse_ll *f, - struct fuse_chan *ch, +fuse_send_data_iov(struct fuse_chan *ch, struct iovec *iov, int iov_count, struct fuse_bufvec *buf, @@ -464,7 +425,7 @@ fuse_send_data_iov(struct fuse_ll *f, size_t len = fuse_buf_size(buf); (void) flags; - return fuse_send_data_iov_fallback(f, ch, iov, iov_count, buf, len); + return fuse_send_data_iov_fallback(ch, iov, iov_count, buf, len); } int @@ -484,10 +445,10 @@ fuse_reply_data(fuse_req_t *req, out.unique = req->ctx.unique; out.error = 0; - res = fuse_send_msg(req->f,req->ch,iov,2); + res = fuse_send_msg(req->ch,iov,2); if(res <= 0) { - destroy_req(req); + fuse_req_free(req); return res; } else @@ -501,7 +462,7 @@ fuse_reply_statfs(fuse_req_t *req, const struct statvfs *stbuf) { struct fuse_statfs_out arg = {0}; - size_t size = req->f->conn.proto_minor < 4 ? + size_t size = f.conn.proto_minor < 4 ? FUSE_COMPAT_STATFS_SIZE : sizeof(arg); convert_statfs(stbuf, &arg.st); @@ -593,7 +554,7 @@ fuse_reply_ioctl_retry(fuse_req_t *req, iov[count].iov_len = sizeof(arg); count++; - if(req->f->conn.proto_minor < 16) + if(f.conn.proto_minor < 16) { if(in_count) { @@ -708,23 +669,12 @@ fuse_reply_ioctl_iov(fuse_req_t *req, return res; } -int -fuse_reply_poll(fuse_req_t *req, - unsigned revents) -{ - struct fuse_poll_out arg = {0}; - - arg.revents = revents; - - return send_reply_ok(req, &arg, sizeof(arg)); -} - static void do_lookup(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.lookup(req,hdr_); + f.op.lookup(req,hdr_); } static @@ -732,7 +682,7 @@ void do_forget(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.forget(req,hdr_); + f.op.forget(req,hdr_); } static @@ -740,7 +690,7 @@ void do_batch_forget(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.forget_multi(req,hdr_); + f.op.forget_multi(req,hdr_); } static @@ -748,7 +698,7 @@ void do_getattr(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.getattr(req, hdr_); + f.op.getattr(req, hdr_); } static @@ -756,7 +706,7 @@ void do_setattr(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.setattr(req_,hdr_); + f.op.setattr(req_,hdr_); } static @@ -764,7 +714,7 @@ void do_access(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.access(req,hdr_); + f.op.access(req,hdr_); } static @@ -772,7 +722,7 @@ void do_readlink(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.readlink(req,hdr_); + f.op.readlink(req,hdr_); } static @@ -780,7 +730,7 @@ void do_mknod(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.mknod(req,hdr_); + f.op.mknod(req,hdr_); } static @@ -788,7 +738,7 @@ void do_mkdir(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.mkdir(req,hdr_); + f.op.mkdir(req,hdr_); } static @@ -796,7 +746,7 @@ void do_unlink(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.unlink(req,hdr_); + f.op.unlink(req,hdr_); } static @@ -804,7 +754,7 @@ void do_rmdir(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.rmdir(req,hdr_); + f.op.rmdir(req,hdr_); } static @@ -812,7 +762,7 @@ void do_symlink(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.symlink(req,hdr_); + f.op.symlink(req,hdr_); } static @@ -820,7 +770,7 @@ void do_rename(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.rename(req,hdr_); + f.op.rename(req,hdr_); } static @@ -828,7 +778,7 @@ void do_link(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.link(req,hdr_); + f.op.link(req,hdr_); } static @@ -836,7 +786,7 @@ void do_create(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.create(req,hdr_); + f.op.create(req,hdr_); } static @@ -844,7 +794,7 @@ void do_open(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.open(req,hdr_); + f.op.open(req,hdr_); } static @@ -852,7 +802,7 @@ void do_read(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.read(req,hdr_); + f.op.read(req,hdr_); } static @@ -860,7 +810,7 @@ void do_write(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.write(req,hdr_); + f.op.write(req,hdr_); } static @@ -868,7 +818,7 @@ void do_flush(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.flush(req,hdr_); + f.op.flush(req,hdr_); } static @@ -876,7 +826,7 @@ void do_release(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.release(req,hdr_); + f.op.release(req,hdr_); } static @@ -884,7 +834,7 @@ void do_fsync(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.fsync(req,hdr_); + f.op.fsync(req,hdr_); } static @@ -892,7 +842,7 @@ void do_opendir(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.opendir(req,hdr_); + f.op.opendir(req,hdr_); } static @@ -900,7 +850,7 @@ void do_readdir(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.readdir(req,hdr_); + f.op.readdir(req,hdr_); } static @@ -908,7 +858,7 @@ void do_readdirplus(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.readdir_plus(req_,hdr_); + f.op.readdir_plus(req_,hdr_); } static @@ -916,7 +866,7 @@ void do_releasedir(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.releasedir(req,hdr_); + f.op.releasedir(req,hdr_); } static @@ -924,7 +874,7 @@ void do_fsyncdir(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.fsyncdir(req,hdr_); + f.op.fsyncdir(req,hdr_); } static @@ -932,7 +882,7 @@ void do_statfs(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.statfs(req,hdr_); + f.op.statfs(req,hdr_); } static @@ -940,7 +890,7 @@ void do_setxattr(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.setxattr(req,hdr_); + f.op.setxattr(req,hdr_); } static @@ -948,7 +898,7 @@ void do_getxattr(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.getxattr(req,hdr_); + f.op.getxattr(req,hdr_); } static @@ -956,7 +906,7 @@ void do_listxattr(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.listxattr(req,hdr_); + f.op.listxattr(req,hdr_); } static @@ -964,7 +914,7 @@ void do_removexattr(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.removexattr(req,hdr_); + f.op.removexattr(req,hdr_); } static @@ -988,7 +938,7 @@ void do_getlk(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.getlk(req,hdr_); + f.op.getlk(req,hdr_); } static @@ -1025,13 +975,13 @@ do_setlk_common(fuse_req_t *req, if(!sleep) op |= LOCK_NB; - req->f->op.flock(req,nodeid,&fi,op); + f.op.flock(req,nodeid,&fi,op); } else { convert_fuse_file_lock(&arg->lk, &flock); - req->f->op.setlk(req,nodeid,&fi,&flock,sleep); + f.op.setlk(req,nodeid,&fi,&flock,sleep); } } @@ -1053,10 +1003,10 @@ do_setlkw(fuse_req_t *req, static void -do_interrupt(fuse_req_t *req, +do_interrupt(fuse_req_t *req_, struct fuse_in_header *hdr_) { - destroy_req(req); + fuse_req_free(req_); } static @@ -1064,7 +1014,7 @@ void do_bmap(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.bmap(req,hdr_); + f.op.bmap(req,hdr_); } static @@ -1072,13 +1022,7 @@ void do_ioctl(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.ioctl(req, hdr_); -} - -void -fuse_pollhandle_destroy(fuse_pollhandle_t *ph) -{ - free(ph); + f.op.ioctl(req, hdr_); } static @@ -1086,7 +1030,7 @@ void do_poll(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.poll(req,hdr_); + f.op.poll(req,hdr_); } static @@ -1094,7 +1038,7 @@ void do_fallocate(fuse_req_t *req, struct fuse_in_header *hdr_) { - req->f->op.fallocate(req,hdr_); + f.op.fallocate(req,hdr_); } static @@ -1104,7 +1048,6 @@ do_init(fuse_req_t *req, { struct fuse_init_out outarg = {0}; struct fuse_init_in *arg = (struct fuse_init_in *)&hdr_[1]; - struct fuse_ll *f = req->f; size_t bufsize; uint64_t inargflags; uint64_t outargflags; @@ -1120,10 +1063,10 @@ do_init(fuse_req_t *req, fuse_syslog_fuse_init_in(arg); - f->conn.proto_major = arg->major; - f->conn.proto_minor = arg->minor; - f->conn.capable = 0; - f->conn.want = 0; + f.conn.proto_major = arg->major; + f.conn.proto_minor = arg->minor; + f.conn.capable = 0; + f.conn.want = 0; outarg.major = FUSE_KERNEL_VERSION; outarg.minor = FUSE_KERNEL_MINOR_VERSION; @@ -1154,63 +1097,63 @@ do_init(fuse_req_t *req, max_readahead = arg->max_readahead; if(inargflags & FUSE_ASYNC_READ) - f->conn.capable |= FUSE_CAP_ASYNC_READ; + f.conn.capable |= FUSE_CAP_ASYNC_READ; if(inargflags & FUSE_POSIX_LOCKS) - f->conn.capable |= FUSE_CAP_POSIX_LOCKS; + f.conn.capable |= FUSE_CAP_POSIX_LOCKS; if(inargflags & FUSE_ATOMIC_O_TRUNC) - f->conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC; + f.conn.capable |= FUSE_CAP_ATOMIC_O_TRUNC; if(inargflags & FUSE_EXPORT_SUPPORT) - f->conn.capable |= FUSE_CAP_EXPORT_SUPPORT; + f.conn.capable |= FUSE_CAP_EXPORT_SUPPORT; if(inargflags & FUSE_BIG_WRITES) - f->conn.capable |= FUSE_CAP_BIG_WRITES; + f.conn.capable |= FUSE_CAP_BIG_WRITES; if(inargflags & FUSE_DONT_MASK) - f->conn.capable |= FUSE_CAP_DONT_MASK; + f.conn.capable |= FUSE_CAP_DONT_MASK; if(inargflags & FUSE_FLOCK_LOCKS) - f->conn.capable |= FUSE_CAP_FLOCK_LOCKS; + f.conn.capable |= FUSE_CAP_FLOCK_LOCKS; if(inargflags & FUSE_POSIX_ACL) - f->conn.capable |= FUSE_CAP_POSIX_ACL; + f.conn.capable |= FUSE_CAP_POSIX_ACL; if(inargflags & FUSE_CACHE_SYMLINKS) - f->conn.capable |= FUSE_CAP_CACHE_SYMLINKS; + f.conn.capable |= FUSE_CAP_CACHE_SYMLINKS; if(inargflags & FUSE_ASYNC_DIO) - f->conn.capable |= FUSE_CAP_ASYNC_DIO; + f.conn.capable |= FUSE_CAP_ASYNC_DIO; if(inargflags & FUSE_PARALLEL_DIROPS) - f->conn.capable |= FUSE_CAP_PARALLEL_DIROPS; + f.conn.capable |= FUSE_CAP_PARALLEL_DIROPS; if(inargflags & FUSE_MAX_PAGES) - f->conn.capable |= FUSE_CAP_MAX_PAGES; + f.conn.capable |= FUSE_CAP_MAX_PAGES; if(inargflags & FUSE_WRITEBACK_CACHE) - f->conn.capable |= FUSE_CAP_WRITEBACK_CACHE; + f.conn.capable |= FUSE_CAP_WRITEBACK_CACHE; if(inargflags & FUSE_DO_READDIRPLUS) - f->conn.capable |= FUSE_CAP_READDIR_PLUS; + f.conn.capable |= FUSE_CAP_READDIR_PLUS; if(inargflags & FUSE_READDIRPLUS_AUTO) - f->conn.capable |= FUSE_CAP_READDIR_PLUS_AUTO; + f.conn.capable |= FUSE_CAP_READDIR_PLUS_AUTO; if(inargflags & FUSE_SETXATTR_EXT) - f->conn.capable |= FUSE_CAP_SETXATTR_EXT; + f.conn.capable |= FUSE_CAP_SETXATTR_EXT; if(inargflags & FUSE_DIRECT_IO_ALLOW_MMAP) - f->conn.capable |= FUSE_CAP_DIRECT_IO_ALLOW_MMAP; + f.conn.capable |= FUSE_CAP_DIRECT_IO_ALLOW_MMAP; if(inargflags & FUSE_CREATE_SUPP_GROUP) - f->conn.capable |= FUSE_CAP_CREATE_SUPP_GROUP; + f.conn.capable |= FUSE_CAP_CREATE_SUPP_GROUP; if(inargflags & FUSE_PASSTHROUGH) - f->conn.capable |= FUSE_CAP_PASSTHROUGH; + f.conn.capable |= FUSE_CAP_PASSTHROUGH; if(inargflags & FUSE_HANDLE_KILLPRIV) - f->conn.capable |= FUSE_CAP_HANDLE_KILLPRIV; + f.conn.capable |= FUSE_CAP_HANDLE_KILLPRIV; if(inargflags & FUSE_HANDLE_KILLPRIV_V2) - f->conn.capable |= FUSE_CAP_HANDLE_KILLPRIV_V2; + f.conn.capable |= FUSE_CAP_HANDLE_KILLPRIV_V2; if(inargflags & FUSE_ALLOW_IDMAP) - f->conn.capable |= FUSE_CAP_ALLOW_IDMAP; + f.conn.capable |= FUSE_CAP_ALLOW_IDMAP; } else { - f->conn.want &= ~FUSE_CAP_ASYNC_READ; + f.conn.want &= ~FUSE_CAP_ASYNC_READ; max_readahead = 0; } - if(req->f->conn.proto_minor >= 18) - f->conn.capable |= FUSE_CAP_IOCTL_DIR; + if(f.conn.proto_minor >= 18) + f.conn.capable |= FUSE_CAP_IOCTL_DIR; - if(f->op.getlk && f->op.setlk) - f->conn.want |= FUSE_CAP_POSIX_LOCKS; - if(f->op.flock) - f->conn.want |= FUSE_CAP_FLOCK_LOCKS; + if(f.op.getlk && f.op.setlk) + f.conn.want |= FUSE_CAP_POSIX_LOCKS; + if(f.op.flock) + f.conn.want |= FUSE_CAP_FLOCK_LOCKS; if(bufsize < FUSE_MIN_READ_BUFFER) { @@ -1219,16 +1162,16 @@ do_init(fuse_req_t *req, bufsize = FUSE_MIN_READ_BUFFER; } - bufsize -= pagesize; + bufsize -= getpagesize(); if(bufsize < max_write) max_write = bufsize; - f->got_init = 1; - if(f->op.init) - f->op.init(f->userdata, &f->conn); + f.got_init = 1; + if(f.op.init) + f.op.init(f.userdata, &f.conn); outargflags = outarg.flags; - if((inargflags & FUSE_MAX_PAGES) && (f->conn.want & FUSE_CAP_MAX_PAGES)) + if((inargflags & FUSE_MAX_PAGES) && (f.conn.want & FUSE_CAP_MAX_PAGES)) { outargflags |= FUSE_MAX_PAGES; outarg.max_pages = fuse_cfg.max_pages; @@ -1237,48 +1180,48 @@ do_init(fuse_req_t *req, max_write = (msgbuf_get_pagesize() * outarg.max_pages); } - if(f->conn.want & FUSE_CAP_ASYNC_READ) + if(f.conn.want & FUSE_CAP_ASYNC_READ) outargflags |= FUSE_ASYNC_READ; - if(f->conn.want & FUSE_CAP_POSIX_LOCKS) + if(f.conn.want & FUSE_CAP_POSIX_LOCKS) outargflags |= FUSE_POSIX_LOCKS; - if(f->conn.want & FUSE_CAP_ATOMIC_O_TRUNC) + if(f.conn.want & FUSE_CAP_ATOMIC_O_TRUNC) outargflags |= FUSE_ATOMIC_O_TRUNC; - if(f->conn.want & FUSE_CAP_EXPORT_SUPPORT) + if(f.conn.want & FUSE_CAP_EXPORT_SUPPORT) outargflags |= FUSE_EXPORT_SUPPORT; - if(f->conn.want & FUSE_CAP_BIG_WRITES) + if(f.conn.want & FUSE_CAP_BIG_WRITES) outargflags |= FUSE_BIG_WRITES; - if(f->conn.want & FUSE_CAP_DONT_MASK) + if(f.conn.want & FUSE_CAP_DONT_MASK) outargflags |= FUSE_DONT_MASK; - if(f->conn.want & FUSE_CAP_FLOCK_LOCKS) + if(f.conn.want & FUSE_CAP_FLOCK_LOCKS) outargflags |= FUSE_FLOCK_LOCKS; - if(f->conn.want & FUSE_CAP_POSIX_ACL) + if(f.conn.want & FUSE_CAP_POSIX_ACL) outargflags |= FUSE_POSIX_ACL; - if(f->conn.want & FUSE_CAP_CACHE_SYMLINKS) + if(f.conn.want & FUSE_CAP_CACHE_SYMLINKS) outargflags |= FUSE_CACHE_SYMLINKS; - if(f->conn.want & FUSE_CAP_ASYNC_DIO) + if(f.conn.want & FUSE_CAP_ASYNC_DIO) outargflags |= FUSE_ASYNC_DIO; - if(f->conn.want & FUSE_CAP_PARALLEL_DIROPS) + if(f.conn.want & FUSE_CAP_PARALLEL_DIROPS) outargflags |= FUSE_PARALLEL_DIROPS; - if(f->conn.want & FUSE_CAP_WRITEBACK_CACHE) + if(f.conn.want & FUSE_CAP_WRITEBACK_CACHE) outargflags |= FUSE_WRITEBACK_CACHE; - if(f->conn.want & FUSE_CAP_READDIR_PLUS) + if(f.conn.want & FUSE_CAP_READDIR_PLUS) outargflags |= FUSE_DO_READDIRPLUS; - if(f->conn.want & FUSE_CAP_READDIR_PLUS_AUTO) + if(f.conn.want & FUSE_CAP_READDIR_PLUS_AUTO) outargflags |= FUSE_READDIRPLUS_AUTO; - if(f->conn.want & FUSE_CAP_SETXATTR_EXT) + if(f.conn.want & FUSE_CAP_SETXATTR_EXT) outargflags |= FUSE_SETXATTR_EXT; - if(f->conn.want & FUSE_CAP_CREATE_SUPP_GROUP) + if(f.conn.want & FUSE_CAP_CREATE_SUPP_GROUP) outargflags |= FUSE_CREATE_SUPP_GROUP; - if(f->conn.want & FUSE_CAP_DIRECT_IO_ALLOW_MMAP) + if(f.conn.want & FUSE_CAP_DIRECT_IO_ALLOW_MMAP) outargflags |= FUSE_DIRECT_IO_ALLOW_MMAP; - if(f->conn.want & FUSE_CAP_HANDLE_KILLPRIV) + if(f.conn.want & FUSE_CAP_HANDLE_KILLPRIV) outargflags |= FUSE_HANDLE_KILLPRIV; - if(f->conn.want & FUSE_CAP_HANDLE_KILLPRIV_V2) + if(f.conn.want & FUSE_CAP_HANDLE_KILLPRIV_V2) outargflags |= FUSE_HANDLE_KILLPRIV_V2; - if(f->conn.want & FUSE_CAP_ALLOW_IDMAP) + if(f.conn.want & FUSE_CAP_ALLOW_IDMAP) outargflags |= FUSE_ALLOW_IDMAP; - if(f->conn.want & FUSE_CAP_PASSTHROUGH) + if(f.conn.want & FUSE_CAP_PASSTHROUGH) { outargflags |= FUSE_PASSTHROUGH; outarg.max_stack_depth = fuse_cfg.passthrough_max_stack_depth; @@ -1294,7 +1237,7 @@ do_init(fuse_req_t *req, outarg.max_readahead = max_readahead; outarg.max_write = max_write; - if(f->conn.proto_minor >= 13) + if(f.conn.proto_minor >= 13) { if(fuse_cfg.max_background >= (1 << 16)) fuse_cfg.max_background = ((1 << 16) - 1); @@ -1307,7 +1250,7 @@ do_init(fuse_req_t *req, outarg.congestion_threshold = fuse_cfg.congestion_threshold; } - if(f->conn.proto_minor >= 23) + if(f.conn.proto_minor >= 23) outarg.time_gran = 1; size_t outargsize; @@ -1325,15 +1268,13 @@ do_init(fuse_req_t *req, static void -do_destroy(fuse_req_t *req, +do_destroy(fuse_req_t *req_, struct fuse_in_header *hdr_) { - struct fuse_ll *f = req->f; - - f->got_destroy = 1; - f->op.destroy(f->userdata); + f.got_destroy = 1; + f.op.destroy(f.userdata); - send_reply_ok(req,NULL,0); + send_reply_ok(req_,NULL,0); } static @@ -1371,12 +1312,11 @@ void do_notify_reply(fuse_req_t *req, struct fuse_in_header *hdr_) { - struct fuse_ll *f = req->f; struct fuse_notify_req *nreq; struct fuse_notify_req *head; - mutex_lock(&f->lock); - head = &f->notify_list; + mutex_lock(&f.lock); + head = &f.notify_list; for(nreq = head->next; nreq != head; nreq = nreq->next) { if(nreq->unique == req->ctx.unique) @@ -1385,7 +1325,7 @@ do_notify_reply(fuse_req_t *req, break; } } - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); if(nreq != head) nreq->reply(nreq, req, hdr_->nodeid, &hdr_[1]); @@ -1396,7 +1336,7 @@ void do_copy_file_range(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.copy_file_range(req_,hdr_); + f.op.copy_file_range(req_,hdr_); } static @@ -1404,7 +1344,7 @@ void do_setupmapping(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.setupmapping(req_,hdr_); + f.op.setupmapping(req_,hdr_); } static @@ -1412,7 +1352,7 @@ void do_removemapping(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.removemapping(req_,hdr_); + f.op.removemapping(req_,hdr_); } static @@ -1420,7 +1360,7 @@ void do_syncfs(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.syncfs(req_,hdr_); + f.op.syncfs(req_,hdr_); } static @@ -1428,7 +1368,7 @@ void do_tmpfile(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.tmpfile(req_,hdr_); + f.op.tmpfile(req_,hdr_); } static @@ -1436,7 +1376,7 @@ void do_statx(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.statx(req_,hdr_); + f.op.statx(req_,hdr_); } static @@ -1444,7 +1384,7 @@ void do_rename2(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.rename2(req_,hdr_); + f.op.rename2(req_,hdr_); } static @@ -1452,20 +1392,19 @@ void do_lseek(fuse_req_t *req_, struct fuse_in_header *hdr_) { - req_->f->op.lseek(req_,hdr_); + f.op.lseek(req_,hdr_); } static int -send_notify_iov(struct fuse_ll *f, - struct fuse_chan *ch, +send_notify_iov(struct fuse_chan *ch, int notify_code, struct iovec *iov, int count) { struct fuse_out_header out; - if(!f->got_init) + if(!f.got_init) return -ENOTCONN; out.unique = 0; @@ -1473,28 +1412,7 @@ send_notify_iov(struct fuse_ll *f, iov[0].iov_base = &out; iov[0].iov_len = sizeof(struct fuse_out_header); - return fuse_send_msg(f, ch, iov, count); -} - -int -fuse_lowlevel_notify_poll(fuse_pollhandle_t *ph) -{ - if(ph != NULL) - { - struct fuse_notify_poll_wakeup_out outarg; - struct iovec iov[2]; - - outarg.kh = ph->kh; - - iov[1].iov_base = &outarg; - iov[1].iov_len = sizeof(outarg); - - return send_notify_iov(ph->f, ph->ch, FUSE_NOTIFY_POLL, iov, 2); - } - else - { - return 0; - } + return fuse_send_msg(ch, iov, count); } int @@ -1504,16 +1422,11 @@ fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, off_t len) { struct fuse_notify_inval_inode_out outarg; - struct fuse_ll *f; struct iovec iov[2]; if(!ch) return -EINVAL; - f = (struct fuse_ll*)fuse_session_data(fuse_chan_session(ch)); - if(!f) - return -ENODEV; - outarg.ino = ino; outarg.off = off; outarg.len = len; @@ -1521,7 +1434,7 @@ fuse_lowlevel_notify_inval_inode(struct fuse_chan *ch, iov[1].iov_base = &outarg; iov[1].iov_len = sizeof(outarg); - return send_notify_iov(f, ch, FUSE_NOTIFY_INVAL_INODE, iov, 2); + return send_notify_iov(ch, FUSE_NOTIFY_INVAL_INODE, iov, 2); } int @@ -1531,16 +1444,11 @@ fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, size_t namelen) { struct fuse_notify_inval_entry_out outarg; - struct fuse_ll *f; struct iovec iov[3]; if(!ch) return -EINVAL; - f = (struct fuse_ll*)fuse_session_data(fuse_chan_session(ch)); - if(!f) - return -ENODEV; - outarg.parent = parent; outarg.namelen = namelen; // TODO: Add ability to set `flags` @@ -1551,7 +1459,7 @@ fuse_lowlevel_notify_inval_entry(struct fuse_chan *ch, iov[2].iov_base = (void *)name; iov[2].iov_len = namelen + 1; - return send_notify_iov(f, ch, FUSE_NOTIFY_INVAL_ENTRY, iov, 3); + return send_notify_iov(ch, FUSE_NOTIFY_INVAL_ENTRY, iov, 3); } int @@ -1562,17 +1470,12 @@ fuse_lowlevel_notify_delete(struct fuse_chan *ch, size_t namelen) { struct fuse_notify_delete_out outarg; - struct fuse_ll *f; struct iovec iov[3]; if(!ch) return -EINVAL; - f = (struct fuse_ll*)fuse_session_data(fuse_chan_session(ch)); - if(!f) - return -ENODEV; - - if(f->conn.proto_minor < 18) + if(f.conn.proto_minor < 18) return -ENOSYS; outarg.parent = parent; @@ -1585,7 +1488,7 @@ fuse_lowlevel_notify_delete(struct fuse_chan *ch, iov[2].iov_base = (void *)name; iov[2].iov_len = namelen + 1; - return send_notify_iov(f, ch, FUSE_NOTIFY_DELETE, iov, 3); + return send_notify_iov(ch, FUSE_NOTIFY_DELETE, iov, 3); } int @@ -1597,7 +1500,6 @@ fuse_lowlevel_notify_store(struct fuse_chan *ch, { struct fuse_out_header out; struct fuse_notify_store_out outarg; - struct fuse_ll *f; struct iovec iov[3]; size_t size = fuse_buf_size(bufv); int res; @@ -1605,11 +1507,7 @@ fuse_lowlevel_notify_store(struct fuse_chan *ch, if(!ch) return -EINVAL; - f = (struct fuse_ll*)fuse_session_data(fuse_chan_session(ch)); - if(!f) - return -ENODEV; - - if(f->conn.proto_minor < 15) + if(f.conn.proto_minor < 15) return -ENOSYS; out.unique = 0; @@ -1625,7 +1523,7 @@ fuse_lowlevel_notify_store(struct fuse_chan *ch, iov[1].iov_base = &outarg; iov[1].iov_len = sizeof(outarg); - res = fuse_send_data_iov(f, ch, iov, 2, bufv, flags); + res = fuse_send_data_iov(ch, iov, 2, bufv, flags); if(res > 0) res = -res; @@ -1661,7 +1559,6 @@ fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, void *cookie) { struct fuse_notify_retrieve_out outarg; - struct fuse_ll *f; struct iovec iov[2]; struct fuse_retrieve_req *rreq; int err; @@ -1669,23 +1566,19 @@ fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, if(!ch) return -EINVAL; - f = (struct fuse_ll*)fuse_session_data(fuse_chan_session(ch)); - if(!f) - return -ENODEV; - - if(f->conn.proto_minor < 15) + if(f.conn.proto_minor < 15) return -ENOSYS; rreq = (fuse_retrieve_req*)malloc(sizeof(*rreq)); if(rreq == NULL) return -ENOMEM; - mutex_lock(&f->lock); + mutex_lock(&f.lock); rreq->cookie = cookie; - rreq->nreq.unique = f->notify_ctr++; + rreq->nreq.unique = f.notify_ctr++; rreq->nreq.reply = fuse_ll_retrieve_reply; - list_add_nreq(&rreq->nreq, &f->notify_list); - mutex_unlock(&f->lock); + list_add_nreq(&rreq->nreq, &f.notify_list); + mutex_unlock(&f.lock); outarg.notify_unique = rreq->nreq.unique; outarg.nodeid = ino; @@ -1695,12 +1588,12 @@ fuse_lowlevel_notify_retrieve(struct fuse_chan *ch, iov[1].iov_base = &outarg; iov[1].iov_len = sizeof(outarg); - err = send_notify_iov(f, ch, FUSE_NOTIFY_RETRIEVE, iov, 2); + err = send_notify_iov(ch, FUSE_NOTIFY_RETRIEVE, iov, 2); if(err) { - mutex_lock(&f->lock); + mutex_lock(&f.lock); list_del_nreq(&rreq->nreq); - mutex_unlock(&f->lock); + mutex_unlock(&f.lock); free(rreq); } @@ -1775,24 +1668,18 @@ static void fuse_ll_destroy(void *data) { - struct fuse_ll *f = (struct fuse_ll *)data; - - if(f->got_init && !f->got_destroy) + if(f.got_init && !f.got_destroy) { - if(f->op.destroy) - f->op.destroy(f->userdata); + if(f.op.destroy) + f.op.destroy(f.userdata); } - mutex_destroy(&f->lock); - free(f); - - lfmp_clear(&g_FMP_fuse_req); + mutex_destroy(&f.lock); } static void -fuse_send_errno(struct fuse_ll *f_, - struct fuse_chan *ch_, +fuse_send_errno(struct fuse_chan *ch_, const int errno_, const uint64_t unique_id_) { @@ -1804,25 +1691,23 @@ fuse_send_errno(struct fuse_ll *f_, iov.iov_base = &out; iov.iov_len = sizeof(struct fuse_out_header); - fuse_send_msg(f_,ch_,&iov,1); + fuse_send_msg(ch_,&iov,1); } static void -fuse_send_enomem(struct fuse_ll *f_, - struct fuse_chan *ch_, +fuse_send_enomem(struct fuse_chan *ch_, const uint64_t unique_id_) { - fuse_send_errno(f_,ch_,ENOMEM,unique_id_); + fuse_send_errno(ch_,ENOMEM,unique_id_); } static void -fuse_send_einval(struct fuse_ll *f_, - struct fuse_chan *ch_, +fuse_send_einval(struct fuse_chan *ch_, const uint64_t unique_id_) { - fuse_send_errno(f_,ch_,EINVAL,unique_id_); + fuse_send_errno(ch_,EINVAL,unique_id_); } static @@ -1857,11 +1742,11 @@ fuse_ll_buf_process_read(struct fuse_session *se_, in = (struct fuse_in_header*)msgbuf_->mem; if((in->uid == FUSE_INVALID_UIDGID) || (in->gid == FUSE_INVALID_UIDGID)) - return fuse_send_einval(se_->f,se_->ch,in->unique); + return fuse_send_einval(se_->ch,in->unique); - req = fuse_ll_alloc_req(se_->f); + req = fuse_req_alloc(); if(req == NULL) - return fuse_send_enomem(se_->f,se_->ch,in->unique); + return fuse_send_enomem(se_->ch,in->unique); req->ctx.len = in->len; req->ctx.opcode = in->opcode; @@ -1871,6 +1756,7 @@ fuse_ll_buf_process_read(struct fuse_session *se_, req->ctx.gid = in->gid; req->ctx.pid = in->pid; req->ctx.umask = 0; + req->conn = f.conn; req->ch = se_->ch; err = ENOSYS; @@ -1899,9 +1785,9 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_, in = (struct fuse_in_header*)msgbuf_->mem; - req = fuse_ll_alloc_req(se_->f); + req = fuse_req_alloc(); if(req == NULL) - return fuse_send_enomem(se_->f,se_->ch,in->unique); + return fuse_send_enomem(se_->ch,in->unique); req->ctx.len = in->len; req->ctx.opcode = in->opcode; @@ -1911,6 +1797,7 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_, req->ctx.gid = in->gid; req->ctx.pid = in->pid; req->ctx.umask = 0; + req->conn = f.conn; req->ch = se_->ch; err = EIO; @@ -1958,7 +1845,6 @@ fuse_lowlevel_new_common(struct fuse_args *args, size_t op_size, void *userdata) { - struct fuse_ll *f; struct fuse_session *se; if(sizeof(struct fuse_lowlevel_ops) < op_size) @@ -1967,26 +1853,19 @@ fuse_lowlevel_new_common(struct fuse_args *args, op_size = sizeof(struct fuse_lowlevel_ops); } - f = (struct fuse_ll *) calloc(1, sizeof(struct fuse_ll)); - if(f == NULL) - { - fprintf(stderr, "fuse: failed to allocate fuse object\n"); - goto out; - } + f = (fuse_ll){0}; - list_init_nreq(&f->notify_list); - f->notify_ctr = 1; - mutex_init(&f->lock); + list_init_nreq(&f.notify_list); + f.notify_ctr = 1; + mutex_init(&f.lock); if(fuse_opt_parse(args,NULL,fuse_ll_opts,fuse_ll_opt_proc) == -1) goto out_free; - memcpy(&f->op, op, op_size); - f->owner = getuid(); - f->userdata = userdata; + f.op = *op; + f.userdata = userdata; - se = fuse_session_new(f, - (void*)fuse_ll_buf_receive_read, + se = fuse_session_new((void*)fuse_ll_buf_receive_read, (void*)fuse_ll_buf_process_read_init, (void*)fuse_ll_destroy); @@ -1996,9 +1875,7 @@ fuse_lowlevel_new_common(struct fuse_args *args, return se; out_free: - mutex_destroy(&f->lock); - free(f); - out: + mutex_destroy(&f.lock); return NULL; } diff --git a/libfuse/lib/fuse_req.cpp b/libfuse/lib/fuse_req.cpp new file mode 100644 index 00000000..703a4114 --- /dev/null +++ b/libfuse/lib/fuse_req.cpp @@ -0,0 +1,36 @@ +#include "fuse_req.hpp" + +#include +#include + +typedef struct stack_t stack_t; +struct stack_t +{ + stack_t *next; +}; + +thread_local static stack_t *g_stack = NULL; + +fuse_req_t* +fuse_req_alloc() +{ + if(g_stack == NULL) + return (fuse_req_t*)calloc(1,sizeof(fuse_req_t)); + + fuse_req_t *req; + + req = (fuse_req_t*)g_stack; + g_stack = g_stack->next; + + return req; +} + +void +fuse_req_free(fuse_req_t *req_) +{ + stack_t *stack; + + stack = (stack_t*)req_; + stack->next = g_stack; + g_stack = stack; +} diff --git a/libfuse/lib/fuse_session.cpp b/libfuse/lib/fuse_session.cpp index b9c0460c..189d8780 100644 --- a/libfuse/lib/fuse_session.cpp +++ b/libfuse/lib/fuse_session.cpp @@ -26,19 +26,17 @@ struct fuse_chan }; struct fuse_session * -fuse_session_new(void *data, - void *receive_buf, +fuse_session_new(void *receive_buf, void *process_buf, void *destroy) { - struct fuse_session *se = (struct fuse_session *) malloc(sizeof(*se)); - if (se == NULL) { - fprintf(stderr, "fuse: failed to allocate session\n"); - return NULL; - } + struct fuse_session *se = (struct fuse_session *)calloc(1,sizeof(*se)); + if(se == NULL) + { + fprintf(stderr, "fuse: failed to allocate session\n"); + return NULL; + } - memset(se, 0, sizeof(*se)); - se->f = (fuse_ll*)data; se->receive_buf = (int(*)(fuse_session*,fuse_msgbuf_t*))receive_buf; se->process_buf = (void(*)(fuse_session*,const fuse_msgbuf_t*))process_buf; se->destroy = (void(*)(void*))destroy; @@ -67,7 +65,7 @@ void fuse_session_remove_chan(struct fuse_chan *ch) void fuse_session_destroy(struct fuse_session *se) { - se->destroy(se->f); + se->destroy(NULL); if(se->ch != NULL) fuse_chan_destroy(se->ch); free(se); @@ -90,12 +88,6 @@ fuse_session_exit(struct fuse_session *se_) se_->exited = 1; } -void* -fuse_session_data(struct fuse_session *se) -{ - return se->f; -} - struct fuse_chan * fuse_chan_new(int fd, size_t bufsize) diff --git a/libfuse/lib/node.cpp b/libfuse/lib/node.cpp index c5088f2a..014089ee 100644 --- a/libfuse/lib/node.cpp +++ b/libfuse/lib/node.cpp @@ -9,6 +9,7 @@ struct stack_t }; thread_local static stack_t *g_stack = NULL; +thread_local bool gc = false; node_t* node_alloc() diff --git a/src/fixed_mem_pool.hpp b/src/fixed_mem_pool.hpp deleted file mode 100644 index 2f012b17..00000000 --- a/src/fixed_mem_pool.hpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - ISC License - - Copyright (c) 2020, Antonio SJ Musumeci - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#pragma once - -#include - -#include - - -typedef struct fixed_mem_pool_t fixed_mem_pool_t; -struct fixed_mem_pool_t -{ - fixed_mem_pool_t *next; -}; - -template -class FixedMemPool -{ -public: - FixedMemPool() - { - list.next = NULL; - } - - ~FixedMemPool() - { - void *mem; - while(!empty()) - { - mem = alloc(); - ::free(mem); - } - } - - bool - empty(void) - { - return (list.next == NULL); - } - - uint64_t - size(void) - { - return SIZE; - } - - void* - alloc(void) - { - void *rv; - - if(list.next == NULL) - return malloc(SIZE); - - rv = (void*)list.next; - list.next = list.next->next; - - return rv; - } - - void - free(void *mem_) - { - fixed_mem_pool_t *next; - - next = (fixed_mem_pool_t*)mem_; - next->next = list.next; - list.next = next; - } - -private: - fixed_mem_pool_t list; -}; diff --git a/src/fuse_init.cpp b/src/fuse_init.cpp index 1313e0f6..40f08d79 100644 --- a/src/fuse_init.cpp +++ b/src/fuse_init.cpp @@ -35,24 +35,24 @@ static void -_want(fuse_conn_info *conn_, - const int flag_) +_want(fuse_conn_info_t *conn_, + const int flag_) { conn_->want |= flag_; } static bool -_capable(fuse_conn_info *conn_, - const int flag_) +_capable(fuse_conn_info_t *conn_, + const int flag_) { return !!(conn_->capable & flag_); } static void -_want_if_capable(fuse_conn_info *conn_, - const int flag_) +_want_if_capable(fuse_conn_info_t *conn_, + const int flag_) { if(::_capable(conn_,flag_)) ::_want(conn_,flag_); @@ -60,9 +60,9 @@ _want_if_capable(fuse_conn_info *conn_, static void -_want_if_capable(fuse_conn_info *conn_, - const int flag_, - ConfigBOOL *want_) +_want_if_capable(fuse_conn_info_t *conn_, + const int flag_, + ConfigBOOL *want_) { if(*want_ && ::_capable(conn_,flag_)) { @@ -78,8 +78,8 @@ static const char MAX_PAGES_LIMIT_FILEPATH[] = "/proc/sys/fs/fuse/max_pages_limi static void -_want_if_capable_max_pages(fuse_conn_info *conn_, - Config &cfg_) +_want_if_capable_max_pages(fuse_conn_info_t *conn_, + Config &cfg_) { std::fstream f; uint64_t max_pages_limit; @@ -184,7 +184,7 @@ _spawn_thread_to_set_readahead() } void * -FUSE::init(fuse_conn_info *conn_) +FUSE::init(fuse_conn_info_t *conn_) { procfs::init(); ugid::init(); diff --git a/src/fuse_init.hpp b/src/fuse_init.hpp index 5867d646..fd1ed052 100644 --- a/src/fuse_init.hpp +++ b/src/fuse_init.hpp @@ -22,5 +22,5 @@ namespace FUSE { void * - init(fuse_conn_info *conn); + init(fuse_conn_info_t *conn); } diff --git a/src/fuse_poll.cpp b/src/fuse_poll.cpp deleted file mode 100644 index 616a3a92..00000000 --- a/src/fuse_poll.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - ISC License - - Copyright (c) 2021, Antonio SJ Musumeci - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "fuse_poll.hpp" - -#include "errno.hpp" - -#include "fuse.h" - - -int -FUSE::poll(const fuse_req_ctx_t *ctx_, - const fuse_file_info_t *ffi_, - fuse_pollhandle_t *ph_, - unsigned *reventsp_) -{ - (void)ctx_; - (void)ffi_; - (void)ph_; - (void)reventsp_; - - return -ENOSYS; -} diff --git a/src/fuse_poll.hpp b/src/fuse_poll.hpp deleted file mode 100644 index 1df68f92..00000000 --- a/src/fuse_poll.hpp +++ /dev/null @@ -1,31 +0,0 @@ -/* - ISC License - - Copyright (c) 2021, Antonio SJ Musumeci - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#pragma once - -#include "fuse.h" - - -namespace FUSE -{ - int - poll(const fuse_req_ctx_t *ctx, - const fuse_file_info_t *ffi, - fuse_pollhandle_t *ph, - unsigned *reventsp); -} diff --git a/src/mempools.cpp b/src/mempools.cpp deleted file mode 100644 index c02e4bee..00000000 --- a/src/mempools.cpp +++ /dev/null @@ -1,21 +0,0 @@ -/* - ISC License - - Copyright (c) 2020, Antonio SJ Musumeci - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#include "locked_fixed_mem_pool.hpp" - -LockedFixedMemPool<128 * 1024> g_DENTS_BUF_POOL; diff --git a/src/mempools.hpp b/src/mempools.hpp deleted file mode 100644 index 06df7501..00000000 --- a/src/mempools.hpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - ISC License - - Copyright (c) 2020, Antonio SJ Musumeci - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ - -#pragma once - -#include "locked_fixed_mem_pool.hpp" - -extern LockedFixedMemPool<128 * 1024> g_DENTS_BUF_POOL; diff --git a/src/mergerfs.cpp b/src/mergerfs.cpp index 63d6c146..d92aa022 100644 --- a/src/mergerfs.cpp +++ b/src/mergerfs.cpp @@ -61,7 +61,6 @@ #include "fuse_mknod.hpp" #include "fuse_open.hpp" #include "fuse_opendir.hpp" -#include "fuse_poll.hpp" #include "fuse_read.hpp" #include "fuse_readdir.hpp" #include "fuse_readdir_plus.hpp" @@ -126,7 +125,6 @@ _get_fuse_operations(struct fuse_operations &ops_, ops_.mknod = FUSE::mknod; ops_.open = FUSE::open; ops_.opendir = FUSE::opendir; - ops_.poll = FUSE::poll;; ops_.read = (nullrw_ ? FUSE::read_null : FUSE::read); ops_.readdir = FUSE::readdir; ops_.readdir_plus = FUSE::readdir_plus;