Merge pull request #39216 from Algunenano/rotational_error

Don't report system.errors when the disk is not rotational
This commit is contained in:
Alexey Milovidov 2022-07-16 16:16:52 +03:00 committed by GitHub
commit e37caa5bd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -87,7 +87,10 @@ BlockDeviceType getBlockDeviceType([[maybe_unused]] const String & device_id)
#if defined(OS_LINUX)
try
{
ReadBufferFromFile in("/sys/dev/block/" + device_id + "/queue/rotational");
const auto path{std::filesystem::path("/sys/dev/block/") / device_id / "queue/rotational"};
if (!std::filesystem::exists(path))
return BlockDeviceType::UNKNOWN;
ReadBufferFromFile in(path);
int rotational;
readText(rotational, in);
return rotational ? BlockDeviceType::ROT : BlockDeviceType::NONROT;
@ -109,7 +112,8 @@ UInt64 getBlockDeviceReadAheadBytes([[maybe_unused]] const String & device_id)
#if defined(OS_LINUX)
try
{
ReadBufferFromFile in("/sys/dev/block/" + device_id + "/queue/read_ahead_kb");
const auto path{std::filesystem::path("/sys/dev/block/") / device_id / "queue/read_ahead_kb"};
ReadBufferFromFile in(path);
int read_ahead_kb;
readText(read_ahead_kb, in);
return read_ahead_kb * 1024;