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

@ -14,38 +14,87 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "state.hpp"
#include "config.hpp"
#include "errno.hpp"
#include "fileinfo.hpp"
#include "fs_close.hpp"
#include "fs_fadvise.hpp"
#include "fuse_passthrough.hpp"
#include "fuse.h"
#include <string>
namespace l
static
constexpr
auto
_erase_if_lambda(const fuse_context *fc_,
FileInfo *fi_,
bool *existed_in_map_)
{
static
int
release(FileInfo *fi_,
const bool dropcacheonclose_)
{
// according to Feh of nocache calling it once doesn't always work
// https://github.com/Feh/nocache
if(dropcacheonclose_)
{
fs::fadvise_dontneed(fi_->fd);
fs::fadvise_dontneed(fi_->fd);
}
return
[=](auto &val_)
{
*existed_in_map_ = true;
fs::close(fi_->fd);
if(fi_ != val_.second.fi)
{
fs::close(fi_->fd);
delete fi_;
}
delete fi_;
val_.second.ref_count--;
if(val_.second.ref_count > 0)
return false;
if(val_.second.backing_id > 0)
FUSE::passthrough_close(fc_,val_.second.backing_id);
fs::close(val_.second.fi->fd);
delete val_.second.fi;
return true;
};
}
static
int
_release(const fuse_context *fc_,
FileInfo *fi_,
const bool dropcacheonclose_)
{
bool existed_in_map;
// according to Feh of nocache calling it once doesn't always work
// https://github.com/Feh/nocache
if(dropcacheonclose_)
{
fs::fadvise_dontneed(fi_->fd);
fs::fadvise_dontneed(fi_->fd);
}
// Because of course the API doesn't tell you if the key
// existed. Just how many it erased and in this case I only want to
// erase if there are no more open files.
existed_in_map = false;
state.open_files.erase_if(fc_->nodeid,
::_erase_if_lambda(fc_,fi_,&existed_in_map));
if(existed_in_map)
return 0;
}
fs::close(fi_->fd);
delete fi_;
return 0;
}
static
int
_release(const fuse_context *fc_,
const fuse_file_info_t *ffi_)
{
Config::Read cfg;
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi_->fh);
return ::_release(fc_,fi,cfg->dropcacheonclose);
}
namespace FUSE
@ -53,9 +102,8 @@ namespace FUSE
int
release(const fuse_file_info_t *ffi_)
{
Config::Read cfg;
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi_->fh);
const fuse_context *fc = fuse_get_context();
return l::release(fi,cfg->dropcacheonclose);
return ::_release(fc,ffi_);
}
}