mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 21:00:13 -05:00
fix: make enum, minfreespace and process-name options safe to change
- Options set through the .mergerfs xattr are written while request threads read them, with no synchronization. That is a data race; on 32-bit targets a request could see half of a new 64-bit minfreespace. - Store the default minfreespace as std::atomic<u64> with relaxed loads and stores. Per-branch values are unchanged. - Store every enum option (rename-exdev, xattr, cache.files, statfs, nfsopenhack, follow-symlinks and the rest) atomically. Copies take a snapshot. - getxattr, setxattr and removexattr read the xattr option once per request instead of twice. - cache.files.process-names was cleared and refilled in place while open and create looked names up in it, which could walk freed tree nodes. Build the new set aside and swap it in under a lock that lookups share. - Other options (booleans, numbers and strings) are still plain values; this covers only the ones above.
This commit is contained in:
parent
e4e9d54fe7
commit
8cc6be6ff2
16 changed files with 118 additions and 45 deletions
|
|
@ -416,7 +416,7 @@ test_branch_default_ctor_mode()
|
|||
void
|
||||
test_branch_to_string_modes()
|
||||
{
|
||||
uint64_t global = 0;
|
||||
std::atomic<u64> global{0};
|
||||
Branch b(global);
|
||||
|
||||
b.path = "/mnt/disk1";
|
||||
|
|
@ -434,7 +434,7 @@ test_branch_to_string_modes()
|
|||
void
|
||||
test_branch_to_string_with_minfreespace()
|
||||
{
|
||||
uint64_t global = 0;
|
||||
std::atomic<u64> global{0};
|
||||
Branch b(global);
|
||||
|
||||
b.path = "/mnt/disk1";
|
||||
|
|
@ -481,7 +481,7 @@ test_branch_mode_predicates()
|
|||
void
|
||||
test_branch_minfreespace_pointer_vs_value()
|
||||
{
|
||||
uint64_t global = 9999;
|
||||
std::atomic<u64> global{9999};
|
||||
Branch b(global);
|
||||
|
||||
// Reads through the pointer
|
||||
|
|
@ -503,7 +503,7 @@ test_branch_minfreespace_pointer_vs_value()
|
|||
void
|
||||
test_branch_copy_constructor()
|
||||
{
|
||||
uint64_t global = 100;
|
||||
std::atomic<u64> global{100};
|
||||
Branch orig(global);
|
||||
orig.path = "/orig";
|
||||
orig.mode = Branch::Mode::RO;
|
||||
|
|
@ -517,7 +517,7 @@ test_branch_copy_constructor()
|
|||
void
|
||||
test_branch_copy_assignment()
|
||||
{
|
||||
uint64_t global = 77;
|
||||
std::atomic<u64> global{77};
|
||||
Branch a(global);
|
||||
a.path = "/a";
|
||||
a.mode = Branch::Mode::NC;
|
||||
|
|
@ -758,7 +758,7 @@ test_branches_srcmounts_empty()
|
|||
void
|
||||
test_branch_to_string_1t()
|
||||
{
|
||||
uint64_t global = 0;
|
||||
std::atomic<u64> global{0};
|
||||
Branch b(global);
|
||||
b.path = "/mnt/disk1";
|
||||
b.mode = Branch::Mode::RW;
|
||||
|
|
@ -774,7 +774,7 @@ void
|
|||
test_branch_to_string_non_exact_multiple()
|
||||
{
|
||||
// 1536 = 1.5K: not divisible by any tier, emitted as raw decimal
|
||||
uint64_t global = 0;
|
||||
std::atomic<u64> global{0};
|
||||
Branch b(global);
|
||||
b.path = "/mnt/disk1";
|
||||
b.mode = Branch::Mode::RW;
|
||||
|
|
@ -803,7 +803,7 @@ test_branch_copy_pointer_aliasing()
|
|||
{
|
||||
// A copy of a pointer-backed Branch shares the same pointer —
|
||||
// mutating the original global value is seen by both.
|
||||
uint64_t global = 1024;
|
||||
std::atomic<u64> global{1024};
|
||||
Branch orig(global);
|
||||
orig.path = "/mnt/a";
|
||||
orig.mode = Branch::Mode::RW;
|
||||
|
|
@ -4343,8 +4343,8 @@ test_rnd_shrink_to_rand_elem()
|
|||
void
|
||||
test_branch_copy_assignment_relinks_default_minfreespace()
|
||||
{
|
||||
uint64_t default_a = 1234;
|
||||
uint64_t default_b = 5678;
|
||||
std::atomic<u64> default_a{1234};
|
||||
std::atomic<u64> default_b{5678};
|
||||
Branches::Impl impl_a(&default_a);
|
||||
Branches::Impl impl_b(&default_b);
|
||||
|
||||
|
|
@ -4356,16 +4356,16 @@ test_branch_copy_assignment_relinks_default_minfreespace()
|
|||
TEST_CHECK(impl_a.size() == 1);
|
||||
for(auto &branch : impl_a)
|
||||
{
|
||||
if(std::holds_alternative<const u64*>(branch._minfreespace))
|
||||
TEST_CHECK(std::get<const u64*>(branch._minfreespace) == &default_a);
|
||||
if(std::holds_alternative<const std::atomic<u64>*>(branch._minfreespace))
|
||||
TEST_CHECK(std::get<const std::atomic<u64>*>(branch._minfreespace) == &default_a);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
test_branch_move_assignment_relinks_default_minfreespace()
|
||||
{
|
||||
uint64_t default_a = 1234;
|
||||
uint64_t default_b = 5678;
|
||||
std::atomic<u64> default_a{1234};
|
||||
std::atomic<u64> default_b{5678};
|
||||
Branches::Impl impl_a(&default_a);
|
||||
Branches::Impl impl_b(&default_b);
|
||||
|
||||
|
|
@ -4377,8 +4377,8 @@ test_branch_move_assignment_relinks_default_minfreespace()
|
|||
TEST_CHECK(impl_a.size() == 1);
|
||||
for(auto &branch : impl_a)
|
||||
{
|
||||
if(std::holds_alternative<const u64*>(branch._minfreespace))
|
||||
TEST_CHECK(std::get<const u64*>(branch._minfreespace) == &default_a);
|
||||
if(std::holds_alternative<const std::atomic<u64>*>(branch._minfreespace))
|
||||
TEST_CHECK(std::get<const std::atomic<u64>*>(branch._minfreespace) == &default_a);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue