mirror of https://github.com/trapexit/mergerfs.git
Browse Source
Merge pull request #775 from trapexit/inode-calc
Merge pull request #775 from trapexit/inode-calc
add 'inodecalc' option to allow selection of inode calculation algopull/776/head
trapexit
4 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 474 additions and 134 deletions
-
79README.md
-
177man/mergerfs.1
-
3src/config.cpp
-
2src/config.hpp
-
37src/config_inodecalc.cpp
-
31src/config_inodecalc.hpp
-
164src/fs_inode.cpp
-
41src/fs_inode.hpp
-
9src/fuse_fgetattr.cpp
-
2src/fuse_getattr.cpp
-
17src/fuse_readdir_linux.cpp
-
23src/fuse_readdir_plus_linux.cpp
-
15src/fuse_readdir_plus_posix.cpp
-
8src/fuse_readdir_posix.cpp
@ -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_); |
|||
} |
@ -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 &); |
|||
}; |
@ -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_); |
|||
} |
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue