Add support for FUSE passthrough
Some checks are pending
CodeQL / Analyze (push) Waiting to run
mkdocs / deploy (push) Waiting to run

This commit is contained in:
trapexit 2025-06-05 23:47:42 -05:00 • committed by GitHub
parent 92312c8507
commit e310d24615
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
412 changed files with 43707 additions and 17432 deletions

View file

@ -20,6 +20,7 @@
#include <sys/stat.h>
#include <sys/statvfs.h>
#include <sys/uio.h>
#include <stdint.h>
EXTERN_C_BEGIN
@ -94,15 +95,6 @@ struct fuse_operations
* */
int (*mkdir) (const char *, mode_t);
/** Hide files unlinked / renamed over
*
* Allows storing of a file handle when a file is unlinked
* while open. Helps manage the fact the kernel usually does
* not send fh with getattr requests.
*/
int (*prepare_hide)(const char *name_, uint64_t *fh_);
int (*free_hide)(const uint64_t fh_);
/** Remove a file */
int (*unlink) (const char *);
@ -120,11 +112,11 @@ struct fuse_operations
/** Change the permission bits of a file */
int (*chmod) (const char *, mode_t);
int (*fchmod)(const fuse_file_info_t *, const mode_t);
int (*fchmod)(const uint64_t, const mode_t);
/** Change the owner and group of a file */
int (*chown) (const char *, uid_t, gid_t);
int (*fchown)(const fuse_file_info_t *, const uid_t, const gid_t);
int (*fchown)(const uint64_t, const uid_t, const gid_t);
/** Change the size of a file */
int (*truncate) (const char *, off_t);
@ -205,7 +197,7 @@ struct fuse_operations
*
* Changed in version 2.2
*/
int (*fsync) (const fuse_file_info_t *, int);
int (*fsync) (const uint64_t, int);
/** Set extended attributes */
int (*setxattr) (const char *, const char *, const char *, size_t, int);
@ -335,7 +327,7 @@ struct fuse_operations
*
* Introduced in version 2.5
*/
int (*ftruncate) (const fuse_file_info_t *, off_t);
int (*ftruncate) (const uint64_t, off_t);
/**
* Get attributes from an open file
@ -349,7 +341,7 @@ struct fuse_operations
*
* Introduced in version 2.5
*/
int (*fgetattr) (const fuse_file_info_t *, struct stat *, fuse_timeouts_t *);
int (*fgetattr) (const uint64_t, struct stat *, fuse_timeouts_t *);
/**
* Perform POSIX file locking operation
@ -399,7 +391,7 @@ struct fuse_operations
* Introduced in version 2.6
*/
int (*utimens)(const char *, const struct timespec tv[2]);
int (*futimens)(const fuse_file_info_t *ffi_, const struct timespec tv_[2]);
int (*futimens)(const uint64_t fh, const struct timespec tv[2]);
/**
* Map block index within file to block index within device
@ -519,7 +511,7 @@ struct fuse_operations
*
* Introduced in version 2.9.1
*/
int (*fallocate) (const fuse_file_info_t *, int, off_t, off_t);
int (*fallocate) (const uint64_t, int, off_t, off_t);
/**
* Copy a range of data from one file to another
@ -569,20 +561,14 @@ struct fuse_operations
*/
struct fuse_context
{
/** Pointer to the fuse object */
uint64_t unique;
uint64_t nodeid;
uint32_t opcode;
uid_t uid;
gid_t gid;
pid_t pid;
mode_t umask;
struct fuse *fuse;
/** User ID of the calling process */
uid_t uid;
/** Group ID of the calling process */
gid_t gid;
/** Thread ID of the calling process */
pid_t pid;
/** Umask of the calling process (introduced in version 2.8) */
mode_t umask;
};
/**
@ -790,6 +776,12 @@ void fuse_gc1();
void fuse_gc();
void fuse_invalidate_all_nodes();
int fuse_get_dev_fuse_fd(const struct fuse_context *fc);
int fuse_passthrough_open(const struct fuse_context *fc,
const int fd);
int fuse_passthrough_close(const struct fuse_context *fc,
const int backing_id);
EXTERN_C_END
#endif /* _FUSE_H_ */

View file

