2023-02-11 12:11:45 -05:00
|
|
|
/*
|
|
|
|
|
ISC License
|
|
|
|
|
|
2026-02-23 13:22:21 -06:00
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
2023-02-11 12:11:45 -05:00
|
|
|
|
|
|
|
|
Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
|
purpose with or without fee is hereby granted, provided that the above
|
|
|
|
|
copyright notice and this permission notice appear in all copies.
|
|
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
|
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
|
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
|
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
|
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
|
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
|
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include "config_set.hpp"
|
|
|
|
|
|
|
|
|
|
#include "str.hpp"
|
|
|
|
|
|
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.
2026-11-21 14:42:19 -05:00
|
|
|
#include <mutex>
|
|
|
|
|
|
2023-02-11 12:11:45 -05:00
|
|
|
|
|
|
|
|
ConfigSet::ConfigSet(const std::string &str_)
|
|
|
|
|
{
|
|
|
|
|
from_string(str_);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
|
|
|
|
ConfigSet::to_string(void) const
|
|
|
|
|
{
|
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.
2026-11-21 14:42:19 -05:00
|
|
|
std::shared_lock<std::shared_mutex> lk(_mutex);
|
|
|
|
|
|
|
|
|
|
return str::join(_set,'|');
|
2023-02-11 12:11:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
2025-08-21 23:42:58 -04:00
|
|
|
ConfigSet::from_string(const std::string_view str_)
|
2023-02-11 12:11:45 -05:00
|
|
|
{
|
2026-03-11 19:15:11 -05:00
|
|
|
auto tmp = str::split_to_set(str_,'|');
|
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.
2026-11-21 14:42:19 -05:00
|
|
|
std::unique_lock<std::shared_mutex> lk(_mutex);
|
|
|
|
|
|
|
|
|
|
_set.swap(tmp);
|
2023-02-11 12:11:45 -05:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
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.
2026-11-21 14:42:19 -05:00
|
|
|
|
|
|
|
|
std::size_t
|
|
|
|
|
ConfigSet::count(const std::string &key_) const
|
|
|
|
|
{
|
|
|
|
|
std::shared_lock<std::shared_mutex> lk(_mutex);
|
|
|
|
|
|
|
|
|
|
return _set.count(key_);
|
|
|
|
|
}
|