mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-01 04:16:59 -05:00
Rework config, centralize fuse config (#1547)
This commit is contained in:
parent
00e5467e99
commit
727c522fb8
46 changed files with 1294 additions and 1316 deletions
38
libfuse/include/fuse_cfg.hpp
Normal file
38
libfuse/include/fuse_cfg.hpp
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include "int_types.h"
|
||||
|
||||
#include <climits>
|
||||
#include <string>
|
||||
|
||||
#define FUSE_CFG_INVALID_ID -1
|
||||
#define FUSE_CFG_INVALID_UMASK -1
|
||||
|
||||
|
||||
struct fuse_cfg_t
|
||||
{
|
||||
s64 uid = FUSE_CFG_INVALID_ID;
|
||||
bool valid_uid() const;
|
||||
|
||||
s64 gid = FUSE_CFG_INVALID_ID;
|
||||
bool valid_gid() const;
|
||||
|
||||
s64 umask = FUSE_CFG_INVALID_UMASK;
|
||||
bool valid_umask() const;
|
||||
|
||||
s64 remember_nodes = 0;
|
||||
|
||||
bool debug = false;
|
||||
|
||||
int max_background = 0;
|
||||
int congestion_threshold = 0;
|
||||
u32 max_pages = 32;
|
||||
int passthrough_max_stack_depth = 1;
|
||||
|
||||
int read_thread_count = 0;
|
||||
int process_thread_count = -1;
|
||||
int process_thread_queue_depth = 2;
|
||||
std::string pin_threads = "false";
|
||||
};
|
||||
|
||||
extern fuse_cfg_t fuse_cfg;
|
||||
|
|
@ -139,13 +139,8 @@ struct fuse_conn_info
|
|||
{
|
||||
unsigned proto_major;
|
||||
unsigned proto_minor;
|
||||
unsigned max_write;
|
||||
unsigned max_readahead;
|
||||
uint64_t capable;
|
||||
uint64_t want;
|
||||
unsigned max_background;
|
||||
unsigned congestion_threshold;
|
||||
uint16_t max_pages;
|
||||
};
|
||||
|
||||
struct fuse_session;
|
||||
|
|
|
|||
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
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 <string>
|
||||
|
||||
int fuse_config_get_read_thread_count();
|
||||
int fuse_config_get_process_thread_count();
|
||||
int fuse_config_get_process_thread_queue_depth();
|
||||
std::string fuse_config_get_pin_threads();
|
||||
|
||||
void fuse_config_set_read_thread_count(int const);
|
||||
void fuse_config_set_process_thread_count(int const);
|
||||
void fuse_config_set_process_thread_queue_depth(int const);
|
||||
void fuse_config_set_pin_threads(std::string const);
|
||||
|
|
@ -18,11 +18,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "int_types.h"
|
||||
#include "fuse_msgbuf_t.h"
|
||||
#include "extern_c.h"
|
||||
|
||||
EXTERN_C_BEGIN
|
||||
|
||||
u32 msgbuf_get_pagesize();
|
||||
void msgbuf_set_bufsize(const uint32_t size);
|
||||
uint64_t msgbuf_get_bufsize();
|
||||
|
||||
|
|
@ -35,8 +34,3 @@ void msgbuf_gc_10percent();
|
|||
|
||||
uint64_t msgbuf_alloc_count();
|
||||
uint64_t msgbuf_avail_count();
|
||||
|
||||
void msgbuf_page_align(fuse_msgbuf_t *msgbuf);
|
||||
void msgbuf_write_align(fuse_msgbuf_t *msgbuf);
|
||||
|
||||
EXTERN_C_END
|
||||
|
|
|
|||
13
libfuse/include/int_types.h
Normal file
13
libfuse/include/int_types.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint64_t u32;
|
||||
typedef int64_t s32;
|
||||
typedef uint64_t u64;
|
||||
typedef int64_t s64;
|
||||
|
||||
typedef const uint64_t cu32;
|
||||
typedef const int64_t cs32;
|
||||
typedef const uint64_t cu64;
|
||||
typedef const int64_t cs64;
|
||||
|
|
@ -19,6 +19,7 @@
|
|||
#include "mutex.hpp"
|
||||
#include "node.hpp"
|
||||
|
||||
#include "fuse_cfg.hpp"
|
||||
#include "fuse_req.h"
|
||||
#include "fuse_dirents.hpp"
|
||||
#include "fuse_i.h"
|
||||
|
|
@ -70,16 +71,6 @@ static int g_LOG_METRICS = 0;
|
|||
|
||||
struct fuse_config
|
||||
{
|
||||
unsigned int uid;
|
||||
unsigned int gid;
|
||||
unsigned int umask;
|
||||
int remember;
|
||||
int debug;
|
||||
int nogc;
|
||||
int set_mode;
|
||||
int set_uid;
|
||||
int set_gid;
|
||||
int help;
|
||||
};
|
||||
|
||||
struct lock_queue_element
|
||||
|
|
@ -620,7 +611,7 @@ inline
|
|||
int
|
||||
remember_nodes()
|
||||
{
|
||||
return (f.conf.remember > 0);
|
||||
return (fuse_cfg.remember_nodes > 0);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -703,7 +694,7 @@ find_node(uint64_t parent,
|
|||
goto out_err;
|
||||
|
||||
node->nodeid = generate_nodeid(&f.nodeid_gen);
|
||||
if(f.conf.remember)
|
||||
if(fuse_cfg.remember_nodes)
|
||||
inc_nlookup(node);
|
||||
|
||||
if(hash_name(node,parent,name) == -1)
|
||||
|
|
@ -1264,12 +1255,12 @@ void
|
|||
set_stat(uint64_t nodeid,
|
||||
struct stat *stbuf)
|
||||
{
|
||||
if(f.conf.set_mode)
|
||||
stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~f.conf.umask);
|
||||
if(f.conf.set_uid)
|
||||
stbuf->st_uid = f.conf.uid;
|
||||
if(f.conf.set_gid)
|
||||
stbuf->st_gid = f.conf.gid;
|
||||
if(fuse_cfg.valid_uid())
|
||||
stbuf->st_uid = fuse_cfg.uid;
|
||||
if(fuse_cfg.valid_gid())
|
||||
stbuf->st_gid = fuse_cfg.gid;
|
||||
if(fuse_cfg.valid_umask())
|
||||
stbuf->st_mode = (stbuf->st_mode & S_IFMT) | (0777 & ~fuse_cfg.umask);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -3449,7 +3440,7 @@ fuse_prune_some_remembered_nodes(int *offset_)
|
|||
|
||||
checked++;
|
||||
age = (now - fn->time);
|
||||
if(f.conf.remember > age)
|
||||
if(fuse_cfg.remember_nodes > age)
|
||||
break;
|
||||
|
||||
assert(fn->node->nlookup == 1);
|
||||
|
|
@ -3597,38 +3588,9 @@ enum
|
|||
|
||||
static const struct fuse_opt fuse_lib_opts[] =
|
||||
{
|
||||
FUSE_OPT_KEY("-h", KEY_HELP),
|
||||
FUSE_OPT_KEY("--help", KEY_HELP),
|
||||
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_LIB_OPT("debug", debug,1),
|
||||
FUSE_LIB_OPT("-d", debug,1),
|
||||
FUSE_LIB_OPT("nogc", nogc,1),
|
||||
FUSE_LIB_OPT("umask=", set_mode,1),
|
||||
FUSE_LIB_OPT("umask=%o", umask,0),
|
||||
FUSE_LIB_OPT("uid=", set_uid,1),
|
||||
FUSE_LIB_OPT("uid=%d", uid,0),
|
||||
FUSE_LIB_OPT("gid=", set_gid,1),
|
||||
FUSE_LIB_OPT("gid=%d", gid,0),
|
||||
FUSE_LIB_OPT("noforget", remember,-1),
|
||||
FUSE_LIB_OPT("remember=%u", remember,0),
|
||||
FUSE_OPT_END
|
||||
};
|
||||
|
||||
static void fuse_lib_help(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
" -o umask=M set file permissions (octal)\n"
|
||||
" -o uid=N set file owner\n"
|
||||
" -o gid=N set file group\n"
|
||||
" -o noforget never forget cached inodes\n"
|
||||
" -o remember=T remember cached inodes for T seconds (0s)\n"
|
||||
" -o threads=NUM number of worker threads. 0 = autodetect.\n"
|
||||
" Negative values autodetect then divide by\n"
|
||||
" absolute value. default = 0\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
fuse_lib_opt_proc(void *data,
|
||||
|
|
@ -3636,24 +3598,9 @@ fuse_lib_opt_proc(void *data,
|
|||
int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
(void)arg; (void)outargs;
|
||||
|
||||
if(key == KEY_HELP)
|
||||
{
|
||||
struct fuse_config *conf = (struct fuse_config *)data;
|
||||
fuse_lib_help();
|
||||
conf->help = 1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int
|
||||
fuse_is_lib_option(const char *opt)
|
||||
{
|
||||
return fuse_lowlevel_is_lib_option(opt) || fuse_opt_match(fuse_lib_opts,opt);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
node_table_init(struct node_table *t)
|
||||
|
|
@ -3872,7 +3819,7 @@ fuse_new(struct fuse_chan *ch,
|
|||
if(fuse_opt_parse(args,&f.conf,fuse_lib_opts,fuse_lib_opt_proc) == -1)
|
||||
goto out_free_fs;
|
||||
|
||||
g_LOG_METRICS = f.conf.debug;
|
||||
g_LOG_METRICS = fuse_cfg.debug;
|
||||
|
||||
f.se = fuse_lowlevel_new_common(args,&llop,sizeof(llop),&f);
|
||||
if(f.se == NULL)
|
||||
|
|
|
|||
21
libfuse/lib/fuse_cfg.cpp
Normal file
21
libfuse/lib/fuse_cfg.cpp
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
#include "fuse_cfg.hpp"
|
||||
|
||||
fuse_cfg_t fuse_cfg;
|
||||
|
||||
bool
|
||||
fuse_cfg_t::valid_uid() const
|
||||
{
|
||||
return (uid != FUSE_CFG_INVALID_ID);
|
||||
}
|
||||
|
||||
bool
|
||||
fuse_cfg_t::valid_gid() const
|
||||
{
|
||||
return (gid != FUSE_CFG_INVALID_ID);
|
||||
}
|
||||
|
||||
bool
|
||||
fuse_cfg_t::valid_umask() const
|
||||
{
|
||||
return (umask != FUSE_CFG_INVALID_UMASK);
|
||||
}
|
||||
|
|
@ -1,73 +0,0 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2023, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
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 <string>
|
||||
|
||||
static int g_READ_THREAD_COUNT = -1;
|
||||
static int g_PROCESS_THREAD_COUNT = -1;
|
||||
static int g_PROCESS_THREAD_QUEUE_DEPTH = -1;
|
||||
static std::string g_PIN_THREADS = {};
|
||||
|
||||
|
||||
int
|
||||
fuse_config_get_read_thread_count()
|
||||
{
|
||||
return g_READ_THREAD_COUNT;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_read_thread_count(int const v_)
|
||||
{
|
||||
g_READ_THREAD_COUNT = v_;
|
||||
}
|
||||
|
||||
int
|
||||
fuse_config_get_process_thread_count()
|
||||
{
|
||||
return g_PROCESS_THREAD_COUNT;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_process_thread_count(int const v_)
|
||||
{
|
||||
g_PROCESS_THREAD_COUNT = v_;
|
||||
}
|
||||
|
||||
int
|
||||
fuse_config_get_process_thread_queue_depth()
|
||||
{
|
||||
return g_PROCESS_THREAD_QUEUE_DEPTH;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_process_thread_queue_depth(int const v_)
|
||||
{
|
||||
g_PROCESS_THREAD_QUEUE_DEPTH = v_;
|
||||
}
|
||||
|
||||
std::string
|
||||
fuse_config_get_pin_threads()
|
||||
{
|
||||
return g_PIN_THREADS;
|
||||
}
|
||||
|
||||
void
|
||||
fuse_config_set_pin_threads(std::string const v_)
|
||||
{
|
||||
g_PIN_THREADS = v_;
|
||||
}
|
||||
|
|
@ -45,11 +45,6 @@ struct fuse_notify_req
|
|||
|
||||
struct fuse_ll
|
||||
{
|
||||
unsigned passthrough_max_stack_depth;
|
||||
int debug;
|
||||
int no_remote_posix_lock;
|
||||
int no_remote_flock;
|
||||
int big_writes;
|
||||
struct fuse_lowlevel_ops op;
|
||||
void *userdata;
|
||||
uid_t owner;
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@
|
|||
#include "fuse_kernel.h"
|
||||
#include "fuse_lowlevel.h"
|
||||
|
||||
#include "fuse_config.hpp"
|
||||
#include "fuse_cfg.hpp"
|
||||
#include "fuse_msgbuf.hpp"
|
||||
#include "fuse_ll.hpp"
|
||||
|
||||
|
|
@ -336,10 +336,10 @@ fuse_loop_mt(struct fuse *f_)
|
|||
fuse_populate_maintenance_thread(f_);
|
||||
|
||||
res = fuse_session_loop_mt(fuse_get_session(),
|
||||
fuse_config_get_read_thread_count(),
|
||||
fuse_config_get_process_thread_count(),
|
||||
fuse_config_get_process_thread_queue_depth(),
|
||||
fuse_config_get_pin_threads());
|
||||
fuse_cfg.read_thread_count,
|
||||
fuse_cfg.process_thread_count,
|
||||
fuse_cfg.process_thread_queue_depth,
|
||||
fuse_cfg.pin_threads);
|
||||
|
||||
MaintenanceThread::stop();
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@
|
|||
#include "lfmp.h"
|
||||
|
||||
#include "debug.hpp"
|
||||
#include "fuse_cfg.hpp"
|
||||
#include "fuse_i.h"
|
||||
#include "fuse_kernel.h"
|
||||
#include "fuse_msgbuf.hpp"
|
||||
|
|
@ -43,7 +44,7 @@
|
|||
#define OFFSET_MAX 0x7fffffffffffffffLL
|
||||
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const decltype( ((type*)0)->member ) *__mptr = (ptr); \
|
||||
const decltype( ((type*)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char*)__mptr - offsetof(type,member) );})
|
||||
|
||||
static size_t pagesize;
|
||||
|
|
@ -1117,11 +1118,17 @@ do_init(fuse_req_t *req,
|
|||
struct fuse_in_header *hdr_)
|
||||
{
|
||||
struct fuse_init_out outarg = {0};
|
||||
struct fuse_init_in *arg = (struct fuse_init_in *) &hdr_[1];
|
||||
struct fuse_init_in *arg = (struct fuse_init_in *)&hdr_[1];
|
||||
struct fuse_ll *f = req->f;
|
||||
size_t bufsize = fuse_chan_bufsize(req->ch);
|
||||
size_t bufsize;
|
||||
uint64_t inargflags;
|
||||
uint64_t outargflags;
|
||||
u32 max_write;
|
||||
u32 max_readahead;
|
||||
|
||||
max_write = UINT_MAX;
|
||||
max_readahead = UINT_MAX;
|
||||
bufsize = fuse_chan_bufsize(req->ch);
|
||||
|
||||
inargflags = 0;
|
||||
outargflags = 0;
|
||||
|
|
@ -1158,8 +1165,8 @@ do_init(fuse_req_t *req,
|
|||
if(inargflags & FUSE_INIT_EXT)
|
||||
inargflags |= (((uint64_t)arg->flags2) << 32);
|
||||
|
||||
if(arg->max_readahead < f->conn.max_readahead)
|
||||
f->conn.max_readahead = arg->max_readahead;
|
||||
if(arg->max_readahead < max_readahead)
|
||||
max_readahead = arg->max_readahead;
|
||||
|
||||
if(inargflags & FUSE_ASYNC_READ)
|
||||
f->conn.capable |= FUSE_CAP_ASYNC_READ;
|
||||
|
|
@ -1209,15 +1216,15 @@ do_init(fuse_req_t *req,
|
|||
else
|
||||
{
|
||||
f->conn.want &= ~FUSE_CAP_ASYNC_READ;
|
||||
f->conn.max_readahead = 0;
|
||||
max_readahead = 0;
|
||||
}
|
||||
|
||||
if(req->f->conn.proto_minor >= 18)
|
||||
f->conn.capable |= FUSE_CAP_IOCTL_DIR;
|
||||
|
||||
if(f->op.getlk && f->op.setlk && !f->no_remote_posix_lock)
|
||||
if(f->op.getlk && f->op.setlk)
|
||||
f->conn.want |= FUSE_CAP_POSIX_LOCKS;
|
||||
if(f->op.flock && !f->no_remote_flock)
|
||||
if(f->op.flock)
|
||||
f->conn.want |= FUSE_CAP_FLOCK_LOCKS;
|
||||
|
||||
if(bufsize < FUSE_MIN_READ_BUFFER)
|
||||
|
|
@ -1228,8 +1235,8 @@ do_init(fuse_req_t *req,
|
|||
}
|
||||
|
||||
bufsize -= pagesize;
|
||||
if(bufsize < f->conn.max_write)
|
||||
f->conn.max_write = bufsize;
|
||||
if(bufsize < max_write)
|
||||
max_write = bufsize;
|
||||
|
||||
f->got_init = 1;
|
||||
if(f->op.init)
|
||||
|
|
@ -1238,10 +1245,11 @@ do_init(fuse_req_t *req,
|
|||
outargflags = outarg.flags;
|
||||
if((inargflags & FUSE_MAX_PAGES) && (f->conn.want & FUSE_CAP_MAX_PAGES))
|
||||
{
|
||||
outargflags |= FUSE_MAX_PAGES;
|
||||
outarg.max_pages = f->conn.max_pages;
|
||||
outargflags |= FUSE_MAX_PAGES;
|
||||
outarg.max_pages = fuse_cfg.max_pages;
|
||||
|
||||
msgbuf_set_bufsize(outarg.max_pages + 1);
|
||||
msgbuf_set_bufsize(outarg.max_pages);
|
||||
max_write = (msgbuf_get_pagesize() * outarg.max_pages);
|
||||
}
|
||||
|
||||
if(f->conn.want & FUSE_CAP_ASYNC_READ)
|
||||
|
|
@ -1288,7 +1296,7 @@ do_init(fuse_req_t *req,
|
|||
if(f->conn.want & FUSE_CAP_PASSTHROUGH)
|
||||
{
|
||||
outargflags |= FUSE_PASSTHROUGH;
|
||||
outarg.max_stack_depth = f->passthrough_max_stack_depth;
|
||||
outarg.max_stack_depth = fuse_cfg.passthrough_max_stack_depth;
|
||||
}
|
||||
|
||||
if(inargflags & FUSE_INIT_EXT)
|
||||
|
|
@ -1299,21 +1307,19 @@ do_init(fuse_req_t *req,
|
|||
|
||||
outarg.flags = outargflags;
|
||||
|
||||
outarg.max_readahead = f->conn.max_readahead;
|
||||
outarg.max_write = f->conn.max_write;
|
||||
outarg.max_readahead = max_readahead;
|
||||
outarg.max_write = max_write;
|
||||
if(f->conn.proto_minor >= 13)
|
||||
{
|
||||
if(f->conn.max_background >= (1 << 16))
|
||||
f->conn.max_background = (1 << 16) - 1;
|
||||
if(f->conn.congestion_threshold > f->conn.max_background)
|
||||
f->conn.congestion_threshold = f->conn.max_background;
|
||||
if(!f->conn.congestion_threshold)
|
||||
{
|
||||
f->conn.congestion_threshold = f->conn.max_background * 3 / 4;
|
||||
}
|
||||
if(fuse_cfg.max_background >= (1 << 16))
|
||||
fuse_cfg.max_background = ((1 << 16) - 1);
|
||||
if(fuse_cfg.congestion_threshold > fuse_cfg.max_background)
|
||||
fuse_cfg.congestion_threshold = fuse_cfg.max_background;
|
||||
if(!fuse_cfg.congestion_threshold)
|
||||
fuse_cfg.congestion_threshold = (fuse_cfg.max_background * 3 / 4);
|
||||
|
||||
outarg.max_background = f->conn.max_background;
|
||||
outarg.congestion_threshold = f->conn.congestion_threshold;
|
||||
outarg.max_background = fuse_cfg.max_background;
|
||||
outarg.congestion_threshold = fuse_cfg.congestion_threshold;
|
||||
}
|
||||
|
||||
if(f->conn.proto_minor >= 23)
|
||||
|
|
@ -1780,86 +1786,6 @@ fuse_ll_funcs[FUSE_OPCODE_LEN] =
|
|||
|
||||
#define FUSE_MAXOPS (sizeof(fuse_ll_funcs) / sizeof(fuse_ll_funcs[0]))
|
||||
|
||||
enum {
|
||||
KEY_HELP,
|
||||
KEY_VERSION,
|
||||
};
|
||||
|
||||
static const struct fuse_opt fuse_ll_opts[] =
|
||||
{
|
||||
{ "debug", offsetof(struct fuse_ll, debug), 1 },
|
||||
{ "-d", offsetof(struct fuse_ll, debug), 1 },
|
||||
{ "max_readahead=%u", offsetof(struct fuse_ll, conn.max_readahead), 0 },
|
||||
{ "max_background=%u", offsetof(struct fuse_ll, conn.max_background), 0 },
|
||||
{ "congestion_threshold=%u",
|
||||
offsetof(struct fuse_ll, conn.congestion_threshold), 0 },
|
||||
{ "no_remote_lock", offsetof(struct fuse_ll, no_remote_posix_lock), 1},
|
||||
{ "no_remote_lock", offsetof(struct fuse_ll, no_remote_flock), 1},
|
||||
{ "no_remote_flock", offsetof(struct fuse_ll, no_remote_flock), 1},
|
||||
{ "no_remote_posix_lock", offsetof(struct fuse_ll, no_remote_posix_lock), 1},
|
||||
{ "passthrough-max-stack-depth=%u", offsetof(struct fuse_ll, passthrough_max_stack_depth), 0},
|
||||
FUSE_OPT_KEY("max_read=", FUSE_OPT_KEY_DISCARD),
|
||||
FUSE_OPT_KEY("-h", KEY_HELP),
|
||||
FUSE_OPT_KEY("--help", KEY_HELP),
|
||||
FUSE_OPT_KEY("-V", KEY_VERSION),
|
||||
FUSE_OPT_KEY("--version", KEY_VERSION),
|
||||
FUSE_OPT_END
|
||||
};
|
||||
|
||||
static
|
||||
void
|
||||
fuse_ll_version(void)
|
||||
{
|
||||
fprintf(stderr, "using FUSE kernel interface version %i.%i\n",
|
||||
FUSE_KERNEL_VERSION, FUSE_KERNEL_MINOR_VERSION);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
fuse_ll_help(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
" -o max_readahead=N set maximum readahead\n"
|
||||
" -o max_background=N set number of maximum background requests\n"
|
||||
" -o congestion_threshold=N set kernel's congestion threshold\n"
|
||||
" -o no_remote_lock disable remote file locking\n"
|
||||
" -o no_remote_flock disable remote file locking (BSD)\n"
|
||||
" -o no_remote_posix_lock disable remove file locking (POSIX)\n"
|
||||
);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
fuse_ll_opt_proc(void *data,
|
||||
const char *arg,
|
||||
int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
(void) data; (void) outargs;
|
||||
|
||||
switch (key)
|
||||
{
|
||||
case KEY_HELP:
|
||||
fuse_ll_help();
|
||||
break;
|
||||
|
||||
case KEY_VERSION:
|
||||
fuse_ll_version();
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "fuse: unknown option `%s'\n", arg);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int
|
||||
fuse_lowlevel_is_lib_option(const char *opt)
|
||||
{
|
||||
return fuse_opt_match(fuse_ll_opts, opt);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
fuse_ll_destroy(void *data)
|
||||
|
|
@ -2032,6 +1958,23 @@ fuse_ll_buf_process_read_init(struct fuse_session *se_,
|
|||
return;
|
||||
}
|
||||
|
||||
static const struct fuse_opt fuse_ll_opts[] =
|
||||
{
|
||||
FUSE_OPT_END
|
||||
};
|
||||
|
||||
static
|
||||
int
|
||||
fuse_ll_opt_proc(void *data_,
|
||||
const char *arg_,
|
||||
int key_,
|
||||
struct fuse_args *outargs_)
|
||||
{
|
||||
fmt::print(stderr, "* ERROR: unknown option '{}'\n", arg_);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*
|
||||
* always call fuse_lowlevel_new_common() internally, to work around a
|
||||
* misfeature in the FreeBSD runtime linker, which links the old
|
||||
|
|
@ -2060,9 +2003,6 @@ fuse_lowlevel_new_common(struct fuse_args *args,
|
|||
goto out;
|
||||
}
|
||||
|
||||
f->conn.max_write = UINT_MAX;
|
||||
f->conn.max_readahead = UINT_MAX;
|
||||
f->passthrough_max_stack_depth = 2;
|
||||
list_init_nreq(&f->notify_list);
|
||||
f->notify_ctr = 1;
|
||||
mutex_init(&f->lock);
|
||||
|
|
@ -2075,7 +2015,7 @@ fuse_lowlevel_new_common(struct fuse_args *args,
|
|||
goto out_free;
|
||||
}
|
||||
|
||||
if(fuse_opt_parse(args, f, fuse_ll_opts, fuse_ll_opt_proc) == -1)
|
||||
if(fuse_opt_parse(args,NULL,fuse_ll_opts,fuse_ll_opt_proc) == -1)
|
||||
goto out_key_destroy;
|
||||
|
||||
memcpy(&f->op, op, op_size);
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
|
||||
#include "fuse_msgbuf.hpp"
|
||||
|
||||
#include "fuse.h"
|
||||
#include "fuse_kernel.h"
|
||||
|
||||
|
|
@ -42,22 +43,34 @@ msgbuf_get_bufsize()
|
|||
return g_BUFSIZE;
|
||||
}
|
||||
|
||||
u32
|
||||
msgbuf_get_pagesize()
|
||||
{
|
||||
return g_PAGESIZE;
|
||||
}
|
||||
|
||||
// +1 page so that it is used for the "header" of the allocation as
|
||||
// well as to allow for offseting for write requests to be page
|
||||
// aligned. +1 again for fuse header as the max_pages value is for the
|
||||
// body.
|
||||
void
|
||||
msgbuf_set_bufsize(const uint32_t size_in_pages_)
|
||||
{
|
||||
g_BUFSIZE = ((size_in_pages_ + 1) * g_PAGESIZE);
|
||||
g_BUFSIZE = ((size_in_pages_ + 2) * g_PAGESIZE);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
msgbuf_page_align(fuse_msgbuf_t *msgbuf_)
|
||||
_msgbuf_page_align(fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
msgbuf_->mem = (char*)msgbuf_;
|
||||
msgbuf_->mem += g_PAGESIZE;
|
||||
msgbuf_->size = (g_BUFSIZE - g_PAGESIZE);
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
msgbuf_write_align(fuse_msgbuf_t *msgbuf_)
|
||||
_msgbuf_write_align(fuse_msgbuf_t *msgbuf_)
|
||||
{
|
||||
msgbuf_->mem = (char*)msgbuf_;
|
||||
msgbuf_->mem += g_PAGESIZE;
|
||||
|
|
@ -72,8 +85,8 @@ void
|
|||
_msgbuf_constructor()
|
||||
{
|
||||
g_PAGESIZE = sysconf(_SC_PAGESIZE);
|
||||
// FUSE_MAX_MAX_PAGES for payload + 1 for message header
|
||||
msgbuf_set_bufsize(FUSE_DEFAULT_MAX_MAX_PAGES + 1);
|
||||
|
||||
msgbuf_set_bufsize(FUSE_DEFAULT_MAX_MAX_PAGES);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
@ -86,7 +99,7 @@ _msgbuf_destructor()
|
|||
|
||||
static
|
||||
void*
|
||||
page_aligned_malloc(const uint64_t size_)
|
||||
_page_aligned_malloc(const uint64_t size_)
|
||||
{
|
||||
int rv;
|
||||
void *buf = NULL;
|
||||
|
|
@ -111,7 +124,7 @@ _msgbuf_alloc(msgbuf_setup_func_t setup_func_)
|
|||
{
|
||||
g_MUTEX.unlock();
|
||||
|
||||
msgbuf = (fuse_msgbuf_t*)page_aligned_malloc(g_BUFSIZE);
|
||||
msgbuf = (fuse_msgbuf_t*)_page_aligned_malloc(g_BUFSIZE);
|
||||
if(msgbuf == NULL)
|
||||
return NULL;
|
||||
|
||||
|
|
@ -135,13 +148,13 @@ _msgbuf_alloc(msgbuf_setup_func_t setup_func_)
|
|||
fuse_msgbuf_t*
|
||||
msgbuf_alloc()
|
||||
{
|
||||
return _msgbuf_alloc(msgbuf_write_align);
|
||||
return _msgbuf_alloc(_msgbuf_write_align);
|
||||
}
|
||||
|
||||
fuse_msgbuf_t*
|
||||
msgbuf_alloc_page_aligned()
|
||||
{
|
||||
return _msgbuf_alloc(msgbuf_page_align);
|
||||
return _msgbuf_alloc(_msgbuf_page_align);
|
||||
}
|
||||
|
||||
static
|
||||
|
|
|
|||
|
|
@ -41,74 +41,43 @@ struct fuse_opt fuse_helper_opts[] =
|
|||
FUSE_HELPER_OPT("-f", foreground),
|
||||
FUSE_HELPER_OPT("fsname=", nodefault_subtype),
|
||||
FUSE_HELPER_OPT("subtype=", nodefault_subtype),
|
||||
FUSE_OPT_KEY("-h", KEY_HELP),
|
||||
FUSE_OPT_KEY("--help", KEY_HELP),
|
||||
FUSE_OPT_KEY("-ho", KEY_HELP_NOHEADER),
|
||||
FUSE_OPT_KEY("-V", KEY_VERSION),
|
||||
FUSE_OPT_KEY("--version", KEY_VERSION),
|
||||
FUSE_OPT_KEY("-d", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("debug", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("fsname=", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_KEY("subtype=", FUSE_OPT_KEY_KEEP),
|
||||
FUSE_OPT_END
|
||||
};
|
||||
|
||||
static void usage(const char *progname)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"usage: %s mountpoint [options]\n\n", progname);
|
||||
fprintf(stderr,
|
||||
"general options:\n"
|
||||
" -o opt,[opt...] mount options\n"
|
||||
" -h --help print help\n"
|
||||
" -V --version print version\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
static void helper_help(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"FUSE options:\n"
|
||||
" -d -o debug enable debug output (implies -f)\n"
|
||||
" -f foreground operation\n"
|
||||
"\n"
|
||||
);
|
||||
}
|
||||
|
||||
static int fuse_helper_opt_proc(void *data, const char *arg, int key,
|
||||
struct fuse_args *outargs)
|
||||
static
|
||||
int
|
||||
fuse_helper_opt_proc(void *data,
|
||||
const char *arg,
|
||||
int key,
|
||||
struct fuse_args *outargs)
|
||||
{
|
||||
struct helper_opts *hopts = data;
|
||||
|
||||
switch (key) {
|
||||
case KEY_HELP:
|
||||
usage(outargs->argv[0]);
|
||||
/* fall through */
|
||||
switch (key)
|
||||
{
|
||||
case FUSE_OPT_KEY_NONOPT:
|
||||
if(!hopts->mountpoint)
|
||||
{
|
||||
char mountpoint[PATH_MAX];
|
||||
if(realpath(arg, mountpoint) == NULL)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"fuse: bad mount point `%s': %s\n",
|
||||
arg, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return fuse_opt_add_opt(&hopts->mountpoint, mountpoint);
|
||||
}
|
||||
else
|
||||
{
|
||||
fprintf(stderr, "fuse: invalid argument `%s'\n", arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
case KEY_HELP_NOHEADER:
|
||||
helper_help();
|
||||
return fuse_opt_add_arg(outargs, "-h");
|
||||
|
||||
case KEY_VERSION:
|
||||
return 1;
|
||||
|
||||
case FUSE_OPT_KEY_NONOPT:
|
||||
if (!hopts->mountpoint) {
|
||||
char mountpoint[PATH_MAX];
|
||||
if (realpath(arg, mountpoint) == NULL) {
|
||||
fprintf(stderr,
|
||||
"fuse: bad mount point `%s': %s\n",
|
||||
arg, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return fuse_opt_add_opt(&hopts->mountpoint, mountpoint);
|
||||
} else {
|
||||
fprintf(stderr, "fuse: invalid argument `%s'\n", arg);
|
||||
return -1;
|
||||
}
|
||||
|
||||
default:
|
||||
return 1;
|
||||
default:
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -191,36 +191,37 @@ static int fuse_mount_opt_proc(void *data, const char *arg, int key,
|
|||
{
|
||||
struct mount_opts *mo = data;
|
||||
|
||||
switch (key) {
|
||||
case KEY_RO:
|
||||
arg = "ro";
|
||||
/* fall through */
|
||||
case KEY_KERN_FLAG:
|
||||
set_mount_flag(arg, &mo->flags);
|
||||
return 0;
|
||||
switch (key)
|
||||
{
|
||||
case KEY_RO:
|
||||
arg = "ro";
|
||||
/* fall through */
|
||||
case KEY_KERN_FLAG:
|
||||
set_mount_flag(arg, &mo->flags);
|
||||
return 0;
|
||||
|
||||
case KEY_KERN_OPT:
|
||||
return fuse_opt_add_opt(&mo->kernel_opts, arg);
|
||||
case KEY_KERN_OPT:
|
||||
return fuse_opt_add_opt(&mo->kernel_opts, arg);
|
||||
|
||||
case KEY_FUSERMOUNT_OPT:
|
||||
return fuse_opt_add_opt_escaped(&mo->fusermount_opts, arg);
|
||||
case KEY_FUSERMOUNT_OPT:
|
||||
return fuse_opt_add_opt_escaped(&mo->fusermount_opts, arg);
|
||||
|
||||
case KEY_SUBTYPE_OPT:
|
||||
return fuse_opt_add_opt(&mo->subtype_opt, arg);
|
||||
case KEY_SUBTYPE_OPT:
|
||||
return fuse_opt_add_opt(&mo->subtype_opt, arg);
|
||||
|
||||
case KEY_MTAB_OPT:
|
||||
return fuse_opt_add_opt(&mo->mtab_opts, arg);
|
||||
case KEY_MTAB_OPT:
|
||||
return fuse_opt_add_opt(&mo->mtab_opts, arg);
|
||||
|
||||
case KEY_HELP:
|
||||
mount_help();
|
||||
mo->ishelp = 1;
|
||||
break;
|
||||
case KEY_HELP:
|
||||
mount_help();
|
||||
mo->ishelp = 1;
|
||||
break;
|
||||
|
||||
case KEY_VERSION:
|
||||
mount_version();
|
||||
mo->ishelp = 1;
|
||||
break;
|
||||
}
|
||||
case KEY_VERSION:
|
||||
mount_version();
|
||||
mo->ishelp = 1;
|
||||
break;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -542,8 +543,8 @@ int fuse_kern_mount(const char *mountpoint, struct fuse_args *args)
|
|||
memset(&mo, 0, sizeof(mo));
|
||||
mo.flags = MS_NOSUID | MS_NODEV;
|
||||
|
||||
if (args &&
|
||||
fuse_opt_parse(args, &mo, fuse_mount_opts, fuse_mount_opt_proc) == -1)
|
||||
if(args &&
|
||||
fuse_opt_parse(args, &mo, fuse_mount_opts, fuse_mount_opt_proc) == -1)
|
||||
return -1;
|
||||
|
||||
res = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue