mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 04:46:41 -05:00
fix: leave the source branch out before moveonenospc picks a branch
- The source branch was dropped from the create policy's result. ff, mfs, lfs, lus and pfrd return a single branch, so when that branch was the source nothing was left and the write kept ENOSPC even with room elsewhere. That happens when the source has free space by statvfs but still returns ENOSPC or EDQUOT: a quota, exhausted inodes, full btrfs metadata, or a cached statfs. - Build the candidate list without the source (matched by device and inode, as before) and run the policy on that, so it picks another branch. With no candidate left the move is still refused. - test_fs_movefile_and_open_same_branch now checks that ff relocates past a source listed first, by its own path or an alias, and that a list made only of the source is refused.
This commit is contained in:
parent
4434e3ba62
commit
1423e577a3
2 changed files with 69 additions and 41 deletions
|
|
@ -35,6 +35,7 @@
|
|||
#include "fs_unlink.hpp"
|
||||
#include "policy.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -62,11 +63,15 @@ _cleanup_flags(const int flags_)
|
|||
// Copying onto the source directory would rename the copy over the
|
||||
// file and then unlink it. Match by device and inode so another path
|
||||
// to the same directory, such as a bind mount, is caught too. A
|
||||
// destination that can't be stat'd is dropped as well.
|
||||
// branch that can't be stat'd is left out as well. The source is
|
||||
// removed before the create policy runs: most policies pick a single
|
||||
// branch, and filtering their pick afterwards would leave nothing
|
||||
// when they chose the source.
|
||||
static
|
||||
int
|
||||
_drop_src_branch(const fs::path &src_branch_,
|
||||
std::vector<Branch*> *dst_branches_)
|
||||
_branches_without_src(const fs::path &src_branch_,
|
||||
const Branches::Ptr &branches_,
|
||||
Branches::Ptr *candidates_)
|
||||
{
|
||||
int rv;
|
||||
struct stat src_st;
|
||||
|
|
@ -75,17 +80,19 @@ _drop_src_branch(const fs::path &src_branch_,
|
|||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
std::erase_if(*dst_branches_,
|
||||
[&](const Branch *branch_)
|
||||
{
|
||||
struct stat st;
|
||||
*candidates_ = std::make_shared<Branches::Impl>(&branches_->minfreespace());
|
||||
for(const Branch &branch : *branches_)
|
||||
{
|
||||
struct stat st;
|
||||
|
||||
if(fs::stat(branch_->path,&st) < 0)
|
||||
return true;
|
||||
if(fs::stat(branch.path,&st) < 0)
|
||||
continue;
|
||||
if((st.st_dev == src_st.st_dev) &&
|
||||
(st.st_ino == src_st.st_ino))
|
||||
continue;
|
||||
|
||||
return ((st.st_dev == src_st.st_dev) &&
|
||||
(st.st_ino == src_st.st_ino));
|
||||
});
|
||||
(*candidates_)->push_back(branch);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -106,6 +113,7 @@ _movefile_and_open(const Policy::Create &createFunc_,
|
|||
fs::path src_branch;
|
||||
fs::path src_filepath;
|
||||
fs::path dst_filepath;
|
||||
Branches::Ptr candidates;
|
||||
std::vector<Branch*> dst_branch;
|
||||
|
||||
// `branchpath_` is where the file was opened. An earlier move on the
|
||||
|
|
@ -115,10 +123,13 @@ _movefile_and_open(const Policy::Create &createFunc_,
|
|||
if(rv < 0)
|
||||
return rv;
|
||||
|
||||
rv = createFunc_(branches_,fusepath_,dst_branch);
|
||||
rv = ::_branches_without_src(src_branch,branches_,&candidates);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
rv = ::_drop_src_branch(src_branch,&dst_branch);
|
||||
if(candidates->empty())
|
||||
return -ENOSPC;
|
||||
|
||||
rv = createFunc_(candidates,fusepath_,dst_branch);
|
||||
if(rv < 0)
|
||||
return rv;
|
||||
if(dst_branch.empty())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue