This commit is contained in:
Antonio SJ Musumeci 2025-10-26 14:53:46 -05:00
parent 95e62e6a98
commit e9bfa96f26
21 changed files with 293 additions and 708 deletions

View file

@ -13,6 +13,7 @@
#include "fuse_common.h"
#include "fuse_kernel.h"
#include "fuse_req_ctx.h"
#include "fuse_conn_info.hpp"
#include <fcntl.h>
#include <time.h>
@ -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... *
* ----------------------------------------------------------- */

View file

@ -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 *
* ----------------------------------------------------------- */

View file

@ -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;
};

View file

@ -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);

View file

@ -1,14 +0,0 @@
#pragma once
#include <stdint.h>
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;
};

View file

@ -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();

View file

@ -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 <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <poll.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -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;

View file

@ -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,

View file

@ -16,7 +16,6 @@
#include "fuse_cfg.hpp"
#include "fuse_msgbuf.hpp"
#include "fuse_ll.hpp"
#include <cassert>
#include <memory>

File diff suppressed because it is too large Load diff

36
libfuse/lib/fuse_req.cpp Normal file
View file

@ -0,0 +1,36 @@
#include "fuse_req.hpp"
#include <cstddef>
#include <cstdlib>
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;
}

View file

@ -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)

View file

@ -9,6 +9,7 @@ struct stack_t
};
thread_local static stack_t *g_stack = NULL;
thread_local bool gc = false;
node_t*
node_alloc()