Browse Source

create minfreespace option. closes #71

pull/74/head
Antonio SJ Musumeci 10 years ago
parent
commit
ccb22c1fbe
  1. 4
      src/access.cpp
  2. 6
      src/chmod.cpp
  3. 4
      src/chown.cpp
  4. 1
      src/config.cpp
  5. 2
      src/config.hpp
  6. 6
      src/create.cpp
  7. 48
      src/fs.cpp
  8. 43
      src/fs.hpp
  9. 4
      src/getattr.cpp
  10. 4
      src/getxattr.cpp
  11. 4
      src/ioctl.cpp
  12. 9
      src/link.cpp
  13. 7
      src/listxattr.cpp
  14. 6
      src/mkdir.cpp
  15. 6
      src/mknod.cpp
  16. 4
      src/open.cpp
  17. 46
      src/option_parser.cpp
  18. 4
      src/readlink.cpp
  19. 4
      src/removexattr.cpp
  20. 9
      src/rename.cpp
  21. 4
      src/rmdir.cpp
  22. 4
      src/setxattr.cpp
  23. 4
      src/symlink.cpp
  24. 4
      src/truncate.cpp
  25. 4
      src/unlink.cpp
  26. 4
      src/utimens.cpp

4
src/access.cpp

@ -47,13 +47,14 @@ static
int int
_access(const fs::find::Func searchFunc, _access(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const int mask) const int mask)
{ {
int rv; int rv;
fs::Paths paths; fs::Paths paths;
rv = searchFunc(srcmounts,fusepath,paths,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -77,6 +78,7 @@ namespace mergerfs
return _access(*config.access, return _access(*config.access,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
mask); mask);
} }

6
src/chmod.cpp

@ -41,6 +41,7 @@ static
int int
_chmod(const fs::find::Func actionFunc, _chmod(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const mode_t mode) const mode_t mode)
{ {
@ -48,7 +49,7 @@ _chmod(const fs::find::Func actionFunc,
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -73,12 +74,13 @@ namespace mergerfs
mode_t mode) mode_t mode)
{ {
const struct fuse_context *fc = fuse_get_context(); const struct fuse_context *fc = fuse_get_context();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const config::Config &config = config::get(); const config::Config &config = config::get();
const ugid::SetResetGuard ugid(fc->uid,fc->gid);
const rwlock::ReadGuard readlock(&config.srcmountslock); const rwlock::ReadGuard readlock(&config.srcmountslock);
return _chmod(*config.chmod, return _chmod(*config.chmod,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
mode); mode);
} }

4
src/chown.cpp

@ -42,6 +42,7 @@ static
int int
_chown(const fs::find::Func actionFunc, _chown(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const uid_t uid, const uid_t uid,
const gid_t gid) const gid_t gid)
@ -50,7 +51,7 @@ _chown(const fs::find::Func actionFunc,
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -82,6 +83,7 @@ namespace mergerfs
return _chown(*config.chown, return _chown(*config.chown,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
uid, uid,
gid); gid);

1
src/config.cpp

@ -46,6 +46,7 @@ namespace mergerfs
: destmount(), : destmount(),
srcmounts(), srcmounts(),
srcmountslock(), srcmountslock(),
minfreespace(UINT32_MAX),
POLICYINIT(access), POLICYINIT(access),
POLICYINIT(chmod), POLICYINIT(chmod),
POLICYINIT(chown), POLICYINIT(chown),

2
src/config.hpp

@ -28,6 +28,7 @@
#include <fuse.h> #include <fuse.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <stdint.h>
#include <string> #include <string>
#include <vector> #include <vector>
@ -54,6 +55,7 @@ namespace mergerfs
std::string destmount; std::string destmount;
std::vector<std::string> srcmounts; std::vector<std::string> srcmounts;
mutable pthread_rwlock_t srcmountslock; mutable pthread_rwlock_t srcmountslock;
size_t minfreespace;
public: public:
const Policy *policies[FuseFunc::Enum::END]; const Policy *policies[FuseFunc::Enum::END];

6
src/create.cpp

@ -46,6 +46,7 @@ int
_create(const fs::find::Func searchFunc, _create(const fs::find::Func searchFunc,
const fs::find::Func createFunc, const fs::find::Func createFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const mode_t mode, const mode_t mode,
const int flags, const int flags,
@ -59,11 +60,11 @@ _create(const fs::find::Func searchFunc,
fs::Paths existingpath; fs::Paths existingpath;
dirname = fs::dirname(fusepath); dirname = fs::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,existingpath,1);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
rv = createFunc(srcmounts,dirname,createpath,1);
rv = createFunc(srcmounts,dirname,minfreespace,createpath);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -101,6 +102,7 @@ namespace mergerfs
return _create(*config.getattr, return _create(*config.getattr,
*config.create, *config.create,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
(mode & ~fc->umask), (mode & ~fc->umask),
fileinfo->flags, fileinfo->flags,

48
src/fs.cpp

@ -520,8 +520,8 @@ namespace fs
int int
invalid(const vector<string> &basepaths, invalid(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &rv,
size_t count)
const size_t minfreespace,
Paths &rv)
{ {
return (errno = EINVAL,-1); return (errno = EINVAL,-1);
} }
@ -529,8 +529,8 @@ namespace fs
int int
ff(const vector<string> &basepaths, ff(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &paths,
size_t count)
const size_t minfreespace,
Paths &paths)
{ {
errno = ENOENT; errno = ENOENT;
for(vector<string>::const_iterator for(vector<string>::const_iterator
@ -558,8 +558,8 @@ namespace fs
int int
ffwp(const vector<string> &basepaths, ffwp(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &paths,
size_t count)
const size_t minfreespace,
Paths &paths)
{ {
Path fallback; Path fallback;
@ -597,8 +597,8 @@ namespace fs
int int
newest(const vector<string> &basepaths, newest(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &paths,
size_t count)
const size_t minfreespace,
Paths &paths)
{ {
time_t newest; time_t newest;
string npath; string npath;
@ -635,8 +635,8 @@ namespace fs
int int
mfs(const vector<string> &basepaths, mfs(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &paths,
size_t count)
const size_t minfreespace,
Paths &paths)
{ {
fsblkcnt_t mfs; fsblkcnt_t mfs;
size_t mfsidx; size_t mfsidx;
@ -675,11 +675,11 @@ namespace fs
int int
epmfs(const vector<string> &basepaths, epmfs(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &paths,
size_t count)
const size_t minfreespace,
Paths &paths)
{ {
fsblkcnt_t existingmfs = 0;
fsblkcnt_t generalmfs = 0;
fsblkcnt_t existingmfs;
fsblkcnt_t generalmfs;
string fullpath; string fullpath;
string generalmfspath; string generalmfspath;
string existingmfspath; string existingmfspath;
@ -689,6 +689,8 @@ namespace fs
if(iter == eiter) if(iter == eiter)
return (errno = ENOENT,-1); return (errno = ENOENT,-1);
existingmfs = 0;
generalmfs = 0;
do do
{ {
int rv; int rv;
@ -736,8 +738,8 @@ namespace fs
int int
all(const vector<string> &basepaths, all(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &paths,
size_t count)
const size_t minfreespace,
Paths &paths)
{ {
int rv; int rv;
struct stat st; struct stat st;
@ -745,17 +747,14 @@ namespace fs
for(vector<string>::const_iterator for(vector<string>::const_iterator
iter = basepaths.begin(), eiter = basepaths.end(); iter = basepaths.begin(), eiter = basepaths.end();
iter != eiter && count;
iter != eiter;
++iter) ++iter)
{ {
fullpath = fs::make_path(*iter,fusepath); fullpath = fs::make_path(*iter,fusepath);
rv = ::lstat(fullpath.c_str(),&st); rv = ::lstat(fullpath.c_str(),&st);
if(rv == 0) if(rv == 0)
{
paths.push_back(Path(*iter,fullpath)); paths.push_back(Path(*iter,fullpath));
count--;
}
} }
return paths.empty() ? (errno=ENOENT,-1) : 0; return paths.empty() ? (errno=ENOENT,-1) : 0;
@ -764,20 +763,17 @@ namespace fs
int int
rand(const vector<string> &basepaths, rand(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &paths,
size_t count)
const size_t minfreespace,
Paths &paths)
{ {
int rv; int rv;
rv = all(basepaths,fusepath,paths,-1);
rv = all(basepaths,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -1; return -1;
std::random_shuffle(paths.begin(),paths.end()); std::random_shuffle(paths.begin(),paths.end());
if(paths.size() > count)
paths.resize(count);
return 0; return 0;
} }
} }

43
src/fs.hpp

@ -39,12 +39,21 @@ namespace fs
struct Path struct Path
{ {
Path() {} Path() {}
explicit
Path(const string &b, Path(const string &b,
const string &f) const string &f)
: base(b), : base(b),
full(f) full(f)
{} {}
explicit
Path(const char *b,
const string &f)
: base(b),
full(f)
{}
string base; string base;
string full; string full;
}; };
@ -113,40 +122,40 @@ namespace fs
namespace find namespace find
{ {
typedef int (*Func)(const vector<string>&,const string&,Paths&,size_t);
typedef int (*Func)(const vector<string>&,const string&,const size_t,Paths&);
int invalid(const vector<string> &basepaths, int invalid(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
int all(const vector<string> &basepaths, int all(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
int ff(const vector<string> &basepaths, int ff(const vector<string> &basepaths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
int ffwp(const vector<string> &paths, int ffwp(const vector<string> &paths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
int newest(const vector<string> &paths, int newest(const vector<string> &paths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
int mfs(const vector<string> &paths, int mfs(const vector<string> &paths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
int epmfs(const vector<string> &paths, int epmfs(const vector<string> &paths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
int rand(const vector<string> &paths, int rand(const vector<string> &paths,
const string &fusepath, const string &fusepath,
Paths &path,
size_t max);
const size_t minfreespace,
Paths &path);
} }
}; };

4
src/getattr.cpp

@ -67,13 +67,14 @@ static
int int
_getattr(const fs::find::Func searchFunc, _getattr(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
struct stat &buf) struct stat &buf)
{ {
int rv; int rv;
fs::Paths path; fs::Paths path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -101,6 +102,7 @@ namespace mergerfs
return _getattr(*config.getattr, return _getattr(*config.getattr,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
*st); *st);
} }

4
src/getxattr.cpp

@ -192,6 +192,7 @@ static
int int
_getxattr(const fs::find::Func searchFunc, _getxattr(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const char *attrname, const char *attrname,
char *buf, char *buf,
@ -201,7 +202,7 @@ _getxattr(const fs::find::Func searchFunc,
int rv; int rv;
fs::Paths path; fs::Paths path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -240,6 +241,7 @@ namespace mergerfs
return _getxattr(*config.getxattr, return _getxattr(*config.getxattr,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
attrname, attrname,
buf, buf,

4
src/ioctl.cpp

@ -84,6 +84,7 @@ static
int int
_ioctl_dir_base(const fs::find::Func searchFunc, _ioctl_dir_base(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const int cmd, const int cmd,
void *arg, void *arg,
@ -94,7 +95,7 @@ _ioctl_dir_base(const fs::find::Func searchFunc,
int rv; int rv;
fs::Paths path; fs::Paths path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -124,6 +125,7 @@ _ioctl_dir(const string &fusepath,
return _ioctl_dir_base(*config.getattr, return _ioctl_dir_base(*config.getattr,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
cmd, cmd,
arg, arg,

9
src/link.cpp

@ -43,6 +43,7 @@ static
int int
_single_link(const fs::find::Func searchFunc, _single_link(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &base, const string &base,
const string &oldpath, const string &oldpath,
const string &newpath) const string &newpath)
@ -58,7 +59,7 @@ _single_link(const fs::find::Func searchFunc,
fs::Paths foundpath; fs::Paths foundpath;
newpathdir = fs::dirname(newpath); newpathdir = fs::dirname(newpath);
rv = searchFunc(srcmounts,newpathdir,foundpath,1);
rv = searchFunc(srcmounts,newpathdir,minfreespace,foundpath);
if(rv == -1) if(rv == -1)
return -1; return -1;
@ -78,6 +79,7 @@ int
_link(const fs::find::Func searchFunc, _link(const fs::find::Func searchFunc,
const fs::find::Func actionFunc, const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &oldpath, const string &oldpath,
const string &newpath) const string &newpath)
{ {
@ -85,7 +87,7 @@ _link(const fs::find::Func searchFunc,
int error; int error;
fs::Paths oldpaths; fs::Paths oldpaths;
rv = actionFunc(srcmounts,oldpath,oldpaths,-1);
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -93,7 +95,7 @@ _link(const fs::find::Func searchFunc,
for(fs::Paths::const_iterator for(fs::Paths::const_iterator
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i) i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
{ {
rv = _single_link(searchFunc,srcmounts,i->base,oldpath,newpath);
rv = _single_link(searchFunc,srcmounts,minfreespace,i->base,oldpath,newpath);
if(rv == -1) if(rv == -1)
error = errno; error = errno;
} }
@ -117,6 +119,7 @@ namespace mergerfs
return _link(*config.getattr, return _link(*config.getattr,
*config.link, *config.link,
config.srcmounts, config.srcmounts,
config.minfreespace,
from, from,
to); to);
} }

7
src/listxattr.cpp

@ -71,6 +71,7 @@ static
int int
_listxattr(const fs::find::Func searchFunc, _listxattr(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
char *list, char *list,
const size_t size) const size_t size)
@ -79,7 +80,7 @@ _listxattr(const fs::find::Func searchFunc,
int rv; int rv;
fs::Paths path; fs::Paths path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -103,8 +104,7 @@ namespace mergerfs
const config::Config &config = config::get(); const config::Config &config = config::get();
if(fusepath == config.controlfile) if(fusepath == config.controlfile)
return _listxattr_controlfile(list,
size);
return _listxattr_controlfile(list,size);
const struct fuse_context *fc = fuse_get_context(); const struct fuse_context *fc = fuse_get_context();
const ugid::SetResetGuard ugid(fc->uid,fc->gid); const ugid::SetResetGuard ugid(fc->uid,fc->gid);
@ -112,6 +112,7 @@ namespace mergerfs
return _listxattr(*config.listxattr, return _listxattr(*config.listxattr,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
list, list,
size); size);

6
src/mkdir.cpp

@ -44,6 +44,7 @@ int
_mkdir(const fs::find::Func searchFunc, _mkdir(const fs::find::Func searchFunc,
const fs::find::Func createFunc, const fs::find::Func createFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const mode_t mode) const mode_t mode)
{ {
@ -55,11 +56,11 @@ _mkdir(const fs::find::Func searchFunc,
fs::Paths existingpath; fs::Paths existingpath;
dirname = fs::dirname(fusepath); dirname = fs::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,existingpath,1);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
rv = createFunc(srcmounts,dirname,createpaths,-1);
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -99,6 +100,7 @@ namespace mergerfs
return _mkdir(*config.getattr, return _mkdir(*config.getattr,
*config.mkdir, *config.mkdir,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
(mode & ~fc->umask)); (mode & ~fc->umask));
} }

6
src/mknod.cpp

@ -46,6 +46,7 @@ int
_mknod(const fs::find::Func searchFunc, _mknod(const fs::find::Func searchFunc,
const fs::find::Func createFunc, const fs::find::Func createFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const mode_t mode, const mode_t mode,
const dev_t dev) const dev_t dev)
@ -58,11 +59,11 @@ _mknod(const fs::find::Func searchFunc,
fs::Paths existingpath; fs::Paths existingpath;
dirname = fs::dirname(fusepath); dirname = fs::dirname(fusepath);
rv = searchFunc(srcmounts,dirname,existingpath,1);
rv = searchFunc(srcmounts,dirname,minfreespace,existingpath);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
rv = createFunc(srcmounts,dirname,createpaths,-1);
rv = createFunc(srcmounts,dirname,minfreespace,createpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -103,6 +104,7 @@ namespace mergerfs
return _mknod(*config.getattr, return _mknod(*config.getattr,
*config.mknod, *config.mknod,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
(mode & ~fc->umask), (mode & ~fc->umask),
rdev); rdev);

4
src/open.cpp

@ -43,6 +43,7 @@ static
int int
_open(const fs::find::Func searchFunc, _open(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const int flags, const int flags,
uint64_t &fh) uint64_t &fh)
@ -51,7 +52,7 @@ _open(const fs::find::Func searchFunc,
int rv; int rv;
fs::Paths path; fs::Paths path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -79,6 +80,7 @@ namespace mergerfs
return _open(*config.open, return _open(*config.open,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
fileinfo->flags, fileinfo->flags,
fileinfo->fh); fileinfo->fh);

46
src/option_parser.cpp

@ -27,6 +27,7 @@
#include <stddef.h> #include <stddef.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <string> #include <string>
#include <vector> #include <vector>
@ -100,6 +101,38 @@ set_default_options(struct fuse_args &args)
set_option(args,"atomic_o_trunc"); set_option(args,"atomic_o_trunc");
} }
static
int
parse_and_process_minfreespace(const std::string &value,
size_t &minfreespace)
{
char *endptr;
minfreespace = strtoll(value.c_str(),&endptr,10);
switch(*endptr)
{
case 'k':
case 'K':
minfreespace *= 1024;
break;
case 'm':
case 'M':
minfreespace *= (1024 * 1024);
break;
case 'b':
case 'B':
minfreespace *= (1024 * 1024 * 1024);
break;
default:
return 1;
}
return 0;
}
static static
int int
parse_and_process_arg(config::Config &config, parse_and_process_arg(config::Config &config,
@ -121,19 +154,22 @@ parse_and_process_kv_arg(config::Config &config,
const std::string &key, const std::string &key,
const std::string &value) const std::string &value)
{ {
int rv;
int rv = -1;
std::vector<std::string> keypart; std::vector<std::string> keypart;
str::split(keypart,key,'.'); str::split(keypart,key,'.');
if(keypart.size() != 2)
return 1;
if(keypart.size() == 2)
{
if(keypart[0] == "func") if(keypart[0] == "func")
rv = config.set_func_policy(keypart[1],value); rv = config.set_func_policy(keypart[1],value);
else if(keypart[0] == "category") else if(keypart[0] == "category")
rv = config.set_category_policy(keypart[1],value); rv = config.set_category_policy(keypart[1],value);
}
else else
rv = -1;
{
if(key == "minfreespace")
rv = parse_and_process_minfreespace(value,config.minfreespace);
}
if(rv == -1) if(rv == -1)
rv = 1; rv = 1;

4
src/readlink.cpp

@ -43,6 +43,7 @@ static
int int
_readlink(const fs::find::Func searchFunc, _readlink(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
char *buf, char *buf,
const size_t size) const size_t size)
@ -50,7 +51,7 @@ _readlink(const fs::find::Func searchFunc,
int rv; int rv;
fs::Paths path; fs::Paths path;
rv = searchFunc(srcmounts,fusepath,path,1);
rv = searchFunc(srcmounts,fusepath,minfreespace,path);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -79,6 +80,7 @@ namespace mergerfs
return _readlink(*config.readlink, return _readlink(*config.readlink,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
buf, buf,
size); size);

4
src/removexattr.cpp

@ -43,6 +43,7 @@ static
int int
_removexattr(const fs::find::Func actionFunc, _removexattr(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const char *attrname) const char *attrname)
{ {
@ -51,7 +52,7 @@ _removexattr(const fs::find::Func actionFunc,
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -89,6 +90,7 @@ namespace mergerfs
return _removexattr(*config.removexattr, return _removexattr(*config.removexattr,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
attrname); attrname);
} }

9
src/rename.cpp

@ -43,6 +43,7 @@ static
int int
_single_rename(const fs::find::Func searchFunc, _single_rename(const fs::find::Func searchFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const fs::Path &oldpath, const fs::Path &oldpath,
const string &newpath) const string &newpath)
{ {
@ -56,7 +57,7 @@ _single_rename(const fs::find::Func searchFunc,
fs::Paths newpathdir; fs::Paths newpathdir;
dirname = fs::dirname(newpath); dirname = fs::dirname(newpath);
rv = searchFunc(srcmounts,dirname,newpathdir,1);
rv = searchFunc(srcmounts,dirname,minfreespace,newpathdir);
if(rv == -1) if(rv == -1)
return -1; return -1;
@ -76,6 +77,7 @@ int
_rename(const fs::find::Func searchFunc, _rename(const fs::find::Func searchFunc,
const fs::find::Func actionFunc, const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &oldpath, const string &oldpath,
const string &newpath) const string &newpath)
{ {
@ -83,7 +85,7 @@ _rename(const fs::find::Func searchFunc,
int error; int error;
fs::Paths oldpaths; fs::Paths oldpaths;
rv = actionFunc(srcmounts,oldpath,oldpaths,-1);
rv = actionFunc(srcmounts,oldpath,minfreespace,oldpaths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -91,7 +93,7 @@ _rename(const fs::find::Func searchFunc,
for(fs::Paths::const_iterator for(fs::Paths::const_iterator
i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i) i = oldpaths.begin(), ei = oldpaths.end(); i != ei; ++i)
{ {
rv = _single_rename(searchFunc,srcmounts,*i,newpath);
rv = _single_rename(searchFunc,srcmounts,minfreespace,*i,newpath);
if(rv == -1) if(rv == -1)
error = errno; error = errno;
} }
@ -115,6 +117,7 @@ namespace mergerfs
return _rename(*config.getattr, return _rename(*config.getattr,
*config.rename, *config.rename,
config.srcmounts, config.srcmounts,
config.minfreespace,
oldpath, oldpath,
newpath); newpath);
} }

4
src/rmdir.cpp

@ -42,13 +42,14 @@ static
int int
_rmdir(const fs::find::Func actionFunc, _rmdir(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath) const string &fusepath)
{ {
int rv; int rv;
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -78,6 +79,7 @@ namespace mergerfs
return _rmdir(*config.rmdir, return _rmdir(*config.rmdir,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath); fusepath);
} }
} }

4
src/setxattr.cpp

@ -242,6 +242,7 @@ static
int int
_setxattr(const fs::find::Func actionFunc, _setxattr(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const char *attrname, const char *attrname,
const char *attrval, const char *attrval,
@ -253,7 +254,7 @@ _setxattr(const fs::find::Func actionFunc,
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -302,6 +303,7 @@ namespace mergerfs
return _setxattr(*config.setxattr, return _setxattr(*config.setxattr,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
attrname, attrname,
attrval, attrval,

4
src/symlink.cpp

@ -41,6 +41,7 @@ static
int int
_symlink(const fs::find::Func createFunc, _symlink(const fs::find::Func createFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &oldpath, const string &oldpath,
const string &newpath) const string &newpath)
{ {
@ -50,7 +51,7 @@ _symlink(const fs::find::Func createFunc,
fs::Paths newpathdirs; fs::Paths newpathdirs;
newpathdir = fs::dirname(newpath); newpathdir = fs::dirname(newpath);
rv = createFunc(srcmounts,newpathdir,newpathdirs,-1);
rv = createFunc(srcmounts,newpathdir,minfreespace,newpathdirs);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -83,6 +84,7 @@ namespace mergerfs
return _symlink(*config.symlink, return _symlink(*config.symlink,
config.srcmounts, config.srcmounts,
config.minfreespace,
oldpath, oldpath,
newpath); newpath);
} }

4
src/truncate.cpp

@ -43,6 +43,7 @@ static
int int
_truncate(const fs::find::Func actionFunc, _truncate(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const off_t size) const off_t size)
{ {
@ -50,7 +51,7 @@ _truncate(const fs::find::Func actionFunc,
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -81,6 +82,7 @@ namespace mergerfs
return _truncate(*config.truncate, return _truncate(*config.truncate,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
size); size);
} }

4
src/unlink.cpp

@ -42,13 +42,14 @@ static
int int
_unlink(const fs::find::Func actionFunc, _unlink(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath) const string &fusepath)
{ {
int rv; int rv;
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -78,6 +79,7 @@ namespace mergerfs
return _unlink(*config.unlink, return _unlink(*config.unlink,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath); fusepath);
} }
} }

4
src/utimens.cpp

@ -43,6 +43,7 @@ static
int int
_utimens(const fs::find::Func actionFunc, _utimens(const fs::find::Func actionFunc,
const vector<string> &srcmounts, const vector<string> &srcmounts,
const size_t minfreespace,
const string &fusepath, const string &fusepath,
const struct timespec ts[2]) const struct timespec ts[2])
{ {
@ -50,7 +51,7 @@ _utimens(const fs::find::Func actionFunc,
int error; int error;
fs::Paths paths; fs::Paths paths;
rv = actionFunc(srcmounts,fusepath,paths,-1);
rv = actionFunc(srcmounts,fusepath,minfreespace,paths);
if(rv == -1) if(rv == -1)
return -errno; return -errno;
@ -81,6 +82,7 @@ namespace mergerfs
return _utimens(*config.utimens, return _utimens(*config.utimens,
config.srcmounts, config.srcmounts,
config.minfreespace,
fusepath, fusepath,
ts); ts);
} }

Loading…
Cancel
Save