mirror of
https://github.com/trapexit/mergerfs.git
synced 2026-12-02 04:46:41 -05:00
- 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.
70 lines
1.6 KiB
C++
70 lines
1.6 KiB
C++
/*
|
|
ISC License
|
|
|
|
Copyright (c) 2026, Antonio SJ Musumeci <trapexit@spawn.link>
|
|
|
|
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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "base_types.h"
|
|
#include "strvec.hpp"
|
|
#include "fs_path.hpp"
|
|
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <variant>
|
|
|
|
|
|
class Branch final
|
|
{
|
|
public:
|
|
enum class Mode
|
|
{
|
|
RO,
|
|
RW,
|
|
NC
|
|
};
|
|
|
|
public:
|
|
// 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 std::atomic<u64> &default_minfreespace);
|
|
|
|
public:
|
|
Branch& operator=(const Branch&) = default;
|
|
|
|
public:
|
|
bool ro(void) const;
|
|
bool nc(void) const;
|
|
bool ro_or_nc(void) const;
|
|
|
|
public:
|
|
std::string to_string(void) const;
|
|
|
|
public:
|
|
u64 minfreespace() const;
|
|
void set_minfreespace(const u64);
|
|
};
|