mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-22 16:06:27 -05:00
Add flushonclose feature
This commit is contained in:
parent
7d6c8e9333
commit
6aa6452d3e
11 changed files with 196 additions and 3 deletions
|
|
@ -94,8 +94,9 @@ Config::Config()
|
|||
category(func),
|
||||
direct_io(false),
|
||||
dropcacheonclose(false),
|
||||
fsname(),
|
||||
flushonclose(FlushOnClose::ENUM::ALWAYS),
|
||||
follow_symlinks(FollowSymlinks::ENUM::NEVER),
|
||||
fsname(),
|
||||
func(),
|
||||
fuse_msg_size(FUSE_MAX_MAX_PAGES),
|
||||
ignorepponrename(false),
|
||||
|
|
@ -149,6 +150,7 @@ Config::Config()
|
|||
_map["category.search"] = &category.search;
|
||||
_map["direct_io"] = &direct_io;
|
||||
_map["dropcacheonclose"] = &dropcacheonclose;
|
||||
_map["flush-on-close"] = &flushonclose;
|
||||
_map["follow-symlinks"] = &follow_symlinks;
|
||||
_map["fsname"] = &fsname;
|
||||
_map["func.access"] = &func.access;
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
#include "branches.hpp"
|
||||
#include "category.hpp"
|
||||
#include "config_cachefiles.hpp"
|
||||
#include "config_flushonclose.hpp"
|
||||
#include "config_follow_symlinks.hpp"
|
||||
#include "config_inodecalc.hpp"
|
||||
#include "config_link_exdev.hpp"
|
||||
|
|
@ -116,8 +117,9 @@ public:
|
|||
Categories category;
|
||||
ConfigBOOL direct_io;
|
||||
ConfigBOOL dropcacheonclose;
|
||||
ConfigSTR fsname;
|
||||
FlushOnClose flushonclose;
|
||||
FollowSymlinks follow_symlinks;
|
||||
ConfigSTR fsname;
|
||||
Funcs func;
|
||||
ConfigUINT64 fuse_msg_size;
|
||||
ConfigBOOL ignorepponrename;
|
||||
|
|
|
|||
54
src/config_flushonclose.cpp
Normal file
54
src/config_flushonclose.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
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 "config_flushonclose.hpp"
|
||||
#include "ef.hpp"
|
||||
#include "errno.hpp"
|
||||
|
||||
template<>
|
||||
std::string
|
||||
FlushOnClose::to_string() const
|
||||
{
|
||||
switch(_data)
|
||||
{
|
||||
case FlushOnClose::ENUM::NEVER:
|
||||
return "never";
|
||||
case FlushOnClose::ENUM::OPENED_FOR_WRITE:
|
||||
return "opened-for-write";
|
||||
case FlushOnClose::ENUM::ALWAYS:
|
||||
return "always";
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
template<>
|
||||
int
|
||||
FlushOnClose::from_string(const std::string &s_)
|
||||
{
|
||||
if(s_ == "never")
|
||||
_data = FlushOnClose::ENUM::NEVER;
|
||||
ef(s_ == "opened-for-write")
|
||||
_data = FlushOnClose::ENUM::OPENED_FOR_WRITE;
|
||||
ef(s_ == "always")
|
||||
_data = FlushOnClose::ENUM::ALWAYS;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
31
src/config_flushonclose.hpp
Normal file
31
src/config_flushonclose.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
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 "enum.hpp"
|
||||
|
||||
|
||||
enum class FlushOnCloseEnum
|
||||
{
|
||||
NEVER,
|
||||
OPENED_FOR_WRITE,
|
||||
ALWAYS
|
||||
};
|
||||
|
||||
typedef Enum<FlushOnCloseEnum> FlushOnClose;
|
||||
|
|
@ -51,6 +51,31 @@ namespace l
|
|||
*flags_ &= ~O_APPEND;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
rdonly(const int flags_)
|
||||
{
|
||||
return ((flags_ & O_ACCMODE) == O_RDONLY);
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
calculate_flush(FlushOnClose const flushonclose_,
|
||||
int const flags_)
|
||||
{
|
||||
switch(flushonclose_)
|
||||
{
|
||||
case FlushOnCloseEnum::NEVER:
|
||||
return false;
|
||||
case FlushOnCloseEnum::OPENED_FOR_WRITE:
|
||||
return !l::rdonly(flags_);
|
||||
case FlushOnCloseEnum::ALWAYS:
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
config_to_ffi_flags(Config::Read &cfg_,
|
||||
|
|
@ -200,6 +225,9 @@ namespace FUSE
|
|||
if(cfg->writeback_cache)
|
||||
l::tweak_flags_writeback_cache(&ffi_->flags);
|
||||
|
||||
ffi_->noflush = !l::calculate_flush(cfg->flushonclose,
|
||||
ffi_->flags);
|
||||
|
||||
rv = l::create(cfg->func.getattr.policy,
|
||||
cfg->func.create.policy,
|
||||
cfg->branches,
|
||||
|
|
|
|||
|
|
@ -114,6 +114,24 @@ namespace l
|
|||
*flags_ &= ~O_APPEND;
|
||||
}
|
||||
|
||||
static
|
||||
bool
|
||||
calculate_flush(FlushOnClose const flushonclose_,
|
||||
int const flags_)
|
||||
{
|
||||
switch(flushonclose_)
|
||||
{
|
||||
case FlushOnCloseEnum::NEVER:
|
||||
return false;
|
||||
case FlushOnCloseEnum::OPENED_FOR_WRITE:
|
||||
return !l::rdonly(flags_);
|
||||
case FlushOnCloseEnum::ALWAYS:
|
||||
return true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static
|
||||
void
|
||||
config_to_ffi_flags(Config::Read &cfg_,
|
||||
|
|
@ -236,6 +254,9 @@ namespace FUSE
|
|||
if(cfg->writeback_cache)
|
||||
l::tweak_flags_writeback_cache(&ffi_->flags);
|
||||
|
||||
ffi_->noflush = !l::calculate_flush(cfg->flushonclose,
|
||||
ffi_->flags);
|
||||
|
||||
rv = l::open(cfg->func.open.policy,
|
||||
cfg->branches,
|
||||
fusepath_,
|
||||
|
|
|
|||
|
|
@ -30,6 +30,8 @@ namespace FUSE
|
|||
|
||||
ffi_->fh = reinterpret_cast<uint64_t>(new DirInfo(fusepath_));
|
||||
|
||||
ffi_->noflush = true;
|
||||
|
||||
if(cfg->cache_readdir)
|
||||
{
|
||||
ffi_->keep_cache = 1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue