mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-10-26 19:01:56 -04:00
branches: add per branch minfreespace w/ original value as default
example: /mnt/disk0=RW,1G:/mnt/disk1=RW,2G
This commit is contained in:
parent
98c49b8001
commit
fc3453932a
68 changed files with 3005 additions and 813 deletions
|
|
@ -34,49 +34,101 @@ namespace eplus
|
|||
{
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
const uint64_t minfreespace_,
|
||||
vector<string> *paths_)
|
||||
create(const BranchVec &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(&branches_.lock);
|
||||
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *eplusbasepath;
|
||||
const string *basepath;
|
||||
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
eplusbasepath = NULL;
|
||||
basepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::exists(branch->path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch->path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
rv = fs::info(branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace_)
|
||||
if(info.spaceavail < branch->minfreespace())
|
||||
error_and_continue(error,ENOSPC);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
eplus = info.spaceused;
|
||||
eplusbasepath = &branch->path;
|
||||
basepath = &branch->path;
|
||||
}
|
||||
|
||||
if(eplusbasepath == NULL)
|
||||
if(basepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths_->push_back(*eplusbasepath);
|
||||
paths_->push_back(*basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(branches_.lock);
|
||||
|
||||
return eplus::create(branches_.vec,fusepath_,paths_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
action(const BranchVec &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *basepath;
|
||||
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
basepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch->path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
rv = fs::info(branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
eplus = info.spaceused;
|
||||
basepath = &branch->path;
|
||||
}
|
||||
|
||||
if(basepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths_->push_back(*basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -87,62 +139,25 @@ namespace eplus
|
|||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(&branches_.lock);
|
||||
rwlock::ReadGuard guard(branches_.lock);
|
||||
|
||||
int rv;
|
||||
int error;
|
||||
uint64_t eplus;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *eplusbasepath;
|
||||
|
||||
error = ENOENT;
|
||||
eplus = std::numeric_limits<uint64_t>::max();
|
||||
eplusbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::exists(branch->path,fusepath_))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
rv = fs::info(branch->path,&info);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceused >= eplus)
|
||||
continue;
|
||||
|
||||
eplus = info.spaceused;
|
||||
eplusbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(eplusbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths_->push_back(*eplusbasepath);
|
||||
|
||||
return 0;
|
||||
return eplus::action(branches_.vec,fusepath_,paths_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
search(const BranchVec &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(&branches_.lock);
|
||||
|
||||
int rv;
|
||||
uint64_t eplus;
|
||||
uint64_t spaceused;
|
||||
const Branch *branch;
|
||||
const string *eplusbasepath;
|
||||
const string *basepath;
|
||||
|
||||
eplus = 0;
|
||||
eplusbasepath = NULL;
|
||||
basepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
|
@ -156,29 +171,39 @@ namespace eplus
|
|||
continue;
|
||||
|
||||
eplus = spaceused;
|
||||
eplusbasepath = &branch->path;
|
||||
basepath = &branch->path;
|
||||
}
|
||||
|
||||
if(eplusbasepath == NULL)
|
||||
if(basepath == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths_->push_back(*eplusbasepath);
|
||||
paths_->push_back(*basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
search(const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(branches_.lock);
|
||||
|
||||
return eplus::search(branches_.vec,fusepath_,paths_);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
Policy::Func::eplus(const Category type_,
|
||||
const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
const uint64_t minfreespace_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
switch(type_)
|
||||
{
|
||||
case Category::CREATE:
|
||||
return eplus::create(branches_,fusepath_,minfreespace_,paths_);
|
||||
return eplus::create(branches_,fusepath_,paths_);
|
||||
case Category::ACTION:
|
||||
return eplus::action(branches_,fusepath_,paths_);
|
||||
case Category::SEARCH:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue