From 356386246db1fe1fd60c304a82a9a7b0c14476dd Mon Sep 17 00:00:00 2001 From: David Anderson Date: Mon, 27 Aug 2018 14:02:47 -0700 Subject: [PATCH] fs_mgr: Better error messages in fs_mgr_update_verity_state. With verity disabled, fs_mgr_update_verity_state spews some confusing error messages from device-mapper. This change checks whether a device exists and logs an explicit error. Bug: N/A Test: AVB properties are set correctly on AVB device Messages are logged correctly with AVB disabled Change-Id: If490c18cfec2d63ad784972c13ceef63d9aa3e4c --- fs_mgr/fs_mgr.cpp | 9 +++++++-- fs_mgr/libdm/dm.cpp | 13 ++++++++++--- fs_mgr/libdm/include/libdm/dm.h | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index 99f2df811..b0c55e339 100644 --- a/fs_mgr/fs_mgr.cpp +++ b/fs_mgr/fs_mgr.cpp @@ -79,7 +79,8 @@ #define ARRAY_SIZE(a) (sizeof(a) / sizeof(*(a))) -using DeviceMapper = android::dm::DeviceMapper; +using android::dm::DeviceMapper; +using android::dm::DmDeviceState; // record fs stat enum FsStatFlags { @@ -1400,8 +1401,12 @@ bool fs_mgr_update_verity_state(std::function call mount_point = basename(fstab->recs[i].mount_point); } - const char* status = nullptr; + if (dm.GetState(mount_point) == DmDeviceState::INVALID) { + PERROR << "Could not find verity device for mount point: " << mount_point; + continue; + } + const char* status = nullptr; std::vector table; if (!dm.GetTableStatus(mount_point, &table) || table.empty() || table[0].data.empty()) { if (fstab->recs[i].fs_mgr_flags & MF_VERIFYATBOOT) { diff --git a/fs_mgr/libdm/dm.cpp b/fs_mgr/libdm/dm.cpp index 8bcbec2c9..2b526f65a 100644 --- a/fs_mgr/libdm/dm.cpp +++ b/fs_mgr/libdm/dm.cpp @@ -98,9 +98,16 @@ const std::unique_ptr DeviceMapper::table(const std::string& /* name */ return nullptr; } -DmDeviceState DeviceMapper::state(const std::string& /* name */) const { - // TODO(b/110035986): Return the state, as read from the kernel instead - return DmDeviceState::INVALID; +DmDeviceState DeviceMapper::GetState(const std::string& name) const { + struct dm_ioctl io; + InitIo(&io, name); + if (ioctl(fd_, DM_DEV_STATUS, &io) < 0) { + return DmDeviceState::INVALID; + } + if ((io.flags & DM_ACTIVE_PRESENT_FLAG) && !(io.flags & DM_SUSPEND_FLAG)) { + return DmDeviceState::ACTIVE; + } + return DmDeviceState::SUSPENDED; } bool DeviceMapper::CreateDevice(const std::string& name, const DmTable& table) { diff --git a/fs_mgr/libdm/include/libdm/dm.h b/fs_mgr/libdm/include/libdm/dm.h index 9b61ddcec..91f8bb422 100644 --- a/fs_mgr/libdm/include/libdm/dm.h +++ b/fs_mgr/libdm/include/libdm/dm.h @@ -79,7 +79,7 @@ class DeviceMapper final { // Returns the current state of the underlying device mapper device // with given name. // One of INVALID, SUSPENDED or ACTIVE. - DmDeviceState state(const std::string& name) const; + DmDeviceState GetState(const std::string& name) const; // Creates a device, loads the given table, and activates it. If the device // is not able to be activated, it is destroyed, and false is returned.