From f85781b65a1dd442b85861a9f41808943a912855 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Thu, 16 Mar 2023 11:42:49 -0700 Subject: [PATCH] ircd::fs::dev: Move dev::blk related into class nested. --- include/ircd/fs/dev.h | 9 ++-- ircd/fs_aio.cc | 4 +- ircd/fs_dev.cc | 102 ++++++++++++++++++++++-------------------- modules/console.cc | 3 +- 4 files changed, 60 insertions(+), 58 deletions(-) diff --git a/include/ircd/fs/dev.h b/include/ircd/fs/dev.h index def86bedd..6bf2da528 100644 --- a/include/ircd/fs/dev.h +++ b/include/ircd/fs/dev.h @@ -16,7 +16,6 @@ namespace ircd::fs::dev struct blk; using major_minor = std::pair; - using blk_closure = std::function; // Convert device ID's with the major(3) / minor(3) / makedev(3) ulong id(const major_minor &); @@ -36,13 +35,12 @@ namespace ircd::fs::dev sysfs(const ulong &id, const string_view &path, const R &def = 0); - - bool for_each(const string_view &devtype, const blk_closure &); - bool for_each(const blk_closure &); } struct ircd::fs::dev::blk { + using closure = util::function_bool; + static const size_t SECTOR_SIZE; static const string_view BASE_PATH; @@ -66,6 +64,9 @@ struct ircd::fs::dev::blk blk(const ulong &id); blk() = default; + + static bool for_each(const string_view &devtype, const closure &); + static bool for_each(const closure &); }; /// Return a lex_cast'able (an integer) from a sysfs target. diff --git a/ircd/fs_aio.cc b/ircd/fs_aio.cc index 9443f4f96..1f03e3cce 100644 --- a/ircd/fs_aio.cc +++ b/ircd/fs_aio.cc @@ -114,15 +114,13 @@ size_t ircd::fs::aio::init::query_max_events() { size_t ret(0); - fs::dev::for_each("disk", [&ret] + fs::dev::blk::for_each("disk", [&ret] (const ulong &id, const fs::dev::blk &device) { ret = std::clamp ( device.queue_depth, ret, MAX_EVENTS ); - - return true; }); if(!ret) diff --git a/ircd/fs_dev.cc b/ircd/fs_dev.cc index 8f1ee2f60..2b0e9a061 100644 --- a/ircd/fs_dev.cc +++ b/ircd/fs_dev.cc @@ -10,55 +10,6 @@ #include (major), lex_cast(minor)}) - }; - - char dtbuf[32]; - if(type && blk::devtype(dtbuf, id) != type) - continue; - - if(!closure(id, blk(id))) - return false; - } - catch(const ctx::interrupted &) - { - throw; - } - catch(const std::exception &e) - { - log::error - { - log, "%s :%s", - dir, - e.what(), - }; - } - - return true; -} - ircd::string_view ircd::fs::dev::sysfs(const mutable_buffer &out, const ulong &id, @@ -123,6 +74,59 @@ ircd::fs::dev::blk::BASE_PATH "/sys/dev/block" }; +bool +ircd::fs::dev::blk::for_each(const closure &closure) +{ + return for_each(string_view{}, closure); +} + +bool +ircd::fs::dev::blk::for_each(const string_view &type, + const closure &closure) +{ + for(const auto &dir : fs::ls(blk::BASE_PATH)) try + { + const auto &[major, minor] + { + split(filename(path_scratch, dir), ':') + }; + + if(!major || !minor) + continue; + + const ulong id + { + dev::id({lex_cast(major), lex_cast(minor)}) + }; + + char dtbuf[32]; + if(type && blk::devtype(dtbuf, id) != type) + continue; + + if(!closure(id, blk(id))) + return false; + } + catch(const ctx::interrupted &) + { + throw; + } + catch(const std::exception &e) + { + log::error + { + log, "%s :%s", + dir, + e.what(), + }; + } + + return true; +} + +// +// dev::blk::blk +// + ircd::fs::dev::blk::blk(const ulong &id) :type { diff --git a/modules/console.cc b/modules/console.cc index d263debb7..64100f19a 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1057,7 +1057,7 @@ console_cmd__fs__dev(opt &out, const string_view &line) << std::setw(24) << std::left << "SCHED" << ' ' << std::endl; - fs::dev::for_each(type, [&out] + fs::dev::blk::for_each(type, [&out] (const ulong &id, const fs::dev::blk &dev) { const auto mm(fs::dev::id(id)); @@ -1082,7 +1082,6 @@ console_cmd__fs__dev(opt &out, const string_view &line) << std::setw(16) << std::left << dev.vendor << ' ' << std::setw(24) << std::left << dev.scheduler << ' ' << std::endl; - return true; }); return true;