@ -87,11 +87,14 @@ struct fuse_file_info_t
uint32_t parallel_direct_writes:1;
uint32_t noflush:1;
uint32_t passthrough:1;
/** File handle. May be filled in by filesystem in open().
Available in all other file operations */
uint64_t fh;
int32_t backing_id;
/** Lock owner id. Available in locking operations and flush */
uint64_t lock_owner;
};
@ -127,7 +130,9 @@ struct fuse_file_info_t
#define FUSE_CAP_SETXATTR_EXT (1ULL << 22)
#define FUSE_CAP_DIRECT_IO_ALLOW_MMAP (1ULL << 23)
#define FUSE_CAP_CREATE_SUPP_GROUP (1ULL << 24)
#define FUSE_CAP_PASSTHROUGH (1ULL << 25)
#define FUSE_CAP_HANDLE_KILLPRIV (1ULL << 26)
#define FUSE_CAP_HANDLE_KILLPRIV_V2 (1ULL << 27)
/**
* Ioctl flags

View file

@ -211,6 +211,24 @@
* 7.39
* - add FUSE_DIRECT_IO_ALLOW_MMAP
* - add FUSE_STATX and related structures
*
* 7.40
* - add max_stack_depth to fuse_init_out, add FUSE_PASSTHROUGH init flag
* - add backing_id to fuse_open_out, add FOPEN_PASSTHROUGH open flag
* - add FUSE_NO_EXPORT_SUPPORT init flag
* - add FUSE_NOTIFY_RESEND, add FUSE_HAS_RESEND init flag
*
* 7.41
* - add FUSE_ALLOW_IDMAP
* 7.42
* - Add FUSE_OVER_IO_URING and all other io-uring related flags and data
* structures:
* - struct fuse_uring_ent_in_out
* - struct fuse_uring_req_header
* - struct fuse_uring_cmd_req
* - FUSE_URING_IN_OUT_HEADER_SZ
* - FUSE_URING_OP_IN_OUT_SZ
* - enum fuse_uring_cmd
*/
#ifndef _LINUX_FUSE_H
@ -246,7 +264,7 @@
#define FUSE_KERNEL_VERSION 7
/** Minor version number of this interface */
#define FUSE_KERNEL_MINOR_VERSION 39
#define FUSE_KERNEL_MINOR_VERSION 42
/** The node ID of the root inode */
#define FUSE_ROOT_ID 1
@ -353,6 +371,7 @@ struct fuse_file_lock {
* FOPEN_STREAM: the file is stream-like (no file position at all)
* FOPEN_NOFLUSH: don't flush data cache on close (unless FUSE_WRITEBACK_CACHE)
* FOPEN_PARALLEL_DIRECT_WRITES: Allow concurrent direct writes on the same inode
* FOPEN_PASSTHROUGH: passthrough read/write io for this open file
*/
#define FOPEN_DIRECT_IO (1 << 0)
#define FOPEN_KEEP_CACHE (1 << 1)
@ -361,6 +380,7 @@ struct fuse_file_lock {
#define FOPEN_STREAM (1 << 4)
#define FOPEN_NOFLUSH (1 << 5)
#define FOPEN_PARALLEL_DIRECT_WRITES (1 << 6)
#define FOPEN_PASSTHROUGH (1 << 7)
/**
* INIT request/reply flags
@ -410,38 +430,43 @@ struct fuse_file_lock {
* symlink and mknod (single group that matches parent)
* FUSE_HAS_EXPIRE_ONLY: kernel supports expiry-only entry invalidation
* FUSE_DIRECT_IO_ALLOW_MMAP: allow shared mmap in FOPEN_DIRECT_IO mode.
* FUSE_NO_EXPORT_SUPPORT: explicitly disable export support
* FUSE_HAS_RESEND: kernel supports resending pending requests, and the high bit
* of the request ID indicates resend requests
* FUSE_ALLOW_IDMAP: allow creation of idmapped mounts
* FUSE_OVER_IO_URING: Indicate that client supports io-uring
*/
#define FUSE_ASYNC_READ (1 << 0)
#define FUSE_POSIX_LOCKS (1 << 1)
#define FUSE_FILE_OPS (1 << 2)
#define FUSE_ATOMIC_O_TRUNC (1 << 3)
#define FUSE_EXPORT_SUPPORT (1 << 4)
#define FUSE_BIG_WRITES (1 << 5)
#define FUSE_DONT_MASK (1 << 6)
#define FUSE_SPLICE_WRITE (1 << 7)
#define FUSE_SPLICE_MOVE (1 << 8)
#define FUSE_SPLICE_READ (1 << 9)
#define FUSE_FLOCK_LOCKS (1 << 10)
#define FUSE_HAS_IOCTL_DIR (1 << 11)
#define FUSE_AUTO_INVAL_DATA (1 << 12)
#define FUSE_DO_READDIRPLUS (1 << 13)
#define FUSE_READDIRPLUS_AUTO (1 << 14)
#define FUSE_ASYNC_DIO (1 << 15)
#define FUSE_WRITEBACK_CACHE (1 << 16)
#define FUSE_NO_OPEN_SUPPORT (1 << 17)
#define FUSE_PARALLEL_DIROPS (1 << 18)
#define FUSE_HANDLE_KILLPRIV (1 << 19)
#define FUSE_POSIX_ACL (1 << 20)
#define FUSE_ABORT_ERROR (1 << 21)
#define FUSE_MAX_PAGES (1 << 22)
#define FUSE_CACHE_SYMLINKS (1 << 23)
#define FUSE_NO_OPENDIR_SUPPORT (1 << 24)
#define FUSE_EXPLICIT_INVAL_DATA (1 << 25)
#define FUSE_MAP_ALIGNMENT (1 << 26)
#define FUSE_SUBMOUNTS (1 << 27)
#define FUSE_HANDLE_KILLPRIV_V2 (1 << 28)
#define FUSE_SETXATTR_EXT (1 << 29)
#define FUSE_INIT_EXT (1 << 30)
#define FUSE_ASYNC_READ (1ULL << 0)
#define FUSE_POSIX_LOCKS (1ULL << 1)
#define FUSE_FILE_OPS (1ULL << 2)
#define FUSE_ATOMIC_O_TRUNC (1ULL << 3)
#define FUSE_EXPORT_SUPPORT (1ULL << 4)
#define FUSE_BIG_WRITES (1ULL << 5)
#define FUSE_DONT_MASK (1ULL << 6)
#define FUSE_SPLICE_WRITE (1ULL << 7)
#define FUSE_SPLICE_MOVE (1ULL << 8)
#define FUSE_SPLICE_READ (1ULL << 9)
#define FUSE_FLOCK_LOCKS (1ULL << 10)
#define FUSE_HAS_IOCTL_DIR (1ULL << 11)
#define FUSE_AUTO_INVAL_DATA (1ULL << 12)
#define FUSE_DO_READDIRPLUS (1ULL << 13)
#define FUSE_READDIRPLUS_AUTO (1ULL << 14)
#define FUSE_ASYNC_DIO (1ULL << 15)
#define FUSE_WRITEBACK_CACHE (1ULL << 16)
#define FUSE_NO_OPEN_SUPPORT (1ULL << 17)
#define FUSE_PARALLEL_DIROPS (1ULL << 18)
#define FUSE_HANDLE_KILLPRIV (1ULL << 19)
#define FUSE_POSIX_ACL (1ULL << 20)
#define FUSE_ABORT_ERROR (1ULL << 21)
#define FUSE_MAX_PAGES (1ULL << 22)
#define FUSE_CACHE_SYMLINKS (1ULL << 23)
#define FUSE_NO_OPENDIR_SUPPORT (1ULL << 24)
#define FUSE_EXPLICIT_INVAL_DATA (1ULL << 25)
#define FUSE_MAP_ALIGNMENT (1ULL << 26)
#define FUSE_SUBMOUNTS (1ULL << 27)
#define FUSE_HANDLE_KILLPRIV_V2 (1ULL << 28)
#define FUSE_SETXATTR_EXT (1ULL << 29)
#define FUSE_INIT_EXT (1ULL << 30)
#define FUSE_INIT_RESERVED (1ULL << 31)
/* bits 32..63 get shifted down 32 bits into the flags2 field */
#define FUSE_SECURITY_CTX (1ULL << 32)
@ -449,9 +474,14 @@ struct fuse_file_lock {
#define FUSE_CREATE_SUPP_GROUP (1ULL << 34)
#define FUSE_HAS_EXPIRE_ONLY (1ULL << 35)
#define FUSE_DIRECT_IO_ALLOW_MMAP (1ULL << 36)
#define FUSE_PASSTHROUGH (1ULL << 37)
#define FUSE_NO_EXPORT_SUPPORT (1ULL << 38)
#define FUSE_HAS_RESEND (1ULL << 39)
/* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */
#define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP
#define FUSE_ALLOW_IDMAP (1ULL << 40)
#define FUSE_OVER_IO_URING (1ULL << 41)
/**
* CUSE INIT request/reply flags
@ -635,6 +665,7 @@ enum fuse_notify_code {
FUSE_NOTIFY_STORE = 4,
FUSE_NOTIFY_RETRIEVE = 5,
FUSE_NOTIFY_DELETE = 6,
FUSE_NOTIFY_RESEND = 7,
FUSE_NOTIFY_CODE_MAX,
};
@ -761,7 +792,7 @@ struct fuse_create_in {
struct fuse_open_out {
uint64_t fh;
uint32_t open_flags;
uint32_t padding;
int32_t backing_id;
};
struct fuse_release_in {
@ -877,7 +908,8 @@ struct fuse_init_out {
uint16_t max_pages;
uint16_t map_alignment;
uint32_t flags2;
uint32_t unused[7];
uint32_t max_stack_depth;
uint32_t unused[6];
};
#define CUSE_INIT_INFO_MAX 4096
@ -960,6 +992,29 @@ struct fuse_fallocate_in {
uint32_t padding;
};
/**
* FUSE request unique ID flag
*
* Indicates whether this is a resend request. The receiver should handle this
* request accordingly.
*/
#define FUSE_UNIQUE_RESEND (1ULL << 63)
/**
* This value will be set by the kernel to
* (struct fuse_in_header).{uid,gid} fields in
* case when:
* - fuse daemon enabled FUSE_ALLOW_IDMAP
* - idmapping information is not available and uid/gid
* can not be mapped in accordance with an idmapping.
*
* Note: an idmapping information always available
* for inode creation operations like:
* FUSE_MKNOD, FUSE_SYMLINK, FUSE_MKDIR, FUSE_TMPFILE,
* FUSE_CREATE and FUSE_RENAME2 (with RENAME_WHITEOUT).
*/
#define FUSE_INVALID_UIDGID ((uint32_t)(-1))
struct fuse_in_header {
uint32_t len;
uint32_t opcode;
@ -1049,9 +1104,18 @@ struct fuse_notify_retrieve_in {
uint64_t dummy4;
};
struct fuse_backing_map {
int32_t fd;
uint32_t flags;
uint64_t padding;
};
/* Device ioctls: */
#define FUSE_DEV_IOC_MAGIC 229
#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
#define FUSE_DEV_IOC_BACKING_OPEN _IOW(FUSE_DEV_IOC_MAGIC, 1, \
struct fuse_backing_map)
#define FUSE_DEV_IOC_BACKING_CLOSE _IOW(FUSE_DEV_IOC_MAGIC, 2, uint32_t)
struct fuse_lseek_in {
uint64_t fh;
@ -1153,4 +1217,67 @@ struct fuse_supp_groups {
uint32_t groups[];
};
/**
* Size of the ring buffer header
*/
#define FUSE_URING_IN_OUT_HEADER_SZ 128
#define FUSE_URING_OP_IN_OUT_SZ 128
/* Used as part of the fuse_uring_req_header */
struct fuse_uring_ent_in_out {
uint64_t flags;
/*
* commit ID to be used in a reply to a ring request (see also
* struct fuse_uring_cmd_req)
*/
uint64_t commit_id;
/* size of user payload buffer */
uint32_t payload_sz;
uint32_t padding;
uint64_t reserved;
};
/**
* Header for all fuse-io-uring requests
*/
struct fuse_uring_req_header {
/* struct fuse_in_header / struct fuse_out_header */
char in_out[FUSE_URING_IN_OUT_HEADER_SZ];
/* per op code header */
char op_in[FUSE_URING_OP_IN_OUT_SZ];
struct fuse_uring_ent_in_out ring_ent_in_out;
};
/**
* sqe commands to the kernel
*/
enum fuse_uring_cmd {
FUSE_IO_URING_CMD_INVALID = 0,
/* register the request buffer and fetch a fuse request */
FUSE_IO_URING_CMD_REGISTER = 1,
/* commit fuse request result and fetch next request */
FUSE_IO_URING_CMD_COMMIT_AND_FETCH = 2,
};
/**
* In the 80B command area of the SQE.
*/
struct fuse_uring_cmd_req {
uint64_t flags;
/* entry identifier for commits */
uint64_t commit_id;
/* queue the command is for (queue index) */
uint16_t qid;
uint8_t padding[6];
};
#endif /* _LINUX_FUSE_H */

View file

@ -91,17 +91,13 @@ struct fuse_entry_param
/** Additional context associated with requests */
struct fuse_ctx
{
/** User ID of the calling process */
uid_t uid;
/** Group ID of the calling process */
gid_t gid;
/** Thread ID of the calling process */
pid_t pid;
/** Umask of the calling process (introduced in version 2.8) */
mode_t umask;
uint64_t unique;
uint64_t nodeid;
uint32_t opcode;
uid_t uid;
gid_t gid;
pid_t pid;
mode_t umask;
};
/* ----------------------------------------------------------- *

View file

@ -17,12 +17,12 @@
*/
#include "cpu.hpp"
#include "ghc/filesystem.hpp"
#include "fmt/core.h"
#include <pthread.h>
#include <sched.h>
#include <filesystem>
#include <fstream>
@ -71,10 +71,10 @@ CPU::setaffinity(const pthread_t thread_id_,
}
static
ghc::filesystem::path
std::filesystem::path
generate_cpu_core_id_path(const int cpu_id_)
{
const ghc::filesystem::path basepath{"/sys/devices/system/cpu"};
const std::filesystem::path basepath{"/sys/devices/system/cpu"};
return basepath / fmt::format("cpu{}",cpu_id_) / "topology" / "core_id";
}
@ -123,7 +123,7 @@ CPU::cpu2core()
{
int core_id;
std::ifstream ifs;
ghc::filesystem::path path;
std::filesystem::path path;
if(!CPU_ISSET(i,&cpuset))
continue;
@ -156,7 +156,7 @@ CPU::core2cpus()
{
int core_id;
std::ifstream ifs;
ghc::filesystem::path path;
std::filesystem::path path;
if(!CPU_ISSET(i,&cpuset))
continue;

View file

@ -20,8 +20,14 @@
#define _GNU_SOURCE
#endif
#include "syslog.hpp"
#include "fuse_kernel.h"
#include "fmt/core.h"
#include <string>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
@ -201,11 +207,68 @@ fuse_flag_to_str(const uint64_t offset_)
FUSE_INIT_FLAG_CASE(CREATE_SUPP_GROUP);
FUSE_INIT_FLAG_CASE(HAS_EXPIRE_ONLY);
FUSE_INIT_FLAG_CASE(DIRECT_IO_ALLOW_MMAP);
FUSE_INIT_FLAG_CASE(PASSTHROUGH);
FUSE_INIT_FLAG_CASE(NO_EXPORT_SUPPORT);
FUSE_INIT_FLAG_CASE(HAS_RESEND);
FUSE_INIT_FLAG_CASE(ALLOW_IDMAP);
FUSE_INIT_FLAG_CASE(OVER_IO_URING);
}
return NULL;
}
std::string
fuse_debug_init_flag_name(const uint64_t flag_)
{
switch(flag_)
{
FUSE_INIT_FLAG_CASE(ASYNC_READ);
FUSE_INIT_FLAG_CASE(POSIX_LOCKS);
FUSE_INIT_FLAG_CASE(FILE_OPS);
FUSE_INIT_FLAG_CASE(ATOMIC_O_TRUNC);
FUSE_INIT_FLAG_CASE(EXPORT_SUPPORT);
FUSE_INIT_FLAG_CASE(BIG_WRITES);
FUSE_INIT_FLAG_CASE(DONT_MASK);
FUSE_INIT_FLAG_CASE(SPLICE_WRITE);
FUSE_INIT_FLAG_CASE(SPLICE_MOVE);
FUSE_INIT_FLAG_CASE(SPLICE_READ);
FUSE_INIT_FLAG_CASE(FLOCK_LOCKS);
FUSE_INIT_FLAG_CASE(HAS_IOCTL_DIR);
FUSE_INIT_FLAG_CASE(AUTO_INVAL_DATA);
FUSE_INIT_FLAG_CASE(DO_READDIRPLUS);
FUSE_INIT_FLAG_CASE(READDIRPLUS_AUTO);
FUSE_INIT_FLAG_CASE(ASYNC_DIO);
FUSE_INIT_FLAG_CASE(WRITEBACK_CACHE);
FUSE_INIT_FLAG_CASE(NO_OPEN_SUPPORT);
FUSE_INIT_FLAG_CASE(PARALLEL_DIROPS);
FUSE_INIT_FLAG_CASE(HANDLE_KILLPRIV);
FUSE_INIT_FLAG_CASE(POSIX_ACL);
FUSE_INIT_FLAG_CASE(ABORT_ERROR);
FUSE_INIT_FLAG_CASE(MAX_PAGES);
FUSE_INIT_FLAG_CASE(CACHE_SYMLINKS);
FUSE_INIT_FLAG_CASE(NO_OPENDIR_SUPPORT);
FUSE_INIT_FLAG_CASE(EXPLICIT_INVAL_DATA);
FUSE_INIT_FLAG_CASE(MAP_ALIGNMENT);
FUSE_INIT_FLAG_CASE(SUBMOUNTS);
FUSE_INIT_FLAG_CASE(HANDLE_KILLPRIV_V2);
FUSE_INIT_FLAG_CASE(SETXATTR_EXT);
FUSE_INIT_FLAG_CASE(INIT_EXT);
FUSE_INIT_FLAG_CASE(INIT_RESERVED);
FUSE_INIT_FLAG_CASE(SECURITY_CTX);
FUSE_INIT_FLAG_CASE(HAS_INODE_DAX);
FUSE_INIT_FLAG_CASE(CREATE_SUPP_GROUP);
FUSE_INIT_FLAG_CASE(HAS_EXPIRE_ONLY);
FUSE_INIT_FLAG_CASE(DIRECT_IO_ALLOW_MMAP);
FUSE_INIT_FLAG_CASE(PASSTHROUGH);
FUSE_INIT_FLAG_CASE(NO_EXPORT_SUPPORT);
FUSE_INIT_FLAG_CASE(HAS_RESEND);
FUSE_INIT_FLAG_CASE(ALLOW_IDMAP);
FUSE_INIT_FLAG_CASE(OVER_IO_URING);
}
return "unknown";
}
#undef FUSE_INIT_FLAG_CASE
static
@ -758,6 +821,69 @@ debug_fuse_init_in(const struct fuse_init_in *arg_)
fprintf(g_OUTPUT,")\n");
}
void
fuse_syslog_fuse_init_in(const struct fuse_init_in *arg_)
{
uint64_t flags;
std::string output;
flags = (((uint64_t)arg_->flags) | ((uint64_t)arg_->flags2) << 32);
output = fmt::format("fuse_init_in:"
" major={};"
" minor={};"
" flags=(",
arg_->major,
arg_->minor);
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
{
if(!(flags & (1ULL << i)))
continue;
output += fuse_debug_init_flag_name(1ULL << i);
output += ",";
}
output.pop_back();
output += ");";
SysLog::info(output);
}
void
fuse_syslog_fuse_init_out(const struct fuse_init_out *arg_)
{
uint64_t flags;
std::string output;
flags = (((uint64_t)arg_->flags) | ((uint64_t)arg_->flags2) << 32);
output = fmt::format("fuse_init_out:"
" major={};"
" minor={};"
" max_pages={};"
" flags=(",
arg_->major,
arg_->minor,
arg_->max_pages);
for(uint64_t i = 0; i < (sizeof(flags)*8); i++)
{
if(!(flags & (1ULL << i)))
continue;
output += fuse_debug_init_flag_name(1ULL << i);
output += ",";
}
output.pop_back();
output += ");";
SysLog::info(output);
}
void
debug_fuse_init_out(const uint64_t unique_,
const struct fuse_init_out *arg_,
@ -768,10 +894,6 @@ debug_fuse_init_out(const uint64_t unique_,
flags = (((uint64_t)arg->flags) | ((uint64_t)arg->flags2) << 32);
fprintf(g_OUTPUT,
/* "unique=0x%016" PRIx64 ";" */
/* " opcode=RESPONSE;" */
/* " error=0 (Success);" */
/* " len=%" PRIu64 "; || " */
"FUSE_INIT_OUT:"
" major=%u;"
" minor=%u;"

View file

@ -49,3 +49,7 @@ void debug_fuse_lk_out(const uint64_t unique,
void debug_fuse_bmap_out(const uint64_t unique,
const struct fuse_bmap_out *arg);
void debug_fuse_in_header(const struct fuse_in_header *hdr);
std::string fuse_debug_init_flag_name(const uint64_t);
void fuse_syslog_fuse_init_in(const struct fuse_init_in *arg);
void fuse_syslog_fuse_init_out(const struct fuse_init_out *arg);

View file

@ -37,7 +37,6 @@
#include <inttypes.h>
#include <limits.h>
#include <poll.h>
#include <signal.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
@ -45,6 +44,7 @@
#include <stdlib.h>
#include <string.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/param.h>
#include <sys/time.h>
@ -364,9 +364,6 @@ free_node(struct fuse *f_,
{
filename_free(f_,node_->name);
if(node_->hidden_fh)
f_->fs->op.free_hide(node_->hidden_fh);
node_free(node_);
}
@ -938,8 +935,8 @@ try_get_path2(struct fuse *f,
const char *name2,
char **path1,
char **path2,
node_t **wnode1,
node_t **wnode2)
node_t **wnode1,
node_t **wnode2)
{
int err;
@ -1160,7 +1157,7 @@ static
void
free_path_wrlock(struct fuse *f,
uint64_t nodeid,
node_t *wnode,
node_t *wnode,
char *path)
{
mutex_lock(&f->lock);
@ -1408,7 +1405,7 @@ lookup_path(struct fuse *f,
rv = ((fi == NULL) ?
f->fs->op.getattr(path,&e->attr,&e->timeout) :
f->fs->op.fgetattr(fi,&e->attr,&e->timeout));
f->fs->op.fgetattr(fi->fh,&e->attr,&e->timeout));
if(rv)
return rv;
@ -1487,14 +1484,19 @@ static
struct fuse*
req_fuse_prepare(fuse_req_t req)
{
struct fuse_context_i *c = fuse_get_context_internal();
struct fuse_context_i *c = fuse_get_context_internal();
const struct fuse_ctx *ctx = fuse_req_ctx(req);
c->req = req;
c->ctx.fuse = req_fuse(req);
c->ctx.uid = ctx->uid;
c->ctx.gid = ctx->gid;
c->ctx.pid = ctx->pid;
c->ctx.umask = ctx->umask;
c->req = req;
c->ctx.fuse = req_fuse(req);
c->ctx.opcode = ctx->opcode;
c->ctx.unique = ctx->unique;
c->ctx.nodeid = ctx->nodeid;
c->ctx.uid = ctx->uid;
c->ctx.gid = ctx->gid;
c->ctx.pid = ctx->pid;
c->ctx.umask = ctx->umask;
return c->ctx.fuse;
}
@ -1672,41 +1674,36 @@ fuse_lib_getattr(fuse_req_t req,
{
int err;
char *path;
uint64_t fh;
struct fuse *f;
struct stat buf;
node_t *node;
fuse_timeouts_t timeout;
fuse_file_info_t ffi = {0};
const struct fuse_getattr_in *arg;
arg = (fuse_getattr_in*)fuse_hdr_arg(hdr_);
f = req_fuse_prepare(req);
fh = 0;
if(arg->getattr_flags & FUSE_GETATTR_FH)
{
ffi.fh = arg->fh;
}
else
{
mutex_lock(&f->lock);
node = get_node(f,hdr_->nodeid);
if(node->hidden_fh)
ffi.fh = node->hidden_fh;
mutex_unlock(&f->lock);
}
fh = arg->fh;
memset(&buf,0,sizeof(buf));
err = 0;
path = NULL;
if(ffi.fh == 0)
err = get_path(f,hdr_->nodeid,&path);
if(fh == 0)
{
err = get_path(f,hdr_->nodeid,&path);
if(err == -ESTALE) // unlinked but open
err = 0;
}
if(!err)
{
err = ((ffi.fh == 0) ?
err = ((path != NULL) ?
f->fs->op.getattr(path,&buf,&timeout) :
f->fs->op.fgetattr(&ffi,&buf,&timeout));
f->fs->op.fgetattr(fh,&buf,&timeout));
free_path(f,hdr_->nodeid,path);
}
@ -1738,6 +1735,7 @@ fuse_lib_statx_path(fuse_req_t req_,
struct fuse_statx st{};
fuse_timeouts_t timeouts{};
// TODO: if node unlinked... but FUSE may not send it
err = get_path(f_,hdr_->nodeid,&fusepath);
if(err)
{
@ -1803,63 +1801,51 @@ void
fuse_lib_setattr(fuse_req_t req,
struct fuse_in_header *hdr_)
{
uint64_t fh;
struct fuse *f = req_fuse_prepare(req);
struct stat stbuf = {0};
char *path;
int err;
node_t *node;
fuse_timeouts_t timeout;
fuse_file_info_t *fi;
fuse_file_info_t ffi = {0};
struct fuse_setattr_in *arg;
arg = (fuse_setattr_in*)fuse_hdr_arg(hdr_);
fi = NULL;
fh = 0;
if(arg->valid & FATTR_FH)
{
fi = &ffi;
fi->fh = arg->fh;
}
else
{
mutex_lock(&f->lock);
node = get_node(f,hdr_->nodeid);
if(node->hidden_fh)
{
fi = &ffi;
fi->fh = node->hidden_fh;
}
mutex_unlock(&f->lock);
}
fh = arg->fh;
err = 0;
path = NULL;
if(fi == NULL)
err = get_path(f,hdr_->nodeid,&path);
if(fh == 0)
{
err = get_path(f,hdr_->nodeid,&path);
if(err == -ESTALE)
err = 0;
}
if(!err)
{
err = 0;
if(!err && (arg->valid & FATTR_MODE))
err = ((fi == NULL) ?
err = ((path != NULL) ?
f->fs->op.chmod(path,arg->mode) :
f->fs->op.fchmod(fi,arg->mode));
f->fs->op.fchmod(fh,arg->mode));
if(!err && (arg->valid & (FATTR_UID | FATTR_GID)))
{
uid_t uid = ((arg->valid & FATTR_UID) ? arg->uid : (uid_t)-1);
gid_t gid = ((arg->valid & FATTR_GID) ? arg->gid : (gid_t)-1);
err = ((fi == NULL) ?
err = ((path != NULL) ?
f->fs->op.chown(path,uid,gid) :
f->fs->op.fchown(fi,uid,gid));
f->fs->op.fchown(fh,uid,gid));
}
if(!err && (arg->valid & FATTR_SIZE))
err = ((fi == NULL) ?
err = ((path != NULL) ?
f->fs->op.truncate(path,arg->size) :
f->fs->op.ftruncate(fi,arg->size));
f->fs->op.ftruncate(fh,arg->size));
#ifdef HAVE_UTIMENSAT
if(!err && (arg->valid & (FATTR_ATIME | FATTR_MTIME)))
@ -1881,9 +1867,9 @@ fuse_lib_setattr(fuse_req_t req,
else if(arg->valid & FATTR_MTIME)
tv[1] = (struct timespec){ static_cast<time_t>(arg->mtime), arg->mtimensec };
err = ((fi == NULL) ?
err = ((path != NULL) ?
f->fs->op.utimens(path,tv) :
f->fs->op.futimens(fi,tv));
f->fs->op.futimens(fh,tv));
}
else
#endif
@ -1894,15 +1880,15 @@ fuse_lib_setattr(fuse_req_t req,
tv[0].tv_nsec = arg->atimensec;
tv[1].tv_sec = arg->mtime;
tv[1].tv_nsec = arg->mtimensec;
err = ((fi == NULL) ?
err = ((path != NULL) ?
f->fs->op.utimens(path,tv) :
f->fs->op.futimens(fi,tv));
f->fs->op.futimens(fh,tv));
}
if(!err)
err = ((fi == NULL) ?
err = ((path != NULL) ?
f->fs->op.getattr(path,&stbuf,&timeout) :
f->fs->op.fgetattr(fi,&stbuf,&timeout));
f->fs->op.fgetattr(fh,&stbuf,&timeout));
free_path(f,hdr_->nodeid,path);
}
@ -2076,10 +2062,8 @@ fuse_lib_unlink(fuse_req_t req,
if(!err)
{
mutex_lock(&f->lock);
if(node_open(wnode))
err = f->fs->op.prepare_hide(path,&wnode->hidden_fh);
mutex_unlock(&f->lock);
fuse_get_context()->nodeid = wnode->nodeid;
err = f->fs->op.unlink(path);
if(!err)
@ -2172,11 +2156,6 @@ fuse_lib_rename(fuse_req_t req,
if(!err)
{
mutex_lock(&f->lock);
if(node_open(wnode2))
err = f->fs->op.prepare_hide(newpath,&wnode2->hidden_fh);
mutex_unlock(&f->lock);
err = f->fs->op.rename(oldpath,newpath);
if(!err)
err = rename_node(f,hdr_->nodeid,oldname,arg->newdir,newname);
@ -2244,11 +2223,8 @@ fuse_do_release(struct fuse *f,
uint64_t ino,
fuse_file_info_t *fi)
{
uint64_t fh;
node_t *node;
fh = 0;
f->fs->op.release(fi);
mutex_lock(&f->lock);
@ -2256,17 +2232,8 @@ fuse_do_release(struct fuse *f,
node = get_node(f,ino);
assert(node->open_count > 0);
node->open_count--;
if(node->hidden_fh && (node->open_count == 0))
{
fh = node->hidden_fh;
node->hidden_fh = 0;
}
}
mutex_unlock(&f->lock);
if(fh)
f->fs->op.free_hide(fh);
}
static
@ -2278,6 +2245,7 @@ fuse_lib_create(fuse_req_t req,
char *path;
struct fuse *f;
const char *name;
uint64_t new_nodeid;
fuse_file_info_t ffi = {0};
struct fuse_entry_param e;
struct fuse_create_in *arg;
@ -2294,6 +2262,14 @@ fuse_lib_create(fuse_req_t req,
f = req_fuse_prepare(req);
// opportunistically allocate a node so we have a new nodeid for
// later in the actual create. Added for use with passthrough.
{
node_t *node = find_node(f,hdr_->nodeid,name);
new_nodeid = node->nodeid;
fuse_get_context()->nodeid = new_nodeid;
}
err = get_path_name(f,hdr_->nodeid,name,&path);
if(!err)
{
@ -2330,6 +2306,7 @@ fuse_lib_create(fuse_req_t req,
}
else
{
forget_node(f,new_nodeid,1);
fuse_reply_err(req,err);
}
@ -2355,7 +2332,7 @@ open_auto_cache(struct fuse *f,
struct stat stbuf;
mutex_unlock(&f->lock);
err = f->fs->op.fgetattr(fi,&stbuf,&timeout);
err = f->fs->op.fgetattr(fi->fh,&stbuf,&timeout);
mutex_lock(&f->lock);
if(!err)
@ -2494,14 +2471,12 @@ fuse_lib_fsync(fuse_req_t req,
int err;
struct fuse *f;
struct fuse_fsync_in *arg;
fuse_file_info_t ffi = {0};
arg = (fuse_fsync_in*)fuse_hdr_arg(hdr_);
ffi.fh = arg->fh;
f = req_fuse_prepare(req);
err = f->fs->op.fsync(&ffi,
err = f->fs->op.fsync(arg->fh,
!!(arg->fsync_flags & 1));
fuse_reply_err(req,err);
@ -3569,15 +3544,13 @@ fuse_lib_fallocate(fuse_req_t req,
{
int err;
struct fuse *f;
fuse_file_info_t ffi = {0};
const struct fuse_fallocate_in *arg;
arg = (fuse_fallocate_in*)fuse_hdr_arg(hdr_);
ffi.fh = arg->fh;
f = req_fuse_prepare(req);
err = f->fs->op.fallocate(&ffi,
err = f->fs->op.fallocate(arg->fh,
arg->mode,
arg->offset,
arg->length);
@ -4218,20 +4191,6 @@ fuse_destroy(struct fuse *f)
memset(c,0,sizeof(*c));
c->ctx.fuse = f;
for(i = 0; i < f->id_table.size; i++)
{
node_t *node;
for(node = f->id_table.array[i]; node != NULL; node = node->id_next)
{
if(!node->hidden_fh)
continue;
f->fs->op.free_hide(node->hidden_fh);
node->hidden_fh = 0;
}
}
}
for(i = 0; i < f->id_table.size; i++)
@ -4266,3 +4225,36 @@ fuse_log_metrics_get(void)
{
return g_LOG_METRICS;
}
int
fuse_get_dev_fuse_fd(const struct fuse_context *fc_)
{
return fuse_chan_fd(fc_->fuse->se->ch);
}
int
fuse_passthrough_open(const struct fuse_context *fc_,
const int fd_)
{
int rv;
int dev_fuse_fd;
struct fuse_backing_map bm = {0};
dev_fuse_fd = fuse_get_dev_fuse_fd(fc_);
bm.fd = fd_;
rv = ::ioctl(dev_fuse_fd,FUSE_DEV_IOC_BACKING_OPEN,&bm);
return rv;
}
int
fuse_passthrough_close(const struct fuse_context *fc_,
const int backing_id_)
{
int dev_fuse_fd;
dev_fuse_fd = fuse_get_dev_fuse_fd(fc_);
return ::ioctl(dev_fuse_fd,FUSE_DEV_IOC_BACKING_CLOSE,&backing_id_);
}

View file

@ -280,6 +280,11 @@ fill_open(struct fuse_open_out *arg_,
arg_->open_flags |= FOPEN_PARALLEL_DIRECT_WRITES;
if(ffi_->noflush)
arg_->open_flags |= FOPEN_NOFLUSH;
if(ffi_->passthrough && (ffi_->backing_id > 0))
{
arg_->open_flags |= FOPEN_PASSTHROUGH;
arg_->backing_id = ffi_->backing_id;
}
}
int
@ -1122,8 +1127,7 @@ do_init(fuse_req_t req,
inargflags = 0;
outargflags = 0;
if(f->debug)
debug_fuse_init_in(arg);
fuse_syslog_fuse_init_in(arg);
f->conn.proto_major = arg->major;
f->conn.proto_minor = arg->minor;
@ -1194,6 +1198,12 @@ do_init(fuse_req_t req,
f->conn.capable |= FUSE_CAP_DIRECT_IO_ALLOW_MMAP;
if(inargflags & FUSE_CREATE_SUPP_GROUP)
f->conn.capable |= FUSE_CAP_CREATE_SUPP_GROUP;
if(inargflags & FUSE_PASSTHROUGH)
f->conn.capable |= FUSE_CAP_PASSTHROUGH;
if(inargflags & FUSE_HANDLE_KILLPRIV)
f->conn.capable |= FUSE_CAP_HANDLE_KILLPRIV;
if(inargflags & FUSE_HANDLE_KILLPRIV_V2)
f->conn.capable |= FUSE_CAP_HANDLE_KILLPRIV_V2;
}
else
{
@ -1267,6 +1277,15 @@ do_init(fuse_req_t req,
outargflags |= FUSE_CREATE_SUPP_GROUP;
if(f->conn.want & FUSE_CAP_DIRECT_IO_ALLOW_MMAP)
outargflags |= FUSE_DIRECT_IO_ALLOW_MMAP;
if(f->conn.want & FUSE_CAP_HANDLE_KILLPRIV)
outargflags |= FUSE_HANDLE_KILLPRIV;
if(f->conn.want & FUSE_CAP_HANDLE_KILLPRIV_V2)
outargflags |= FUSE_HANDLE_KILLPRIV_V2;
if(f->conn.want & FUSE_CAP_PASSTHROUGH)
{
outargflags |= FUSE_PASSTHROUGH;
outarg.max_stack_depth = 2;
}
if(inargflags & FUSE_INIT_EXT)
{
@ -1304,8 +1323,7 @@ do_init(fuse_req_t req,
else
outargsize = sizeof(outarg);
if(f->debug)
debug_fuse_init_out(req->unique,&outarg,outargsize);
fuse_syslog_fuse_init_out(&outarg);
send_reply_ok(req, &outarg, outargsize);
}
@ -1943,11 +1961,14 @@ fuse_ll_buf_process_read(struct fuse_session *se_,
if(req == NULL)
return fuse_send_enomem(se_->f,se_->ch,in->unique);
req->unique = in->unique;
req->ctx.uid = in->uid;
req->ctx.gid = in->gid;
req->ctx.pid = in->pid;
req->ch = se_->ch;
req->unique = in->unique;
req->ctx.opcode = in->opcode;
req->ctx.unique = in->unique;
req->ctx.nodeid = in->nodeid;
req->ctx.uid = in->uid;
req->ctx.gid = in->gid;
req->ctx.pid = in->pid;
req->ch = se_->ch;
err = ENOSYS;
if(in->opcode >= FUSE_MAXOPS)
@ -1979,11 +2000,14 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_,
if(req == NULL)
return fuse_send_enomem(se_->f,se_->ch,in->unique);
req->unique = in->unique;
req->ctx.uid = in->uid;
req->ctx.gid = in->gid;
req->ctx.pid = in->pid;
req->ch = se_->ch;
req->unique = in->unique;
req->ctx.opcode = in->opcode;
req->ctx.unique = in->unique;
req->ctx.nodeid = in->nodeid;
req->ctx.uid = in->uid;
req->ctx.gid = in->gid;
req->ctx.pid = in->pid;
req->ch = se_->ch;
err = EIO;
if(in->opcode != FUSE_INIT)

File diff suppressed because it is too large Load diff

View file

@ -16,7 +16,6 @@ struct node_s
uint64_t nlookup;
uint32_t refctr;
uint32_t open_count;
uint64_t hidden_fh;
int32_t treelock;
lock_t *locks;