Browse Source

create lfs policy. closes #73

pull/76/head
Antonio SJ Musumeci 10 years ago
parent
commit
8e5b79647b
  1. 43
      src/fs.cpp
  2. 4
      src/fs.hpp
  3. 2
      src/policy.cpp
  4. 2
      src/policy.hpp

43
src/fs.cpp

@ -663,6 +663,49 @@ namespace fs
return -1;
}
int
lfs(const vector<string> &basepaths,
const string &fusepath,
const size_t minfreespace,
Paths &paths)
{
fsblkcnt_t lfs;
const char *lfsstr;
lfs = -1;
lfsstr = NULL;
for(size_t i = 0, size = basepaths.size(); i != size; i++)
{
int rv;
const char *basepath;
struct statvfs fsstats;
basepath = basepaths[i].c_str();
rv = ::statvfs(basepath,&fsstats);
if(rv == 0)
{
fsblkcnt_t spaceavail;
spaceavail = (fsstats.f_frsize * fsstats.f_bavail);
if((spaceavail > minfreespace) &&
(spaceavail < lfs))
{
lfs = spaceavail;
lfsstr = basepath;
}
}
}
if(lfsstr == NULL)
return mfs(basepaths,fusepath,minfreespace,paths);
paths.push_back(Path(lfsstr,
fs::make_path(lfsstr,fusepath)));
return 0;
}
int
mfs(const vector<string> &basepaths,
const string &fusepath,

4
src/fs.hpp

@ -148,6 +148,10 @@ namespace fs
const string &fusepath,
const size_t minfreespace,
Paths &path);
int lfs(const vector<string> &paths,
const string &fusepath,
const size_t minfreespace,
Paths &path);
int mfs(const vector<string> &paths,
const string &fusepath,
const size_t minfreespace,

2
src/policy.cpp

@ -40,6 +40,7 @@ namespace mergerfs
(POLICY(ff))
(POLICY(ffwp))
(POLICY(fwfs))
(POLICY(lfs))
(POLICY(mfs))
(POLICY(newest))
(POLICY(rand));
@ -52,6 +53,7 @@ namespace mergerfs
const Policy &Policy::ff = Policy::policies[Policy::Enum::ff];
const Policy &Policy::ffwp = Policy::policies[Policy::Enum::ffwp];
const Policy &Policy::fwfs = Policy::policies[Policy::Enum::fwfs];
const Policy &Policy::lfs = Policy::policies[Policy::Enum::lfs];
const Policy &Policy::mfs = Policy::policies[Policy::Enum::mfs];
const Policy &Policy::newest = Policy::policies[Policy::Enum::newest];
const Policy &Policy::rand = Policy::policies[Policy::Enum::rand];

2
src/policy.hpp

@ -46,6 +46,7 @@ namespace mergerfs
ff,
ffwp,
fwfs,
lfs,
mfs,
newest,
rand,
@ -107,6 +108,7 @@ namespace mergerfs
static const Policy &ff;
static const Policy &ffwp;
static const Policy &fwfs;
static const Policy &lfs;
static const Policy &mfs;
static const Policy &newest;
static const Policy &rand;

Loading…
Cancel
Save