Move everything to negative errno return types (#1499)
Some checks failed
CodeQL / Analyze (push) Has been cancelled
mkdocs / deploy (push) Has been cancelled

This commit is contained in:
trapexit 2025-07-25 17:53:48 -05:00 • committed by GitHub
parent 2b500f194a
commit e8cd74cab0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
177 changed files with 5952 additions and 5843 deletions

View file

@ -14,6 +14,8 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "fuse_init.hpp"
#include "config.hpp"
#include "fs_readahead.hpp"
#include "procfs.hpp"
@ -31,213 +33,208 @@
#include <thread>
namespace l
static
void
_want(fuse_conn_info *conn_,
const int flag_)
{
static
void
want(fuse_conn_info *conn_,
const int flag_)
{
conn_->want |= flag_;
}
conn_->want |= flag_;
}
static
bool
capable(fuse_conn_info *conn_,
const int flag_)
{
return !!(conn_->capable & flag_);
}
static
bool
_capable(fuse_conn_info *conn_,
const int flag_)
{
return !!(conn_->capable & flag_);
}
static
void
want_if_capable(fuse_conn_info *conn_,
const int flag_)
{
if(capable(conn_,flag_))
want(conn_,flag_);
}
static
void
_want_if_capable(fuse_conn_info *conn_,
const int flag_)
{
if(::_capable(conn_,flag_))
::_want(conn_,flag_);
}
static
void
want_if_capable(fuse_conn_info *conn_,
const int flag_,
ConfigBOOL *want_)
{
if(*want_ && l::capable(conn_,flag_))
{
l::want(conn_,flag_);
return;
}
*want_ = false;
}
#define MAX_FUSE_MSG_SIZE 65535
static const char MAX_PAGES_LIMIT_FILEPATH[] = "/proc/sys/fs/fuse/max_pages_limit";
static
void
want_if_capable_max_pages(fuse_conn_info *conn_,
Config::Write &cfg_)
{
std::fstream f;
uint64_t max_pages_limit;
if(fs::exists(MAX_PAGES_LIMIT_FILEPATH))
{
if(cfg_->fuse_msg_size > MAX_FUSE_MSG_SIZE)
SysLog::info("fuse_msg_size > {}: setting it to {}",
MAX_FUSE_MSG_SIZE,
MAX_FUSE_MSG_SIZE);
cfg_->fuse_msg_size = std::min((uint64_t)cfg_->fuse_msg_size,
(uint64_t)MAX_FUSE_MSG_SIZE);
f.open(MAX_PAGES_LIMIT_FILEPATH,f.in|f.out);
if(f.is_open())
{
f >> max_pages_limit;
SysLog::info("{} currently set to {}",
MAX_PAGES_LIMIT_FILEPATH,
max_pages_limit);
if(cfg_->fuse_msg_size > max_pages_limit)
{
f.seekp(0);
f << (uint64_t)cfg_->fuse_msg_size;
f.flush();
SysLog::info("{} changed to {}",
MAX_PAGES_LIMIT_FILEPATH,
(uint64_t)cfg_->fuse_msg_size);
}
f.close();
}
else
{
if(cfg_->fuse_msg_size != FUSE_DEFAULT_MAX_MAX_PAGES)
SysLog::info("unable to open {}",MAX_PAGES_LIMIT_FILEPATH);
}
}
else
{
if(cfg_->fuse_msg_size > FUSE_DEFAULT_MAX_MAX_PAGES)
SysLog::info("fuse_msg_size request {} > {}: setting it to {}",
(uint64_t)cfg_->fuse_msg_size,
FUSE_DEFAULT_MAX_MAX_PAGES,
FUSE_DEFAULT_MAX_MAX_PAGES);
cfg_->fuse_msg_size = std::min((uint64_t)cfg_->fuse_msg_size,
(uint64_t)FUSE_DEFAULT_MAX_MAX_PAGES);
}
if(l::capable(conn_,FUSE_CAP_MAX_PAGES))
{
l::want(conn_,FUSE_CAP_MAX_PAGES);
conn_->max_pages = cfg_->fuse_msg_size;
SysLog::info("requesting max pages size of {}",
(uint64_t)cfg_->fuse_msg_size);
}
else
{
cfg_->fuse_msg_size = FUSE_DEFAULT_MAX_PAGES_PER_REQ;
}
}
static
void
readahead(const fs::Path path_,
const int readahead_)
{
int rv;
rv = fs::readahead(path_,readahead_);
if(rv == 0)
SysLog::info("{} - readahead set to {}",path_.string(),readahead_);
else
SysLog::error("{} - unable to set readahead",path_.string());
}
static
void
set_readahead_on_mount_and_branches()
{
Config::Read cfg;
Branches::Ptr branches;
if((uint64_t)cfg->readahead == 0)
static
void
_want_if_capable(fuse_conn_info *conn_,
const int flag_,
ConfigBOOL *want_)
{
if(*want_ && ::_capable(conn_,flag_))
{
::_want(conn_,flag_);
return;
}
l::readahead(cfg->mountpoint,cfg->readahead);
branches = cfg->branches;
for(auto const &branch : *branches)
l::readahead(branch.path,cfg->readahead);
}
// Spawn a thread to do this because before init returns calls to
// set the value will block leading to a deadlock. This is just
// easier.
static
void
spawn_thread_to_set_readahead()
{
std::thread readahead_thread(l::set_readahead_on_mount_and_branches);
readahead_thread.detach();
}
*want_ = false;
}
namespace FUSE
#define MAX_FUSE_MSG_SIZE 65535
static const char MAX_PAGES_LIMIT_FILEPATH[] = "/proc/sys/fs/fuse/max_pages_limit";
static
void
_want_if_capable_max_pages(fuse_conn_info *conn_,
Config::Write &cfg_)
{
void *
init(fuse_conn_info *conn_)
{
Config::Write cfg;
std::fstream f;
uint64_t max_pages_limit;
procfs::init();
ugid::init();
if(fs::exists(MAX_PAGES_LIMIT_FILEPATH))
{
if(cfg_->fuse_msg_size > MAX_FUSE_MSG_SIZE)
SysLog::info("fuse_msg_size > {}: setting it to {}",
MAX_FUSE_MSG_SIZE,
MAX_FUSE_MSG_SIZE);
cfg_->fuse_msg_size = std::min((uint64_t)cfg_->fuse_msg_size,
(uint64_t)MAX_FUSE_MSG_SIZE);
cfg->readdir.initialize();
f.open(MAX_PAGES_LIMIT_FILEPATH,f.in|f.out);
if(f.is_open())
{
f >> max_pages_limit;
SysLog::info("{} currently set to {}",
MAX_PAGES_LIMIT_FILEPATH,
max_pages_limit);
if(cfg_->fuse_msg_size > max_pages_limit)
{
f.seekp(0);
f << (uint64_t)cfg_->fuse_msg_size;
f.flush();
SysLog::info("{} changed to {}",
MAX_PAGES_LIMIT_FILEPATH,
(uint64_t)cfg_->fuse_msg_size);
}
f.close();
}
else
{
if(cfg_->fuse_msg_size != FUSE_DEFAULT_MAX_MAX_PAGES)
SysLog::info("unable to open {}",MAX_PAGES_LIMIT_FILEPATH);
}
}
else
{
if(cfg_->fuse_msg_size > FUSE_DEFAULT_MAX_MAX_PAGES)
SysLog::info("fuse_msg_size request {} > {}: setting it to {}",
(uint64_t)cfg_->fuse_msg_size,
FUSE_DEFAULT_MAX_MAX_PAGES,
FUSE_DEFAULT_MAX_MAX_PAGES);
cfg_->fuse_msg_size = std::min((uint64_t)cfg_->fuse_msg_size,
(uint64_t)FUSE_DEFAULT_MAX_MAX_PAGES);
}
l::want_if_capable(conn_,FUSE_CAP_ASYNC_DIO);
l::want_if_capable(conn_,FUSE_CAP_ASYNC_READ,&cfg->async_read);
l::want_if_capable(conn_,FUSE_CAP_ATOMIC_O_TRUNC);
l::want_if_capable(conn_,FUSE_CAP_BIG_WRITES);
l::want_if_capable(conn_,FUSE_CAP_CACHE_SYMLINKS,&cfg->cache_symlinks);
l::want_if_capable(conn_,FUSE_CAP_DIRECT_IO_ALLOW_MMAP,&cfg->direct_io_allow_mmap);
l::want_if_capable(conn_,FUSE_CAP_DONT_MASK);
l::want_if_capable(conn_,FUSE_CAP_EXPORT_SUPPORT,&cfg->export_support);
l::want_if_capable(conn_,FUSE_CAP_HANDLE_KILLPRIV,&cfg->handle_killpriv);
l::want_if_capable(conn_,FUSE_CAP_HANDLE_KILLPRIV_V2,&cfg->handle_killpriv_v2);
l::want_if_capable(conn_,FUSE_CAP_IOCTL_DIR);
l::want_if_capable(conn_,FUSE_CAP_PARALLEL_DIROPS);
l::want_if_capable(conn_,FUSE_CAP_PASSTHROUGH);
l::want_if_capable(conn_,FUSE_CAP_POSIX_ACL,&cfg->posix_acl);
l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS,&cfg->readdirplus);
l::want_if_capable(conn_,FUSE_CAP_WRITEBACK_CACHE,&cfg->writeback_cache);
// l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS_AUTO);
l::want_if_capable_max_pages(conn_,cfg);
conn_->want &= ~FUSE_CAP_POSIX_LOCKS;
conn_->want &= ~FUSE_CAP_FLOCK_LOCKS;
l::spawn_thread_to_set_readahead();
if(!(conn_->capable & FUSE_CAP_PASSTHROUGH) && (cfg->passthrough != Passthrough::ENUM::OFF))
{
SysLog::warning("passthrough enabled but not supported by kernel. disabling.");
cfg->passthrough = Passthrough::ENUM::OFF;
}
if((cfg->passthrough != Passthrough::ENUM::OFF) &&
(cfg->cache_files == CacheFiles::ENUM::OFF))
{
SysLog::warning("passthrough enabled and cache.files disabled: passthrough will not function");
}
if((cfg->passthrough != Passthrough::ENUM::OFF) &&
(cfg->writeback_cache == true))
{
SysLog::warning("passthrough and cache.writeback are incompatible. ");
}
return NULL;
}
if(::_capable(conn_,FUSE_CAP_MAX_PAGES))
{
::_want(conn_,FUSE_CAP_MAX_PAGES);
conn_->max_pages = cfg_->fuse_msg_size;
SysLog::info("requesting max pages size of {}",
(uint64_t)cfg_->fuse_msg_size);
}
else
{
cfg_->fuse_msg_size = FUSE_DEFAULT_MAX_PAGES_PER_REQ;
}
}
static
void
_readahead(const fs::Path path_,
const int readahead_)
{
int rv;
rv = fs::readahead(path_,readahead_);
if(rv == 0)
SysLog::info("{} - readahead set to {}",path_.string(),readahead_);
else
SysLog::error("{} - unable to set readahead",path_.string());
}
static
void
_set_readahead_on_mount_and_branches()
{
Config::Read cfg;
Branches::Ptr branches;
if((uint64_t)cfg->readahead == 0)
return;
::_readahead(cfg->mountpoint,cfg->readahead);
branches = cfg->branches;
for(auto const &branch : *branches)
::_readahead(branch.path,cfg->readahead);
}
// Spawn a thread to do this because before init returns calls to
// set the value will block leading to a deadlock. This is just
// easier.
static
void
_spawn_thread_to_set_readahead()
{
std::thread readahead_thread(::_set_readahead_on_mount_and_branches);
readahead_thread.detach();
}
void *
FUSE::init(fuse_conn_info *conn_)
{
Config::Write cfg;
procfs::init();
ugid::init();
cfg->readdir.initialize();
::_want_if_capable(conn_,FUSE_CAP_ASYNC_DIO);
::_want_if_capable(conn_,FUSE_CAP_ASYNC_READ,&cfg->async_read);
::_want_if_capable(conn_,FUSE_CAP_ATOMIC_O_TRUNC);
::_want_if_capable(conn_,FUSE_CAP_BIG_WRITES);
::_want_if_capable(conn_,FUSE_CAP_CACHE_SYMLINKS,&cfg->cache_symlinks);
::_want_if_capable(conn_,FUSE_CAP_DIRECT_IO_ALLOW_MMAP,&cfg->direct_io_allow_mmap);
::_want_if_capable(conn_,FUSE_CAP_DONT_MASK);
::_want_if_capable(conn_,FUSE_CAP_EXPORT_SUPPORT,&cfg->export_support);
::_want_if_capable(conn_,FUSE_CAP_HANDLE_KILLPRIV,&cfg->handle_killpriv);
::_want_if_capable(conn_,FUSE_CAP_HANDLE_KILLPRIV_V2,&cfg->handle_killpriv_v2);
::_want_if_capable(conn_,FUSE_CAP_IOCTL_DIR);
::_want_if_capable(conn_,FUSE_CAP_PARALLEL_DIROPS);
::_want_if_capable(conn_,FUSE_CAP_PASSTHROUGH);
::_want_if_capable(conn_,FUSE_CAP_POSIX_ACL,&cfg->posix_acl);
::_want_if_capable(conn_,FUSE_CAP_READDIR_PLUS,&cfg->readdirplus);
::_want_if_capable(conn_,FUSE_CAP_WRITEBACK_CACHE,&cfg->writeback_cache);
// ::_want_if_capable(conn_,FUSE_CAP_READDIR_PLUS_AUTO);
::_want_if_capable_max_pages(conn_,cfg);
conn_->want &= ~FUSE_CAP_POSIX_LOCKS;
conn_->want &= ~FUSE_CAP_FLOCK_LOCKS;
::_spawn_thread_to_set_readahead();
if(!(conn_->capable & FUSE_CAP_PASSTHROUGH) && (cfg->passthrough != Passthrough::ENUM::OFF))
{
SysLog::warning("passthrough enabled but not supported by kernel. disabling.");
cfg->passthrough = Passthrough::ENUM::OFF;
}
if((cfg->passthrough != Passthrough::ENUM::OFF) &&
(cfg->cache_files == CacheFiles::ENUM::OFF))
{
SysLog::warning("passthrough enabled and cache.files disabled:"
" passthrough will not function");
}
if((cfg->passthrough != Passthrough::ENUM::OFF) &&
(cfg->writeback_cache == true))
{
SysLog::warning("passthrough and cache.writeback are incompatible.");
}
return NULL;
}