diff --git a/fs_mgr/fs_mgr.cpp b/fs_mgr/fs_mgr.cpp index 99f2df8115ea0868f4cfb823412aac32367549d2..b0c55e3390ceda5abe61ac03046608ef8e9863fe 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<fs_mgr_verity_state_callback> 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<DeviceMapper::TargetInfo> 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 8bcbec2c9c9033490b5b44c87ce1ff6969ebc42f..2b526f65aaaac1c96f888bb35a5622eb3237f802 100644 --- a/fs_mgr/libdm/dm.cpp +++ b/fs_mgr/libdm/dm.cpp @@ -98,9 +98,16 @@ const std::unique_ptr<DmTable> 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 9b61ddcec3fe934cf766546a08782f3835ffe5a6..91f8bb4229e7bb0199c8a90dadab04d92caad16c 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.