Browse Source

Merge pull request #374 from trapexit/flush-cache-on-close

add option to drop file caches before closing files
pull/376/head
Antonio SJ Musumeci 8 years ago
committed by GitHub
parent
commit
dca6cb4826
  1. 1
      src/config.cpp
  2. 1
      src/config.hpp
  3. 40
      src/option_parser.cpp
  4. 19
      src/release.cpp

1
src/config.cpp

@ -40,6 +40,7 @@ namespace mergerfs
minfreespace(MINFREESPACE_DEFAULT), minfreespace(MINFREESPACE_DEFAULT),
moveonenospc(false), moveonenospc(false),
direct_io(false), direct_io(false),
dropcacheonclose(false),
POLICYINIT(access), POLICYINIT(access),
POLICYINIT(chmod), POLICYINIT(chmod),
POLICYINIT(chown), POLICYINIT(chown),

1
src/config.hpp

@ -48,6 +48,7 @@ namespace mergerfs
uint64_t minfreespace; uint64_t minfreespace;
bool moveonenospc; bool moveonenospc;
bool direct_io; bool direct_io;
bool dropcacheonclose;
public: public:
const Policy *policies[FuseFunc::Enum::END]; const Policy *policies[FuseFunc::Enum::END];

40
src/option_parser.cpp

@ -120,13 +120,13 @@ parse_and_process_minfreespace(const std::string &value,
static static
int int
parse_and_process_moveonenospc(const std::string &value,
bool &moveonenospc)
parse_and_process_boolean(const std::string &value,
bool &boolean)
{ {
if(value == "false") if(value == "false")
moveonenospc = false;
boolean = false;
else if(value == "true") else if(value == "true")
moveonenospc = true;
boolean = true;
else else
return 1; return 1;
@ -169,7 +169,9 @@ parse_and_process_kv_arg(Config &config,
if(key == "minfreespace") if(key == "minfreespace")
rv = parse_and_process_minfreespace(value,config.minfreespace); rv = parse_and_process_minfreespace(value,config.minfreespace);
else if(key == "moveonenospc") else if(key == "moveonenospc")
rv = parse_and_process_moveonenospc(value,config.moveonenospc);
rv = parse_and_process_boolean(value,config.moveonenospc);
else if(key == "dropcacheonclose")
rv = parse_and_process_boolean(value,config.dropcacheonclose);
} }
if(rv == -1) if(rv == -1)
@ -246,20 +248,25 @@ usage(void)
"mergerfs options:\n" "mergerfs options:\n"
" <srcpaths> ':' delimited list of directories. Supports\n" " <srcpaths> ':' delimited list of directories. Supports\n"
" shell globbing (must be escaped in shell)\n" " shell globbing (must be escaped in shell)\n"
" -o defaults default FUSE options which seem to provide the\n"
" -o defaults Default FUSE options which seem to provide the\n"
" best performance: atomic_o_trunc, auto_cache,\n" " best performance: atomic_o_trunc, auto_cache,\n"
" big_writes, default_permissions, splice_read,\n" " big_writes, default_permissions, splice_read,\n"
" splice_write, splice_move\n" " splice_write, splice_move\n"
" -o direct_io bypass additional caching, increases write\n"
" speeds at the cost of reads\n"
" -o use_ino mergerfs will generate inode values rather than\n"
" autogenerated by libfuse\n"
" -o minfreespace=<int> minimum free space needed for certain policies:\n"
" default 4G\n"
" -o func.<f>=<p> Set function <f> to policy <p>\n"
" -o category.<c>=<p> Set functions in category <c> to <p>\n"
" -o direct_io Bypass additional caching, increases write\n"
" speeds at the cost of reads. Please read docs\n"
" for more details as there are tradeoffs.\n"
" -o use_ino Have mergerfs generate inode values rather than\n"
" autogenerated by libfuse. Suggested.\n"
" -o minfreespace=<int> minimum free space needed for certain policies.\n"
" default=4G\n"
" -o moveonenospc=<bool> try to move file to another drive when ENOSPC\n" " -o moveonenospc=<bool> try to move file to another drive when ENOSPC\n"
" on write: default false\n"
" -o func.<f>=<p> set function <f> to policy <p>\n"
" -o category.<c>=<p> set functions in category <c> to <p>\n"
" on write. default=false\n"
" -o dropcacheonclose=<bool>\n"
" when a file is closed suggest to OS it drop\n"
" the file's cache. This is useful when direct_io\n"
" is disabled. default=false\n"
<< std::endl; << std::endl;
} }
@ -267,7 +274,8 @@ static
void void
version(void) version(void)
{ {
std::cout << "mergerfs version: " << MERGERFS_VERSION
std::cout << "mergerfs version: "
<< MERGERFS_VERSION
<< std::endl; << std::endl;
} }

19
src/release.cpp

@ -18,14 +18,25 @@
#include <string> #include <string>
#include "config.hpp"
#include "errno.hpp" #include "errno.hpp"
#include "fileinfo.hpp" #include "fileinfo.hpp"
#include "fs_base_close.hpp" #include "fs_base_close.hpp"
#include "fs_fadvise.hpp"
static static
int int
_release(FileInfo *fi)
_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(fi->fd,0,0,POSIX_FADV_DONTNEED);
fs::fadvise(fi->fd,0,0,POSIX_FADV_DONTNEED);
}
fs::close(fi->fd); fs::close(fi->fd);
delete fi; delete fi;
@ -41,9 +52,11 @@ namespace mergerfs
release(const char *fusepath, release(const char *fusepath,
fuse_file_info *ffi) fuse_file_info *ffi)
{ {
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
const fuse_context *fc = fuse_get_context();
const Config &config = Config::get(fc);
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi->fh);
return _release(fi);
return _release(fi,config.dropcacheonclose);
} }
} }
} }
Loading…
Cancel
Save