2014-09-27 06:31:22 +08:00
|
|
|
/*
|
2016-01-15 05:50:22 +08:00
|
|
|
Copyright (c) 2016, 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.
|
2014-09-27 06:31:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.hpp"
|
2015-09-09 03:56:02 +08:00
|
|
|
#include "ugid.hpp"
|
2023-03-01 12:10:36 +08:00
|
|
|
#include "fs_readahead.hpp"
|
|
|
|
#include "syslog.hpp"
|
|
|
|
|
|
|
|
#include "fmt/core.h"
|
2014-09-27 06:31:22 +08:00
|
|
|
|
2020-12-20 04:06:08 +08:00
|
|
|
#include "fuse.h"
|
|
|
|
|
2023-03-01 12:10:36 +08:00
|
|
|
#include <thread>
|
|
|
|
|
2019-01-25 20:03:46 +08:00
|
|
|
|
2019-05-20 03:18:36 +08:00
|
|
|
namespace l
|
|
|
|
{
|
2019-05-22 11:23:26 +08:00
|
|
|
static
|
|
|
|
void
|
|
|
|
want(fuse_conn_info *conn_,
|
|
|
|
const int flag_)
|
|
|
|
{
|
|
|
|
conn_->want |= flag_;
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
bool
|
|
|
|
capable(fuse_conn_info *conn_,
|
|
|
|
const int flag_)
|
|
|
|
{
|
2019-05-29 03:15:18 +08:00
|
|
|
return !!(conn_->capable & flag_);
|
2019-05-22 11:23:26 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static
|
2019-05-20 03:18:36 +08:00
|
|
|
void
|
|
|
|
want_if_capable(fuse_conn_info *conn_,
|
|
|
|
const int flag_)
|
|
|
|
{
|
2019-05-22 11:23:26 +08:00
|
|
|
if(capable(conn_,flag_))
|
|
|
|
want(conn_,flag_);
|
2019-05-20 03:18:36 +08:00
|
|
|
}
|
2019-05-29 03:15:18 +08:00
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
want_if_capable(fuse_conn_info *conn_,
|
|
|
|
const int flag_,
|
2019-09-24 22:27:46 +08:00
|
|
|
ConfigBOOL *want_)
|
2019-05-29 03:15:18 +08:00
|
|
|
{
|
|
|
|
if(*want_ && l::capable(conn_,flag_))
|
|
|
|
{
|
|
|
|
l::want(conn_,flag_);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
*want_ = false;
|
|
|
|
}
|
2019-05-31 06:59:18 +08:00
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
want_if_capable_max_pages(fuse_conn_info *conn_,
|
2020-12-20 04:06:08 +08:00
|
|
|
Config::Write &cfg_)
|
2019-05-31 06:59:18 +08:00
|
|
|
{
|
|
|
|
if(l::capable(conn_,FUSE_CAP_MAX_PAGES))
|
|
|
|
{
|
|
|
|
l::want(conn_,FUSE_CAP_MAX_PAGES);
|
2020-12-20 04:06:08 +08:00
|
|
|
conn_->max_pages = cfg_->fuse_msg_size;
|
2019-05-31 06:59:18 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-12-20 04:06:08 +08:00
|
|
|
cfg_->fuse_msg_size = FUSE_DEFAULT_MAX_PAGES_PER_REQ;
|
2019-05-31 06:59:18 +08:00
|
|
|
}
|
|
|
|
}
|
2023-03-01 12:10:36 +08:00
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
readahead(const std::string path_,
|
|
|
|
const int readahead_)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
|
|
|
|
rv = fs::readahead(path_,readahead_);
|
|
|
|
if(rv == 0)
|
|
|
|
syslog_info("%s - readahead set to %d",path_.c_str(),readahead_);
|
|
|
|
else
|
|
|
|
syslog_error("%s - unable to set readahead",path_.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
void
|
|
|
|
set_readahead_on_mount_and_branches()
|
|
|
|
{
|
|
|
|
Config::Read cfg;
|
|
|
|
Branches::CPtr branches;
|
|
|
|
|
|
|
|
if((uint64_t)cfg->readahead == 0)
|
|
|
|
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();
|
|
|
|
}
|
2019-05-20 03:18:36 +08:00
|
|
|
}
|
|
|
|
|
2019-01-25 20:03:46 +08:00
|
|
|
namespace FUSE
|
2014-09-27 06:31:22 +08:00
|
|
|
{
|
2019-01-25 20:03:46 +08:00
|
|
|
void *
|
|
|
|
init(fuse_conn_info *conn_)
|
2014-09-27 06:31:22 +08:00
|
|
|
{
|
2020-12-20 04:06:08 +08:00
|
|
|
Config::Write cfg;
|
2019-05-22 11:23:26 +08:00
|
|
|
|
2019-01-25 20:03:46 +08:00
|
|
|
ugid::init();
|
2015-09-09 03:56:02 +08:00
|
|
|
|
2023-08-28 13:24:25 +08:00
|
|
|
cfg->readdir.initialize();
|
|
|
|
|
2019-05-29 03:15:18 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_ASYNC_DIO);
|
2020-12-20 04:06:08 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_ASYNC_READ,&cfg->async_read);
|
2019-05-20 03:18:36 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_ATOMIC_O_TRUNC);
|
|
|
|
l::want_if_capable(conn_,FUSE_CAP_BIG_WRITES);
|
2020-12-20 04:06:08 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_CACHE_SYMLINKS,&cfg->cache_symlinks);
|
2019-05-20 03:18:36 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_DONT_MASK);
|
|
|
|
l::want_if_capable(conn_,FUSE_CAP_IOCTL_DIR);
|
2019-05-20 12:36:42 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_PARALLEL_DIROPS);
|
2020-12-20 04:06:08 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS,&cfg->readdirplus);
|
2019-06-14 20:59:04 +08:00
|
|
|
//l::want_if_capable(conn_,FUSE_CAP_READDIR_PLUS_AUTO);
|
2020-12-20 04:06:08 +08:00
|
|
|
l::want_if_capable(conn_,FUSE_CAP_POSIX_ACL,&cfg->posix_acl);
|
|
|
|
l::want_if_capable(conn_,FUSE_CAP_WRITEBACK_CACHE,&cfg->writeback_cache);
|
|
|
|
l::want_if_capable_max_pages(conn_,cfg);
|
2021-11-27 13:01:12 +08:00
|
|
|
conn_->want &= ~FUSE_CAP_POSIX_LOCKS;
|
|
|
|
conn_->want &= ~FUSE_CAP_FLOCK_LOCKS;
|
2019-05-22 11:23:26 +08:00
|
|
|
|
2023-03-01 12:10:36 +08:00
|
|
|
l::spawn_thread_to_set_readahead();
|
|
|
|
|
2020-12-20 04:06:08 +08:00
|
|
|
return NULL;
|
2014-09-27 06:31:22 +08:00
|
|
|
}
|
|
|
|
}
|