From d185d4a8b4acb20d3cd972ace48f8594b50d2652 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Sat, 11 Dec 2021 10:45:20 +0900 Subject: [PATCH] android::base::ResultError/Error are template classes They are changed to template classes. s/Error/Error<>/g to reflect that. In addition, the direct uses of ResultError for error reporting is replaced with Error and Errorf. Bug: 209929099 Test: m Change-Id: I815526a8e6fa30e63fa3efcf5700b146bf70a507 --- fs_mgr/blockdev.cpp | 17 ++++++----------- fs_mgr/fs_mgr.cpp | 4 +++- init/builtins.cpp | 5 +++-- init/subcontext.cpp | 4 ++-- 4 files changed, 14 insertions(+), 16 deletions(-) diff --git a/fs_mgr/blockdev.cpp b/fs_mgr/blockdev.cpp index 14b217ca8..388dadc64 100644 --- a/fs_mgr/blockdev.cpp +++ b/fs_mgr/blockdev.cpp @@ -30,7 +30,6 @@ using android::base::Basename; using android::base::ErrnoError; using android::base::Error; using android::base::Result; -using android::base::ResultError; using android::base::StartsWith; using android::base::StringPrintf; using android::base::unique_fd; @@ -94,10 +93,8 @@ static Result BlockDeviceQueueDepth(const std::string& file_path) { std::string blockdev = "/dev/block/" + BlockdevName(statbuf.st_dev); LOG(DEBUG) << __func__ << ": " << file_path << " -> " << blockdev; if (blockdev.empty()) { - const std::string err_msg = - StringPrintf("Failed to convert %u:%u (path %s)", major(statbuf.st_dev), - minor(statbuf.st_dev), file_path.c_str()); - return ResultError(err_msg, 0); + return Errorf("Failed to convert {}:{} (path {})", major(statbuf.st_dev), + minor(statbuf.st_dev), file_path.c_str()); } auto& dm = DeviceMapper::Instance(); for (;;) { @@ -110,7 +107,7 @@ static Result BlockDeviceQueueDepth(const std::string& file_path) { } std::optional maybe_blockdev = android::dm::ExtractBlockDeviceName(blockdev); if (!maybe_blockdev) { - return ResultError("Failed to remove /dev/block/ prefix from " + blockdev, 0); + return Errorf("Failed to remove /dev/block/ prefix from {}", blockdev); } blockdev = PartitionParent(*maybe_blockdev); LOG(DEBUG) << __func__ << ": " @@ -119,7 +116,7 @@ static Result BlockDeviceQueueDepth(const std::string& file_path) { StringPrintf("/sys/class/block/%s/mq/0/nr_tags", blockdev.c_str()); std::string nr_tags; if (!android::base::ReadFileToString(nr_tags_path, &nr_tags)) { - return ResultError("Failed to read " + nr_tags_path, 0); + return Errorf("Failed to read {}", nr_tags_path); } rtrim(nr_tags); LOG(DEBUG) << __func__ << ": " << file_path << " is backed by /dev/" << blockdev @@ -137,11 +134,9 @@ Result ConfigureQueueDepth(const std::string& loop_device_path, const std::string loop_device_name = Basename(loop_device_path); - const Result qd = BlockDeviceQueueDepth(file_path); + const auto qd = BlockDeviceQueueDepth(file_path); if (!qd.ok()) { - LOG(DEBUG) << __func__ << ": " - << "BlockDeviceQueueDepth() returned " << qd.error(); - return ResultError(qd.error()); + return qd.error(); } const std::string nr_requests = StringPrintf("%u", *qd); const std::string sysfs_path = diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index a320c0edb..137b06626 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp @@ -2044,7 +2044,9 @@ static bool PrepareZramBackingDevice(off64_t size) { ConfigureIoScheduler(loop_device); - ConfigureQueueDepth(loop_device, "/"); + if (auto ret = ConfigureQueueDepth(loop_device, "/"); !ret.ok()) { + LOG(DEBUG) << "Failed to config queue depth: " << ret.error().message(); + } // set block size & direct IO unique_fd loop_fd(TEMP_FAILURE_RETRY(open(loop_device.c_str(), O_RDWR | O_CLOEXEC))); diff --git a/init/builtins.cpp b/init/builtins.cpp index 8045c7179..cc445be4c 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -88,6 +88,7 @@ using namespace std::literals::string_literals; using android::base::Basename; +using android::base::ResultError; using android::base::SetProperty; using android::base::Split; using android::base::StartsWith; @@ -116,7 +117,7 @@ class ErrorIgnoreEnoent { android::base::GetMinimumLogSeverity() > android::base::DEBUG) {} template - operator android::base::expected() { + operator android::base::expected>() { if (ignore_error_) { return {}; } @@ -130,7 +131,7 @@ class ErrorIgnoreEnoent { } private: - Error error_; + Error<> error_; bool ignore_error_; }; diff --git a/init/subcontext.cpp b/init/subcontext.cpp index 6eaa80fad..7aa4a9d2c 100644 --- a/init/subcontext.cpp +++ b/init/subcontext.cpp @@ -297,7 +297,7 @@ Result Subcontext::Execute(const std::vector& args) { if (subcontext_reply->reply_case() == SubcontextReply::kFailure) { auto& failure = subcontext_reply->failure(); - return ResultError(failure.error_string(), failure.error_errno()); + return ResultError<>(failure.error_string(), failure.error_errno()); } if (subcontext_reply->reply_case() != SubcontextReply::kSuccess) { @@ -321,7 +321,7 @@ Result> Subcontext::ExpandArgs(const std::vectorreply_case() == SubcontextReply::kFailure) { auto& failure = subcontext_reply->failure(); - return ResultError(failure.error_string(), failure.error_errno()); + return ResultError<>(failure.error_string(), failure.error_errno()); } if (subcontext_reply->reply_case() != SubcontextReply::kExpandArgsReply) {