fix: make the default minfreespace safe to change at runtime

- Setting minfreespace through the .mergerfs xattr wrote the shared
  default while request threads read it through each branch, with no
  synchronization. That is a data race; on 32-bit targets a request
  could see half of the new 64-bit value.
- Store the default as std::atomic<u64> and read and write it with
  relaxed loads and stores. Per-branch values are unchanged.
This commit is contained in:
Antonio SJ Musumeci 2026-11-21 14:42:19 -05:00
parent 416af29cc1
commit 4a665bbf32
10 changed files with 61 additions and 30 deletions

View file

@ -36,7 +36,7 @@
#include <fnmatch.h>
Branches::Impl::Impl(const u64 *default_minfreespace_)
Branches::Impl::Impl(const std::atomic<u64> *default_minfreespace_)
: _default_minfreespace(default_minfreespace_)
{
}
@ -56,7 +56,7 @@ Branches::Impl::operator=(Branches::Impl &rval_)
// Impl's _default_minfreespace.
for(auto &branch : *this)
{
if(std::holds_alternative<const u64*>(branch._minfreespace))
if(std::holds_alternative<const std::atomic<u64>*>(branch._minfreespace))
branch._minfreespace = _default_minfreespace;
}
@ -78,7 +78,7 @@ Branches::Impl::operator=(Branches::Impl &&rval_)
// Impl's _default_minfreespace.
for(auto &branch : *this)
{
if(std::holds_alternative<const u64*>(branch._minfreespace))
if(std::holds_alternative<const std::atomic<u64>*>(branch._minfreespace))
branch._minfreespace = _default_minfreespace;
}
@ -86,7 +86,7 @@ Branches::Impl::operator=(Branches::Impl &&rval_)
}
const
u64&
std::atomic<u64>&
Branches::Impl::minfreespace(void) const
{
return *_default_minfreespace;