Merge pull request #663 from trapexit/random

only return 1 branch for rand/eprand policies
This commit is contained in:
trapexit 2019-09-07 17:27:56 -04:00 committed by GitHub
commit 0b0f0a1b9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 14 deletions

View File

@ -253,14 +253,14 @@ If all branches are filtered an error will be returned. Typically **EROFS** or *
| eplfs (existing path, least free space) | Of all the branches on which the relative path exists choose the drive with the least free space. | | eplfs (existing path, least free space) | Of all the branches on which the relative path exists choose the drive with the least free space. |
| eplus (existing path, least used space) | Of all the branches on which the relative path exists choose the drive with the least used space. | | eplus (existing path, least used space) | Of all the branches on which the relative path exists choose the drive with the least used space. |
| epmfs (existing path, most free space) | Of all the branches on which the relative path exists choose the drive with the most free space. | | epmfs (existing path, most free space) | Of all the branches on which the relative path exists choose the drive with the most free space. |
| eprand (existing path, random) | Calls **epall** and then randomizes. | | eprand (existing path, random) | Calls **epall** and then randomizes. Returns 1. |
| erofs | Exclusively return **-1** with **errno** set to **EROFS** (read-only filesystem). | | erofs | Exclusively return **-1** with **errno** set to **EROFS** (read-only filesystem). |
| ff (first found) | Search category: same as **epff**. Action category: same as **epff**. Create category: Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found. | | ff (first found) | Search category: same as **epff**. Action category: same as **epff**. Create category: Given the order of the drives, as defined at mount time or configured at runtime, act on the first one found. |
| lfs (least free space) | Search category: same as **eplfs**. Action category: same as **eplfs**. Create category: Pick the drive with the least available free space. | | lfs (least free space) | Search category: same as **eplfs**. Action category: same as **eplfs**. Create category: Pick the drive with the least available free space. |
| lus (least used space) | Search category: same as **eplus**. Action category: same as **eplus**. Create category: Pick the drive with the least used space. | | lus (least used space) | Search category: same as **eplus**. Action category: same as **eplus**. Create category: Pick the drive with the least used space. |
| mfs (most free space) | Search category: same as **epmfs**. Action category: same as **epmfs**. Create category: Pick the drive with the most available free space. | | mfs (most free space) | Search category: same as **epmfs**. Action category: same as **epmfs**. Create category: Pick the drive with the most available free space. |
| newest | Pick the file / directory with the largest mtime. | | newest | Pick the file / directory with the largest mtime. |
| rand (random) | Calls **all** and then randomizes. | | rand (random) | Calls **all** and then randomizes. Returns 1. |
#### Defaults #### #### Defaults ####

View File

@ -622,6 +622,7 @@ T{
eprand (existing path, random) eprand (existing path, random)
T}@T{ T}@T{
Calls \f[B]epall\f[] and then randomizes. Calls \f[B]epall\f[] and then randomizes.
Returns 1.
T} T}
T{ T{
erofs erofs
@ -667,6 +668,7 @@ T{
rand (random) rand (random)
T}@T{ T}@T{
Calls \f[B]all\f[] and then randomizes. Calls \f[B]all\f[] and then randomizes.
Returns 1.
T} T}
.TE .TE
.SS Defaults .SS Defaults

View File

@ -25,17 +25,20 @@ using std::string;
using std::vector; using std::vector;
int int
Policy::Func::eprand(const Category::Enum::Type type, Policy::Func::eprand(const Category::Enum::Type type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath_,
const uint64_t minfreespace, const uint64_t minfreespace_,
vector<const string*> &paths) vector<const string*> &paths_)
{ {
int rv; int rv;
rv = Policy::Func::epall(type,branches_,fusepath,minfreespace,paths); rv = Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_);
if(rv == 0) if(rv == 0)
std::random_shuffle(paths.begin(),paths.end()); {
std::random_shuffle(paths_.begin(),paths_.end());
paths_.resize(1);
}
return rv; return rv;
} }

View File

@ -25,17 +25,20 @@ using std::string;
using std::vector; using std::vector;
int int
Policy::Func::rand(const Category::Enum::Type type, Policy::Func::rand(const Category::Enum::Type type_,
const Branches &branches_, const Branches &branches_,
const char *fusepath, const char *fusepath_,
const uint64_t minfreespace, const uint64_t minfreespace_,
vector<const string*> &paths) vector<const string*> &paths_)
{ {
int rv; int rv;
rv = Policy::Func::all(type,branches_,fusepath,minfreespace,paths); rv = Policy::Func::all(type_,branches_,fusepath_,minfreespace_,paths_);
if(rv == 0) if(rv == 0)
std::random_shuffle(paths.begin(),paths.end()); {
std::random_shuffle(paths_.begin(),paths_.end());
paths_.resize(1);
}
return rv; return rv;
} }