mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-25 01:16:30 -05:00
add 'inodecalc' option to allow selection of inode calculation algo
This commit is contained in:
parent
cb74573fc2
commit
b4397f7f2e
14 changed files with 470 additions and 130 deletions
|
|
@ -83,6 +83,7 @@ Config::Config()
|
|||
func(),
|
||||
fuse_msg_size(FUSE_MAX_MAX_PAGES),
|
||||
ignorepponrename(false),
|
||||
inodecalc("hybrid-hash"),
|
||||
link_cow(false),
|
||||
minfreespace(MINFREESPACE_DEFAULT),
|
||||
mount(),
|
||||
|
|
@ -142,6 +143,7 @@ Config::Config()
|
|||
_map["func.utimens"] = &func.utimens;
|
||||
_map["fuse_msg_size"] = &fuse_msg_size;
|
||||
_map["ignorepponrename"] = &ignorepponrename;
|
||||
_map["inodecalc"] = &inodecalc;
|
||||
_map["kernel_cache"] = &kernel_cache;
|
||||
_map["link_cow"] = &link_cow;
|
||||
_map["minfreespace"] = &minfreespace;
|
||||
|
|
@ -392,7 +394,6 @@ Config::set(const std::string &key_,
|
|||
return set_raw(key_,value_);
|
||||
}
|
||||
|
||||
|
||||
std::ostream&
|
||||
operator<<(std::ostream &os_,
|
||||
const Config &c_)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "branch.hpp"
|
||||
#include "config_inodecalc.hpp"
|
||||
#include "config_readdir.hpp"
|
||||
#include "enum.hpp"
|
||||
#include "errno.hpp"
|
||||
|
|
@ -103,6 +104,7 @@ public:
|
|||
Funcs func;
|
||||
ConfigUINT64 fuse_msg_size;
|
||||
ConfigBOOL ignorepponrename;
|
||||
InodeCalc inodecalc;
|
||||
ConfigBOOL kernel_cache;
|
||||
ConfigBOOL link_cow;
|
||||
ConfigUINT64 minfreespace;
|
||||
|
|
|
|||
37
src/config_inodecalc.cpp
Normal file
37
src/config_inodecalc.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2020, 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_inodecalc.hpp"
|
||||
#include "fs_inode.hpp"
|
||||
|
||||
InodeCalc::InodeCalc(const std::string &s_)
|
||||
{
|
||||
fs::inode::set_algo(s_);
|
||||
}
|
||||
|
||||
std::string
|
||||
InodeCalc::to_string(void) const
|
||||
{
|
||||
return fs::inode::get_algo();
|
||||
}
|
||||
|
||||
int
|
||||
InodeCalc::from_string(const std::string &s_)
|
||||
{
|
||||
return fs::inode::set_algo(s_);
|
||||
}
|
||||
31
src/config_inodecalc.hpp
Normal file
31
src/config_inodecalc.hpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2020, 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 "tofrom_string.hpp"
|
||||
|
||||
class InodeCalc : public ToFromString
|
||||
{
|
||||
public:
|
||||
InodeCalc(const std::string &);
|
||||
|
||||
public:
|
||||
std::string to_string(void) const;
|
||||
int from_string(const std::string &);
|
||||
};
|
||||
164
src/fs_inode.cpp
Normal file
164
src/fs_inode.cpp
Normal file
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
ISC License
|
||||
|
||||
Copyright (c) 2020, 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 "ef.hpp"
|
||||
#include "fasthash.h"
|
||||
#include "fs_inode.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
typedef uint64_t (*inodefunc_t)(const char*,const uint64_t,const mode_t,const dev_t,const ino_t);
|
||||
|
||||
static uint64_t hybrid_hash(const char*,const uint64_t,const mode_t,const dev_t,const ino_t);
|
||||
|
||||
static inodefunc_t g_func = hybrid_hash;
|
||||
|
||||
static
|
||||
uint64_t
|
||||
passthrough(const char *fusepath_,
|
||||
const uint64_t fusepath_len_,
|
||||
const mode_t mode_,
|
||||
const dev_t dev_,
|
||||
const ino_t ino_)
|
||||
{
|
||||
return ino_;
|
||||
}
|
||||
|
||||
static
|
||||
uint64_t
|
||||
path_hash(const char *fusepath_,
|
||||
const uint64_t fusepath_len_,
|
||||
const mode_t mode_,
|
||||
const dev_t dev_,
|
||||
const ino_t ino_)
|
||||
{
|
||||
return fasthash64(fusepath_,
|
||||
fusepath_len_,
|
||||
fs::inode::MAGIC);
|
||||
}
|
||||
|
||||
static
|
||||
uint64_t
|
||||
devino_hash(const char *fusepath_,
|
||||
const uint64_t fusepath_len_,
|
||||
const mode_t mode_,
|
||||
const dev_t dev_,
|
||||
const ino_t ino_)
|
||||
{
|
||||
uint64_t buf[2];
|
||||
|
||||
buf[0] = dev_;
|
||||
buf[1] = ino_;
|
||||
|
||||
return fasthash64((void*)&buf[0],
|
||||
sizeof(buf),
|
||||
fs::inode::MAGIC);
|
||||
}
|
||||
|
||||
static
|
||||
uint64_t
|
||||
hybrid_hash(const char *fusepath_,
|
||||
const uint64_t fusepath_len_,
|
||||
const mode_t mode_,
|
||||
const dev_t dev_,
|
||||
const ino_t ino_)
|
||||
{
|
||||
return (S_ISDIR(mode_) ?
|
||||
path_hash(fusepath_,fusepath_len_,mode_,dev_,ino_) :
|
||||
devino_hash(fusepath_,fusepath_len_,mode_,dev_,ino_));
|
||||
}
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace inode
|
||||
{
|
||||
int
|
||||
set_algo(const std::string &algo_)
|
||||
{
|
||||
if(algo_ == "passthrough")
|
||||
g_func = passthrough;
|
||||
ef(algo_ == "path-hash")
|
||||
g_func = path_hash;
|
||||
ef(algo_ == "devino-hash")
|
||||
g_func = devino_hash;
|
||||
ef(algo_ == "hybrid-hash")
|
||||
g_func = hybrid_hash;
|
||||
else
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::string
|
||||
get_algo(void)
|
||||
{
|
||||
if(g_func == passthrough)
|
||||
return "passthrough";
|
||||
if(g_func == path_hash)
|
||||
return "path-hash";
|
||||
if(g_func == devino_hash)
|
||||
return "devino-hash";
|
||||
if(g_func == hybrid_hash)
|
||||
return "hybrid-hash";
|
||||
|
||||
return std::string();
|
||||
}
|
||||
|
||||
uint64_t
|
||||
calc(const char *fusepath_,
|
||||
const uint64_t fusepath_len_,
|
||||
const mode_t mode_,
|
||||
const dev_t dev_,
|
||||
const ino_t ino_)
|
||||
{
|
||||
return g_func(fusepath_,fusepath_len_,mode_,dev_,ino_);
|
||||
}
|
||||
|
||||
void
|
||||
calc(const char *fusepath_,
|
||||
const uint64_t fusepath_len_,
|
||||
struct stat *st_)
|
||||
{
|
||||
st_->st_ino = calc(fusepath_,
|
||||
fusepath_len_,
|
||||
st_->st_mode,
|
||||
st_->st_dev,
|
||||
st_->st_ino);
|
||||
}
|
||||
|
||||
void
|
||||
calc(const char *fusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
calc(fusepath_,strlen(fusepath_),st_);
|
||||
}
|
||||
|
||||
void
|
||||
calc(const std::string &fusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
calc(fusepath_.c_str(),fusepath_.size(),st_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -18,38 +18,33 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "fasthash.h"
|
||||
#include <string>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
|
||||
namespace fs
|
||||
{
|
||||
namespace inode
|
||||
{
|
||||
static const uint64_t MAGIC = 0x7472617065786974;
|
||||
|
||||
inline
|
||||
uint64_t
|
||||
recompute(ino_t ino_,
|
||||
dev_t dev_)
|
||||
{
|
||||
uint64_t buf[5];
|
||||
int set_algo(const std::string &s);
|
||||
std::string get_algo(void);
|
||||
|
||||
buf[0] = ino_;
|
||||
buf[1] = dev_;
|
||||
buf[2] = buf[0] ^ buf[1];
|
||||
buf[3] = buf[0] & buf[1];
|
||||
buf[4] = buf[0] | buf[1];
|
||||
uint64_t calc(const char *fusepath,
|
||||
const uint64_t fusepath_len,
|
||||
const mode_t mode,
|
||||
const dev_t dev,
|
||||
const ino_t ion);
|
||||
void calc(const char *fusepath,
|
||||
const uint64_t fusepath_len,
|
||||
struct stat *st);
|
||||
void calc(const char *fusepath,
|
||||
struct stat *st);
|
||||
void calc(const std::string &fusepath,
|
||||
struct stat *st);
|
||||
|
||||
return fasthash64(&buf[0],sizeof(buf),MAGIC);
|
||||
}
|
||||
|
||||
inline
|
||||
void
|
||||
recompute(struct stat *st_)
|
||||
{
|
||||
st_->st_ino = recompute(st_->st_ino,st_->st_dev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@ namespace l
|
|||
{
|
||||
static
|
||||
int
|
||||
fgetattr(const int fd_,
|
||||
struct stat *st_)
|
||||
fgetattr(const int fd_,
|
||||
const std::string &fusepath_,
|
||||
struct stat *st_)
|
||||
{
|
||||
int rv;
|
||||
|
||||
|
|
@ -35,7 +36,7 @@ namespace l
|
|||
if(rv == -1)
|
||||
return -errno;
|
||||
|
||||
fs::inode::recompute(st_);
|
||||
fs::inode::calc(fusepath_,st_);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -53,7 +54,7 @@ namespace FUSE
|
|||
const Config &config = Config::ro();
|
||||
FileInfo *fi = reinterpret_cast<FileInfo*>(ffi_->fh);
|
||||
|
||||
rv = l::fgetattr(fi->fd,st_);
|
||||
rv = l::fgetattr(fi->fd,fi->fusepath,st_);
|
||||
|
||||
timeout_->entry = ((rv >= 0) ?
|
||||
config.cache_entry :
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ namespace l
|
|||
if(symlinkify_ && symlinkify::can_be_symlink(*st_,symlinkify_timeout_))
|
||||
st_->st_mode = symlinkify::convert(st_->st_mode);
|
||||
|
||||
fs::inode::recompute(st_);
|
||||
fs::inode::calc(fusepath_,st_);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
Copyright (c) 2020, 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
|
||||
|
|
@ -40,6 +40,13 @@ using std::vector;
|
|||
|
||||
namespace l
|
||||
{
|
||||
static
|
||||
char
|
||||
denttype(struct linux_dirent *d_)
|
||||
{
|
||||
return *((char*)d_ + d_->reclen - 1);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
close_free_ret_enomem(int fd_,
|
||||
|
|
@ -61,6 +68,7 @@ namespace l
|
|||
char *buf;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
string fullpath;
|
||||
uint64_t namelen;
|
||||
struct linux_dirent *d;
|
||||
|
||||
|
|
@ -100,7 +108,12 @@ namespace l
|
|||
if(rv == 0)
|
||||
continue;
|
||||
|
||||
d->ino = fs::inode::recompute(d->ino,dev);
|
||||
fullpath = fs::path::make(dirname_,d->name);
|
||||
d->ino = fs::inode::calc(fullpath.c_str(),
|
||||
fullpath.size(),
|
||||
DTTOIF(l::denttype(d)),
|
||||
dev,
|
||||
d->ino);
|
||||
|
||||
rv = fuse_dirents_add_linux(buf_,d,namelen);
|
||||
if(rv)
|
||||
|
|
|
|||
|
|
@ -41,6 +41,14 @@ using std::vector;
|
|||
|
||||
namespace l
|
||||
{
|
||||
static
|
||||
char
|
||||
denttype(struct linux_dirent *d_)
|
||||
{
|
||||
return *((char*)d_ + d_->reclen - 1);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
close_free_ret_enomem(int fd_,
|
||||
void *buf_)
|
||||
|
|
@ -63,6 +71,7 @@ namespace l
|
|||
char *buf;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
string fullpath;
|
||||
uint64_t namelen;
|
||||
struct stat st;
|
||||
fuse_entry_t entry;
|
||||
|
|
@ -110,10 +119,16 @@ namespace l
|
|||
|
||||
rv = fs::fstatat_nofollow(dirfd,d->name,&st);
|
||||
if(rv == -1)
|
||||
memset(&st,0,sizeof(st));
|
||||
{
|
||||
memset(&st,0,sizeof(st));
|
||||
st.st_ino = d->ino;
|
||||
st.st_dev = dev;
|
||||
st.st_mode = DTTOIF(l::denttype(d));
|
||||
}
|
||||
|
||||
d->ino = fs::inode::recompute(d->ino,dev);
|
||||
st.st_ino = d->ino;
|
||||
fullpath = fs::path::make(dirname_,d->name);
|
||||
fs::inode::calc(fullpath,&st);
|
||||
d->ino = st.st_ino;
|
||||
|
||||
rv = fuse_dirents_add_linux_plus(buf_,d,namelen,&entry,&st);
|
||||
if(rv)
|
||||
|
|
|
|||
|
|
@ -66,6 +66,7 @@ namespace l
|
|||
dev_t dev;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
string fullpath;
|
||||
struct stat st;
|
||||
uint64_t namelen;
|
||||
fuse_entry_t entry;
|
||||
|
|
@ -104,10 +105,16 @@ namespace l
|
|||
|
||||
rv = fs::fstatat_nofollow(dirfd,de->d_name,&st);
|
||||
if(rv == -1)
|
||||
memset(&st,0,sizeof(st));
|
||||
{
|
||||
memset(&st,0,sizeof(st));
|
||||
st.st_ino = de->d_ino;
|
||||
st.st_dev = dev;
|
||||
st.st_mode = DTTOIF(de->d_type);
|
||||
}
|
||||
|
||||
de->d_ino = fs::inode::recompute(de->d_ino,dev);
|
||||
st.st_ino = de->d_ino;
|
||||
fullpath = fs::path::make(dirname_,de->d_name);
|
||||
fs::inode::calc(fullpath,&st);
|
||||
de->d_ino = st.st_ino;
|
||||
|
||||
rv = fuse_dirents_add_plus(buf_,de,namelen,&entry,&st);
|
||||
if(rv)
|
||||
|
|
|
|||
|
|
@ -63,6 +63,7 @@ namespace l
|
|||
dev_t dev;
|
||||
HashSet names;
|
||||
string basepath;
|
||||
string fullpath;
|
||||
uint64_t namelen;
|
||||
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
|
|
@ -91,7 +92,12 @@ namespace l
|
|||
if(rv == 0)
|
||||
continue;
|
||||
|
||||
de->d_ino = fs::inode::recompute(de->d_ino,dev);
|
||||
fullpath = fs::path::make(dirname_,de->d_name);
|
||||
de->d_ino = fs::inode::calc(fullpath.c_str(),
|
||||
fullpath.size(),
|
||||
DTTOIF(de->d_type),
|
||||
dev,
|
||||
de->d_ino);
|
||||
|
||||
rv = fuse_dirents_add(buf_,de,namelen);
|
||||
if(rv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue