mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-11-19 14:36:36 -05: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
|
|
@ -36,32 +36,29 @@ namespace newest
|
|||
{
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
const uint64_t minfreespace_,
|
||||
vector<string> *paths_)
|
||||
create(const BranchVec &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(&branches_.lock);
|
||||
|
||||
int rv;
|
||||
int error;
|
||||
time_t newest;
|
||||
struct stat st;
|
||||
fs::info_t info;
|
||||
const Branch *branch;
|
||||
const string *newestbasepath;
|
||||
const string *basepath;
|
||||
|
||||
error = ENOENT;
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
basepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::exists(branch->path,fusepath_,&st))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro_or_nc())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch->path,fusepath_,&st))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
rv = fs::info(branch->path,&info);
|
||||
|
|
@ -69,17 +66,73 @@ namespace newest
|
|||
error_and_continue(error,ENOENT);
|
||||
if(info.readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
if(info.spaceavail < minfreespace_)
|
||||
if(info.spaceavail < branch->minfreespace())
|
||||
error_and_continue(error,ENOSPC);
|
||||
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = &branch->path;
|
||||
basepath = &branch->path;
|
||||
}
|
||||
|
||||
if(newestbasepath == NULL)
|
||||
if(basepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths_->push_back(*newestbasepath);
|
||||
paths_->push_back(*basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
create(const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(branches_.lock);
|
||||
|
||||
return newest::create(branches_.vec,fusepath_,paths_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
action(const BranchVec &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
int rv;
|
||||
int error;
|
||||
bool readonly;
|
||||
time_t newest;
|
||||
struct stat st;
|
||||
const Branch *branch;
|
||||
const string *basepath;
|
||||
|
||||
error = ENOENT;
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
basepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
if(!fs::exists(branch->path,fusepath_,&st))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
rv = fs::statvfs_cache_readonly(branch->path,&readonly);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
|
||||
newest = st.st_mtime;
|
||||
basepath = &branch->path;
|
||||
}
|
||||
|
||||
if(basepath == NULL)
|
||||
return (errno=error,-1);
|
||||
|
||||
paths_->push_back(*basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -90,43 +143,41 @@ namespace newest
|
|||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(&branches_.lock);
|
||||
rwlock::ReadGuard guard(branches_.lock);
|
||||
|
||||
int rv;
|
||||
int error;
|
||||
bool readonly;
|
||||
return newest::action(branches_.vec,fusepath_,paths_);
|
||||
}
|
||||
|
||||
static
|
||||
int
|
||||
search(const BranchVec &branches_,
|
||||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
time_t newest;
|
||||
struct stat st;
|
||||
const Branch *branch;
|
||||
const string *newestbasepath;
|
||||
const string *basepath;
|
||||
|
||||
error = ENOENT;
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
basepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::exists(branch->path,fusepath_,&st))
|
||||
error_and_continue(error,ENOENT);
|
||||
if(branch->ro())
|
||||
error_and_continue(error,EROFS);
|
||||
continue;
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
rv = fs::statvfs_cache_readonly(branch->path,&readonly);
|
||||
if(rv == -1)
|
||||
error_and_continue(error,ENOENT);
|
||||
if(readonly)
|
||||
error_and_continue(error,EROFS);
|
||||
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = &branch->path;
|
||||
basepath = &branch->path;
|
||||
}
|
||||
|
||||
if(newestbasepath == NULL)
|
||||
return (errno=error,-1);
|
||||
if(basepath == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths_->push_back(*newestbasepath);
|
||||
paths_->push_back(*basepath);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -137,34 +188,9 @@ namespace newest
|
|||
const char *fusepath_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
rwlock::ReadGuard guard(&branches_.lock);
|
||||
rwlock::ReadGuard guard(branches_.lock);
|
||||
|
||||
time_t newest;
|
||||
struct stat st;
|
||||
const Branch *branch;
|
||||
const string *newestbasepath;
|
||||
|
||||
newest = std::numeric_limits<time_t>::min();
|
||||
newestbasepath = NULL;
|
||||
for(size_t i = 0, ei = branches_.size(); i != ei; i++)
|
||||
{
|
||||
branch = &branches_[i];
|
||||
|
||||
if(!fs::exists(branch->path,fusepath_,&st))
|
||||
continue;
|
||||
if(st.st_mtime < newest)
|
||||
continue;
|
||||
|
||||
newest = st.st_mtime;
|
||||
newestbasepath = &branch->path;
|
||||
}
|
||||
|
||||
if(newestbasepath == NULL)
|
||||
return (errno=ENOENT,-1);
|
||||
|
||||
paths_->push_back(*newestbasepath);
|
||||
|
||||
return 0;
|
||||
return newest::search(branches_.vec,fusepath_,paths_);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -172,13 +198,12 @@ int
|
|||
Policy::Func::newest(const Category type_,
|
||||
const Branches &branches_,
|
||||
const char *fusepath_,
|
||||
const uint64_t minfreespace_,
|
||||
vector<string> *paths_)
|
||||
{
|
||||
switch(type_)
|
||||
{
|
||||
case Category::CREATE:
|
||||
return newest::create(branches_,fusepath_,minfreespace_,paths_);
|
||||
return newest::create(branches_,fusepath_,paths_);
|
||||
case Category::ACTION:
|
||||
return newest::action(branches_,fusepath_,paths_);
|
||||
case Category::SEARCH:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue