49 fs::path
const path_file_dwarfs;
50 fs::path
const path_file_ciopfs;
51 fs::path
const path_file_overlayfs;
52 fs::path
const path_file_unionfs;
53 fs::path
const path_file_janitor;
59 bool const is_casefold;
60 uint32_t
const compression_level;
61 ns_reserved::ns_overlay::OverlayType overlay_type;
63 fs::path
const path_dir_mount;
65 fs::path
const path_dir_work;
66 fs::path
const path_dir_upper;
67 fs::path
const path_dir_layers;
69 fs::path
const path_dir_ciopfs;
70 fs::path
const path_bin_janitor;
71 fs::path
const path_bin_self;
80 fs::path m_path_dir_mount;
81 fs::path m_path_dir_work;
82 std::vector<fs::path> m_vec_path_dir_mountpoints;
83 std::vector<std::unique_ptr<ns_dwarfs::Dwarfs>> m_dwarfs;
84 std::vector<std::unique_ptr<ns_filesystem::Filesystem>> m_filesystems;
85 std::unique_ptr<ns_subprocess::Child> m_child_janitor;
88 [[nodiscard]] uint64_t mount_dwarfs(fs::path
const& path_dir_mount);
89 void mount_ciopfs(fs::path
const& path_dir_lower, fs::path
const& path_dir_upper);
90 void mount_unionfs(std::vector<fs::path>
const& vec_path_dir_layer
91 , fs::path
const& path_dir_data
92 , fs::path
const& path_dir_mount
94 void mount_overlayfs(std::vector<fs::path>
const& vec_path_dir_layer
95 , fs::path
const& path_dir_data
96 , fs::path
const& path_dir_mount
97 , fs::path
const& path_dir_workdir
100 [[nodiscard]]
Value<void> spawn_janitor(fs::path
const& path_bin_janitor, fs::path
const& path_file_log);
118 , m_path_dir_mount(config.path_dir_mount)
119 , m_path_dir_work(config.path_dir_work)
120 , m_vec_path_dir_mountpoints()
123 , m_child_janitor(nullptr)
124 , m_layers(config.layers)
127 [[maybe_unused]] uint64_t index_fs = mount_dwarfs(config.path_dir_layers);
129 if ( config.overlay_type == ns_reserved::ns_overlay::OverlayType::UNIONFS )
131 logger(
"D::Overlay type: UNIONFS_FUSE");
133 , config.path_dir_upper
134 , config.path_dir_mount
138 else if ( config.overlay_type == ns_reserved::ns_overlay::OverlayType::OVERLAYFS )
140 logger(
"D::Overlay type: FUSE_OVERLAYFS");
142 , config.path_dir_upper
143 , config.path_dir_mount
144 , config.path_dir_work
149 logger(
"D::Overlay type: BWRAP");
152 if (config.is_casefold)
154 if(config.overlay_type == ns_reserved::ns_overlay::OverlayType::BWRAP)
156 logger(
"W::casefold cannot be used with bwrap overlays");
160 mount_ciopfs(config.path_dir_mount, config.path_dir_ciopfs);
161 logger(
"D::casefold is enabled");
166 logger(
"D::casefold is disabled");
169 spawn_janitor(config.path_bin_janitor, logs.path_file_janitor).discard(
"E::Could not spawn janitor");
179 return_if(not m_child_janitor,,
"E::Janitor is not running");
181 m_child_janitor->kill(SIGTERM);
192[[nodiscard]]
inline Value<void> Controller::spawn_janitor(fs::path
const& path_bin_janitor
193 , fs::path
const& path_file_log)
197 .
with_args(getpid(), path_file_log, this->m_vec_path_dir_mountpoints)
201 return_if(not m_child_janitor, Error(
"E::Failed to start janitor"));
203 if(
auto pid = m_child_janitor->get_pid().value_or(-1); pid > 0)
205 logger(
"D::Spawned janitor with PID '{}'", pid);
209 return Error(
"E::Failed to fork janitor");
224inline uint64_t Controller::mount_dwarfs(fs::path
const& path_dir_mount)
229 auto f_mount = [
this](fs::path
const& _path_file_binary
230 , fs::path
const& _path_dir_mount
233 , uint64_t _size_fs) -> Value<void>
236 fs::path path_dir_mount_index = _path_dir_mount / std::to_string(_index_fs);
237 Try(fs::create_directories(path_dir_mount_index));
240 this->m_dwarfs.emplace_back(
241 std::make_unique<ns_dwarfs::Dwarfs>(getpid()
242 , path_dir_mount_index
244 , m_logs.path_file_dwarfs
250 m_vec_path_dir_mountpoints.push_back(path_dir_mount_index);
255 for (
auto const& [path_file_layer, offset, size] : m_layers.get_layers())
257 logger(
"D::Mounting layer from '{}' with offset '{}'", path_file_layer.filename(), offset);
260 ,
"E::Invalid dwarfs filesystem appended on the image"
263 if (not f_mount(path_file_layer, path_dir_mount, index_fs, offset, size))
265 logger(
"E::Failed to mount filesystem at index {}", index_fs);
282inline void Controller::mount_unionfs(std::vector<fs::path>
const& vec_path_dir_layer
283 , fs::path
const& path_dir_data
284 , fs::path
const& path_dir_mount)
286 m_filesystems.emplace_back(std::make_unique<ns_unionfs::UnionFs>(getpid()
289 , m_logs.path_file_unionfs
292 m_vec_path_dir_mountpoints.push_back(path_dir_mount);
303inline void Controller::mount_overlayfs(std::vector<fs::path>
const& vec_path_dir_layer
304 , fs::path
const& path_dir_data
305 , fs::path
const& path_dir_mount
306 , fs::path
const& path_dir_workdir)
308 m_filesystems.emplace_back(std::make_unique<ns_overlayfs::Overlayfs>(getpid()
312 , m_logs.path_file_overlayfs
315 m_vec_path_dir_mountpoints.push_back(path_dir_mount);
324inline void Controller::mount_ciopfs(fs::path
const& path_dir_lower, fs::path
const& path_dir_upper)
326 m_filesystems.emplace_back(std::make_unique<ns_ciopfs::Ciopfs>(getpid()
329 , m_logs.path_file_ciopfs
331 m_vec_path_dir_mountpoints.push_back(path_dir_upper);
Case-insensitive filesystem management using CIOPFS.
Controller(Logs const &logs, Config const &config)
Construct a new Controller:: Controller object.
~Controller()
Destroy the Controller:: Controller object and stops the janitor if it is running.
Manages external DwarFS layer files and directories for the filesystem controller.
std::unique_ptr< Child > spawn()
Spawns (forks) the child process and begins execution.
Subprocess & with_log_file(std::filesystem::path const &path)
Configures logging output for child process stdout/stderr.
Subprocess & with_args(Args &&... args)
Arguments forwarded as the process' arguments.
Manage dwarfs filesystems.
Enhanced error handling framework built on std::expected.
The base class for filesystems.
Layer management for DwarFS filesystems.
#define logger(fmt,...)
Compile-time log level dispatch macro with automatic location capture.
Filesystem stack orchestration and management.
bool is_dwarfs(fs::path const &path_file_dwarfs, uint64_t offset=0)
Checks if the filesystem is a Dwarfs filesystem with a given offset.
std::vector< fs::path > get_mounted_layers(fs::path const &path_dir_layers)
Get a path for each layer directory.
Manages the overlay reserved space.
Manages the fuse-overlayfs filesystem.
Enhanced expected type with integrated logging capabilities.
Manages unionfs filesystems.
Filesystem utilities for managing instances and layers.