mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
Move everything to negative errno return types (#1499)
This commit is contained in:
parent
2b500f194a
commit
e8cd74cab0
177 changed files with 5952 additions and 5843 deletions
|
|
@ -14,6 +14,8 @@
|
|||
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "policy_eppfrd.hpp"
|
||||
|
||||
#include "errno.hpp"
|
||||
#include "fs_exists.hpp"
|
||||
#include "fs_info.hpp"
|
||||
|
|
@ -37,191 +39,188 @@ struct BranchInfo
|
|||
|
||||
typedef std::vector<BranchInfo> BranchInfoVec;
|
||||
|
||||
namespace eppfrd
|
||||
static
|
||||
int
|
||||
_get_branchinfo_create(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
BranchInfoVec *branchinfo_,
|
||||
uint64_t *sum_)
|
||||
{
|
||||
static
|
||||
int
|
||||
get_branchinfo_create(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
BranchInfoVec *branchinfo_,
|
||||
uint64_t *sum_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::info_t info;
|
||||
int rv;
|
||||
int error;
|
||||
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_ = 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 < 0)
|
||||
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;
|
||||
*sum_ += info.spaceavail;
|
||||
|
||||
branchinfo_->push_back({info.spaceavail,&branch});
|
||||
}
|
||||
branchinfo_->push_back({info.spaceavail,&branch});
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
return -error;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
get_branchinfo_action(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
BranchInfoVec *branchinfo_,
|
||||
uint64_t *sum_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
fs::info_t info;
|
||||
static
|
||||
int
|
||||
_get_branchinfo_action(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
BranchInfoVec *branchinfo_,
|
||||
uint64_t *sum_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
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_ = 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 < 0)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
|
||||
*sum_ += info.spaceavail;
|
||||
*sum_ += info.spaceavail;
|
||||
|
||||
branchinfo_->push_back({info.spaceavail,&branch});
|
||||
}
|
||||
branchinfo_->push_back({info.spaceavail,&branch});
|
||||
}
|
||||
|
||||
return error;
|
||||
}
|
||||
return -error;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
get_branchinfo_search(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
BranchInfoVec *branchinfo_,
|
||||
uint64_t *sum_)
|
||||
{
|
||||
int rv;
|
||||
uint64_t spaceavail;
|
||||
static
|
||||
int
|
||||
_get_branchinfo_search(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
BranchInfoVec *branchinfo_,
|
||||
uint64_t *sum_)
|
||||
{
|
||||
int rv;
|
||||
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_ = 0;
|
||||
for(auto &branch : *branches_)
|
||||
{
|
||||
if(!fs::exists(branch.path,fusepath_))
|
||||
continue;
|
||||
rv = fs::statvfs_cache_spaceavail(branch.path,&spaceavail);
|
||||
if(rv < 0)
|
||||
continue;
|
||||
|
||||
*sum_ += spaceavail;
|
||||
*sum_ += spaceavail;
|
||||
|
||||
branchinfo_->push_back({spaceavail,&branch});
|
||||
}
|
||||
branchinfo_->push_back({spaceavail,&branch});
|
||||
}
|
||||
|
||||
return ENOENT;
|
||||
}
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static
|
||||
Branch*
|
||||
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].branch;
|
||||
}
|
||||
static
|
||||
Branch*
|
||||
_get_branch(const BranchInfoVec &branchinfo_,
|
||||
const uint64_t sum_)
|
||||
{
|
||||
uint64_t idx;
|
||||
uint64_t threshold;
|
||||
|
||||
if(sum_ == 0)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
create(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int error;
|
||||
uint64_t sum;
|
||||
Branch *branch;
|
||||
BranchInfoVec branchinfo;
|
||||
idx = 0;
|
||||
threshold = RND::rand64(sum_);
|
||||
for(size_t i = 0; i < branchinfo_.size(); i++)
|
||||
{
|
||||
idx += branchinfo_[i].spaceavail;
|
||||
|
||||
error = eppfrd::get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum);
|
||||
branch = eppfrd::get_branch(branchinfo,sum);
|
||||
if(!branch)
|
||||
return (errno=error,-1);
|
||||
if(idx < threshold)
|
||||
continue;
|
||||
|
||||
paths_.emplace_back(branch);
|
||||
return branchinfo_[i].branch;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
action(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int error;
|
||||
uint64_t sum;
|
||||
Branch *branch;
|
||||
BranchInfoVec branchinfo;
|
||||
static
|
||||
int
|
||||
_create(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int err;
|
||||
uint64_t sum;
|
||||
Branch *branch;
|
||||
BranchInfoVec branchinfo;
|
||||
|
||||
error = eppfrd::get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum);
|
||||
branch = eppfrd::get_branch(branchinfo,sum);
|
||||
if(!branch)
|
||||
return (errno=error,-1);
|
||||
err = ::_get_branchinfo_create(branches_,fusepath_,&branchinfo,&sum);
|
||||
branch = ::_get_branch(branchinfo,sum);
|
||||
if(!branch)
|
||||
return err;
|
||||
|
||||
paths_.emplace_back(branch);
|
||||
paths_.emplace_back(branch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
search(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int error;
|
||||
uint64_t sum;
|
||||
Branch *branch;
|
||||
BranchInfoVec branchinfo;
|
||||
static
|
||||
int
|
||||
_action(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int err;
|
||||
uint64_t sum;
|
||||
Branch *branch;
|
||||
BranchInfoVec branchinfo;
|
||||
|
||||
error = eppfrd::get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum);
|
||||
branch = eppfrd::get_branch(branchinfo,sum);
|
||||
if(!branch)
|
||||
return (errno=error,-1);
|
||||
err = ::_get_branchinfo_action(branches_,fusepath_,&branchinfo,&sum);
|
||||
branch = ::_get_branch(branchinfo,sum);
|
||||
if(!branch)
|
||||
return err;
|
||||
|
||||
paths_.emplace_back(branch);
|
||||
paths_.emplace_back(branch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
_search(const Branches::Ptr &branches_,
|
||||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_)
|
||||
{
|
||||
int err;
|
||||
uint64_t sum;
|
||||
Branch *branch;
|
||||
BranchInfoVec branchinfo;
|
||||
|
||||
err = ::_get_branchinfo_search(branches_,fusepath_,&branchinfo,&sum);
|
||||
branch = ::_get_branch(branchinfo,sum);
|
||||
if(!branch)
|
||||
return err;
|
||||
|
||||
paths_.emplace_back(branch);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -229,7 +228,7 @@ Policy::EPPFRD::Action::operator()(const Branches::Ptr &branches_,
|
|||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_) const
|
||||
{
|
||||
return ::eppfrd::action(branches_,fusepath_,paths_);
|
||||
return ::_action(branches_,fusepath_,paths_);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -237,7 +236,7 @@ Policy::EPPFRD::Create::operator()(const Branches::Ptr &branches_,
|
|||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_) const
|
||||
{
|
||||
return ::eppfrd::create(branches_,fusepath_,paths_);
|
||||
return ::_create(branches_,fusepath_,paths_);
|
||||
}
|
||||
|
||||
int
|
||||
|
|
@ -245,5 +244,5 @@ Policy::EPPFRD::Search::operator()(const Branches::Ptr &branches_,
|
|||
const char *fusepath_,
|
||||
std::vector<Branch*> &paths_) const
|
||||
{
|
||||
return ::eppfrd::search(branches_,fusepath_,paths_);
|
||||
return ::_search(branches_,fusepath_,paths_);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue