refactor: simpler ways to construct filesystem_v2

This commit is contained in:
Marcus Holland-Moritz 2024-08-02 22:37:30 +02:00
parent 0987dba63d
commit dc4ccadd53
6 changed files with 31 additions and 15 deletions

View File

@ -59,6 +59,14 @@ class filesystem_v2 {
public:
filesystem_v2() = default;
filesystem_v2(logger& lgr, os_access const& os,
std::filesystem::path const& path);
filesystem_v2(logger& lgr, os_access const& os,
std::filesystem::path const& path,
filesystem_options const& options,
std::shared_ptr<performance_monitor const> perfmon = nullptr);
filesystem_v2(logger& lgr, os_access const& os, std::shared_ptr<mmif> mm);
filesystem_v2(logger& lgr, os_access const& os, std::shared_ptr<mmif> mm,

View File

@ -43,6 +43,7 @@
#include <dwarfs/logger.h>
#include <dwarfs/mmif.h>
#include <dwarfs/options.h>
#include <dwarfs/os_access.h>
#include <dwarfs/performance_monitor.h>
#include <dwarfs/util.h>
#include <dwarfs/writer_progress.h>
@ -1177,6 +1178,17 @@ filesystem_<LoggerPolicy>::header() const {
} // namespace internal
filesystem_v2::filesystem_v2(logger& lgr, os_access const& os,
std::filesystem::path const& path)
: filesystem_v2(lgr, os, os.map_file(os.canonical(path))) {}
filesystem_v2::filesystem_v2(logger& lgr, os_access const& os,
std::filesystem::path const& path,
filesystem_options const& options,
std::shared_ptr<performance_monitor const> perfmon)
: filesystem_v2(lgr, os, os.map_file(os.canonical(path)), options,
std::move(perfmon)) {}
filesystem_v2::filesystem_v2(logger& lgr, os_access const& os,
std::shared_ptr<mmif> mm)
: filesystem_v2(lgr, os, std::move(mm), filesystem_options()) {}

View File

@ -1462,9 +1462,8 @@ void load_filesystem(dwarfs_userdata& userdata) {
LOG_DEBUG << "attempting to load filesystem from " << fsimage;
userdata.fs =
filesystem_v2(userdata.lgr, *userdata.iol.os,
std::make_shared<mmap>(fsimage), fsopts, userdata.perfmon);
userdata.fs = filesystem_v2(userdata.lgr, *userdata.iol.os, fsimage, fsopts,
userdata.perfmon);
ti << "file system initialized";
}

View File

@ -99,8 +99,7 @@ int dwarfsbench_main(int argc, sys_char** argv, iolayer const& iol) {
fsopts.block_cache.num_workers = num_workers;
fsopts.block_cache.decompress_ratio = to<double>(decompress_ratio_str);
dwarfs::filesystem_v2 fs(
lgr, *iol.os, std::make_shared<dwarfs::mmap>(filesystem), fsopts);
dwarfs::filesystem_v2 fs(lgr, *iol.os, filesystem, fsopts);
thread_pool pool(lgr, *iol.os, "reader", num_readers);

View File

@ -56,7 +56,7 @@ constexpr std::string_view kDash{"-"};
} // namespace
int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) {
sys_string filesystem, output, trace_file;
sys_string fs_image, output, trace_file;
std::string format, cache_size_str, image_offset;
logger_options logopts;
#if DWARFS_PERFMON_ENABLED
@ -70,7 +70,7 @@ int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) {
po::options_description opts("Command line options");
opts.add_options()
("input,i",
po_sys_value<sys_string>(&filesystem),
po_sys_value<sys_string>(&fs_image),
"input filesystem file")
("output,o",
po_sys_value<sys_string>(&output),
@ -164,9 +164,7 @@ int dwarfsextract_main(int argc, sys_char** argv, iolayer const& iol) {
std::shared_ptr<performance_monitor> perfmon = performance_monitor::create(
perfmon_enabled, iol.file, perfmon_trace_file);
auto fs_path = iol.os->canonical(filesystem);
filesystem_v2 fs(lgr, *iol.os, iol.os->map_file(fs_path), fsopts, perfmon);
filesystem_v2 fs(lgr, *iol.os, fs_image, fsopts, perfmon);
filesystem_extractor fsx(lgr, *iol.os);
if (format.empty()) {

View File

@ -1159,14 +1159,14 @@ int mkdwarfs_main(int argc, sys_char** argv, iolayer const& iol) {
}
}
std::unique_ptr<filesystem_v2> input_filesystem;
std::optional<filesystem_v2> input_filesystem;
std::shared_ptr<category_resolver> cat_resolver;
if (recompress) {
filesystem_options fsopts;
fsopts.image_offset = filesystem_options::IMAGE_OFFSET_AUTO;
input_filesystem = std::make_unique<filesystem_v2>(
lgr, *iol.os, iol.os->map_file(path), fsopts);
input_filesystem.emplace(
lgr, *iol.os, path,
filesystem_options{.image_offset =
filesystem_options::IMAGE_OFFSET_AUTO});
LOG_INFO << "checking input filesystem...";