Skip to content

Commit

Permalink
Merge pull request trapexit#815 from trapexit/policy-pfrd
Browse files Browse the repository at this point in the history
add {,ep,msp}pfrd policies
  • Loading branch information
trapexit authored Aug 26, 2020
2 parents 7ff9956 + 0468440 commit 3534fb1
Show file tree
Hide file tree
Showing 9 changed files with 729 additions and 17 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
% mergerfs(1) mergerfs user manual
% Antonio SJ Musumeci <trapexit@spawn.link>
% 2020-08-07
% 2020-08-20

# NAME

Expand Down Expand Up @@ -306,22 +306,25 @@ Because of the nature of the behavior the policies act diffierently depending on

| Policy | Description |
|------------------|------------------------------------------------------------|
| all | Search: same as **epall**. Action: same as **epall**. Create: for **mkdir**, **mknod**, and **symlink** it will apply to all branches. **create** works like **ff**. |
| epall (existing path, all) | Search: same as **epff** (but more expensive because it doesn't stop after finding a valid branch). Action: apply to all found. Create: for **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **epff** (but more expensive because it doesn't stop after finding a valid branch). |
| all | Search: Same as **epall**. Action: Same as **epall**. Create: for **mkdir**, **mknod**, and **symlink** it will apply to all branches. **create** works like **ff**. |
| epall (existing path, all) | Search: Same as **epff** (but more expensive because it doesn't stop after finding a valid branch). Action: apply to all found. Create: for **mkdir**, **mknod**, and **symlink** it will apply to all found. **create** works like **epff** (but more expensive because it doesn't stop after finding a valid branch). |
| epff (existing path, first found) | Given the order of the branches, as defined at mount time or configured at runtime, act on the first one found where the relative path exists. |
| 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. |
| eppfrd (existing path, percentage free random distribution) | Like **pfrd** but limited to existing paths. |
| 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: same as **epff**. Action: same as **epff**. Create: 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: same as **eplfs**. Action: same as **eplfs**. Create: Pick the drive with the least available free space. |
| lus (least used space) | Search: same as **eplus**. Action: same as **eplus**. Create: Pick the drive with the least used space. |
| mfs (most free space) | Search: same as **epmfs**. Action: same as **epmfs**. Create: Pick the drive with the most available free space. |
| msplfs (most shared path, least free space) | Search: same as **eplfs**. Action: same as **eplfs**. Create: like **eplfs** but walk back the path if it fails to find a branch at that level. |
| msplus (most shared path, least used space) | Search: same as **eplus**. Action: same as **eplus**. Create: like **eplus** but walk back the path if it fails to find a branch at that level. |
| mspmfs (most shared path, most free space) | Search: same as **epmfss**. Action: same as **epmfs**. Create: like **eplmfs** but walk back the path if it fails to find a branch at that level. |
| ff (first found) | Search: Same as **epff**. Action: Same as **epff**. Create: 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: Same as **eplfs**. Action: Same as **eplfs**. Create: Pick the drive with the least available free space. |
| lus (least used space) | Search: Same as **eplus**. Action: Same as **eplus**. Create: Pick the drive with the least used space. |
| mfs (most free space) | Search: Same as **epmfs**. Action: Same as **epmfs**. Create: Pick the drive with the most available free space. |
| msplfs (most shared path, least free space) | Search: Same as **eplfs**. Action: Same as **eplfs**. Create: like **eplfs** but walk back the path if it fails to find a branch at that level. |
| msplus (most shared path, least used space) | Search: Same as **eplus**. Action: Same as **eplus**. Create: like **eplus** but walk back the path if it fails to find a branch at that level. |
| mspmfs (most shared path, most free space) | Search: Same as **epmfss**. Action: Same as **epmfs**. Create: like **eplmfs** but walk back the path if it fails to find a branch at that level. |
| msppfrd (most shared path, percentage free random distribution) | Search: Same as **eppfrd**. Action: Same as **eppfrd**. Create: Like **eppfrd** but will walk back the path if it fails to find a branch at that level. |
| newest | Pick the file / directory with the largest mtime. |
| pfrd (percentage free random distribution) | Search: Same as **eppfrd**. Action: Same as **eppfrd**. Create: Chooses a branch at random with the likelihood of selection based on a branch's available space relative to the total. |
| rand (random) | Calls **all** and then randomizes. Returns 1. |

