ircd::fs::dev: Move dev::blk related into class nested.
This commit is contained in:
parent
d01e937f3e
commit
f85781b65a
|
@ -16,7 +16,6 @@ namespace ircd::fs::dev
|
|||
struct blk;
|
||||
|
||||
using major_minor = std::pair<ulong, ulong>;
|
||||
using blk_closure = std::function<bool (const ulong &id, const blk &)>;
|
||||
|
||||
// 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<const ulong &, const blk &>;
|
||||
|
||||
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.
|
||||
|
|
|
@ -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)
|
||||
|
|
102
ircd/fs_dev.cc
102
ircd/fs_dev.cc
|
@ -10,55 +10,6 @@
|
|||
|
||||
#include <RB_INC_SYS_SYSMACROS_H
|
||||
|
||||
bool
|
||||
ircd::fs::dev::for_each(const blk_closure &closure)
|
||||
{
|
||||
return for_each(string_view{}, closure);
|
||||
}
|
||||
|
||||
bool
|
||||
ircd::fs::dev::for_each(const string_view &type,
|
||||
const blk_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<ulong>(major), lex_cast<ulong>(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<ulong>(major), lex_cast<ulong>(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
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue