Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 35638624 authored by David Anderson's avatar David Anderson
Browse files

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
parent 53ba407a
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -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) {
+10 −3
Original line number Diff line number Diff line
@@ -98,10 +98,17 @@ 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
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) {
    if (!CreateDevice(name)) {
+1 −1
Original line number Diff line number Diff line
@@ -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.