mirror of https://github.com/trapexit/mergerfs.git
75 changed files with 71 additions and 4998 deletions
-
2config.toml
-
93src/branch.cpp
-
67src/branch.hpp
-
12src/branch_group.cpp
-
4src/branch_group.hpp
-
407src/branches.cpp
-
77src/branches.hpp
-
9src/fs_clonepath_branches.hpp
-
2src/fuse_access_policy_ff.hpp
-
2src/fuse_chmod_policy_all.hpp
-
2src/fuse_chown_policy_all.hpp
-
2src/fuse_create_policy_epff.hpp
-
2src/fuse_getattr_policy_aggregate.hpp
-
2src/fuse_getattr_policy_check_ff.hpp
-
2src/fuse_getattr_policy_ff.hpp
-
2src/fuse_getattr_policy_newest.hpp
-
2src/fuse_getxattr_policy_ff.hpp
-
2src/fuse_ioctl_policy_all.hpp
-
2src/fuse_listxattr_policy_ff.hpp
-
2src/fuse_mkdir_policy_epff.hpp
-
2src/fuse_mkdir_policy_ff.hpp
-
2src/fuse_mknod_policy_epff.hpp
-
2src/fuse_mknod_policy_ff.hpp
-
2src/fuse_open_policy_ff.hpp
-
2src/fuse_readdir_policy_posix.hpp
-
2src/fuse_readlink_policy_ff.hpp
-
2src/fuse_symlink_policy_ff.hpp
-
2src/fuse_truncate_policy_all.hpp
-
2src/fuse_utimens_policy_all.hpp
-
194src/policy.hpp
-
86src/policy_all.cpp
-
61src/policy_all.hpp
-
131src/policy_cache.cpp
-
62src/policy_cache.hpp
-
143src/policy_epall.cpp
-
64src/policy_epall.hpp
-
142src/policy_epff.cpp
-
61src/policy_epff.hpp
-
178src/policy_eplfs.cpp
-
61src/policy_eplfs.hpp
-
176src/policy_eplus.cpp
-
61src/policy_eplus.hpp
-
177src/policy_epmfs.cpp
-
64src/policy_epmfs.hpp
-
262src/policy_eppfrd.cpp
-
61src/policy_eppfrd.hpp
-
73src/policy_eprand.cpp
-
61src/policy_eprand.hpp
-
48src/policy_erofs.cpp
-
61src/policy_erofs.hpp
-
51src/policy_error.hpp
-
85src/policy_ff.cpp
-
61src/policy_ff.hpp
-
98src/policy_lfs.cpp
-
61src/policy_lfs.hpp
-
99src/policy_lus.cpp
-
61src/policy_lus.hpp
-
94src/policy_mfs.cpp
-
61src/policy_mfs.hpp
-
126src/policy_msplfs.cpp
-
61src/policy_msplfs.hpp
-
124src/policy_msplus.cpp
-
61src/policy_msplus.hpp
-
127src/policy_mspmfs.cpp
-
61src/policy_mspmfs.hpp
-
179src/policy_msppfrd.cpp
-
61src/policy_msppfrd.hpp
-
176src/policy_newest.cpp
-
61src/policy_newest.hpp
-
149src/policy_pfrd.cpp
-
61src/policy_pfrd.hpp
-
73src/policy_rand.cpp
-
61src/policy_rand.hpp
-
51src/policy_rv.hpp
-
2src/state.hpp
@ -1,194 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "branches.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
class ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
ActionImpl(const std::string &name_) |
|
||||
: name(name_) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
std::string name; |
|
||||
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0; |
|
||||
}; |
|
||||
|
|
||||
class Action |
|
||||
{ |
|
||||
public: |
|
||||
Action(ActionImpl *impl_) |
|
||||
: impl(impl_) |
|
||||
{} |
|
||||
|
|
||||
Action& |
|
||||
operator=(ActionImpl *impl_) |
|
||||
{ |
|
||||
impl = impl_; |
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
const |
|
||||
std::string& |
|
||||
name(void) const |
|
||||
{ |
|
||||
return impl->name; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (*impl)(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
operator()(const Branches::CPtr &branches_, |
|
||||
const std::string &fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (*impl)(branches_,fusepath_.c_str(),paths_); |
|
||||
} |
|
||||
|
|
||||
private: |
|
||||
ActionImpl *impl; |
|
||||
}; |
|
||||
|
|
||||
class CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
CreateImpl(const std::string &name_) |
|
||||
: name(name_) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
std::string name; |
|
||||
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0; |
|
||||
virtual bool path_preserving(void) const = 0; |
|
||||
}; |
|
||||
|
|
||||
class Create |
|
||||
{ |
|
||||
public: |
|
||||
Create(CreateImpl *impl_) |
|
||||
: impl(impl_) |
|
||||
{} |
|
||||
|
|
||||
Create& |
|
||||
operator=(CreateImpl *impl_) |
|
||||
{ |
|
||||
impl = impl_; |
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
const |
|
||||
std::string& |
|
||||
name(void) const |
|
||||
{ |
|
||||
return impl->name; |
|
||||
} |
|
||||
|
|
||||
bool |
|
||||
path_preserving(void) const |
|
||||
{ |
|
||||
return impl->path_preserving(); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (*impl)(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
operator()(const Branches::CPtr &branches_, |
|
||||
const std::string &fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (*impl)(branches_,fusepath_.c_str(),paths_); |
|
||||
} |
|
||||
|
|
||||
private: |
|
||||
CreateImpl *impl; |
|
||||
}; |
|
||||
|
|
||||
class SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
SearchImpl(const std::string &name_) |
|
||||
: name(name_) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
std::string name; |
|
||||
virtual int operator()(const Branches::CPtr&,const char*,StrVec*) const = 0; |
|
||||
}; |
|
||||
|
|
||||
class Search |
|
||||
{ |
|
||||
public: |
|
||||
Search(SearchImpl *impl_) |
|
||||
: impl(impl_) |
|
||||
{} |
|
||||
|
|
||||
Search& |
|
||||
operator=(SearchImpl *impl_) |
|
||||
{ |
|
||||
impl = impl_; |
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
const |
|
||||
std::string& |
|
||||
name(void) const |
|
||||
{ |
|
||||
return impl->name; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (*impl)(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
operator()(const Branches::CPtr &branches_, |
|
||||
const std::string &fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (*impl)(branches_,fusepath_.c_str(),paths_); |
|
||||
} |
|
||||
|
|
||||
private: |
|
||||
SearchImpl *impl; |
|
||||
}; |
|
||||
} |
|
@ -1,86 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
namespace all |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(branch.ro_or_nc()) |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
} |
|
||||
|
|
||||
if(paths_->empty()) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::All::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::epall(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::All::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::all::create(branches_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::All::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::epall(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace All |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("all") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("all") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("all") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,131 +0,0 @@ |
|||||
#include "policy_cache.hpp"
|
|
||||
|
|
||||
#include <cstdlib>
|
|
||||
#include <map>
|
|
||||
#include <string>
|
|
||||
|
|
||||
#include <time.h>
|
|
||||
|
|
||||
using std::map; |
|
||||
using std::string; |
|
||||
|
|
||||
static const uint64_t DEFAULT_TIMEOUT = 0; |
|
||||
|
|
||||
namespace l |
|
||||
{ |
|
||||
static |
|
||||
uint64_t |
|
||||
get_time(void) |
|
||||
{ |
|
||||
uint64_t rv; |
|
||||
|
|
||||
rv = ::time(NULL); |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
|
|
||||
PolicyCache::Value::Value() |
|
||||
: time(0), |
|
||||
paths() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
|
|
||||
PolicyCache::PolicyCache(void) |
|
||||
: timeout(DEFAULT_TIMEOUT) |
|
||||
{ |
|
||||
pthread_mutex_init(&_lock,NULL); |
|
||||
} |
|
||||
|
|
||||
void |
|
||||
PolicyCache::erase(const char *fusepath_) |
|
||||
{ |
|
||||
if(timeout == 0) |
|
||||
return; |
|
||||
|
|
||||
pthread_mutex_lock(&_lock); |
|
||||
|
|
||||
_cache.erase(fusepath_); |
|
||||
|
|
||||
pthread_mutex_unlock(&_lock); |
|
||||
} |
|
||||
|
|
||||
void |
|
||||
PolicyCache::cleanup(const int prob_) |
|
||||
{ |
|
||||
uint64_t now; |
|
||||
map<string,Value>::iterator i; |
|
||||
|
|
||||
if(timeout == 0) |
|
||||
return; |
|
||||
|
|
||||
if(rand() % prob_) |
|
||||
return; |
|
||||
|
|
||||
now = l::get_time(); |
|
||||
|
|
||||
pthread_mutex_lock(&_lock); |
|
||||
|
|
||||
i = _cache.begin(); |
|
||||
while(i != _cache.end()) |
|
||||
{ |
|
||||
if((now - i->second.time) >= timeout) |
|
||||
_cache.erase(i++); |
|
||||
else |
|
||||
++i; |
|
||||
} |
|
||||
|
|
||||
pthread_mutex_unlock(&_lock); |
|
||||
} |
|
||||
|
|
||||
void |
|
||||
PolicyCache::clear(void) |
|
||||
{ |
|
||||
pthread_mutex_lock(&_lock); |
|
||||
|
|
||||
_cache.clear(); |
|
||||
|
|
||||
pthread_mutex_unlock(&_lock); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
PolicyCache::operator()(const Policy::Search &policy_, |
|
||||
const Branches &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
Value *v; |
|
||||
uint64_t now; |
|
||||
|
|
||||
if(timeout == 0) |
|
||||
return policy_(branches_,fusepath_,paths_); |
|
||||
|
|
||||
now = l::get_time(); |
|
||||
|
|
||||
pthread_mutex_lock(&_lock); |
|
||||
v = &_cache[fusepath_]; |
|
||||
|
|
||||
if((now - v->time) >= timeout) |
|
||||
{ |
|
||||
pthread_mutex_unlock(&_lock); |
|
||||
|
|
||||
rv = policy_(branches_,fusepath_,paths_); |
|
||||
if(rv == -1) |
|
||||
return -1; |
|
||||
|
|
||||
pthread_mutex_lock(&_lock); |
|
||||
v->time = now; |
|
||||
v->paths = *paths_; |
|
||||
} |
|
||||
else |
|
||||
{ |
|
||||
*paths_ = v->paths; |
|
||||
} |
|
||||
|
|
||||
pthread_mutex_unlock(&_lock); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
@ -1,62 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <cstdint>
|
|
||||
#include <string>
|
|
||||
#include <map>
|
|
||||
|
|
||||
#include <pthread.h>
|
|
||||
|
|
||||
|
|
||||
class PolicyCache |
|
||||
{ |
|
||||
public: |
|
||||
struct Value |
|
||||
{ |
|
||||
Value(); |
|
||||
|
|
||||
uint64_t time; |
|
||||
StrVec paths; |
|
||||
}; |
|
||||
|
|
||||
public: |
|
||||
PolicyCache(void); |
|
||||
|
|
||||
public: |
|
||||
void erase(const char *fusepath); |
|
||||
void cleanup(const int prob = 1); |
|
||||
void clear(void); |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Policy::Search &policy, |
|
||||
const Branches &branches, |
|
||||
const char *fusepath, |
|
||||
StrVec *paths); |
|
||||
|
|
||||
public: |
|
||||
uint64_t timeout; |
|
||||
|
|
||||
private: |
|
||||
pthread_mutex_t _lock; |
|
||||
std::map<std::string,Value> _cache; |
|
||||
}; |
|
@ -1,143 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_epall.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
|
|
||||
namespace epall |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
} |
|
||||
|
|
||||
if(paths_->empty()) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
bool readonly; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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); |
|
||||
if(readonly) |
|
||||
error_and_continue(error,EROFS); |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
} |
|
||||
|
|
||||
if(paths_->empty()) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(!fs::exists(branch.path,fusepath_)) |
|
||||
continue; |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
} |
|
||||
|
|
||||
if(paths_->empty()) |
|
||||
return (errno=ENOENT,-1); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPAll::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epall::action(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPAll::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epall::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPAll::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epall::search(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,64 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace EPAll |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("epall") |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("epall") |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("epall") |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,142 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "branches.hpp"
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_epff.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "rwlock.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
namespace epff |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
return (errno=error,-1); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
bool readonly; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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); |
|
||||
if(readonly) |
|
||||
error_and_continue(error,EROFS); |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
return (errno=error,-1); |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(!fs::exists(branch.path,fusepath_)) |
|
||||
continue; |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
return (errno=ENOENT,-1); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPFF::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epff::action(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPFF::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epff::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPFF::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epff::search(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace EPFF |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("epff") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("epff") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("epff") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,178 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_eplfs.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
namespace eplfs |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t eplfs; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
eplfs = std::numeric_limits<uint64_t>::max(); |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
if(info.spaceavail > eplfs) |
|
||||
continue; |
|
||||
|
|
||||
eplfs = info.spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t eplfs; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
eplfs = std::numeric_limits<uint64_t>::max(); |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
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; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
uint64_t eplfs; |
|
||||
uint64_t spaceavail; |
|
||||
const string *basepath; |
|
||||
|
|
||||
eplfs = std::numeric_limits<uint64_t>::max(); |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
if(!fs::exists(branch.path,fusepath_)) |
|
||||
continue; |
|
||||
rv = fs::statvfs_cache_spaceavail(branch.path,&spaceavail); |
|
||||
if(rv == -1) |
|
||||
continue; |
|
||||
if(spaceavail > eplfs) |
|
||||
continue; |
|
||||
|
|
||||
eplfs = spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=ENOENT,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPLFS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eplfs::action(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPLFS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eplfs::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPLFS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eplfs::search(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace EPLFS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("eplfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("eplfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("eplfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,176 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_eplus.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "rwlock.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
namespace eplus |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t eplus; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
eplus = std::numeric_limits<uint64_t>::max(); |
|
||||
basepath = NULL; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
if(info.spaceused >= eplus) |
|
||||
continue; |
|
||||
|
|
||||
eplus = info.spaceused; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t eplus; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
eplus = std::numeric_limits<uint64_t>::max(); |
|
||||
basepath = NULL; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
uint64_t eplus; |
|
||||
uint64_t spaceused; |
|
||||
const string *basepath; |
|
||||
|
|
||||
eplus = 0; |
|
||||
basepath = NULL; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(!fs::exists(branch.path,fusepath_)) |
|
||||
continue; |
|
||||
rv = fs::statvfs_cache_spaceused(branch.path,&spaceused); |
|
||||
if(rv == -1) |
|
||||
continue; |
|
||||
if(spaceused >= eplus) |
|
||||
continue; |
|
||||
|
|
||||
eplus = spaceused; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=ENOENT,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPLUS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eplus::action(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPLUS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eplus::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPLUS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eplus::search(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace EPLUS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("eplus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("eplus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("eplus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,177 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_epmfs.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
|
|
||||
namespace epmfs |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t epmfs; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
epmfs = std::numeric_limits<uint64_t>::min(); |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
if(info.spaceavail < epmfs) |
|
||||
continue; |
|
||||
|
|
||||
epmfs = info.spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t epmfs; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
epmfs = std::numeric_limits<uint64_t>::min(); |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
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; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
uint64_t epmfs; |
|
||||
uint64_t spaceavail; |
|
||||
const string *basepath; |
|
||||
|
|
||||
epmfs = 0; |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
if(!fs::exists(branch.path,fusepath_)) |
|
||||
continue; |
|
||||
rv = fs::statvfs_cache_spaceavail(branch.path,&spaceavail); |
|
||||
if(rv == -1) |
|
||||
continue; |
|
||||
if(spaceavail < epmfs) |
|
||||
continue; |
|
||||
|
|
||||
epmfs = spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=ENOENT,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPMFS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epmfs::action(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPMFS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epmfs::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPMFS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::epmfs::search(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,64 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace EPMFS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("epmfs") |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("epmfs") |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("epmfs") |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,262 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_eppfrd.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "rnd.hpp"
|
|
||||
#include "rwlock.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
struct BranchInfo |
|
||||
{ |
|
||||
uint64_t spaceavail; |
|
||||
const string *basepath; |
|
||||
}; |
|
||||
|
|
||||
typedef vector<BranchInfo> BranchInfoVec; |
|
||||
|
|
||||
namespace eppfrd |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
get_branchinfo_create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
BranchInfoVec *branchinfo_, |
|
||||
uint64_t *sum_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
BranchInfo bi; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
*sum_ = 0; |
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
*sum_ += info.spaceavail; |
|
||||
|
|
||||
bi.spaceavail = info.spaceavail; |
|
||||
bi.basepath = &branch.path; |
|
||||
branchinfo_->push_back(bi); |
|
||||
} |
|
||||
|
|
||||
return error; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
get_branchinfo_action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
BranchInfoVec *branchinfo_, |
|
||||
uint64_t *sum_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
BranchInfo bi; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
*sum_ = 0; |
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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); |
|
||||
|
|
||||
*sum_ += info.spaceavail; |
|
||||
|
|
||||
bi.spaceavail = info.spaceavail; |
|
||||
bi.basepath = &branch.path; |
|
||||
branchinfo_->push_back(bi); |
|
||||
} |
|
||||
|
|
||||
return error; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
get_branchinfo_search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
BranchInfoVec *branchinfo_, |
|
||||
uint64_t *sum_) |
|
||||
{ |
|
||||
int rv; |
|
||||
BranchInfo bi; |
|
||||
uint64_t spaceavail; |
|
||||
|
|
||||
*sum_ = 0; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(!fs::exists(branch.path,fusepath_)) |
|
||||
continue; |
|
||||
rv = fs::statvfs_cache_spaceavail(branch.path,&spaceavail); |
|
||||
if(rv == -1) |
|
||||
continue; |
|
||||
|
|
||||
*sum_ += spaceavail; |
|
||||
|
|
||||
bi.spaceavail = spaceavail; |
|
||||
bi.basepath = &branch.path; |
|
||||
branchinfo_->push_back(bi); |
|
||||
} |
|
||||
|
|
||||
return ENOENT; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
const |
|
||||
string* |
|
||||
get_branch(const BranchInfoVec &branchinfo_, |
|
||||
const uint64_t sum_) |
|
||||
{ |
|
||||
uint64_t idx; |
|
||||
uint64_t threshold; |
|
||||
|
|
||||
if(sum_ == 0) |
|
||||
return NULL; |
|
||||
|
|
||||
idx = 0; |
|
||||
threshold = RND::rand64(sum_); |
|
||||
for(size_t i = 0; i < branchinfo_.size(); i++) |
|
||||
{ |
|
||||
idx += branchinfo_[i].spaceavail; |
|
||||
|
|
||||
if(idx < threshold) |
|
||||
continue; |
|
||||
|
|
||||
return branchinfo_[i].basepath; |
|
||||
} |
|
||||
|
|
||||
return NULL; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
uint64_t sum; |
|
||||
const string *basepath; |
|
||||
BranchInfoVec branchinfo; |
|
||||
|
|
||||
error = eppfrd::get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum); |
|
||||
basepath = eppfrd::get_branch(branchinfo,sum); |
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
uint64_t sum; |
|
||||
const string *basepath; |
|
||||
BranchInfoVec branchinfo; |
|
||||
|
|
||||
error = eppfrd::get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum); |
|
||||
basepath = eppfrd::get_branch(branchinfo,sum); |
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
uint64_t sum; |
|
||||
const string *basepath; |
|
||||
BranchInfoVec branchinfo; |
|
||||
|
|
||||
error = eppfrd::get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum); |
|
||||
basepath = eppfrd::get_branch(branchinfo,sum); |
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPPFRD::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eppfrd::action(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPPFRD::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eppfrd::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPPFRD::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::eppfrd::search(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace EPPFRD |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("eppfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("eppfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("eppfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,73 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_eprand.hpp"
|
|
||||
|
|
||||
#include <algorithm>
|
|
||||
|
|
||||
int |
|
||||
Policy::EPRand::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
int rv; |
|
||||
|
|
||||
rv = Policies::Action::epall(branches_,fusepath_,paths_); |
|
||||
if(rv == 0) |
|
||||
{ |
|
||||
std::random_shuffle(paths_->begin(),paths_->end()); |
|
||||
paths_->resize(1); |
|
||||
} |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPRand::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
int rv; |
|
||||
|
|
||||
rv = Policies::Create::epall(branches_,fusepath_,paths_); |
|
||||
if(rv == 0) |
|
||||
{ |
|
||||
std::random_shuffle(paths_->begin(),paths_->end()); |
|
||||
paths_->resize(1); |
|
||||
} |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::EPRand::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
int rv; |
|
||||
|
|
||||
rv = Policies::Search::epall(branches_,fusepath_,paths_); |
|
||||
if(rv == 0) |
|
||||
{ |
|
||||
std::random_shuffle(paths_->begin(),paths_->end()); |
|
||||
paths_->resize(1); |
|
||||
} |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace EPRand |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("eprand") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("eprand") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("eprand") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,48 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_erofs.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
|
|
||||
int |
|
||||
Policy::ERoFS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (errno=EROFS,-1); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::ERoFS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (errno=EROFS,-1); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::ERoFS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return (errno=EROFS,-1); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace ERoFS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("erofs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("erofs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("erofs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,51 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2018, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#define error_and_continue(CUR,ERR) \
|
|
||||
{ \ |
|
||||
policy::calc_error(CUR,ERR); \ |
|
||||
continue; \ |
|
||||
} |
|
||||
|
|
||||
namespace policy |
|
||||
{ |
|
||||
static |
|
||||
inline |
|
||||
void |
|
||||
calc_error(int &cur_, |
|
||||
int err_) |
|
||||
{ |
|
||||
switch(cur_) |
|
||||
{ |
|
||||
default: |
|
||||
case ENOENT: |
|
||||
cur_ = err_; |
|
||||
break; |
|
||||
case ENOSPC: |
|
||||
if(err_ != ENOENT) |
|
||||
cur_ = err_; |
|
||||
break; |
|
||||
case EROFS: |
|
||||
if((err_ != ENOENT) && (err_ != ENOSPC)) |
|
||||
cur_ = err_; |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
} |
|
@ -1,85 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_ff.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
namespace ff |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(branch.ro_or_nc()) |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
paths_->push_back(branch.path); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
return (errno=error,-1); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::FF::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::epff(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::FF::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::ff::create(branches_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::FF::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::epff(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace FF |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("ff") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("ff") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving(void) const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("ff") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,98 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_lfs.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
namespace lfs |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t lfs; |
|
||||
fs::info_t info; |
|
||||
const Branch *branch; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
lfs = std::numeric_limits<uint64_t>::max(); |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
if(branch.ro_or_nc()) |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
if(info.spaceavail > lfs) |
|
||||
continue; |
|
||||
|
|
||||
lfs = info.spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::LFS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::eplfs(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::LFS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::lfs::create(branches_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::LFS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::eplfs(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace LFS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("lfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("lfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("lfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,99 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_lus.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
namespace lus |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t lus; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
lus = std::numeric_limits<uint64_t>::max(); |
|
||||
basepath = NULL; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(branch.ro_or_nc()) |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
if(info.spaceused >= lus) |
|
||||
continue; |
|
||||
|
|
||||
lus = info.spaceused; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::LUS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::eplus(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::LUS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::lus::create(branches_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::LUS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::eplus(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace LUS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("lus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("lus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("lus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,94 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
namespace mfs |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
uint64_t mfs; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
mfs = 0; |
|
||||
basepath = NULL; |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
if(branch.ro_or_nc()) |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
if(info.spaceavail < mfs) |
|
||||
continue; |
|
||||
|
|
||||
mfs = info.spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MFS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::epmfs(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MFS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::mfs::create(branches_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MFS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::epmfs(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace MFS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("mfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("mfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("mfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,126 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_msplfs.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
|
|
||||
namespace msplfs |
|
||||
{ |
|
||||
static |
|
||||
const |
|
||||
string* |
|
||||
create_1(const Branches::CPtr &branches_, |
|
||||
const string &fusepath_, |
|
||||
int *err_) |
|
||||
{ |
|
||||
int rv; |
|
||||
uint64_t lfs; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
basepath = NULL; |
|
||||
lfs = std::numeric_limits<uint64_t>::max(); |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(*err_,ENOSPC); |
|
||||
if(info.spaceavail > lfs) |
|
||||
continue; |
|
||||
|
|
||||
lfs = info.spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
return basepath; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
string fusepath; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
fusepath = fusepath_; |
|
||||
for(;;) |
|
||||
{ |
|
||||
basepath = msplfs::create_1(branches_,fusepath,&error); |
|
||||
if(basepath) |
|
||||
break; |
|
||||
if(fusepath == "/") |
|
||||
break; |
|
||||
fusepath = fs::path::dirname(fusepath); |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPLFS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::eplfs(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPLFS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::msplfs::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPLFS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::eplfs(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace MSPLFS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("msplfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("msplfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("msplfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,124 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_msplus.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
namespace msplus |
|
||||
{ |
|
||||
static |
|
||||
const |
|
||||
string* |
|
||||
create_1(const Branches::CPtr &branches_, |
|
||||
const string &fusepath_, |
|
||||
int *err_) |
|
||||
{ |
|
||||
int rv; |
|
||||
uint64_t lus; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
basepath = NULL; |
|
||||
lus = std::numeric_limits<uint64_t>::max(); |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(*err_,ENOSPC); |
|
||||
if(info.spaceused >= lus) |
|
||||
continue; |
|
||||
|
|
||||
lus = info.spaceused;; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
return basepath; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
string fusepath; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
fusepath = fusepath_; |
|
||||
for(;;) |
|
||||
{ |
|
||||
basepath = msplus::create_1(branches_,fusepath,&error); |
|
||||
if(basepath) |
|
||||
break; |
|
||||
if(fusepath == "/") |
|
||||
break; |
|
||||
fusepath = fs::path::dirname(fusepath); |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPLUS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::eplus(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPLUS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::msplus::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPLUS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::eplus(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace MSPLUS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("msplus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("msplus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("msplus") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,127 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_mspmfs.hpp"
|
|
||||
|
|
||||
#include <limits>
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
|
|
||||
namespace mspmfs |
|
||||
{ |
|
||||
static |
|
||||
const |
|
||||
string* |
|
||||
create_1(const Branches::CPtr &branches_, |
|
||||
const string &fusepath_, |
|
||||
int *err_) |
|
||||
{ |
|
||||
int rv; |
|
||||
uint64_t mfs; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
basepath = NULL; |
|
||||
mfs = std::numeric_limits<uint64_t>::min(); |
|
||||
for(const auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(*err_,ENOSPC); |
|
||||
if(info.spaceavail < mfs) |
|
||||
continue; |
|
||||
|
|
||||
mfs = info.spaceavail; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
return basepath; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
string fusepath; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
fusepath = fusepath_; |
|
||||
for(;;) |
|
||||
{ |
|
||||
basepath = mspmfs::create_1(branches_,fusepath,&error); |
|
||||
if(basepath) |
|
||||
break; |
|
||||
if(fusepath == "/") |
|
||||
break; |
|
||||
fusepath = fs::path::dirname(fusepath); |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPMFS::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::epmfs(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPMFS::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::mspmfs::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPMFS::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::epmfs(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace MSPMFS |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("mspmfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("mspmfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return true; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("mspmfs") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,179 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_msppfrd.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "rnd.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
struct BranchInfo |
|
||||
{ |
|
||||
uint64_t spaceavail; |
|
||||
const string *basepath; |
|
||||
}; |
|
||||
|
|
||||
typedef vector<BranchInfo> BranchInfoVec; |
|
||||
|
|
||||
namespace msppfrd |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create_1(const Branches::CPtr &branches_, |
|
||||
const string &fusepath_, |
|
||||
BranchInfoVec *branchinfo_, |
|
||||
uint64_t *sum_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
BranchInfo bi; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
*sum_ = 0; |
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
*sum_ += info.spaceavail; |
|
||||
|
|
||||
bi.spaceavail = info.spaceavail; |
|
||||
bi.basepath = &branch.path; |
|
||||
branchinfo_->push_back(bi); |
|
||||
} |
|
||||
|
|
||||
return error; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
get_branchinfo(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
BranchInfoVec *branchinfo_, |
|
||||
uint64_t *sum_) |
|
||||
{ |
|
||||
int error; |
|
||||
string fusepath; |
|
||||
|
|
||||
fusepath = fusepath_; |
|
||||
for(;;) |
|
||||
{ |
|
||||
error = msppfrd::create_1(branches_,fusepath,branchinfo_,sum_); |
|
||||
if(branchinfo_->size()) |
|
||||
break; |
|
||||
if(fusepath == "/") |
|
||||
break; |
|
||||
fusepath = fs::path::dirname(fusepath); |
|
||||
} |
|
||||
|
|
||||
return error; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
const |
|
||||
string* |
|
||||
get_branch(const BranchInfoVec &branchinfo_, |
|
||||
const uint64_t sum_) |
|
||||
{ |
|
||||
uint64_t idx; |
|
||||
uint64_t threshold; |
|
||||
|
|
||||
if(sum_ == 0) |
|
||||
return NULL; |
|
||||
|
|
||||
idx = 0; |
|
||||
threshold = RND::rand64(sum_); |
|
||||
for(size_t i = 0; i < branchinfo_.size(); i++) |
|
||||
{ |
|
||||
idx += branchinfo_[i].spaceavail; |
|
||||
|
|
||||
if(idx < threshold) |
|
||||
continue; |
|
||||
|
|
||||
return branchinfo_[i].basepath; |
|
||||
} |
|
||||
|
|
||||
return NULL; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
uint64_t sum; |
|
||||
const string *basepath; |
|
||||
BranchInfoVec branchinfo; |
|
||||
|
|
||||
error = msppfrd::get_branchinfo(branches_,fusepath_,&branchinfo,&sum); |
|
||||
basepath = msppfrd::get_branch(branchinfo,sum); |
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPPFRD::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::eppfrd(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPPFRD::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::msppfrd::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::MSPPFRD::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::eppfrd(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace MSPPFRD |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("msppfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("msppfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return true; }; |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("msppfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,176 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_exists.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "fs_statvfs_cache.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_newest.hpp"
|
|
||||
#include "rwlock.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
#include <limits>
|
|
||||
|
|
||||
#include <sys/stat.h>
|
|
||||
|
|
||||
using std::string; |
|
||||
|
|
||||
namespace newest |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
time_t newest; |
|
||||
struct stat st; |
|
||||
fs::info_t info; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
newest = std::numeric_limits<time_t>::min(); |
|
||||
basepath = NULL; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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); |
|
||||
if(rv == -1) |
|
||||
error_and_continue(error,ENOENT); |
|
||||
if(info.readonly) |
|
||||
error_and_continue(error,EROFS); |
|
||||
if(info.spaceavail < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
newest = st.st_mtime; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
action(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
bool readonly; |
|
||||
time_t newest; |
|
||||
struct stat st; |
|
||||
const string *basepath; |
|
||||
|
|
||||
error = ENOENT; |
|
||||
newest = std::numeric_limits<time_t>::min(); |
|
||||
basepath = NULL; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
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; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
search(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
time_t newest; |
|
||||
struct stat st; |
|
||||
const string *basepath; |
|
||||
|
|
||||
newest = std::numeric_limits<time_t>::min(); |
|
||||
basepath = NULL; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(!fs::exists(branch.path,fusepath_,&st)) |
|
||||
continue; |
|
||||
if(st.st_mtime < newest) |
|
||||
continue; |
|
||||
|
|
||||
newest = st.st_mtime; |
|
||||
basepath = &branch.path; |
|
||||
} |
|
||||
|
|
||||
if(basepath == NULL) |
|
||||
return (errno=ENOENT,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::Newest::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::newest::action(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::Newest::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::newest::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::Newest::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::newest::search(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace Newest |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("newest") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("newest") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("newest") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,149 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "fs_info.hpp"
|
|
||||
#include "fs_path.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_error.hpp"
|
|
||||
#include "policy_pfrd.hpp"
|
|
||||
#include "rnd.hpp"
|
|
||||
#include "strvec.hpp"
|
|
||||
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
using std::string; |
|
||||
using std::vector; |
|
||||
|
|
||||
struct BranchInfo |
|
||||
{ |
|
||||
uint64_t spaceavail; |
|
||||
const string *basepath; |
|
||||
}; |
|
||||
|
|
||||
typedef vector<BranchInfo> BranchInfoVec; |
|
||||
|
|
||||
namespace pfrd |
|
||||
{ |
|
||||
static |
|
||||
int |
|
||||
get_branchinfo(const Branches::CPtr &branches_, |
|
||||
BranchInfoVec *branchinfo_, |
|
||||
uint64_t *sum_) |
|
||||
{ |
|
||||
int rv; |
|
||||
int error; |
|
||||
BranchInfo bi; |
|
||||
fs::info_t info; |
|
||||
|
|
||||
*sum_ = 0; |
|
||||
error = ENOENT; |
|
||||
for(auto &branch : *branches_) |
|
||||
{ |
|
||||
if(branch.ro_or_nc()) |
|
||||
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 < branch.minfreespace()) |
|
||||
error_and_continue(error,ENOSPC); |
|
||||
|
|
||||
*sum_ += info.spaceavail; |
|
||||
|
|
||||
bi.spaceavail = info.spaceavail; |
|
||||
bi.basepath = &branch.path; |
|
||||
branchinfo_->push_back(bi); |
|
||||
} |
|
||||
|
|
||||
return error; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
const |
|
||||
string* |
|
||||
get_branch(const BranchInfoVec &branchinfo_, |
|
||||
const uint64_t sum_) |
|
||||
{ |
|
||||
uint64_t idx; |
|
||||
uint64_t threshold; |
|
||||
|
|
||||
if(sum_ == 0) |
|
||||
return NULL; |
|
||||
|
|
||||
idx = 0; |
|
||||
threshold = RND::rand64(sum_); |
|
||||
for(size_t i = 0; i < branchinfo_.size(); i++) |
|
||||
{ |
|
||||
idx += branchinfo_[i].spaceavail; |
|
||||
|
|
||||
if(idx < threshold) |
|
||||
continue; |
|
||||
|
|
||||
return branchinfo_[i].basepath; |
|
||||
} |
|
||||
|
|
||||
return NULL; |
|
||||
} |
|
||||
|
|
||||
static |
|
||||
int |
|
||||
create(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) |
|
||||
{ |
|
||||
int error; |
|
||||
uint64_t sum; |
|
||||
const string *basepath; |
|
||||
BranchInfoVec branchinfo; |
|
||||
|
|
||||
error = pfrd::get_branchinfo(branches_,&branchinfo,&sum); |
|
||||
basepath = pfrd::get_branch(branchinfo,sum); |
|
||||
if(basepath == NULL) |
|
||||
return (errno=error,-1); |
|
||||
|
|
||||
paths_->push_back(*basepath); |
|
||||
|
|
||||
return 0; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::PFRD::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Action::eppfrd(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::PFRD::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return ::pfrd::create(branches_,fusepath_,paths_); |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::PFRD::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
return Policies::Search::eppfrd(branches_,fusepath_,paths_); |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace PFRD |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("pfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("pfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("pfrd") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,73 +0,0 @@ |
|||||
/*
|
|
||||
Copyright (c) 2016, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#include "errno.hpp"
|
|
||||
#include "policy.hpp"
|
|
||||
#include "policy_rand.hpp"
|
|
||||
#include "policies.hpp"
|
|
||||
|
|
||||
#include <algorithm>
|
|
||||
|
|
||||
int |
|
||||
Policy::Rand::Action::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
int rv; |
|
||||
|
|
||||
rv = Policies::Action::all(branches_,fusepath_,paths_); |
|
||||
if(rv == 0) |
|
||||
{ |
|
||||
std::random_shuffle(paths_->begin(),paths_->end()); |
|
||||
paths_->resize(1); |
|
||||
} |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::Rand::Create::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
int rv; |
|
||||
|
|
||||
rv = Policies::Create::all(branches_,fusepath_,paths_); |
|
||||
if(rv == 0) |
|
||||
{ |
|
||||
std::random_shuffle(paths_->begin(),paths_->end()); |
|
||||
paths_->resize(1); |
|
||||
} |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
||||
|
|
||||
int |
|
||||
Policy::Rand::Search::operator()(const Branches::CPtr &branches_, |
|
||||
const char *fusepath_, |
|
||||
StrVec *paths_) const |
|
||||
{ |
|
||||
int rv; |
|
||||
|
|
||||
rv = Policies::Search::all(branches_,fusepath_,paths_); |
|
||||
if(rv == 0) |
|
||||
{ |
|
||||
std::random_shuffle(paths_->begin(),paths_->end()); |
|
||||
paths_->resize(1); |
|
||||
} |
|
||||
|
|
||||
return rv; |
|
||||
} |
|
@ -1,61 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include "policy.hpp"
|
|
||||
|
|
||||
namespace Policy |
|
||||
{ |
|
||||
namespace Rand |
|
||||
{ |
|
||||
class Action final : public Policy::ActionImpl |
|
||||
{ |
|
||||
public: |
|
||||
Action() |
|
||||
: Policy::ActionImpl("rand") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
|
|
||||
class Create final : public Policy::CreateImpl |
|
||||
{ |
|
||||
public: |
|
||||
Create() |
|
||||
: Policy::CreateImpl("rand") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
bool path_preserving() const final { return false; } |
|
||||
}; |
|
||||
|
|
||||
class Search final : public Policy::SearchImpl |
|
||||
{ |
|
||||
public: |
|
||||
Search() |
|
||||
: Policy::SearchImpl("rand") |
|
||||
{} |
|
||||
|
|
||||
public: |
|
||||
int operator()(const Branches::CPtr&,const char*,StrVec*) const final; |
|
||||
}; |
|
||||
} |
|
||||
} |
|
@ -1,51 +0,0 @@ |
|||||
/*
|
|
||||
ISC License |
|
||||
|
|
||||
Copyright (c) 2020, Antonio SJ Musumeci <trapexit@spawn.link> |
|
||||
|
|
||||
Permission to use, copy, modify, and/or distribute this software for any |
|
||||
purpose with or without fee is hereby granted, provided that the above |
|
||||
copyright notice and this permission notice appear in all copies. |
|
||||
|
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
|
||||
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
|
||||
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
|
||||
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
|
||||
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
|
||||
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
|
||||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
|
||||
*/ |
|
||||
|
|
||||
#pragma once
|
|
||||
|
|
||||
#include <string>
|
|
||||
#include <vector>
|
|
||||
|
|
||||
struct PolicyRV |
|
||||
{ |
|
||||
struct RV |
|
||||
{ |
|
||||
RV(const int rv_, |
|
||||
const std::string &basepath_) |
|
||||
: rv(rv_), |
|
||||
basepath(basepath_) |
|
||||
{ |
|
||||
} |
|
||||
|
|
||||
int rv; |
|
||||
std::string basepath; |
|
||||
}; |
|
||||
|
|
||||
std::vector<RV> success; |
|
||||
std::vector<RV> error; |
|
||||
|
|
||||
void |
|
||||
insert(const int err_, |
|
||||
const std::string &basepath_) |
|
||||
{ |
|
||||
if(err_ == 0) |
|
||||
success.push_back(RV(err_,basepath_)); |
|
||||
else |
|
||||
error.push_back(RV(-err_,basepath_)); |
|
||||
} |
|
||||
}; |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue