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

Commit 67cd9f09 authored by David Anderson's avatar David Anderson
Browse files

init: Initiate other misc devices from BlockDevInitializer.

This allows init to easily ensure misc devices other than device-mapper
are present.

Bug: 154536437
Test: manual test
Change-Id: I49495684edee322f9787ce7ab7f79d0e8060171d
parent e80a153f
Loading
Loading
Loading
Loading
+12 −4
Original line number Diff line number Diff line
@@ -37,7 +37,15 @@ BlockDevInitializer::BlockDevInitializer() : uevent_listener_(16 * 1024 * 1024)
}

bool BlockDevInitializer::InitDeviceMapper() {
    const std::string dm_path = "/devices/virtual/misc/device-mapper";
    return InitMiscDevice("device-mapper");
}

bool BlockDevInitializer::InitDmUser() {
    return InitMiscDevice("dm-user");
}

bool BlockDevInitializer::InitMiscDevice(const std::string& name) {
    const std::string dm_path = "/devices/virtual/misc/" + name;
    bool found = false;
    auto dm_callback = [this, &dm_path, &found](const Uevent& uevent) {
        if (uevent.path == dm_path) {
@@ -49,13 +57,13 @@ bool BlockDevInitializer::InitDeviceMapper() {
    };
    uevent_listener_.RegenerateUeventsForPath("/sys" + dm_path, dm_callback);
    if (!found) {
        LOG(INFO) << "device-mapper device not found in /sys, waiting for its uevent";
        LOG(INFO) << name << " device not found in /sys, waiting for its uevent";
        Timer t;
        uevent_listener_.Poll(dm_callback, 10s);
        LOG(INFO) << "Wait for device-mapper returned after " << t;
        LOG(INFO) << "Wait for " << name << " returned after " << t;
    }
    if (!found) {
        LOG(ERROR) << "device-mapper device not found after polling timeout";
        LOG(ERROR) << name << " device not found after polling timeout";
        return false;
    }
    return true;
+3 −0
Original line number Diff line number Diff line
@@ -27,12 +27,15 @@ class BlockDevInitializer final {
    BlockDevInitializer();

    bool InitDeviceMapper();
    bool InitDmUser();
    bool InitDevices(std::set<std::string> devices);
    bool InitDmDevice(const std::string& device);

  private:
    ListenerAction HandleUevent(const Uevent& uevent, std::set<std::string>* devices);

    bool InitMiscDevice(const std::string& name);

    std::unique_ptr<DeviceHandler> device_handler_;
    UeventListener uevent_listener_;
};