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

@ -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;