**NOTE:** If you are using an underlying filesystem that reserves blocks such as ext2, ext3, or ext4 be aware that mergerfs respects the reservation by using `f_bavail` (number of free blocks for unprivileged users) rather than `f_bfree` (number of free blocks) in policy calculations. **df** does NOT use `f_bavail`, it uses `f_bfree`, so direct comparisons between **df** output and mergerfs' policies is not appropriate.
Expand Down
23 changes: 22 additions & 1 deletion man/mergerfs.1
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.\"t
.\" Automatically generated by Pandoc 1.19.2.4
.\"
.TH "mergerfs" "1" "2020\-08\-07" "mergerfs user manual" ""
.TH "mergerfs" "1" "2020\-08\-20" "mergerfs user manual" ""
.hy
.SH NAME
.PP
Expand Down Expand Up @@ -778,6 +778,11 @@ Of all the branches on which the relative path exists choose the drive
with the most free space.
T}
T{
eppfrd (existing path, percentage free random distribution)
T}@T{
Like \f[B]pfrd\f[] but limited to existing paths.
T}
T{
eprand (existing path, random)
T}@T{
Calls \f[B]epall\f[] and then randomizes.
Expand Down Expand Up @@ -843,11 +848,27 @@ Create: like \f[B]eplmfs\f[] but walk back the path if it fails to find
a branch at that level.
T}
T{
msppfrd (most shared path, percentage free random distribution)
T}@T{
Search: same as \f[B]eppfrd\f[].
Action: same as \f[B]eppfrd\f[].
Create: Like \f[B]eppfrd\f[] but will walk back the path if it fails to
find a branch at that level.
T}
T{
newest
T}@T{
Pick the file / directory with the largest mtime.
T}
T{
pfrd (percentage free random distribution)
T}@T{
Search: same as \f[B]eppfrd\f[].
Action: same as \f[B]eppfrd\f[].
Create: Chooses a branch at random with the likelihood of selection
based on a branch\[aq]s available space relative to the total.
T}
T{
rand (random)
T}@T{
Calls \f[B]all\f[] and then randomizes.
Expand Down
18 changes: 12 additions & 6 deletions src/policy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const std::vector<Policy> Policy::_policies_ =
(POLICY(eplfs,PRESERVES_PATH))
(POLICY(eplus,PRESERVES_PATH))
(POLICY(epmfs,PRESERVES_PATH))
(POLICY(eppfrd,PRESERVES_PATH))
(POLICY(eprand,PRESERVES_PATH))
(POLICY(erofs,DOESNT_PRESERVE_PATH))
(POLICY(ff,DOESNT_PRESERVE_PATH))
Expand All @@ -41,7 +42,9 @@ const std::vector<Policy> Policy::_policies_ =
(POLICY(msplfs,PRESERVES_PATH))
(POLICY(msplus,PRESERVES_PATH))
(POLICY(mspmfs,PRESERVES_PATH))
(POLICY(msppfrd,PRESERVES_PATH))
(POLICY(newest,DOESNT_PRESERVE_PATH))
(POLICY(pfrd,DOESNT_PRESERVE_PATH))
(POLICY(rand,DOESNT_PRESERVE_PATH));

const Policy * const Policy::policies = &_policies_[1];
Expand All @@ -55,6 +58,7 @@ CONST_POLICY(epff);
CONST_POLICY(eplfs);
CONST_POLICY(eplus);
CONST_POLICY(epmfs);
CONST_POLICY(eppfrd);
CONST_POLICY(eprand);
CONST_POLICY(erofs);
CONST_POLICY(ff);
Expand All @@ -64,19 +68,21 @@ CONST_POLICY(mfs);
CONST_POLICY(msplfs);
CONST_POLICY(msplus);
CONST_POLICY(mspmfs);
CONST_POLICY(msppfrd);
CONST_POLICY(newest);
CONST_POLICY(pfrd);
CONST_POLICY(rand);

const Policy&
Policy::find(const std::string &str)
{
for(int i = Enum::BEGIN; i != Enum::END; ++i)
{
if(policies[i] == str)
return policies[i];
}
for(int i = Enum::BEGIN; i != Enum::END; ++i)
{
if(policies[i] == str)
return policies[i];
}

return invalid;
return invalid;
}

const Policy&
Expand Down
9 changes: 9 additions & 0 deletions src/policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class Policy
eplfs,
eplus,
epmfs,
eppfrd,
eprand,
erofs,
ff,
Expand All @@ -46,7 +47,9 @@ class Policy
msplfs,
msplus,
mspmfs,
msppfrd,
newest,
pfrd,
rand,
END
};
Expand Down Expand Up @@ -117,6 +120,7 @@ class Policy
static int eplfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int eplus(Category,const Branches&,const char *,cuint64_t,strvec*);
static int epmfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int eppfrd(Category,const Branches&,const char *,cuint64_t,strvec*);
static int eprand(Category,const Branches&,const char *,cuint64_t,strvec*);
static int erofs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int ff(Category,const Branches&,const char *,cuint64_t,strvec*);
Expand All @@ -126,7 +130,9 @@ class Policy
static int msplfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int msplus(Category,const Branches&,const char *,cuint64_t,strvec*);
static int mspmfs(Category,const Branches&,const char *,cuint64_t,strvec*);
static int msppfrd(Category,const Branches&,const char *,cuint64_t,strvec*);
static int newest(Category,const Branches&,const char *,cuint64_t,strvec*);
static int pfrd(Category,const Branches&,const char *,cuint64_t,strvec*);
static int rand(Category,const Branches&,const char *,cuint64_t,strvec*);
};

Expand Down Expand Up @@ -198,6 +204,7 @@ class Policy
static const Policy &eplfs;
static const Policy &eplus;
static const Policy &epmfs;
static const Policy &eppfrd;
static const Policy &eprand;
static const Policy &erofs;
static const Policy &ff;
Expand All @@ -207,7 +214,9 @@ class Policy
static const Policy &msplfs;
static const Policy &msplus;
static const Policy &mspmfs;
static const Policy &msppfrd;
static const Policy &newest;
static const Policy &pfrd;
static const Policy &rand;
};

Expand Down
Loading

0 comments on commit 3534fb1

Please sign in to comment.