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
|
|
@ -22,6 +22,7 @@
|
|||
#include "strvec.hpp"
|
||||
#include "fs_path.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
|
@ -41,14 +42,16 @@ public:
|
|||
};
|
||||
|
||||
public:
|
||||
std::variant<u64,const u64*> _minfreespace;
|
||||
// A default held by pointer can be changed at runtime while
|
||||
// requests read it.
|
||||
std::variant<u64,const std::atomic<u64>*> _minfreespace;
|
||||
Mode mode;
|
||||
fs::path path;
|
||||
|
||||
public:
|
||||
Branch();
|
||||
Branch(const Branch&);
|
||||
Branch(const u64 &default_minfreespace);
|
||||
Branch(const std::atomic<u64> &default_minfreespace);
|
||||
|
||||
public:
|
||||
Branch& operator=(const Branch&) = default;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue