From 0fffabfbe35d2bff3ab0d7eabf0b06100863ed91 Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sat, 7 Sep 2019 17:23:48 -0400 Subject: [PATCH] only return 1 branch for rand/eprand policies --- README.md | 4 ++-- man/mergerfs.1 | 2 ++ src/policy_eprand.cpp | 15 +++++++++------ src/policy_rand.cpp | 15 +++++++++------ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index f3682e45..274bbb6a 100644 --- a/README.md +++ b/README.md @@ -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. | | 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. | -| 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). | | 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. | | 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. | | 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 #### diff --git a/man/mergerfs.1 b/man/mergerfs.1 index 2297839d..9b60dc24 100644 --- a/man/mergerfs.1 +++ b/man/mergerfs.1 @@ -622,6 +622,7 @@ T{ eprand (existing path, random) T}@T{ Calls \f[B]epall\f[] and then randomizes. +Returns 1. T} T{ erofs @@ -667,6 +668,7 @@ T{ rand (random) T}@T{ Calls \f[B]all\f[] and then randomizes. +Returns 1. T} .TE .SS Defaults diff --git a/src/policy_eprand.cpp b/src/policy_eprand.cpp index ee5eb9d3..1e71bd59 100644 --- a/src/policy_eprand.cpp +++ b/src/policy_eprand.cpp @@ -25,17 +25,20 @@ using std::string; using std::vector; int -Policy::Func::eprand(const Category::Enum::Type type, +Policy::Func::eprand(const Category::Enum::Type type_, const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector &paths) + const char *fusepath_, + const uint64_t minfreespace_, + vector &paths_) { int rv; - rv = Policy::Func::epall(type,branches_,fusepath,minfreespace,paths); + rv = Policy::Func::epall(type_,branches_,fusepath_,minfreespace_,paths_); if(rv == 0) - std::random_shuffle(paths.begin(),paths.end()); + { + std::random_shuffle(paths_.begin(),paths_.end()); + paths_.resize(1); + } return rv; } diff --git a/src/policy_rand.cpp b/src/policy_rand.cpp index a96307b8..9cd35751 100644 --- a/src/policy_rand.cpp +++ b/src/policy_rand.cpp @@ -25,17 +25,20 @@ using std::string; using std::vector; int -Policy::Func::rand(const Category::Enum::Type type, +Policy::Func::rand(const Category::Enum::Type type_, const Branches &branches_, - const char *fusepath, - const uint64_t minfreespace, - vector &paths) + const char *fusepath_, + const uint64_t minfreespace_, + vector &paths_) { int rv; - rv = Policy::Func::all(type,branches_,fusepath,minfreespace,paths); + rv = Policy::Func::all(type_,branches_,fusepath_,minfreespace_,paths_); if(rv == 0) - std::random_shuffle(paths.begin(),paths.end()); + { + std::random_shuffle(paths_.begin(),paths_.end()); + paths_.resize(1); + } return rv; }