0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-24 12:58:21 +02:00

ircd::fs::dev: Fix device size calculation; cleanup constants; improve cmd output.

This commit is contained in:
Jason Volk 2020-06-09 18:41:36 -07:00
parent 7f377d6072
commit d42126693b
3 changed files with 97 additions and 12 deletions

View file

@ -14,6 +14,7 @@
namespace ircd::fs::dev
{
struct blk;
using major_minor = std::pair<ulong, ulong>;
using blk_closure = std::function<bool (const ulong &id, const blk &)>;
@ -42,16 +43,26 @@ namespace ircd::fs::dev
struct ircd::fs::dev::blk
{
static const size_t SECTOR_SIZE;
static const string_view BASE_PATH;
static string_view devtype(const mutable_buffer &, const ulong &id);
std::string type;
std::string vendor;
std::string model;
std::string rev;
size_t size {0};
size_t sector_size {0};
size_t physical_block {0};
size_t logical_block {0};
size_t minimum_io {0};
size_t optimal_io {0};
size_t sectors {0};
size_t queue_depth {0};
size_t nr_requests {0};
std::string scheduler;
bool rotational {false};
bool merges {false};
blk(const ulong &id);
blk() = default;

View file

@ -20,7 +20,7 @@ bool
ircd::fs::dev::for_each(const string_view &type,
const blk_closure &closure)
{
for(const auto &dir : fs::ls("/sys/dev/block")) try
for(const auto &dir : fs::ls(blk::BASE_PATH)) try
{
const auto &[major, minor]
{
@ -64,7 +64,8 @@ try
{
const string_view path{fmt::sprintf
{
path_scratch, "/sys/dev/block/%s/%s",
path_scratch, "%s/%s/%s",
blk::BASE_PATH,
sysfs_id(name_scratch, id),
relpath
}};
@ -142,6 +143,18 @@ ircd::fs::dev::id(const ulong &id)
// dev::blk
//
decltype(ircd::fs::dev::blk::SECTOR_SIZE)
ircd::fs::dev::blk::SECTOR_SIZE
{
512
};
decltype(ircd::fs::dev::blk::BASE_PATH)
ircd::fs::dev::blk::BASE_PATH
{
"/sys/dev/block"
};
ircd::fs::dev::blk::blk(const ulong &id)
:type
{
@ -175,7 +188,27 @@ ircd::fs::dev::blk::blk(const ulong &id)
return sysfs(buf, id, "device/rev");
})
}
,size
,sector_size
{
sysfs(id, "queue/hw_sector_size")
}
,physical_block
{
sysfs(id, "queue/physical_block_size")
}
,logical_block
{
sysfs(id, "queue/logical_block_size")
}
,minimum_io
{
sysfs(id, "queue/minimum_io_size")
}
,optimal_io
{
sysfs(id, "queue/optimal_io_size")
}
,sectors
{
sysfs(id, "size")
}
@ -187,10 +220,22 @@ ircd::fs::dev::blk::blk(const ulong &id)
{
sysfs(id, "queue/nr_requests")
}
,scheduler
{
ircd::string(64, [&id]
(const mutable_buffer &buf)
{
return sysfs(buf, id, "queue/scheduler");
})
}
,rotational
{
sysfs<bool>(id, "queue/rotational", false)
}
,merges
{
!sysfs<bool>(id, "queue/nomerges", true)
}
{
}

View file

@ -926,21 +926,51 @@ console_cmd__fs__dev(opt &out, const string_view &line)
param["type"]
};
out
<< std::setw(3) << std::right << "maj" << ':'
<< std::setw(3) << std::left << "min" << ' '
<< std::setw(10) << std::right << "TYPE" << ' '
<< std::setw(12) << std::left << " " << ' '
<< std::setw(6) << std::right << "NR_REQ" << ' '
<< std::setw(6) << std::right << "DEPTH" << ' '
<< std::setw(5) << std::right << "MERGE" << ' '
<< std::setw(5) << std::right << "OPTSZ" << ' '
<< std::setw(5) << std::right << "MINSZ" << ' '
<< std::setw(5) << std::right << "LOGSZ" << ' '
<< std::setw(5) << std::right << "PHYSZ" << ' '
<< std::setw(6) << std::right << "SECTSZ" << ' '
<< std::setw(14) << std::right << "SECTORS" << ' '
<< std::setw(26) << "SIZE" << ' '
<< std::setw(10) << std::right << "REV" << ' '
<< std::setw(20) << std::left << "MODEL" << ' '
<< std::setw(16) << std::left << "VENDOR" << ' '
<< std::setw(24) << std::left << "SCHED" << ' '
<< std::endl;
fs::dev::for_each(type, [&out]
(const ulong &id, const fs::dev::blk &dev)
{
const auto mm(fs::dev::id(id));
char pbuf[48];
out
<< std::setw(16) << dev.type << ' '
<< std::setw(3) << std::right << std::get<0>(mm) << ':'
<< std::setw(3) << std::left << std::get<1>(mm) << ' '
<< std::setw(16) << dev.vendor << ' '
<< std::setw(20) << dev.model << ' '
<< std::setw(10) << dev.rev << ' '
<< "qd:" << std::setw(3) << dev.queue_depth << ' '
<< "nr:" << std::setw(3) << dev.nr_requests << ' '
<< pretty(pbuf, iec(dev.size)) << ' '
<< std::setw(10) << std::right << dev.type << ' '
<< std::setw(12) << std::left << (dev.rotational? "rotating"_sv : string_view{}) << ' '
<< std::setw(6) << std::right << dev.nr_requests << ' '
<< std::setw(6) << std::right << dev.queue_depth << ' '
<< std::setw(5) << std::right << (dev.merges? 'Y' : 'N') << ' '
<< std::setw(5) << std::right << dev.optimal_io << ' '
<< std::setw(5) << std::right << dev.minimum_io << ' '
<< std::setw(5) << std::right << dev.logical_block << ' '
<< std::setw(5) << std::right << dev.physical_block << ' '
<< std::setw(6) << std::right << dev.sector_size << ' '
<< std::setw(14) << std::right << dev.sectors << ' '
<< std::setw(26) << pretty(pbuf, iec(dev.sectors * dev.sector_size)) << ' '
<< std::setw(10) << std::right << dev.rev << ' '
<< std::setw(20) << std::left << dev.model << ' '
<< std::setw(16) << std::left << dev.vendor << ' '
<< std::setw(24) << std::left << dev.scheduler << ' '
<< std::endl;
return true;
});
@ -948,7 +978,6 @@ console_cmd__fs__dev(opt &out, const string_view &line)
return true;
}
bool
console_cmd__ls(opt &out, const string_view &line)
{