mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 04:46:41 -05:00
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:
parent
416af29cc1
commit
4a665bbf32
10 changed files with 61 additions and 30 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue