Merge pull request #821 from trapexit/minfreespace

branches: add per branch minfreespace w/ original value as default
This commit is contained in:
trapexit 2020-09-04 21:26:38 -04:00 committed by GitHub
commit b1c6d4864f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
68 changed files with 3005 additions and 813 deletions

View File

@ -18,8 +18,11 @@
#include "branch.hpp"
#include "ef.hpp"
#include "from_string.hpp"
#include "fs_glob.hpp"
#include "fs_realpathize.hpp"
#include "nonstd/optional.hpp"
#include "num.hpp"
#include "str.hpp"
#include <string>
@ -29,239 +32,381 @@
using std::string;
using std::vector;
using nonstd::optional;
Branch::Branch(const uint64_t &default_minfreespace_)
: _default_minfreespace(&default_minfreespace_)
{
}
int
Branch::from_string(const std::string &str_)
{
return -EINVAL;
}
std::string
Branch::to_string(void) const
{
std::string rv;
rv = path;
rv += '=';
switch(mode)
{
default:
case Branch::Mode::RW:
rv += "RW";
break;
case Branch::Mode::RO:
rv += "RO";
break;
case Branch::Mode::NC:
rv += "NC";
break;
}
if(_minfreespace.has_value())
{
rv += ',';
rv += num::humanize(_minfreespace.value());
}
return rv;
}
void
Branch::set_minfreespace(const uint64_t minfreespace_)
{
_minfreespace = minfreespace_;
}
uint64_t
Branch::minfreespace(void) const
{
if(_minfreespace.has_value())
return _minfreespace.value();
return *_default_minfreespace;
}
bool
Branch::ro(void) const
{
return (mode == Branch::RO);
return (mode == Branch::Mode::RO);
}
bool
Branch::nc(void) const
{
return (mode == Branch::NC);
return (mode == Branch::Mode::NC);
}
bool
Branch::ro_or_nc(void) const
{
return ((mode == Branch::RO) ||
(mode == Branch::NC));
return ((mode == Branch::Mode::RO) ||
(mode == Branch::Mode::NC));
}
static
void
split(const std::string &s_,
std::string *instr_,
std::string *values_)
namespace l
{
uint64_t offset;
static
void
split(const std::string &s_,
std::string *instr_,
std::string *values_)
{
uint64_t offset;
offset = s_.find_first_of('/');
*instr_ = s_.substr(0,offset);
if(offset != std::string::npos)
*values_ = s_.substr(offset);
offset = s_.find_first_of('/');
*instr_ = s_.substr(0,offset);
if(offset != std::string::npos)
*values_ = s_.substr(offset);
}
}
Branches::Branches()
Branches::Branches(const uint64_t &default_minfreespace_)
: default_minfreespace(default_minfreespace_)
{
pthread_rwlock_init(&lock,NULL);
}
static
void
parse(const string &str_,
Branches &branches_)
namespace l
{
string str;
Branch branch;
vector<string> globbed;
static
int
parse_mode(const string &str_,
Branch::Mode *mode_)
{
if(str_ == "RW")
*mode_ = Branch::Mode::RW;
ef(str_ == "RO")
*mode_ = Branch::Mode::RO;
ef(str_ == "NC")
*mode_ = Branch::Mode::NC;
else
return -EINVAL;
str = str_;
branch.mode = Branch::INVALID;
if(str::endswith(str,"=RO"))
branch.mode = Branch::RO;
ef(str::endswith(str,"=RW"))
branch.mode = Branch::RW;
ef(str::endswith(str,"=NC"))
branch.mode = Branch::NC;
return 0;
}
if(branch.mode != Branch::INVALID)
str.resize(str.size() - 3);
else
branch.mode = Branch::RW;
static
int
parse_minfreespace(const string &str_,
optional<uint64_t> *minfreespace_)
{
int rv;
uint64_t uint64;
fs::glob(str,&globbed);
fs::realpathize(&globbed);
for(size_t i = 0; i < globbed.size(); i++)
{
branch.path = globbed[i];
branches_.push_back(branch);
}
}
rv = str::from(str_,&uint64);
if(rv < 0)
return rv;
static
void
set(Branches &branches_,
const std::string &str_)
{
vector<string> paths;
*minfreespace_ = uint64;
branches_.clear();
return 0;
}
str::split(str_,':',&paths);
static
int
parse_branch(const string &str_,
string *glob_,
Branch::Mode *mode_,
optional<uint64_t> *minfreespace_)
{
int rv;
string options;
vector<string> v;
for(size_t i = 0; i < paths.size(); i++)
{
Branches tmp;
str::rsplit1(str_,'=',&v);
switch(v.size())
{
case 1:
*glob_ = v[0];
*mode_ = Branch::Mode::RW;
break;
case 2:
*glob_ = v[0];
options = v[1];
v.clear();
str::split(options,',',&v);
switch(v.size())
{
case 2:
rv = l::parse_minfreespace(v[1],minfreespace_);
if(rv < 0)
return rv;
case 1:
rv = l::parse_mode(v[0],mode_);
if(rv < 0)
return rv;
break;
case 0:
return -EINVAL;
}
break;
default:
return -EINVAL;
}
parse(paths[i],tmp);
return 0;
}
branches_.insert(branches_.end(),
tmp.begin(),
tmp.end());
}
}
static
int
parse(const string &str_,
const uint64_t &default_minfreespace_,
BranchVec *branches_)
{
int rv;
string glob;
vector<string> globbed;
optional<uint64_t> minfreespace;
Branch branch(default_minfreespace_);
static
void
add_begin(Branches &branches_,
const std::string &str_)
{
vector<string> paths;
rv = l::parse_branch(str_,&glob,&branch.mode,&minfreespace);
if(rv < 0)
return rv;
str::split(str_,':',&paths);
if(minfreespace.has_value())
branch.set_minfreespace(minfreespace.value());
for(size_t i = 0; i < paths.size(); i++)
{
Branches tmp;
fs::glob(glob,&globbed);
fs::realpathize(&globbed);
for(size_t i = 0; i < globbed.size(); i++)
{
branch.path = globbed[i];
branches_->push_back(branch);
}
parse(paths[i],tmp);
return 0;
}
branches_.insert(branches_.begin(),
tmp.begin(),
tmp.end());
}
}
static
int
set(const std::string &str_,
Branches *branches_)
{
int rv;
vector<string> paths;
BranchVec tmp_branchvec;
static
void
add_end(Branches &branches_,
const std::string &str_)
{
vector<string> paths;
str::split(str_,':',&paths);
str::split(str_,':',&paths);
for(size_t i = 0; i < paths.size(); i++)
{
rv = l::parse(paths[i],branches_->default_minfreespace,&tmp_branchvec);
if(rv < 0)
return rv;
}
for(size_t i = 0; i < paths.size(); i++)
{
Branches tmp;
branches_->vec.clear();
branches_->vec.insert(branches_->vec.end(),
tmp_branchvec.begin(),
tmp_branchvec.end());
parse(paths[i],tmp);
return 0;
}
branches_.insert(branches_.end(),
tmp.begin(),
tmp.end());
}
}
static
int
add_begin(const std::string &str_,
Branches *branches_)
{
int rv;
vector<string> paths;
BranchVec tmp_branchvec;
static
void
erase_begin(Branches &branches_)
{
branches_.erase(branches_.begin());
}
str::split(str_,':',&paths);
static
void
erase_end(Branches &branches_)
{
branches_.pop_back();
}
for(size_t i = 0; i < paths.size(); i++)
{
rv = l::parse(paths[i],branches_->default_minfreespace,&tmp_branchvec);
if(rv < 0)
return rv;
}
static
void
erase_fnmatch(Branches &branches_,
const std::string &str_)
{
vector<string> patterns;
branches_->vec.insert(branches_->vec.begin(),
tmp_branchvec.begin(),
tmp_branchvec.end());
str::split(str_,':',&patterns);
return 0;
}
for(Branches::iterator i = branches_.begin();
i != branches_.end();)
{
int match = FNM_NOMATCH;
static
int
add_end(const std::string &str_,
Branches *branches_)
{
int rv;
vector<string> paths;
BranchVec tmp_branchvec;
for(vector<string>::const_iterator pi = patterns.begin();
pi != patterns.end() && match != 0;
++pi)
{
match = ::fnmatch(pi->c_str(),i->path.c_str(),0);
}
str::split(str_,':',&paths);
i = ((match == 0) ? branches_.erase(i) : (i+1));
}
for(size_t i = 0; i < paths.size(); i++)
{
rv = l::parse(paths[i],branches_->default_minfreespace,&tmp_branchvec);
if(rv < 0)
return rv;
}
branches_->vec.insert(branches_->vec.end(),
tmp_branchvec.begin(),
tmp_branchvec.end());
return 0;
}
static
int
erase_begin(BranchVec *branches_)
{
branches_->erase(branches_->begin());
return 0;
}
static
int
erase_end(BranchVec *branches_)
{
branches_->pop_back();
return 0;
}
static
int
erase_fnmatch(const std::string &str_,
Branches *branches_)
{
vector<string> patterns;
str::split(str_,':',&patterns);
for(BranchVec::iterator i = branches_->vec.begin();
i != branches_->vec.end();)
{
int match = FNM_NOMATCH;
for(vector<string>::const_iterator pi = patterns.begin();
pi != patterns.end() && match != 0;
++pi)
{
match = ::fnmatch(pi->c_str(),i->path.c_str(),0);
}
i = ((match == 0) ? branches_->vec.erase(i) : (i+1));
}
return 0;
}
}
int
Branches::from_string(const std::string &s_)
{
rwlock::WriteGuard guard(&lock);
rwlock::WriteGuard guard(lock);
std::string instr;
std::string values;
::split(s_,&instr,&values);
l::split(s_,&instr,&values);
if(instr == "+")
::add_end(*this,values);
ef(instr == "+<")
::add_begin(*this,values);
ef(instr == "+>")
::add_end(*this,values);
ef(instr == "-")
::erase_fnmatch(*this,values);
ef(instr == "-<")
::erase_begin(*this);
ef(instr == "->")
::erase_end(*this);
ef(instr == "=")
::set(*this,values);
ef(instr.empty())
::set(*this,values);
else
return -EINVAL;
return l::add_end(values,this);
if(instr == "+<")
return l::add_begin(values,this);
if(instr == "+>")
return l::add_end(values,this);
if(instr == "-")
return l::erase_fnmatch(values,this);
if(instr == "-<")
return l::erase_begin(&vec);
if(instr == "->")
return l::erase_end(&vec);
if(instr == "=")
return l::set(values,this);
if(instr.empty())
return l::set(values,this);
return 0;
return -EINVAL;
}
string
Branches::to_string(void) const
{
rwlock::ReadGuard guard(&lock);
rwlock::ReadGuard guard(lock);
string tmp;
for(size_t i = 0; i < size(); i++)
for(size_t i = 0; i < vec.size(); i++)
{
const Branch &branch = (*this)[i];
tmp += branch.path;
tmp += '=';
switch(branch.mode)
{
default:
case Branch::RW:
tmp += "RW";
break;
case Branch::RO:
tmp += "RO";
break;
case Branch::NC:
tmp += "NC";
break;
}
const Branch &branch = vec[i];
tmp += branch.to_string();
tmp += ':';
}
@ -274,11 +419,11 @@ Branches::to_string(void) const
void
Branches::to_paths(vector<string> &vec_) const
{
rwlock::ReadGuard guard(&lock);
rwlock::ReadGuard guard(lock);
for(size_t i = 0; i < size(); i++)
for(size_t i = 0; i < vec.size(); i++)
{
const Branch &branch = (*this)[i];
const Branch &branch = vec[i];
vec_.push_back(branch.path);
}
@ -299,12 +444,13 @@ SrcMounts::from_string(const std::string &s_)
std::string
SrcMounts::to_string(void) const
{
rwlock::ReadGuard guard(&_branches.lock);
rwlock::ReadGuard guard(_branches.lock);
std::string rv;
for(uint64_t i = 0; i < _branches.size(); i++)
for(uint64_t i = 0; i < _branches.vec.size(); i++)
{
rv += _branches[i].path;
rv += _branches.vec[i].path;
rv += ':';
}

View File

@ -20,16 +20,25 @@
#include "rwlock.hpp"
#include "tofrom_string.hpp"
#include "nonstd/optional.hpp"
#include <string>
#include <vector>
#include <stdint.h>
#include <pthread.h>
class Branch
class Branch : public ToFromString
{
public:
enum Mode
Branch(const uint64_t &default_minfreespace);
public:
int from_string(const std::string &str);
std::string to_string(void) const;
public:
enum class Mode
{
INVALID,
RO,
@ -37,18 +46,30 @@ public:
NC
};
public:
Mode mode;
std::string path;
uint64_t minfreespace() const;
public:
void set_minfreespace(const uint64_t minfreespace);
public:
bool ro(void) const;
bool nc(void) const;
bool ro_or_nc(void) const;
private:
nonstd::optional<uint64_t> _minfreespace;
const uint64_t *_default_minfreespace;
};
class Branches : public std::vector<Branch>, public ToFromString
typedef std::vector<Branch> BranchVec;
class Branches : public ToFromString
{
public:
Branches();
Branches(const uint64_t &default_minfreespace_);
public:
int from_string(const std::string &str);
@ -59,6 +80,8 @@ public:
public:
mutable pthread_rwlock_t lock;
BranchVec vec;
const uint64_t &default_minfreespace;
};
class SrcMounts : public ToFromString

View File

@ -67,7 +67,7 @@ Config::Config()
async_read(true),
auto_cache(false),
branches(),
branches(minfreespace),
cache_attr(1),
cache_entry(1),
cache_files(CacheFiles::ENUM::LIBFUSE),

View File

@ -67,22 +67,22 @@ namespace str
{
case 'k':
case 'K':
tmp *= 1024;
tmp *= 1024ULL;
break;
case 'm':
case 'M':
tmp *= (1024 * 1024);
tmp *= (1024ULL * 1024ULL);
break;
case 'g':
case 'G':
tmp *= (1024 * 1024 * 1024);
tmp *= (1024ULL * 1024ULL * 1024ULL);
break;
case 't':
case 'T':
tmp *= (1024ULL * 1024 * 1024 * 1024);
tmp *= (1024ULL * 1024ULL * 1024ULL * 1024ULL);
break;
case '\0':

View File

@ -24,10 +24,11 @@
#include <string>
namespace fs
namespace l
{
static
int
findonfs(const Branches &branches_,
findonfs(const BranchVec &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
@ -37,7 +38,6 @@ namespace fs
struct stat st;
std::string fullpath;
const Branch *branch;
const rwlock::ReadGuard guard(&branches_.lock);
rv = fs::fstat(fd_,&st);
if(rv == -1)
@ -65,3 +65,17 @@ namespace fs
return (errno=ENOENT,-1);
}
}
namespace fs
{
int
findonfs(const Branches &branches_,
const std::string &fusepath_,
const int fd_,
std::string *basepath_)
{
rwlock::ReadGuard guard(branches_.lock);
return l::findonfs(branches_.vec,fusepath_,fd_,basepath_);
}
}

View File

@ -49,7 +49,6 @@ namespace l
int
movefile(Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreepsace_,
const string &fusepath_,
int *origfd_)
{
@ -73,7 +72,7 @@ namespace l
if(rv == -1)
return -1;
rv = createFunc_(branches_,fusepath_,minfreepsace_,&fdout_path);
rv = createFunc_(branches_,fusepath_,&fdout_path);
if(rv == -1)
return -1;
@ -135,22 +134,20 @@ namespace fs
int
movefile(const Policy *policy_,
const Branches &basepaths_,
const uint64_t minfreepsace_,
const string &fusepath_,
int *origfd_)
{
return l::movefile(policy_,basepaths_,minfreepsace_,fusepath_,origfd_);
return l::movefile(policy_,basepaths_,fusepath_,origfd_);
}
int
movefile_as_root(const Policy *policy_,
const Branches &basepaths_,
const uint64_t minfreepsace_,
const string &fusepath_,
int *origfd_)
{
const ugid::Set ugid(0,0);
return fs::movefile(policy_,basepaths_,minfreepsace_,fusepath_,origfd_);
return fs::movefile(policy_,basepaths_,fusepath_,origfd_);
}
}

View File

@ -26,14 +26,12 @@ namespace fs
int
movefile(const Policy *policy,
const Branches &branches,
const uint64_t minfreepsace,
const std::string &fusepath,
int *origfd);
int
movefile_as_root(const Policy *policy,
const Branches &branches,
const uint64_t minfreepsace,
const std::string &fusepath,
int *origfd);
}

View File

@ -32,7 +32,6 @@ namespace l
int
access(Policy::Func::Search searchFunc,
const Branches &branches_,
const uint64_t minfreespace,
const char *fusepath,
const int mask)
{
@ -40,7 +39,7 @@ namespace l
string fullpath;
vector<string> basepaths;
rv = searchFunc(branches_,fusepath,minfreespace,&basepaths);
rv = searchFunc(branches_,fusepath,&basepaths);
if(rv == -1)
return -errno;
@ -64,7 +63,6 @@ namespace FUSE
return l::access(config.func.access.policy,
config.branches,
config.minfreespace,
fusepath,
mask);
}

View File

@ -71,14 +71,13 @@ namespace l
int
chmod(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const mode_t mode_)
{
int rv;
vector<string> basepaths;
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -98,7 +97,6 @@ namespace FUSE
return l::chmod(config.func.chmod.policy,
config.branches,
config.minfreespace,
fusepath_,
mode_);
}

View File

@ -71,7 +71,6 @@ namespace l
int
chown(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const uid_t uid_,
const gid_t gid_)
@ -79,7 +78,7 @@ namespace l
int rv;
vector<string> basepaths;
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -100,7 +99,6 @@ namespace FUSE
return l::chown(config.func.chown.policy,
config.branches,
config.minfreespace,
fusepath_,
uid_,
gid_);

View File

@ -128,7 +128,6 @@ namespace l
create(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_,
@ -143,11 +142,11 @@ namespace l
fusedirpath = fs::path::dirname(fusepath_);
rv = searchFunc_(branches_,fusedirpath,minfreespace_,&existingpaths);
rv = searchFunc_(branches_,fusedirpath,&existingpaths);
if(rv == -1)
return -errno;
rv = createFunc_(branches_,fusedirpath,minfreespace_,&createpaths);
rv = createFunc_(branches_,fusedirpath,&createpaths);
if(rv == -1)
return -errno;
@ -183,7 +182,6 @@ namespace FUSE
return l::create(config.func.getattr.policy,
config.func.create.policy,
config.branches,
config.minfreespace,
fusepath_,
mode_,
fc->umask,

View File

@ -61,7 +61,6 @@ namespace l
int
getattr(Policy::Func::Search searchFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
struct stat *st_,
const bool symlinkify_,
@ -71,7 +70,7 @@ namespace l
string fullpath;
vector<string> basepaths;
rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -108,7 +107,6 @@ namespace FUSE
rv = l::getattr(config.func.getattr.policy,
config.branches,
config.minfreespace,
fusepath_,
st_,
config.symlinkify,

View File

@ -165,7 +165,6 @@ namespace l
int
getxattr(Policy::Func::Search searchFunc_,
const Branches &branches_,
const size_t minfreespace_,
const char *fusepath_,
const char *attrname_,
char *buf_,
@ -175,7 +174,7 @@ namespace l
string fullpath;
vector<string> basepaths;
rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -222,7 +221,6 @@ namespace FUSE
return l::getxattr(config.func.getxattr.policy,
config.branches,
config.minfreespace,
fusepath_,
attrname_,
buf_,

View File

@ -136,7 +136,6 @@ namespace l
int
ioctl_dir_base(Policy::Func::Search searchFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const uint32_t cmd_,
void *data_,
@ -147,7 +146,7 @@ namespace l
string fullpath;
vector<string> basepaths;
rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -178,7 +177,6 @@ namespace l
return l::ioctl_dir_base(config.func.open.policy,
config.branches,
config.minfreespace,
di->fusepath.c_str(),
cmd_,
data_,
@ -257,14 +255,13 @@ namespace l
int
file_basepath(Policy::Func::Search searchFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
void *data_)
{
int rv;
vector<string> basepaths;
rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -281,7 +278,6 @@ namespace l
return l::file_basepath(config.func.open.policy,
config.branches,
config.minfreespace,
fusepath.c_str(),
data_);
}
@ -300,7 +296,6 @@ namespace l
int
file_fullpath(Policy::Func::Search searchFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const string &fusepath_,
void *data_)
{
@ -308,7 +303,7 @@ namespace l
string fullpath;
vector<string> basepaths;
rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -327,7 +322,6 @@ namespace l
return l::file_fullpath(config.func.open.policy,
config.branches,
config.minfreespace,
fusepath,
data_);
}

View File

@ -83,7 +83,6 @@ namespace l
link_create_path(Policy::Func::Search searchFunc_,
Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *oldfusepath_,
const char *newfusepath_)
{
@ -92,13 +91,13 @@ namespace l
vector<string> oldbasepaths;
vector<string> newbasepaths;
rv = actionFunc_(branches_,oldfusepath_,minfreespace_,&oldbasepaths);
rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths);
if(rv == -1)
return -errno;
newfusedirpath = fs::path::dirname(newfusepath_);
rv = searchFunc_(branches_,newfusedirpath,minfreespace_,&newbasepaths);
rv = searchFunc_(branches_,newfusedirpath,&newbasepaths);
if(rv == -1)
return -errno;
@ -112,7 +111,6 @@ namespace l
clonepath_if_would_create(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const string &oldbasepath_,
const char *oldfusepath_,
const char *newfusepath_)
@ -123,14 +121,14 @@ namespace l
newfusedirpath = fs::path::dirname(newfusepath_);
rv = createFunc_(branches_,newfusedirpath,minfreespace_,&newbasepath);
rv = createFunc_(branches_,newfusedirpath,&newbasepath);
if(rv == -1)
return -1;
if(oldbasepath_ != newbasepath[0])
return (errno=EXDEV,-1);
rv = searchFunc_(branches_,newfusedirpath,minfreespace_,&newbasepath);
rv = searchFunc_(branches_,newfusedirpath,&newbasepath);
if(rv == -1)
return -1;
@ -142,7 +140,6 @@ namespace l
link_preserve_path_core(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const string &oldbasepath_,
const char *oldfusepath_,
const char *newfusepath_,
@ -159,7 +156,7 @@ namespace l
if((rv == -1) && (errno == ENOENT))
{
rv = l::clonepath_if_would_create(searchFunc_,createFunc_,
branches_,minfreespace_,
branches_,
oldbasepath_,
oldfusepath_,newfusepath_);
if(rv != -1)
@ -174,7 +171,6 @@ namespace l
link_preserve_path_loop(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *oldfusepath_,
const char *newfusepath_,
const vector<string> &oldbasepaths_)
@ -185,7 +181,7 @@ namespace l
for(size_t i = 0, ei = oldbasepaths_.size(); i != ei; i++)
{
error = l::link_preserve_path_core(searchFunc_,createFunc_,
branches_,minfreespace_,
branches_,
oldbasepaths_[i],
oldfusepath_,newfusepath_,
error);
@ -200,19 +196,18 @@ namespace l
Policy::Func::Action actionFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *oldfusepath_,
const char *newfusepath_)
{
int rv;
vector<string> oldbasepaths;
rv = actionFunc_(branches_,oldfusepath_,minfreespace_,&oldbasepaths);
rv = actionFunc_(branches_,oldfusepath_,&oldbasepaths);
if(rv == -1)
return -errno;
return l::link_preserve_path_loop(searchFunc_,createFunc_,
branches_,minfreespace_,
branches_,
oldfusepath_,newfusepath_,
oldbasepaths);
}
@ -233,14 +228,12 @@ namespace FUSE
config.func.link.policy,
config.func.create.policy,
config.branches,
config.minfreespace,
from_,
to_);
return l::link_create_path(config.func.link.policy,
config.func.create.policy,
config.branches,
config.minfreespace,
from_,
to_);
}

View File

@ -59,7 +59,6 @@ namespace l
int
listxattr(Policy::Func::Search searchFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
char *list_,
const size_t size_)
@ -68,7 +67,7 @@ namespace l
string fullpath;
vector<string> basepaths;
rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -107,7 +106,6 @@ namespace FUSE
return l::listxattr(config.func.listxattr.policy,
config.branches,
config.minfreespace,
fusepath_,
list_,
size_);

View File

@ -97,7 +97,6 @@ namespace l
mkdir(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_)
@ -109,11 +108,11 @@ namespace l
fusedirpath = fs::path::dirname(fusepath_);
rv = searchFunc_(branches_,fusedirpath,minfreespace_,&existingpaths);
rv = searchFunc_(branches_,fusedirpath,&existingpaths);
if(rv == -1)
return -errno;
rv = createFunc_(branches_,fusedirpath,minfreespace_,&createpaths);
rv = createFunc_(branches_,fusedirpath,&createpaths);
if(rv == -1)
return -errno;
@ -139,7 +138,6 @@ namespace FUSE
return l::mkdir(config.func.getattr.policy,
config.func.mkdir.policy,
config.branches,
config.minfreespace,
fusepath_,
mode_,
fc->umask);

View File

@ -99,7 +99,6 @@ namespace l
mknod(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const mode_t mode_,
const mode_t umask_,
@ -112,11 +111,11 @@ namespace l
fusedirpath = fs::path::dirname(fusepath_);
rv = searchFunc_(branches_,fusedirpath,minfreespace_,&existingpaths);
rv = searchFunc_(branches_,fusedirpath,&existingpaths);
if(rv == -1)
return -errno;
rv = createFunc_(branches_,fusedirpath,minfreespace_,&createpaths);
rv = createFunc_(branches_,fusedirpath,&createpaths);
if(rv == -1)
return -errno;
@ -140,7 +139,6 @@ namespace FUSE
return l::mknod(config.func.getattr.policy,
config.func.mknod.policy,
config.branches,
config.minfreespace,
fusepath_,
mode_,
fc->umask,

View File

@ -183,7 +183,6 @@ namespace l
open(Policy::Func::Search searchFunc_,
PolicyCache &cache,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const int flags_,
const bool link_cow_,
@ -193,7 +192,7 @@ namespace l
int rv;
string basepath;
rv = cache(searchFunc_,branches_,fusepath_,minfreespace_,&basepath);
rv = cache(searchFunc_,branches_,fusepath_,&basepath);
if(rv == -1)
return -errno;
@ -219,7 +218,6 @@ namespace FUSE
return l::open(config.func.open.policy,
config.open_cache,
config.branches,
config.minfreespace,
fusepath_,
ffi_->flags,
config.link_cow,

View File

@ -32,11 +32,10 @@ namespace FUSE
readdir(fuse_file_info *ffi_,
fuse_dirents_t *buf_)
{
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh);
const fuse_context *fc = fuse_get_context();
const Config &config = Config::ro();
const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard guard(&config.branches.lock);
DirInfo *di = reinterpret_cast<DirInfo*>(ffi_->fh);
const fuse_context *fc = fuse_get_context();
const Config &config = Config::ro();
const ugid::Set ugid(fc->uid,fc->gid);
switch(config.readdir)
{

View File

@ -26,6 +26,7 @@
#include "hashset.hpp"
#include "linux_dirent64.h"
#include "mempools.hpp"
#include "rwlock.hpp"
#include <fuse.h>
#include <fuse_dirents.h>
@ -52,9 +53,9 @@ namespace l
static
int
readdir(const Branches &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
readdir(const BranchVec &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
{
int rv;
dev_t dev;
@ -121,6 +122,17 @@ namespace l
return 0;
}
static
int
readdir(const Branches &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
{
rwlock::ReadGuard guard(branches_.lock);
return l::readdir(branches_.vec,dirname_,buf_);
}
}
namespace FUSE

View File

@ -36,7 +36,6 @@ namespace FUSE
const fuse_context *fc = fuse_get_context();
const Config &config = Config::ro();
const ugid::Set ugid(fc->uid,fc->gid);
const rwlock::ReadGuard guard(&config.branches.lock);
switch(config.readdir)
{

View File

@ -53,11 +53,11 @@ namespace l
static
int
readdir_plus(const Branches &branches_,
const char *dirname_,
const uint64_t entry_timeout_,
const uint64_t attr_timeout_,
fuse_dirents_t *buf_)
readdir_plus(const BranchVec &branches_,
const char *dirname_,
const uint64_t entry_timeout_,
const uint64_t attr_timeout_,
fuse_dirents_t *buf_)
{
int rv;
dev_t dev;
@ -136,6 +136,19 @@ namespace l
return 0;
}
static
int
readdir_plus(const Branches &branches_,
const char *dirname_,
const uint64_t entry_timeout_,
const uint64_t attr_timeout_,
fuse_dirents_t *buf_)
{
rwlock::ReadGuard guard(branches_.lock);
return l::readdir_plus(branches_.vec,dirname_,entry_timeout_,attr_timeout_,buf_);
}
}
namespace FUSE

View File

@ -28,6 +28,7 @@
#include "fs_readdir.hpp"
#include "fs_stat.hpp"
#include "hashset.hpp"
#include "rwlock.hpp"
#include <fuse.h>
#include <fuse_dirents.h>
@ -57,11 +58,11 @@ namespace l
static
int
readdir_plus(const Branches &branches_,
const char *dirname_,
const uint64_t entry_timeout_,
const uint64_t attr_timeout_,
fuse_dirents_t *buf_)
readdir_plus(const BranchVec &branches_,
const char *dirname_,
const uint64_t entry_timeout_,
const uint64_t attr_timeout_,
fuse_dirents_t *buf_)
{
dev_t dev;
HashSet names;
@ -126,6 +127,23 @@ namespace l
return 0;
}
static
int
readdir_plus(const Branches &branches_,
const char *dirname_,
const uint64_t entry_timeout_,
const uint64_t attr_timeout_,
fuse_dirents_t *buf_)
{
rwlock::ReadGuard guard(branches_.lock);
return l::readdir_plus(branches_.vec,
dirname_,
entry_timeout_,
attr_timeout_,
buf_);
}
}
namespace FUSE

View File

@ -19,14 +19,15 @@
#include "branch.hpp"
#include "errno.hpp"
#include "fs_closedir.hpp"
#include "fs_devid.hpp"
#include "fs_dirfd.hpp"
#include "fs_inode.hpp"
#include "fs_opendir.hpp"
#include "fs_path.hpp"
#include "fs_readdir.hpp"
#include "fs_stat.hpp"
#include "fs_devid.hpp"
#include "fs_inode.hpp"
#include "fs_path.hpp"
#include "hashset.hpp"
#include "rwlock.hpp"
#include <fuse.h>
#include <fuse_dirents.h>
@ -56,9 +57,9 @@ namespace l
static
int
readdir(const Branches &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
readdir(const BranchVec &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
{
dev_t dev;
HashSet names;
@ -109,6 +110,17 @@ namespace l
return 0;
}
static
int
readdir(const Branches &branches_,
const char *dirname_,
fuse_dirents_t *buf_)
{
rwlock::ReadGuard guard(branches_.lock);
return l::readdir(branches_.vec,dirname_,buf_);
}
}
namespace FUSE

View File

@ -94,7 +94,6 @@ namespace l
int
readlink(Policy::Func::Search searchFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
char *buf_,
const size_t size_,
@ -104,7 +103,7 @@ namespace l
int rv;
vector<string> basepaths;
rv = searchFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = searchFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -126,7 +125,6 @@ namespace FUSE
return l::readlink(config.func.readlink.policy,
config.branches,
config.minfreespace,
fusepath_,
buf_,
size_,

View File

@ -70,14 +70,13 @@ namespace l
int
removexattr(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const char *attrname_)
{
int rv;
vector<string> basepaths;
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -103,7 +102,6 @@ namespace FUSE
return l::removexattr(config.func.removexattr.policy,
config.branches,
config.minfreespace,
fusepath_,
attrname_);
}

View File

@ -99,7 +99,6 @@ int
_rename_create_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
const Branches &branches_,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
@ -111,13 +110,13 @@ _rename_create_path(Policy::Func::Search searchFunc,
vector<string> oldbasepaths;
vector<string> branches;
rv = actionFunc(branches_,oldfusepath,minfreespace,&oldbasepaths);
rv = actionFunc(branches_,oldfusepath,&oldbasepaths);
if(rv == -1)
return -errno;
newfusedirpath = fs::path::dirname(newfusepath);
rv = searchFunc(branches_,newfusedirpath,minfreespace,&newbasepath);
rv = searchFunc(branches_,newfusedirpath,&newbasepath);
if(rv == -1)
return -errno;
@ -146,14 +145,13 @@ static
int
_clonepath(Policy::Func::Search searchFunc,
const Branches &branches_,
const uint64_t minfreespace,
const string &dstbasepath,
const string &fusedirpath)
{
int rv;
vector<string> srcbasepath;
rv = searchFunc(branches_,fusedirpath,minfreespace,&srcbasepath);
rv = searchFunc(branches_,fusedirpath,&srcbasepath);
if(rv == -1)
return -errno;
@ -167,7 +165,6 @@ int
_clonepath_if_would_create(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const Branches &branches_,
const uint64_t minfreespace,
const string &oldbasepath,
const char *oldfusepath,
const char *newfusepath)
@ -178,12 +175,12 @@ _clonepath_if_would_create(Policy::Func::Search searchFunc,
newfusedirpath = fs::path::dirname(newfusepath);
rv = createFunc(branches_,newfusedirpath,minfreespace,&newbasepath);
rv = createFunc(branches_,newfusedirpath,&newbasepath);
if(rv == -1)
return rv;
if(oldbasepath == newbasepath[0])
return _clonepath(searchFunc,branches_,minfreespace,oldbasepath,newfusedirpath);
return _clonepath(searchFunc,branches_,oldbasepath,newfusedirpath);
return (errno=EXDEV,-1);
}
@ -193,7 +190,6 @@ void
_rename_preserve_path_core(Policy::Func::Search searchFunc,
Policy::Func::Create createFunc,
const Branches &branches_,
const uint64_t minfreespace,
const vector<string> &oldbasepaths,
const string &oldbasepath,
const char *oldfusepath,
@ -218,8 +214,8 @@ _rename_preserve_path_core(Policy::Func::Search searchFunc,
if((rv == -1) && (errno == ENOENT))
{
rv = _clonepath_if_would_create(searchFunc,createFunc,
branches_,minfreespace,
oldbasepath,oldfusepath,newfusepath);
branches_,oldbasepath,
oldfusepath,newfusepath);
if(rv == 0)
rv = fs::rename(oldfullpath,newfullpath);
}
@ -240,7 +236,6 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
Policy::Func::Action actionFunc,
Policy::Func::Create createFunc,
const Branches &branches_,
const uint64_t minfreespace,
const char *oldfusepath,
const char *newfusepath)
{
@ -250,7 +245,7 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
vector<string> oldbasepaths;
vector<string> branches;
rv = actionFunc(branches_,oldfusepath,minfreespace,&oldbasepaths);
rv = actionFunc(branches_,oldfusepath,&oldbasepaths);
if(rv == -1)
return -errno;
@ -262,7 +257,7 @@ _rename_preserve_path(Policy::Func::Search searchFunc,
const string &oldbasepath = branches[i];
_rename_preserve_path_core(searchFunc,createFunc,
branches_,minfreespace,
branches_,
oldbasepaths,oldbasepath,
oldfusepath,newfusepath,
error,toremove);
@ -291,14 +286,12 @@ namespace FUSE
config.func.rename.policy,
config.func.create.policy,
config.branches,
config.minfreespace,
oldpath,
newpath);
return _rename_create_path(config.func.getattr.policy,
config.func.rename.policy,
config.branches,
config.minfreespace,
oldpath,
newpath);
}

View File

@ -69,13 +69,12 @@ namespace l
int
rmdir(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_)
{
int rv;
vector<string> basepaths;
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -94,7 +93,6 @@ namespace FUSE
return l::rmdir(config.func.rmdir.policy,
config.branches,
config.minfreespace,
fusepath_);
}
}

View File

@ -124,7 +124,6 @@ namespace l
int
setxattr(Policy::Func::Action actionFunc,
const Branches &branches_,
const uint64_t minfreespace,
const char *fusepath,
const char *attrname,
const char *attrval,
@ -134,7 +133,7 @@ namespace l
int rv;
vector<string> basepaths;
rv = actionFunc(branches_,fusepath,minfreespace,&basepaths);
rv = actionFunc(branches_,fusepath,&basepaths);
if(rv == -1)
return -errno;
@ -171,7 +170,6 @@ namespace FUSE
return l::setxattr(config.func.setxattr.policy,
config.branches,
config.minfreespace,
fusepath,
attrname,
attrval,

View File

@ -19,6 +19,7 @@
#include "fs_lstat.hpp"
#include "fs_path.hpp"
#include "fs_statvfs.hpp"
#include "rwlock.hpp"
#include "statvfs_util.hpp"
#include "ugid.hpp"
@ -84,6 +85,8 @@ namespace l
const StatFSIgnore ignore_,
struct statvfs *fsstat_)
{
rwlock::ReadGuard guard(branches_.lock);
int rv;
string fullpath;
struct stat st;
@ -96,11 +99,11 @@ namespace l
min_bsize = std::numeric_limits<unsigned long>::max();
min_frsize = std::numeric_limits<unsigned long>::max();
min_namemax = std::numeric_limits<unsigned long>::max();
for(size_t i = 0, ei = branches_.size(); i < ei; i++)
for(size_t i = 0, ei = branches_.vec.size(); i < ei; i++)
{
fullpath = ((mode_ == StatFS::ENUM::FULL) ?
fs::path::make(branches_[i].path,fusepath_) :
branches_[i].path);
fs::path::make(branches_.vec[i].path,fusepath_) :
branches_.vec[i].path);
rv = fs::lstat(fullpath,&st);
if(rv == -1)
@ -117,7 +120,7 @@ namespace l
if(stvfs.f_namemax && (min_namemax > stvfs.f_namemax))
min_namemax = stvfs.f_namemax;
if(l::should_ignore(ignore_,&branches_[i],StatVFS::readonly(stvfs)))
if(l::should_ignore(ignore_,&branches_.vec[i],StatVFS::readonly(stvfs)))
{
stvfs.f_bavail = 0;
stvfs.f_favail = 0;

View File

@ -83,7 +83,6 @@ namespace l
symlink(Policy::Func::Search searchFunc_,
Policy::Func::Create createFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *oldpath_,
const char *newpath_)
{
@ -94,11 +93,11 @@ namespace l
newdirpath = fs::path::dirname(newpath_);
rv = searchFunc_(branches_,newdirpath,minfreespace_,&existingpaths);
rv = searchFunc_(branches_,newdirpath,&existingpaths);
if(rv == -1)
return -errno;
rv = createFunc_(branches_,newdirpath,minfreespace_,&newbasepaths);
rv = createFunc_(branches_,newdirpath,&newbasepaths);
if(rv == -1)
return -errno;
@ -120,7 +119,6 @@ namespace FUSE
return l::symlink(config.func.getattr.policy,
config.func.symlink.policy,
config.branches,
config.minfreespace,
oldpath_,
newpath_);
}

View File

@ -72,14 +72,13 @@ namespace l
int
truncate(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const off_t size_)
{
int rv;
vector<string> basepaths;
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -99,7 +98,6 @@ namespace FUSE
return l::truncate(config.func.truncate.policy,
config.branches,
config.minfreespace,
fusepath_,
size_);
}

View File

@ -69,13 +69,12 @@ namespace l
int
unlink(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_)
{
int rv;
vector<string> basepaths;
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -96,7 +95,6 @@ namespace FUSE
return l::unlink(config.func.unlink.policy,
config.branches,
config.minfreespace,
fusepath_);
}
}

View File

@ -71,14 +71,13 @@ namespace l
int
utimens(Policy::Func::Action actionFunc_,
const Branches &branches_,
const uint64_t minfreespace_,
const char *fusepath_,
const timespec ts_[2])
{
int rv;
vector<string> basepaths;
rv = actionFunc_(branches_,fusepath_,minfreespace_,&basepaths);
rv = actionFunc_(branches_,fusepath_,&basepaths);
if(rv == -1)
return -errno;
@ -98,7 +97,6 @@ namespace FUSE
return l::utimens(config.func.utimens.policy,
config.branches,
config.minfreespace,
fusepath_,
ts_);
}

View File

@ -92,7 +92,6 @@ namespace l
rv = fs::movefile_as_root(config.moveonenospc.policy,
config.branches,
config.minfreespace,
fi_->fusepath,
&fi_->fd);
if(rv == -1)

View File

@ -74,7 +74,6 @@ namespace l
rv = fs::movefile_as_root(config.moveonenospc.policy,
config.branches,
config.minfreespace,
fi_->fusepath,
&fi_->fd);
if(rv == -1)

1715
src/nonstd/optional.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -14,11 +14,19 @@
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "ef.hpp"
#include <string>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#define KB (1024UL)
#define MB (KB * 1024UL)
#define GB (MB * 1024UL)
#define TB (GB * 1024UL)
namespace num
{
@ -98,3 +106,27 @@ namespace num
return 0;
}
}
namespace num
{
std::string
humanize(const uint64_t bytes_)
{
char buf[64];
if(bytes_ < KB)
sprintf(buf,"%lu",bytes_);
ef(((bytes_ / TB) * TB) == bytes_)
sprintf(buf,"%luT",bytes_ / TB);
ef(((bytes_ / GB) * GB) == bytes_)
sprintf(buf,"%luG",bytes_ / GB);
ef(((bytes_ / MB) * MB) == bytes_)
sprintf(buf,"%luM",bytes_ / MB);
ef(((bytes_ / KB) * KB) == bytes_)
sprintf(buf,"%luK",bytes_ / KB);
else
sprintf(buf,"%lu",bytes_);
return std::string(buf);
}
}

View File

@ -26,3 +26,8 @@ namespace num
int to_double(const std::string &str, double *value);
int to_time_t(const std::string &str, time_t *value);
}
namespace num
{
std::string humanize(const uint64_t bytes);
}

View File

@ -419,7 +419,7 @@ option_processor(void *data_,
return process_opt(data,arg_);
case FUSE_OPT_KEY_NONOPT:
if(data->config->branches.empty())
if(data->config->branches.vec.empty())
return process_branches(data,arg_);
else
return process_mount(data,arg_);

View File

@ -66,7 +66,7 @@ public:
typedef const uint64_t cuint64_t;
typedef const strvec cstrvec;
typedef int (*Ptr)(Category,const Branches &,const char *,cuint64_t,strvec *);
typedef int (*Ptr)(Category,const Branches&,const char*,strvec *);
template <Category T>
class Base
@ -81,26 +81,26 @@ public:
{}
int
operator()(const Branches &b,const char *c,cuint64_t d,strvec *e)
operator()(const Branches &a,const char *b,strvec *c)
{
return func(T,b,c,d,e);
return func(T,a,b,c);
}
int
operator()(const Branches &b,const string &c,cuint64_t d,strvec *e)
operator()(const Branches &a,const string &b,strvec *c)
{
return func(T,b,c.c_str(),d,e);
return func(T,a,b.c_str(),c);
}
int
operator()(const Branches &b,const char *c,cuint64_t d,string *e)
operator()(const Branches &a,const char *b,string *c)
{
int rv;
strvec v;
rv = func(T,b,c,d,&v);
rv = func(T,a,b,&v);
if(!v.empty())
*e = v[0];
*c = v[0];
return rv;
}
@ -113,27 +113,27 @@ public:
typedef Base<Category::CREATE> Create;
typedef Base<Category::SEARCH> Search;
static int invalid(Category,const Branches&,const char *,cuint64_t,strvec*);
static int all(Category,const Branches&,const char*,cuint64_t,strvec*);
static int epall(Category,const Branches&,const char*,cuint64_t,strvec*);
static int epff(Category,const Branches&,const char *,cuint64_t,strvec*);
static int eplfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int eplus(Category,const Branches&,const char *,cuint64_t,strvec*);
static int epmfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int eppfrd(Category,const Branches&,const char *,cuint64_t,strvec*);
static int eprand(Category,const Branches&,const char *,cuint64_t,strvec*);
static int erofs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int ff(Category,const Branches&,const char *,cuint64_t,strvec*);
static int lfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int lus(Category,const Branches&,const char *,cuint64_t,strvec*);
static int mfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int msplfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int msplus(Category,const Branches&,const char *,cuint64_t,strvec*);
static int mspmfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int msppfrd(Category,const Branches&,const char *,cuint64_t,strvec*);
static int newest(Category,const Branches&,const char *,cuint64_t,strvec*);
static int pfrd(Category,const Branches&,const char *,cuint64_t,strvec*);
static int rand(Category,const Branches&,const char *,cuint64_t,strvec*);
static int invalid(Category,const Branches&,const char *,strvec*);
static int all(Category,const Branches&,const char*,strvec*);
static int epall(Category,const Branches&,const char*,strvec*);
static int epff(Category,const Branches&,const char *,strvec*);
static int eplfs(Category,const Branches&,const char *,strvec*);
static int eplus(Category,const Branches&,const char *,strvec*);
static int epmfs(Category,const Branches&,const char *,strvec*);
static int eppfrd(Category,const Branches&,const char *,strvec*);
static int eprand(Category,const Branches&,const char *,strvec*);
static int erofs(Category,const Branches&,const char *,strvec*);
static int ff(Category,const Branches&,const char *,strvec*);
static int lfs(Category,const Branches&,const char *,strvec*);
static int lus(Category,const Branches&,const char *,strvec*);
static int mfs(Category,const Branches&,const char *,strvec*);
static int msplfs(Category,const Branches&,const char *,strvec*);
static int msplus(Category,const Branches&,const char *,strvec*);
static int mspmfs(Category,const Branches&,const char *,strvec*);
static int msppfrd(Category,const Branches&,const char *,strvec*);
static int newest(Category,const Branches&,const char *,strvec*);
static int pfrd(Category,const Branches&,const char *,strvec*);
static int rand(Category,const Branches&,const char *,strvec*);
};
private:

View File

@ -32,12 +32,9 @@ namespace all
{
static
int
create(const Branches &branches_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
fs::info_t info;
@ -55,7 +52,7 @@ namespace all
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch->path);
@ -66,17 +63,26 @@ namespace all
return 0;
}
static
int
create(const Branches &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return all::create(branches_.vec,paths_);
}
}
int
Policy::Func::all(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return all::create(branches_,minfreespace_,paths_);
return all::create(branches_,paths_);
return Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::epall(type_,branches_,fusepath_,paths_);
}

View File

@ -94,7 +94,6 @@ int
PolicyCache::operator()(Policy::Func::Search &func_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
std::string *branch_)
{
int rv;
@ -103,7 +102,7 @@ PolicyCache::operator()(Policy::Func::Search &func_,
string branch;
if(timeout == 0)
return func_(branches_,fusepath_,minfreespace_,branch_);
return func_(branches_,fusepath_,branch_);
now = l::get_time();
@ -113,7 +112,7 @@ PolicyCache::operator()(Policy::Func::Search &func_,
if((now - v->time) >= timeout)
{
pthread_mutex_unlock(&_lock);
rv = func_(branches_,fusepath_,minfreespace_,&branch);
rv = func_(branches_,fusepath_,&branch);
if(rv == -1)
return -1;

View File

@ -49,7 +49,6 @@ public:
int operator()(Policy::Func::Search &func,
const Branches &branches,
const char *fusepath,
const uint64_t minfreespace,
std::string *branch);
public:

View File

@ -33,13 +33,10 @@ namespace epall
{
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
fs::info_t info;
@ -50,16 +47,16 @@ namespace epall
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro_or_nc())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch->path);
@ -73,12 +70,21 @@ namespace epall
static
int
action(const Branches &branches_,
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
return epall::create(branches_.vec,fusepath_,paths_);
}
static
int
action(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int rv;
int error;
bool readonly;
@ -89,10 +95,10 @@ namespace epall
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::statvfs_cache_readonly(branch->path,&readonly);
if(rv == -1)
error_and_continue(error,ENOENT);
@ -110,12 +116,21 @@ namespace epall
static
int
search(const Branches &branches_,
action(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
return epall::action(branches_.vec,fusepath_,paths_);
}
static
int
search(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
const Branch *branch;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
@ -133,19 +148,29 @@ namespace epall
return 0;
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return epall::search(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::epall(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
switch(type_)
{
case Category::CREATE:
return epall::create(branches_,fusepath_,minfreespace_,paths_);
return epall::create(branches_,fusepath_,paths_);
case Category::ACTION:
return epall::action(branches_,fusepath_,paths_);
case Category::SEARCH:

View File

@ -33,13 +33,10 @@ namespace epff
{
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
fs::info_t info;
@ -50,16 +47,16 @@ namespace epff
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro_or_nc())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch->path);
@ -72,12 +69,21 @@ namespace epff
static
int
action(const Branches &branches_,
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
return epff::create(branches_.vec,fusepath_,paths_);
}
static
int
action(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int rv;
int error;
bool readonly;
@ -88,10 +94,10 @@ namespace epff
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::statvfs_cache_readonly(branch->path,&readonly);
if(rv == -1)
error_and_continue(error,ENOENT);
@ -108,12 +114,21 @@ namespace epff
static
int
search(const Branches &branches_,
action(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
return epff::action(branches_.vec,fusepath_,paths_);
}
static
int
search(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
const Branch *branch;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
@ -130,19 +145,29 @@ namespace epff
return (errno=ENOENT,-1);
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return epff::search(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::epff(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
switch(type_)
{
case Category::CREATE:
return epff::create(branches_,fusepath_,minfreespace_,paths_);
return epff::create(branches_,fusepath_,paths_);
case Category::ACTION:
return epff::action(branches_,fusepath_,paths_);
case Category::SEARCH:

View File

@ -34,49 +34,101 @@ namespace eplfs
{
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
uint64_t eplfs;
fs::info_t info;
const Branch *branch;
const string *eplfsbasepath;
const string *basepath;
error = ENOENT;
eplfs = std::numeric_limits<uint64_t>::max();
eplfsbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro_or_nc())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
if(info.spaceavail > eplfs)
continue;
eplfs = info.spaceavail;
eplfsbasepath = &branch->path;
basepath = &branch->path;
}
if(eplfsbasepath == NULL)
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*eplfsbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return eplfs::create(branches_.vec,fusepath_,paths_);
}
static
int
action(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int rv;
int error;
uint64_t eplfs;
fs::info_t info;
const Branch *branch;
const string *basepath;
error = ENOENT;
eplfs = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(branch->ro())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail > eplfs)
continue;
eplfs = info.spaceavail;
basepath = &branch->path;
}
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*basepath);
return 0;
}
@ -87,62 +139,25 @@ namespace eplfs
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
int rv;
int error;
uint64_t eplfs;
fs::info_t info;
const Branch *branch;
const string *eplfsbasepath;
error = ENOENT;
eplfs = std::numeric_limits<uint64_t>::max();
eplfsbasepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro())
error_and_continue(error,EROFS);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail > eplfs)
continue;
eplfs = info.spaceavail;
eplfsbasepath = &branch->path;
}
if(eplfsbasepath == NULL)
return (errno=error,-1);
paths_->push_back(*eplfsbasepath);
return 0;
return eplfs::action(branches_.vec,fusepath_,paths_);
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
search(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
uint64_t eplfs;
uint64_t spaceavail;
const Branch *branch;
const string *eplfsbasepath;
const string *basepath;
eplfs = std::numeric_limits<uint64_t>::max();
eplfsbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
@ -156,29 +171,39 @@ namespace eplfs
continue;
eplfs = spaceavail;
eplfsbasepath = &branch->path;
basepath = &branch->path;
}
if(eplfsbasepath == NULL)
if(basepath == NULL)
return (errno=ENOENT,-1);
paths_->push_back(*eplfsbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return eplfs::search(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::eplfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
switch(type_)
{
case Category::CREATE:
return eplfs::create(branches_,fusepath_,minfreespace_,paths_);
return eplfs::create(branches_,fusepath_,paths_);
case Category::ACTION:
return eplfs::action(branches_,fusepath_,paths_);
case Category::SEARCH:

View File

@ -34,49 +34,101 @@ namespace eplus
{
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
uint64_t eplus;
fs::info_t info;
const Branch *branch;
const string *eplusbasepath;
const string *basepath;
error = ENOENT;
eplus = std::numeric_limits<uint64_t>::max();
eplusbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro_or_nc())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
if(info.spaceused >= eplus)
continue;
eplus = info.spaceused;
eplusbasepath = &branch->path;
basepath = &branch->path;
}
if(eplusbasepath == NULL)
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*eplusbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return eplus::create(branches_.vec,fusepath_,paths_);
}
static
int
action(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int rv;
int error;
uint64_t eplus;
fs::info_t info;
const Branch *branch;
const string *basepath;
error = ENOENT;
eplus = std::numeric_limits<uint64_t>::max();
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(branch->ro())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceused >= eplus)
continue;
eplus = info.spaceused;
basepath = &branch->path;
}
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*basepath);
return 0;
}
@ -87,62 +139,25 @@ namespace eplus
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
int rv;
int error;
uint64_t eplus;
fs::info_t info;
const Branch *branch;
const string *eplusbasepath;
error = ENOENT;
eplus = std::numeric_limits<uint64_t>::max();
eplusbasepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro())
error_and_continue(error,EROFS);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceused >= eplus)
continue;
eplus = info.spaceused;
eplusbasepath = &branch->path;
}
if(eplusbasepath == NULL)
return (errno=error,-1);
paths_->push_back(*eplusbasepath);
return 0;
return eplus::action(branches_.vec,fusepath_,paths_);
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
search(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
uint64_t eplus;
uint64_t spaceused;
const Branch *branch;
const string *eplusbasepath;
const string *basepath;
eplus = 0;
eplusbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
@ -156,29 +171,39 @@ namespace eplus
continue;
eplus = spaceused;
eplusbasepath = &branch->path;
basepath = &branch->path;
}
if(eplusbasepath == NULL)
if(basepath == NULL)
return (errno=ENOENT,-1);
paths_->push_back(*eplusbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return eplus::search(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::eplus(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
switch(type_)
{
case Category::CREATE:
return eplus::create(branches_,fusepath_,minfreespace_,paths_);
return eplus::create(branches_,fusepath_,paths_);
case Category::ACTION:
return eplus::action(branches_,fusepath_,paths_);
case Category::SEARCH:

View File

@ -34,49 +34,101 @@ namespace epmfs
{
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
uint64_t epmfs;
fs::info_t info;
const Branch *branch;
const string *epmfsbasepath;
const string *basepath;
error = ENOENT;
epmfs = std::numeric_limits<uint64_t>::min();
epmfsbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro_or_nc())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
if(info.spaceavail < epmfs)
continue;
epmfs = info.spaceavail;
epmfsbasepath = &branch->path;
basepath = &branch->path;
}
if(epmfsbasepath == NULL)
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*epmfsbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return epmfs::create(branches_.vec,fusepath_,paths_);
}
static
int
action(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int rv;
int error;
uint64_t epmfs;
fs::info_t info;
const Branch *branch;
const string *basepath;
error = ENOENT;
epmfs = std::numeric_limits<uint64_t>::min();
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(branch->ro())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < epmfs)
continue;
epmfs = info.spaceavail;
basepath = &branch->path;
}
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*basepath);
return 0;
}
@ -87,62 +139,25 @@ namespace epmfs
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
int rv;
int error;
uint64_t epmfs;
fs::info_t info;
const Branch *branch;
const string *epmfsbasepath;
error = ENOENT;
epmfs = std::numeric_limits<uint64_t>::min();
epmfsbasepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_))
error_and_continue(error,ENOENT);
if(branch->ro())
error_and_continue(error,EROFS);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < epmfs)
continue;
epmfs = info.spaceavail;
epmfsbasepath = &branch->path;
}
if(epmfsbasepath == NULL)
return (errno=error,-1);
paths_->push_back(*epmfsbasepath);
return 0;
return epmfs::action(branches_.vec,fusepath_,paths_);
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
search(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
uint64_t epmfs;
uint64_t spaceavail;
const Branch *branch;
const string *epmfsbasepath;
const string *basepath;
epmfs = 0;
epmfsbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
@ -156,29 +171,39 @@ namespace epmfs
continue;
epmfs = spaceavail;
epmfsbasepath = &branch->path;
basepath = &branch->path;
}
if(epmfsbasepath == NULL)
if(basepath == NULL)
return (errno=ENOENT,-1);
paths_->push_back(*epmfsbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
search(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return epmfs::search(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::epmfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
switch(type_)
{
case Category::CREATE:
return epmfs::create(branches_,fusepath_,minfreespace_,paths_);
return epmfs::create(branches_,fusepath_,paths_);
case Category::ACTION:
return epmfs::action(branches_,fusepath_,paths_);
case Category::SEARCH:

View File

@ -42,18 +42,16 @@ namespace eppfrd
{
static
int
get_branchinfo_create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
get_branchinfo_create(const BranchVec &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
const Branch *branch;
rwlock::ReadGuard guard(&branches_.lock);
*sum_ = 0;
error = ENOENT;
@ -70,7 +68,7 @@ namespace eppfrd
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
*sum_ += info.spaceavail;
@ -85,18 +83,30 @@ namespace eppfrd
static
int
get_branchinfo_action(const Branches &branches_,
get_branchinfo_create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
rwlock::ReadGuard guard(branches_.lock);
branchinfo_->reserve(branches_.vec.size());
return eppfrd::get_branchinfo_create(branches_.vec,fusepath_,branchinfo_,sum_);
}
static
int
get_branchinfo_action(const BranchVec &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
const Branch *branch;
rwlock::ReadGuard guard(&branches_.lock);
*sum_ = 0;
error = ENOENT;
@ -126,17 +136,29 @@ namespace eppfrd
static
int
get_branchinfo_search(const Branches &branches_,
get_branchinfo_action(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
rwlock::ReadGuard guard(branches_.lock);
branchinfo_->reserve(branches_.vec.size());
return eppfrd::get_branchinfo_action(branches_.vec,fusepath_,branchinfo_,sum_);
}
static
int
get_branchinfo_search(const BranchVec &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
BranchInfo bi;
uint64_t spaceavail;
const Branch *branch;
rwlock::ReadGuard guard(&branches_.lock);
*sum_ = 0;
for(size_t i = 0, ei = branches_.size(); i < ei; i++)
@ -159,6 +181,20 @@ namespace eppfrd
return ENOENT;
}
static
int
get_branchinfo_search(const Branches &branches_,
const char *fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
rwlock::ReadGuard guard(branches_.lock);
branchinfo_->reserve(branches_.vec.size());
return eppfrd::get_branchinfo_search(branches_.vec,fusepath_,branchinfo_,sum_);
}
static
const
string*
@ -187,7 +223,6 @@ namespace eppfrd
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int error;
@ -195,8 +230,7 @@ namespace eppfrd
const string *basepath;
BranchInfoVec branchinfo;
branchinfo.reserve(branches_.size());
error = eppfrd::get_branchinfo_create(branches_,fusepath_,minfreespace_,&branchinfo,&sum);
error = eppfrd::get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum);
basepath = eppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
return (errno=error,-1);
@ -210,7 +244,6 @@ namespace eppfrd
int
action(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int error;
@ -218,8 +251,7 @@ namespace eppfrd
const string *basepath;
BranchInfoVec branchinfo;
branchinfo.reserve(branches_.size());
error = eppfrd::get_branchinfo_action(branches_,fusepath_,minfreespace_,&branchinfo,&sum);
error = eppfrd::get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum);
basepath = eppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
return (errno=error,-1);
@ -233,7 +265,6 @@ namespace eppfrd
int
search(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int error;
@ -241,8 +272,7 @@ namespace eppfrd
const string *basepath;
BranchInfoVec branchinfo;
branchinfo.reserve(branches_.size());
error = eppfrd::get_branchinfo_search(branches_,fusepath_,minfreespace_,&branchinfo,&sum);
error = eppfrd::get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum);
basepath = eppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
return (errno=error,-1);
@ -257,17 +287,16 @@ int
Policy::Func::eppfrd(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
switch(type_)
{
case Category::CREATE:
return eppfrd::create(branches_,fusepath_,minfreespace_,paths_);
return eppfrd::create(branches_,fusepath_,paths_);
case Category::ACTION:
return eppfrd::action(branches_,fusepath_,minfreespace_,paths_);
return eppfrd::action(branches_,fusepath_,paths_);
default:
case Category::SEARCH:
return eppfrd::search(branches_,fusepath_,minfreespace_,paths_);
return eppfrd::search(branches_,fusepath_,paths_);
}
}

View File

@ -28,12 +28,11 @@ int
Policy::Func::eprand(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int rv;
rv = Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_);
rv = Policy::Func::epall(type_,branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());

View File

@ -27,7 +27,6 @@ int
Policy::Func::erofs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths)
{
return (errno=EROFS,-1);

View File

@ -32,12 +32,9 @@ namespace ff
{
static
int
create(const Branches &branches_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
fs::info_t info;
@ -55,7 +52,7 @@ namespace ff
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
paths_->push_back(branch->path);
@ -65,17 +62,26 @@ namespace ff
return (errno=error,-1);
}
static
int
create(const Branches &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return ff::create(branches_.vec,paths_);
}
}
int
Policy::Func::ff(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return ff::create(branches_,minfreespace_,paths_);
return ff::create(branches_,paths_);
return Policy::Func::epff(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::epff(type_,branches_,fusepath_,paths_);
}

View File

@ -27,7 +27,6 @@ int
Policy::Func::invalid(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
return (errno=EINVAL,-1);

View File

@ -33,22 +33,19 @@ namespace lfs
{
static
int
create(const Branches &branches_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
uint64_t lfs;
fs::info_t info;
const Branch *branch;
const string *lfsbasepath;
const string *basepath;
error = ENOENT;
lfs = std::numeric_limits<uint64_t>::max();
lfsbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
@ -60,33 +57,42 @@ namespace lfs
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
if(info.spaceavail > lfs)
continue;
lfs = info.spaceavail;
lfsbasepath = &branch->path;
basepath = &branch->path;
}
if(lfsbasepath == NULL)
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*lfsbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
create(const Branches &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return lfs::create(branches_.vec,paths_);
}
}
int
Policy::Func::lfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return lfs::create(branches_,minfreespace_,paths_);
return lfs::create(branches_,paths_);
return Policy::Func::eplfs(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eplfs(type_,branches_,fusepath_,paths_);
}

View File

@ -33,22 +33,19 @@ namespace lus
{
static
int
create(const Branches &branches_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
uint64_t lus;
fs::info_t info;
const Branch *branch;
const string *lusbasepath;
const string *basepath;
error = ENOENT;
lus = std::numeric_limits<uint64_t>::max();
lusbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
@ -60,33 +57,42 @@ namespace lus
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
if(info.spaceused >= lus)
continue;
lus = info.spaceused;
lusbasepath = &branch->path;
lus = info.spaceused;
basepath = &branch->path;
}
if(lusbasepath == NULL)
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*lusbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
create(const Branches &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return lus::create(branches_.vec,paths_);
}
}
int
Policy::Func::lus(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return lus::create(branches_,minfreespace_,paths_);
return lus::create(branches_,paths_);
return Policy::Func::eplus(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eplus(type_,branches_,fusepath_,paths_);
}

View File

@ -32,22 +32,19 @@ namespace mfs
{
static
int
create(const Branches &branches_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
uint64_t mfs;
fs::info_t info;
const Branch *branch;
const string *mfsbasepath;
const string *basepath;
error = ENOENT;
mfs = 0;
mfsbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
@ -59,33 +56,42 @@ namespace mfs
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
if(info.spaceavail < mfs)
continue;
mfs = info.spaceavail;
mfsbasepath = &branch->path;
basepath = &branch->path;
}
if(mfsbasepath == NULL)
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*mfsbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
create(const Branches &branches_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return mfs::create(branches_.vec,paths_);
}
}
int
Policy::Func::mfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return mfs::create(branches_,minfreespace_,paths_);
return mfs::create(branches_,paths_);
return Policy::Func::epmfs(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::epmfs(type_,branches_,fusepath_,paths_);
}

View File

@ -36,10 +36,9 @@ namespace msplfs
static
const
string*
create_1(const Branches &branches_,
const string &fusepath_,
const uint64_t minfreespace_,
int *err_)
create_1(const BranchVec &branches_,
const string &fusepath_,
int *err_)
{
int rv;
uint64_t lfs;
@ -54,16 +53,16 @@ namespace msplfs
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath))
error_and_continue(*err_,ENOENT);
if(branch->ro_or_nc())
error_and_continue(*err_,EROFS);
if(!fs::exists(branch->path,fusepath))
error_and_continue(*err_,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(*err_,ENOENT);
if(info.readonly)
error_and_continue(*err_,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(*err_,ENOSPC);
if(info.spaceavail > lfs)
continue;
@ -77,21 +76,19 @@ namespace msplfs
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int error;
string fusepath;
const string *basepath;
rwlock::ReadGuard guard(&branches_.lock);
error = ENOENT;
fusepath = fusepath_;
do
{
basepath = create_1(branches_,fusepath,minfreespace_,&error);
basepath = msplfs::create_1(branches_,fusepath,&error);
if(basepath)
break;
@ -106,17 +103,27 @@ namespace msplfs
return 0;
}
static
int
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return msplfs::create(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::msplfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return msplfs::create(branches_,fusepath_,minfreespace_,paths_);
return msplfs::create(branches_,fusepath_,paths_);
return Policy::Func::eplfs(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eplfs(type_,branches_,fusepath_,paths_);
}

View File

@ -36,10 +36,9 @@ namespace msplus
static
const
string*
create_1(const Branches &branches_,
const string &fusepath_,
const uint64_t minfreespace_,
int *err_)
create_1(const BranchVec &branches_,
const string &fusepath_,
int *err_)
{
int rv;
uint64_t lus;
@ -54,16 +53,16 @@ namespace msplus
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath))
error_and_continue(*err_,ENOENT);
if(branch->ro_or_nc())
error_and_continue(*err_,EROFS);
if(!fs::exists(branch->path,fusepath))
error_and_continue(*err_,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(*err_,ENOENT);
if(info.readonly)
error_and_continue(*err_,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(*err_,ENOSPC);
if(info.spaceused >= lus)
continue;
@ -77,21 +76,19 @@ namespace msplus
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int error;
string fusepath;
const string *basepath;
rwlock::ReadGuard guard(&branches_.lock);
error = ENOENT;
fusepath = fusepath_;
do
{
basepath = create_1(branches_,fusepath,minfreespace_,&error);
basepath = msplus::create_1(branches_,fusepath,&error);
if(basepath)
break;
@ -106,17 +103,27 @@ namespace msplus
return 0;
}
static
int
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return msplus::create(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::msplus(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return msplus::create(branches_,fusepath_,minfreespace_,paths_);
return msplus::create(branches_,fusepath_,paths_);
return Policy::Func::eplus(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eplus(type_,branches_,fusepath_,paths_);
}

View File

@ -36,10 +36,9 @@ namespace mspmfs
static
const
string*
create_1(const Branches &branches_,
const string &fusepath_,
const uint64_t minfreespace_,
int *err_)
create_1(const BranchVec &branches_,
const string &fusepath_,
int *err_)
{
int rv;
uint64_t mfs;
@ -54,16 +53,16 @@ namespace mspmfs
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath))
error_and_continue(*err_,ENOENT);
if(branch->ro_or_nc())
error_and_continue(*err_,EROFS);
if(!fs::exists(branch->path,fusepath))
error_and_continue(*err_,ENOENT);
rv = fs::info(branch->path,&info);
if(rv == -1)
error_and_continue(*err_,ENOENT);
if(info.readonly)
error_and_continue(*err_,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(*err_,ENOSPC);
if(info.spaceavail < mfs)
continue;
@ -77,21 +76,19 @@ namespace mspmfs
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int error;
string fusepath;
const string *basepath;
rwlock::ReadGuard guard(&branches_.lock);
error = ENOENT;
fusepath = fusepath_;
do
{
basepath = create_1(branches_,fusepath,minfreespace_,&error);
basepath = mspmfs::create_1(branches_,fusepath,&error);
if(basepath)
break;
@ -106,17 +103,27 @@ namespace mspmfs
return 0;
}
static
int
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return mspmfs::create(branches_.vec,fusepath_,paths_);
}
}
int
Policy::Func::mspmfs(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return mspmfs::create(branches_,fusepath_,minfreespace_,paths_);
return mspmfs::create(branches_,fusepath_,paths_);
return Policy::Func::epmfs(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::epmfs(type_,branches_,fusepath_,paths_);
}

View File

@ -44,18 +44,16 @@ namespace msppfrd
{
static
int
create_1(const Branches &branches_,
const string &fusepath_,
const uint64_t minfreespace_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
create_1(const BranchVec &branches_,
const string &fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
const Branch *branch;
rwlock::ReadGuard guard(&branches_.lock);
*sum_ = 0;
error = ENOENT;
@ -72,7 +70,7 @@ namespace msppfrd
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
*sum_ += info.spaceavail;
@ -85,11 +83,24 @@ namespace msppfrd
return error;
}
static
int
create_1(const Branches &branches_,
const string &fusepath_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
rwlock::ReadGuard guard(branches_.lock);
branchinfo_->reserve(branches_.vec.size());
return msppfrd::create_1(branches_.vec,fusepath_,branchinfo_,sum_);
}
static
int
get_branchinfo(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
@ -99,7 +110,7 @@ namespace msppfrd
fusepath = fusepath_;
do
{
error = msppfrd::create_1(branches_,fusepath,minfreespace_,branchinfo_,sum_);
error = msppfrd::create_1(branches_,fusepath,branchinfo_,sum_);
if(branchinfo_->size())
return error;
@ -138,7 +149,6 @@ namespace msppfrd
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int error;
@ -146,8 +156,7 @@ namespace msppfrd
const string *basepath;
BranchInfoVec branchinfo;
branchinfo.reserve(branches_.size());
error = msppfrd::get_branchinfo(branches_,fusepath_,minfreespace_,&branchinfo,&sum);
error = msppfrd::get_branchinfo(branches_,fusepath_,&branchinfo,&sum);
basepath = msppfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
return (errno=error,-1);
@ -162,11 +171,10 @@ int
Policy::Func::msppfrd(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return msppfrd::create(branches_,fusepath_,minfreespace_,paths_);
return msppfrd::create(branches_,fusepath_,paths_);
return Policy::Func::eppfrd(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eppfrd(type_,branches_,fusepath_,paths_);
}

View File

@ -36,32 +36,29 @@ namespace newest
{
static
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
create(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
int rv;
int error;
time_t newest;
struct stat st;
fs::info_t info;
const Branch *branch;
const string *newestbasepath;
const string *basepath;
error = ENOENT;
newest = std::numeric_limits<time_t>::min();
newestbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_,&st))
error_and_continue(error,ENOENT);
if(branch->ro_or_nc())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_,&st))
error_and_continue(error,ENOENT);
if(st.st_mtime < newest)
continue;
rv = fs::info(branch->path,&info);
@ -69,17 +66,73 @@ namespace newest
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
newest = st.st_mtime;
newestbasepath = &branch->path;
basepath = &branch->path;
}
if(newestbasepath == NULL)
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*newestbasepath);
paths_->push_back(*basepath);
return 0;
}
static
int
create(const Branches &branches_,
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(branches_.lock);
return newest::create(branches_.vec,fusepath_,paths_);
}
static
int
action(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
int rv;
int error;
bool readonly;
time_t newest;
struct stat st;
const Branch *branch;
const string *basepath;
error = ENOENT;
newest = std::numeric_limits<time_t>::min();
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(branch->ro())
error_and_continue(error,EROFS);
if(!fs::exists(branch->path,fusepath_,&st))
error_and_continue(error,ENOENT);
if(st.st_mtime < newest)
continue;
rv = fs::statvfs_cache_readonly(branch->path,&readonly);
if(rv == -1)
error_and_continue(error,ENOENT);
if(readonly)
error_and_continue(error,EROFS);
newest = st.st_mtime;
basepath = &branch->path;
}
if(basepath == NULL)
return (errno=error,-1);
paths_->push_back(*basepath);
return 0;
}
@ -90,43 +143,41 @@ namespace newest
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
int rv;
int error;
bool readonly;
return newest::action(branches_.vec,fusepath_,paths_);
}
static
int
search(const BranchVec &branches_,
const char *fusepath_,
vector<string> *paths_)
{
time_t newest;
struct stat st;
const Branch *branch;
const string *newestbasepath;
const string *basepath;
error = ENOENT;
newest = std::numeric_limits<time_t>::min();
newestbasepath = NULL;
basepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_,&st))
error_and_continue(error,ENOENT);
if(branch->ro())
error_and_continue(error,EROFS);
continue;
if(st.st_mtime < newest)
continue;
rv = fs::statvfs_cache_readonly(branch->path,&readonly);
if(rv == -1)
error_and_continue(error,ENOENT);
if(readonly)
error_and_continue(error,EROFS);
newest = st.st_mtime;
newestbasepath = &branch->path;
basepath = &branch->path;
}
if(newestbasepath == NULL)
return (errno=error,-1);
if(basepath == NULL)
return (errno=ENOENT,-1);
paths_->push_back(*newestbasepath);
paths_->push_back(*basepath);
return 0;
}
@ -137,34 +188,9 @@ namespace newest
const char *fusepath_,
vector<string> *paths_)
{
rwlock::ReadGuard guard(&branches_.lock);
rwlock::ReadGuard guard(branches_.lock);
time_t newest;
struct stat st;
const Branch *branch;
const string *newestbasepath;
newest = std::numeric_limits<time_t>::min();
newestbasepath = NULL;
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
{
branch = &branches_[i];
if(!fs::exists(branch->path,fusepath_,&st))
continue;
if(st.st_mtime < newest)
continue;
newest = st.st_mtime;
newestbasepath = &branch->path;
}
if(newestbasepath == NULL)
return (errno=ENOENT,-1);
paths_->push_back(*newestbasepath);
return 0;
return newest::search(branches_.vec,fusepath_,paths_);
}
}
@ -172,13 +198,12 @@ int
Policy::Func::newest(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
switch(type_)
{
case Category::CREATE:
return newest::create(branches_,fusepath_,minfreespace_,paths_);
return newest::create(branches_,fusepath_,paths_);
case Category::ACTION:
return newest::action(branches_,fusepath_,paths_);
case Category::SEARCH:

View File

@ -40,17 +40,15 @@ namespace pfrd
{
static
int
get_branchinfo(const Branches &branches_,
const uint64_t minfreespace_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
get_branchinfo(const BranchVec &branches_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
int rv;
int error;
BranchInfo bi;
fs::info_t info;
const Branch *branch;
rwlock::ReadGuard guard(&branches_.lock);
*sum_ = 0;
error = ENOENT;
@ -65,7 +63,7 @@ namespace pfrd
error_and_continue(error,ENOENT);
if(info.readonly)
error_and_continue(error,EROFS);
if(info.spaceavail < minfreespace_)
if(info.spaceavail < branch->minfreespace())
error_and_continue(error,ENOSPC);
*sum_ += info.spaceavail;
@ -78,6 +76,19 @@ namespace pfrd
return error;
}
static
int
get_branchinfo(const Branches &branches_,
BranchInfoVec *branchinfo_,
uint64_t *sum_)
{
rwlock::ReadGuard guard(branches_.lock);
branchinfo_->reserve(branches_.vec.size());
return pfrd::get_branchinfo(branches_.vec,branchinfo_,sum_);
}
static
const
string*
@ -106,7 +117,6 @@ namespace pfrd
int
create(const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int error;
@ -114,8 +124,7 @@ namespace pfrd
const string *basepath;
BranchInfoVec branchinfo;
branchinfo.reserve(branches_.size());
error = pfrd::get_branchinfo(branches_,minfreespace_,&branchinfo,&sum);
error = pfrd::get_branchinfo(branches_,&branchinfo,&sum);
basepath = pfrd::get_branch(branchinfo,sum);
if(basepath == NULL)
return (errno=error,-1);
@ -130,11 +139,10 @@ int
Policy::Func::pfrd(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
if(type_ == Category::CREATE)
return pfrd::create(branches_,fusepath_,minfreespace_,paths_);
return pfrd::create(branches_,fusepath_,paths_);
return Policy::Func::eppfrd(type_,branches_,fusepath_,minfreespace_,paths_);
return Policy::Func::eppfrd(type_,branches_,fusepath_,paths_);
}

View File

@ -28,12 +28,11 @@ int
Policy::Func::rand(const Category type_,
const Branches &branches_,
const char *fusepath_,
const uint64_t minfreespace_,
vector<string> *paths_)
{
int rv;
rv = Policy::Func::all(type_,branches_,fusepath_,minfreespace_,paths_);
rv = Policy::Func::all(type_,branches_,fusepath_,paths_);
if(rv == 0)
{
std::random_shuffle(paths_->begin(),paths_->end());

View File

@ -23,42 +23,42 @@ namespace rwlock
class ReadGuard
{
public:
ReadGuard(pthread_rwlock_t *lock_)
ReadGuard(pthread_rwlock_t &lock_)
: _lock(lock_)
{
pthread_rwlock_rdlock(_lock);
pthread_rwlock_rdlock(&_lock);
}
~ReadGuard()
{
pthread_rwlock_unlock(_lock);
pthread_rwlock_unlock(&_lock);
}
private:
ReadGuard();
private:
pthread_rwlock_t *_lock;
pthread_rwlock_t &_lock;
};
class WriteGuard
{
public:
WriteGuard(pthread_rwlock_t *lock_)
WriteGuard(pthread_rwlock_t &lock_)
: _lock(lock_)
{
pthread_rwlock_wrlock(_lock);
pthread_rwlock_wrlock(&_lock);
}
~WriteGuard()
{
pthread_rwlock_unlock(_lock);
pthread_rwlock_unlock(&_lock);
}
private:
WriteGuard();
private:
pthread_rwlock_t *_lock;
pthread_rwlock_t &_lock;
};
}

View File

@ -46,6 +46,25 @@ namespace str
return str::split(str_.c_str(),delimiter_,result_);
}
void
rsplit1(const string &str_,
const char delimiter_,
vector<string> *result_)
{
std::size_t off;
off = str_.rfind('=');
if(off == std::string::npos)
{
result_->push_back(str_);
}
else
{
result_->push_back(str_.substr(0,off));
result_->push_back(str_.substr(off+1));
}
}
void
splitkv(const string &str_,
const char delimiter_,

View File

@ -30,6 +30,11 @@ namespace str
const char delimiter,
std::vector<std::string> *result);
void
rsplit1(const std::string &str,
const char delimiter,
std::vector<std::string> *result);
void
splitkv(const std::string &str,
const char delimiter,