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
|
|
@ -3681,10 +3681,12 @@ _file_contents(const fs::path &path_)
|
|||
return contents.str();
|
||||
}
|
||||
|
||||
// moveonenospc's create policy can pick the branch the file is already
|
||||
// on, by its own path or by another path to the same directory (a bind
|
||||
// mount; a symlink stands in for one here). The copy would be renamed
|
||||
// over the file and then unlinked, so such a move must be refused.
|
||||
// moveonenospc must never pick the branch the file is already on, by
|
||||
// its own path or by another path to the same directory (a bind mount;
|
||||
// a symlink stands in for one here). The copy would be renamed over
|
||||
// the file and then unlinked. Such branches are removed before the
|
||||
// create policy runs, so a policy that picks one branch (ff here)
|
||||
// chooses another one rather than nothing.
|
||||
void
|
||||
test_fs_movefile_and_open_same_branch()
|
||||
{
|
||||
|
|
@ -3712,54 +3714,69 @@ test_fs_movefile_and_open_same_branch()
|
|||
std::filesystem::create_directory(other,ec);
|
||||
if(!ec)
|
||||
std::filesystem::create_directory_symlink(src,alias,ec);
|
||||
if(!ec)
|
||||
std::ofstream(src / "file",std::ios::binary) << data;
|
||||
fd = ::open((src / "file").c_str(),O_RDWR);
|
||||
TEST_CHECK(!ec && (fd >= 0) && (::fstat(fd,&before) == 0));
|
||||
if(ec || (fd < 0))
|
||||
TEST_CHECK(!ec);
|
||||
if(ec)
|
||||
{
|
||||
std::filesystem::remove_all(tmp_dir);
|
||||
return;
|
||||
}
|
||||
|
||||
// ff picks the first branch. Branches resolves symlinks while
|
||||
// parsing, so the first path is set afterwards.
|
||||
auto move = [&](const std::string &list_,
|
||||
const fs::path &first_)
|
||||
auto reset = [&]()
|
||||
{
|
||||
std::filesystem::remove(other / "file",ec);
|
||||
std::ofstream(src / "file",std::ios::binary|std::ios::trunc) << data;
|
||||
fd = ::open((src / "file").c_str(),O_RDWR);
|
||||
TEST_CHECK((fd >= 0) && (::fstat(fd,&before) == 0));
|
||||
|
||||
return (fd >= 0);
|
||||
};
|
||||
|
||||
// Branches resolves symlinks while parsing, so the paths are set
|
||||
// afterwards.
|
||||
auto move = [&](const fs::path &first_,
|
||||
const fs::path &second_)
|
||||
{
|
||||
Branches branches;
|
||||
branches.minfreespace = 0;
|
||||
TEST_CHECK(branches.from_string(list_) == 0);
|
||||
TEST_CHECK(branches.from_string(src.string() + ":" + other.string()) == 0);
|
||||
Branches::Ptr ptr = branches;
|
||||
ptr->front().path = first_;
|
||||
ptr->back().path = second_;
|
||||
|
||||
return fs::movefile_and_open(ff,ptr,src,"file",fd);
|
||||
};
|
||||
|
||||
for(const auto &first : {src,alias})
|
||||
// Every branch is the source: refused, file left alone.
|
||||
if(reset())
|
||||
{
|
||||
rv = move(src.string() + ":" + other.string(),first);
|
||||
rv = move(src,alias);
|
||||
TEST_CHECK(rv == -ENOSPC);
|
||||
TEST_MSG("first branch: %s; rv: %d",first.c_str(),rv);
|
||||
TEST_MSG("rv: %d",rv);
|
||||
if(rv >= 0)
|
||||
::close(rv);
|
||||
|
||||
TEST_CHECK(::stat((src / "file").c_str(),&after) == 0);
|
||||
TEST_CHECK(after.st_ino == before.st_ino);
|
||||
TEST_CHECK(_file_contents(src / "file") == data);
|
||||
TEST_CHECK(!std::filesystem::exists(other / "file"));
|
||||
::close(fd);
|
||||
}
|
||||
|
||||
// Control: a different first branch still relocates.
|
||||
rv = move(other.string() + ":" + src.string(),other);
|
||||
TEST_CHECK(rv >= 0);
|
||||
TEST_MSG("rv: %d",rv);
|
||||
if(rv >= 0)
|
||||
::close(rv);
|
||||
TEST_CHECK(!std::filesystem::exists(src / "file"));
|
||||
TEST_CHECK(_file_contents(other / "file") == data);
|
||||
// ff would pick the source listed first; it picks `other` instead.
|
||||
for(const auto &first : {src,alias,other})
|
||||
{
|
||||
if(!reset())
|
||||
break;
|
||||
|
||||
rv = move(first,((first == other) ? src : other));
|
||||
TEST_CHECK(rv >= 0);
|
||||
TEST_MSG("first branch: %s; rv: %d",first.c_str(),rv);
|
||||
if(rv >= 0)
|
||||
::close(rv);
|
||||
TEST_CHECK(!std::filesystem::exists(src / "file"));
|
||||
TEST_CHECK(_file_contents(other / "file") == data);
|
||||
::close(fd);
|
||||
}
|
||||
|
||||
::close(fd);
|
||||
std::filesystem::remove_all(tmp_dir);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue