mirror of
https://github.com/trapexit/mergerfs.git
synced 2025-02-21 18:44:09 +08:00
Merge pull request #108 from trapexit/error-policies
create errno policies for simulating errors. closes #107
This commit is contained in:
commit
fd26793305
@ -73,6 +73,7 @@ Filesystem calls are broken up into 3 categories: **action**, **create**, **sear
|
||||
| lfs (least free space) | Pick the path with least available space but more than **minfreespace**. |
|
||||
| rand (random) | Pick an existing destination at random. |
|
||||
| all | Applies action to all found. For searches it will behave like first found **ff**. |
|
||||
| enosys, einval, enotsup, exdev, erofs | Exclusively return `-1` with `errno` set to the respective value. Useful for debugging other applications' behavior to errors. |
|
||||
|
||||
#### Defaults ####
|
||||
|
||||
|
@ -36,7 +36,12 @@ namespace mergerfs
|
||||
buildvector<Policy,true>
|
||||
(POLICY(invalid))
|
||||
(POLICY(all))
|
||||
(POLICY(einval))
|
||||
(POLICY(enosys))
|
||||
(POLICY(enotsup))
|
||||
(POLICY(epmfs))
|
||||
(POLICY(erofs))
|
||||
(POLICY(exdev))
|
||||
(POLICY(ff))
|
||||
(POLICY(ffwp))
|
||||
(POLICY(fwfs))
|
||||
@ -47,16 +52,23 @@ namespace mergerfs
|
||||
|
||||
const Policy * const Policy::policies = &_policies_[1];
|
||||
|
||||
const Policy &Policy::invalid = Policy::policies[Policy::Enum::invalid];
|
||||
const Policy &Policy::all = Policy::policies[Policy::Enum::all];
|
||||
const Policy &Policy::epmfs = Policy::policies[Policy::Enum::epmfs];
|
||||
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];
|
||||
#define CONST_POLICY(X) const Policy &Policy::X = Policy::policies[Policy::Enum::X]
|
||||
|
||||
CONST_POLICY(invalid);
|
||||
CONST_POLICY(all);
|
||||
CONST_POLICY(einval);
|
||||
CONST_POLICY(enosys);
|
||||
CONST_POLICY(enotsup);
|
||||
CONST_POLICY(epmfs);
|
||||
CONST_POLICY(erofs);
|
||||
CONST_POLICY(exdev);
|
||||
CONST_POLICY(ff);
|
||||
CONST_POLICY(ffwp);
|
||||
CONST_POLICY(fwfs);
|
||||
CONST_POLICY(lfs);
|
||||
CONST_POLICY(mfs);
|
||||
CONST_POLICY(newest);
|
||||
CONST_POLICY(rand);
|
||||
|
||||
const Policy&
|
||||
Policy::find(const std::string &str)
|
||||
|
@ -45,7 +45,12 @@ namespace mergerfs
|
||||
invalid = -1,
|
||||
BEGIN = 0,
|
||||
all = BEGIN,
|
||||
einval,
|
||||
enosys,
|
||||
enotsup,
|
||||
epmfs,
|
||||
erofs,
|
||||
exdev,
|
||||
ff,
|
||||
ffwp,
|
||||
fwfs,
|
||||
@ -120,12 +125,17 @@ namespace mergerfs
|
||||
const Ptr func;
|
||||
};
|
||||
|
||||
static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int all(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int einval(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int enosys(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int enotsup(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int epmfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int erofs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int exdev(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int ff(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int ffwp(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int fwfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int invalid(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int lfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int mfs(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
static int newest(CType,cstrvec&,cstring&,csize_t,strvec&);
|
||||
@ -183,7 +193,11 @@ namespace mergerfs
|
||||
|
||||
static const Policy &invalid;
|
||||
static const Policy &all;
|
||||
static const Policy &enosys;
|
||||
static const Policy &enotsup;
|
||||
static const Policy &epmfs;
|
||||
static const Policy &erofs;
|
||||
static const Policy &exdev;
|
||||
static const Policy &ff;
|
||||
static const Policy &ffwp;
|
||||
static const Policy &fwfs;
|
||||
|
46
src/policy_einval.cpp
Normal file
46
src/policy_einval.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::einval(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=EINVAL,-1);
|
||||
}
|
||||
}
|
46
src/policy_enosys.cpp
Normal file
46
src/policy_enosys.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::enosys(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=ENOSYS,-1);
|
||||
}
|
||||
}
|
46
src/policy_enotsup.cpp
Normal file
46
src/policy_enotsup.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::enotsup(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=ENOTSUP,-1);
|
||||
}
|
||||
}
|
46
src/policy_erofs.cpp
Normal file
46
src/policy_erofs.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::erofs(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=EROFS,-1);
|
||||
}
|
||||
}
|
46
src/policy_exdev.cpp
Normal file
46
src/policy_exdev.cpp
Normal file
@ -0,0 +1,46 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Antonio SJ Musumeci <trapexit@spawn.link>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "policy.hpp"
|
||||
|
||||
using std::string;
|
||||
using std::vector;
|
||||
|
||||
namespace mergerfs
|
||||
{
|
||||
int
|
||||
Policy::Func::exdev(const Category::Enum::Type type,
|
||||
const vector<string> &basepaths,
|
||||
const string &fusepath,
|
||||
const size_t minfreespace,
|
||||
vector<string> &paths)
|
||||
{
|
||||
return (errno=EXDEV,-1);
|
||||
}
|
||||
}
|
@ -42,6 +42,6 @@ namespace mergerfs
|
||||
const size_t minfreespace,
|
||||
vector<string> &rv)
|
||||
{
|
||||
return (errno = EINVAL,-1);
|
||||
return (errno=EINVAL,-1);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user