mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-04 22:00:15 -05:00
Add support for file io passthrough
If using Linux 6.9 or above and enabled (passthrough=true) files opened or created will use the FUSE passthrough feature. If direct-io=true / cache.files=off it will override passthrough. If direct-io-allow-mmap is enabled only mmap will passthrough. HANDLE_KILLPRIV and V2 are enabled now by default to remove the kernel's need to issue getattr and getxattr requests. moveonenospc will not work when leveraging passthrough.
This commit is contained in:
parent
b21172c609
commit
07e7d76b7c
18 changed files with 1673 additions and 20 deletions
1328
src/better_enum.hpp
Normal file
1328
src/better_enum.hpp
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -62,6 +62,8 @@ namespace l
|
|||
IFERT("export-support");
|
||||
IFERT("fsname");
|
||||
IFERT("fuse_msg_size");
|
||||
IFERT("handle-killpriv");
|
||||
IFERT("handle-killpriv-v2");
|
||||
IFERT("mount");
|
||||
IFERT("nullrw");
|
||||
IFERT("pid");
|
||||
|
|
@ -103,6 +105,8 @@ Config::Config()
|
|||
fsname(),
|
||||
func(),
|
||||
fuse_msg_size(FUSE_MAX_MAX_PAGES),
|
||||
handle_killpriv(true),
|
||||
handle_killpriv_v2(true),
|
||||
ignorepponrename(false),
|
||||
inodecalc("hybrid-hash"),
|
||||
lazy_umount_mountpoint(false),
|
||||
|
|
@ -114,6 +118,7 @@ Config::Config()
|
|||
nfsopenhack(NFSOpenHack::ENUM::OFF),
|
||||
nullrw(false),
|
||||
parallel_direct_writes(false),
|
||||
passthrough(PassthroughEnum::off),
|
||||
posix_acl(false),
|
||||
readahead(0),
|
||||
readdir("seq"),
|
||||
|
|
@ -180,6 +185,8 @@ Config::Config()
|
|||
_map["func.unlink"] = &func.unlink;
|
||||
_map["func.utimens"] = &func.utimens;
|
||||
_map["fuse_msg_size"] = &fuse_msg_size;
|
||||
_map["handle-killpriv"] = &handle_killpriv;
|
||||
_map["handle-killpriv-v2"] = &handle_killpriv_v2;
|
||||
_map["ignorepponrename"] = &ignorepponrename;
|
||||
_map["inodecalc"] = &inodecalc;
|
||||
_map["kernel_cache"] = &kernel_cache;
|
||||
|
|
@ -194,6 +201,7 @@ Config::Config()
|
|||
_map["nullrw"] = &nullrw;
|
||||
_map["pid"] = &pid;
|
||||
_map["parallel-direct-writes"] = ¶llel_direct_writes;
|
||||
_map["passthrough"] = &passthrough;
|
||||
_map["pin-threads"] = &fuse_pin_threads;
|
||||
_map["posix_acl"] = &posix_acl;
|
||||
_map["readahead"] = &readahead;
|
||||
|
|
|
|||
|
|
@ -21,12 +21,13 @@
|
|||
#include "config_cachefiles.hpp"
|
||||
#include "config_flushonclose.hpp"
|
||||
#include "config_follow_symlinks.hpp"
|
||||
#include "config_pid.hpp"
|
||||
#include "config_inodecalc.hpp"
|
||||
#include "config_link_exdev.hpp"
|
||||
#include "config_log_metrics.hpp"
|
||||
#include "config_moveonenospc.hpp"
|
||||
#include "config_nfsopenhack.hpp"
|
||||
#include "config_passthrough.hpp"
|
||||
#include "config_pid.hpp"
|
||||
#include "config_rename_exdev.hpp"
|
||||
#include "config_set.hpp"
|
||||
#include "config_statfs.hpp"
|
||||
|
|
@ -125,6 +126,8 @@ public:
|
|||
ConfigSTR fsname;
|
||||
Funcs func;
|
||||
ConfigUINT64 fuse_msg_size;
|
||||
ConfigBOOL handle_killpriv;
|
||||
ConfigBOOL handle_killpriv_v2;
|
||||
ConfigBOOL ignorepponrename;
|
||||
InodeCalc inodecalc;
|
||||
ConfigBOOL kernel_cache;
|
||||
|
|
@ -137,6 +140,7 @@ public:
|
|||
NFSOpenHack nfsopenhack;
|
||||
ConfigBOOL nullrw;
|
||||
ConfigBOOL parallel_direct_writes;
|
||||
Passthrough passthrough;
|
||||
ConfigGetPid pid;
|
||||
ConfigBOOL posix_acl;
|
||||
ConfigUINT64 readahead;
|
||||
|
|
|
|||
43
src/config_passthrough.cpp
Normal file
43
src/config_passthrough.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2024, 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 "config_passthrough.hpp"
|
||||
#include "ef.hpp"
|
||||
#include "errno.hpp"
|
||||
|
||||
template<>
|
||||
std::string
|
||||
Passthrough::to_string() const
|
||||
{
|
||||
return _data._to_string();
|
||||
}
|
||||
|
||||
template<>
|
||||
int
|
||||
Passthrough::from_string(const std::string &s_)
|
||||
{
|
||||
better_enums::optional<PassthroughEnum> e;
|
||||
|
||||
e = PassthroughEnum::_from_string_nothrow(s_.c_str());
|
||||
if(!e)
|
||||
return -EINVAL;
|
||||
|
||||
_data = *e;
|
||||
|
||||
return 0;
|
||||
}
|
||||
28
src/config_passthrough.hpp
Normal file
28
src/config_passthrough.hpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2024, 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 "better_enum.hpp"
|
||||
|
||||
#include "enum.hpp"
|
||||
|
||||
|
||||
BETTER_ENUM(PassthroughEnum, uint8_t, off, r, w, ro, wo, rw);
|
||||
|
||||
typedef Enum<PassthroughEnum> Passthrough;
|
||||
|
|
@ -60,6 +60,12 @@ public:
|
|||
return _data;
|
||||
}
|
||||
|
||||
ENUM
|
||||
operator+() const
|
||||
{
|
||||
return _data;
|
||||
}
|
||||
|
||||
public:
|
||||
bool operator==(const ENUM data_) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -31,12 +31,14 @@ public:
|
|||
bool const direct_io_)
|
||||
: FH(fusepath_),
|
||||
fd(fd_),
|
||||
backing_id(0),
|
||||
direct_io(direct_io_)
|
||||
{
|
||||
}
|
||||
|
||||
public:
|
||||
int fd;
|
||||
int backing_id;
|
||||
uint32_t direct_io:1;
|
||||
std::mutex mutex;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -170,6 +170,29 @@ namespace l
|
|||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
passthrough(const fuse_context *fc_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
int backing_id;
|
||||
FileInfo *fi;
|
||||
const ugid::SetRootGuard ugid;
|
||||
|
||||
fi = reinterpret_cast<FileInfo*>(ffi_->fh);
|
||||
|
||||
backing_id = fuse_passthrough_open(fc_,fi->fd);
|
||||
if(backing_id <= 0)
|
||||
return 0;
|
||||
|
||||
ffi_->passthrough = true;
|
||||
ffi_->keep_cache = false;
|
||||
fi->backing_id = backing_id;
|
||||
ffi_->backing_id = backing_id;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
create(const Policy::Search &searchFunc_,
|
||||
|
|
@ -208,6 +231,15 @@ namespace l
|
|||
}
|
||||
}
|
||||
|
||||
constexpr
|
||||
const
|
||||
uint64_t
|
||||
_(const PassthroughEnum e_,
|
||||
const uint64_t m_)
|
||||
{
|
||||
return ((((uint64_t)e_) << 32) | (m_ & O_ACCMODE));
|
||||
}
|
||||
|
||||
namespace FUSE
|
||||
{
|
||||
int
|
||||
|
|
@ -247,6 +279,23 @@ namespace FUSE
|
|||
fc->umask);
|
||||
}
|
||||
|
||||
if(rv != 0)
|
||||
return rv;
|
||||
|
||||
switch(_(cfg->passthrough,ffi_->flags))
|
||||
{
|
||||
case _(PassthroughEnum::r, O_RDONLY):
|
||||
case _(PassthroughEnum::r, O_RDWR):
|
||||
case _(PassthroughEnum::w, O_WRONLY):
|
||||
case _(PassthroughEnum::w, O_RDWR):
|
||||
case _(PassthroughEnum::ro,O_RDONLY):
|
||||
case _(PassthroughEnum::wo,O_WRONLY):
|
||||
case _(PassthroughEnum::rw,O_RDONLY):
|
||||
case _(PassthroughEnum::rw,O_WRONLY):
|
||||
case _(PassthroughEnum::rw,O_RDWR):
|
||||
return l::passthrough(fc,ffi_);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,8 +147,11 @@ namespace FUSE
|
|||
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);
|
||||
|
|
|
|||
|
|
@ -218,6 +218,29 @@ namespace l
|
|||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
passthrough(const fuse_context *fc_,
|
||||
fuse_file_info_t *ffi_)
|
||||
{
|
||||
int backing_id;
|
||||
FileInfo *fi;
|
||||
const ugid::SetRootGuard ugid;
|
||||
|
||||
fi = reinterpret_cast<FileInfo*>(ffi_->fh);
|
||||
|
||||
backing_id = fuse_passthrough_open(fc_,fi->fd);
|
||||
if(backing_id <= 0)
|
||||
return 0;
|
||||
|
||||
ffi_->passthrough = true;
|
||||
ffi_->keep_cache = true;
|
||||
fi->backing_id = backing_id;
|
||||
ffi_->backing_id = backing_id;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
open(const Policy::Search &searchFunc_,
|
||||
|
|
@ -238,6 +261,15 @@ namespace l
|
|||
}
|
||||
}
|
||||
|
||||
constexpr
|
||||
const
|
||||
uint64_t
|
||||
_(const PassthroughEnum e_,
|
||||
const uint64_t m_)
|
||||
{
|
||||
return ((((uint64_t)e_) << 32) | (m_ & O_ACCMODE));
|
||||
}
|
||||
|
||||
namespace FUSE
|
||||
{
|
||||
int
|
||||
|
|
@ -264,6 +296,23 @@ namespace FUSE
|
|||
cfg->link_cow,
|
||||
cfg->nfsopenhack);
|
||||
|
||||
if(rv != 0)
|
||||
return rv;
|
||||
|
||||
switch(_(cfg->passthrough,ffi_->flags))
|
||||
{
|
||||
case _(PassthroughEnum::r, O_RDONLY):
|
||||
case _(PassthroughEnum::r, O_RDWR):
|
||||
case _(PassthroughEnum::w, O_WRONLY):
|
||||
case _(PassthroughEnum::w, O_RDWR):
|
||||
case _(PassthroughEnum::ro,O_RDONLY):
|
||||
case _(PassthroughEnum::wo,O_WRONLY):
|
||||
case _(PassthroughEnum::rw,O_RDONLY):
|
||||
case _(PassthroughEnum::rw,O_WRONLY):
|
||||
case _(PassthroughEnum::rw,O_RDWR):
|
||||
return l::passthrough(fc,ffi_);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "fileinfo.hpp"
|
||||
#include "fs_close.hpp"
|
||||
#include "fs_fadvise.hpp"
|
||||
#include "ugid.hpp"
|
||||
|
||||
#include "fuse.h"
|
||||
|
||||
|
|
@ -40,6 +41,16 @@ namespace l
|
|||
fs::fadvise_dontneed(fi_->fd);
|
||||
}
|
||||
|
||||
if(fi_->backing_id)
|
||||
{
|
||||
const fuse_context *fc;
|
||||
const ugid::SetRootGuard ugid;
|
||||
|
||||
fc = fuse_get_context();
|
||||
|
||||
fuse_passthrough_close(fc,fi_->backing_id);
|
||||
}
|
||||
|
||||
fs::close(fi_->fd);
|
||||
|
||||
delete fi_;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue