From 8e5b79647bb06b891f54fecaf34ebefd4c7c38fc Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Tue, 16 Jun 2015 22:12:55 -0400 Subject: [PATCH] create lfs policy. closes #73 --- src/fs.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ src/fs.hpp | 4 ++++ src/policy.cpp | 2 ++ src/policy.hpp | 2 ++ 4 files changed, 51 insertions(+) diff --git a/src/fs.cpp b/src/fs.cpp index 7ab0ca90..cb7bc451 100644 --- a/src/fs.cpp +++ b/src/fs.cpp @@ -663,6 +663,49 @@ namespace fs return -1; } + int + lfs(const vector &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 &basepaths, const string &fusepath, diff --git a/src/fs.hpp b/src/fs.hpp index 4db89db9..bc1518f9 100644 --- a/src/fs.hpp +++ b/src/fs.hpp @@ -148,6 +148,10 @@ namespace fs const string &fusepath, const size_t minfreespace, Paths &path); + int lfs(const vector &paths, + const string &fusepath, + const size_t minfreespace, + Paths &path); int mfs(const vector &paths, const string &fusepath, const size_t minfreespace, diff --git a/src/policy.cpp b/src/policy.cpp index ac26c686..4ca300cd 100644 --- a/src/policy.cpp +++ b/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]; diff --git a/src/policy.hpp b/src/policy.hpp index 363e762b..752c8983 100644 --- a/src/policy.hpp +++ b/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;