0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-09-28 11:48:54 +02:00

ircd::fs::dev: Use defaulting values rather than exceptions for sysfs() suite.

ircd::fs::dev: Stop exception propagation on per block device during discovery.
This commit is contained in:
Jason Volk 2020-06-07 13:42:13 -07:00
parent 2031966072
commit 64c82829d8
2 changed files with 41 additions and 13 deletions

View file

@ -27,7 +27,7 @@ namespace ircd::fs::dev
// Read data for a device from sysfs; path is relative to /sys/dev/block/$id/...
string_view sysfs(const mutable_buffer &out, const ulong &id, const string_view &path);
template<class T = size_t, size_t bufmax = 32> T sysfs(const ulong &id, const string_view &path);
template<class T = size_t, size_t bufmax = 32> T sysfs(const ulong &id, const string_view &path, const T &def = 0);
extern std::map<major_minor, blkdev> block;
}
@ -60,8 +60,16 @@ template<class T,
size_t bufmax>
T
ircd::fs::dev::sysfs(const ulong &id,
const string_view &path)
const string_view &path,
const T &def)
{
char buf[bufmax];
return lex_cast<T>(sysfs(buf, id, path));
const string_view val
{
sysfs(buf, id, path)
};
return lex_castable<T>(val)?
lex_cast<T>(val):
def;
}

View file

@ -20,7 +20,7 @@ ircd::fs::dev::block;
ircd::fs::dev::init::init()
{
#ifdef __linux__
for(const auto &dir : fs::ls("/sys/dev/block"))
for(const auto &dir : fs::ls("/sys/dev/block")) try
{
const auto &[major, minor]
{
@ -42,6 +42,15 @@ ircd::fs::dev::init::init()
if(!bd.is_device || bd.type != "disk")
block.erase(iit.first);
}
catch(const std::exception &e)
{
log::derror
{
log, "%s :%s",
dir,
e.what(),
};
}
#endif
for(const auto &[mm, bd] : block)
@ -78,6 +87,7 @@ ircd::string_view
ircd::fs::dev::sysfs(const mutable_buffer &out,
const ulong &id,
const string_view &relpath)
try
{
const string_view path{fmt::sprintf
{
@ -97,6 +107,22 @@ ircd::fs::dev::sysfs(const mutable_buffer &out,
ret = rstrip(ret, ' ');
return ret;
}
catch(const ctx::interrupted &)
{
throw;
}
catch(const std::exception &e)
{
log::derror
{
log, "sysfs query dev_id:%lu `%s' :%s",
id,
relpath,
e.what(),
};
return {};
}
#else
ircd::string_view
ircd::fs::dev::sysfs(const mutable_buffer &out,
@ -219,21 +245,15 @@ ircd::fs::dev::blkdev::blkdev(const ulong &id)
}
,queue_depth
{
is_device?
sysfs(id, "device/queue_depth"):
0UL
sysfs(id, "device/queue_depth")
}
,nr_requests
{
is_queue?
sysfs(id, "queue/nr_requests"):
0UL
sysfs(id, "queue/nr_requests")
}
,rotational
{
is_queue?
sysfs<bool>(id, "queue/rotational"):
true
sysfs<bool>(id, "queue/rotational", true)
}
{
}