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:
Antonio SJ Musumeci 2026-11-21 14:42:19 -05:00
parent e4e9d54fe7
commit 8cc6be6ff2
16 changed files with 118 additions and 45 deletions

View file

@ -20,6 +20,8 @@
#include "str.hpp"
#include <mutex>
ConfigSet::ConfigSet(const std::string &str_)
{
@ -29,16 +31,26 @@ ConfigSet::ConfigSet(const std::string &str_)
std::string
ConfigSet::to_string(void) const
{
return str::join(*this,'|');
std::shared_lock<std::shared_mutex> lk(_mutex);
return str::join(_set,'|');
}
int
ConfigSet::from_string(const std::string_view str_)
{
this->clear();
auto tmp = str::split_to_set(str_,'|');
this->insert(tmp.begin(), tmp.end());
std::unique_lock<std::shared_mutex> lk(_mutex);
_set.swap(tmp);
return 0;
}
std::size_t
ConfigSet::count(const std::string &key_) const
{
std::shared_lock<std::shared_mutex> lk(_mutex);
return _set.count(key_);
}