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

Commit d23803f0 authored by David Anderson's avatar David Anderson Committed by Automerger Merge Worker
Browse files

Merge "adds LO_FLAGS_AUTOCLEAR for loop device of zram backing device" am:...

Merge "adds LO_FLAGS_AUTOCLEAR for loop device of zram backing device" am: af09c150 am: d50f25be

Original change: https://android-review.googlesource.com/c/platform/system/core/+/1834393

Change-Id: I3d8e8b1dcbb08146e421b7b7adb4f6b1d18fd5f3
parents e7fcc3cd d50f25be
Loading
Loading
Loading
Loading
+3 −0
Original line number Original line Diff line number Diff line
@@ -2119,6 +2119,9 @@ static bool PrepareZramBackingDevice(off64_t size) {
        PERROR << "Cannot open " << loop_device;
        PERROR << "Cannot open " << loop_device;
        return false;
        return false;
    }
    }
    if (!LoopControl::SetAutoClearStatus(loop_fd.get())) {
        PERROR << "Failed set LO_FLAGS_AUTOCLEAR for " << loop_device;
    }
    if (!LoopControl::EnableDirectIo(loop_fd.get())) {
    if (!LoopControl::EnableDirectIo(loop_fd.get())) {
        return false;
        return false;
    }
    }
+3 −0
Original line number Original line Diff line number Diff line
@@ -46,6 +46,9 @@ class LoopControl final {
    // Enable Direct I/O on a loop device. This requires kernel 4.9+.
    // Enable Direct I/O on a loop device. This requires kernel 4.9+.
    static bool EnableDirectIo(int fd);
    static bool EnableDirectIo(int fd);


    // Set LO_FLAGS_AUTOCLEAR on a loop device.
    static bool SetAutoClearStatus(int fd);

    LoopControl(const LoopControl&) = delete;
    LoopControl(const LoopControl&) = delete;
    LoopControl& operator=(const LoopControl&) = delete;
    LoopControl& operator=(const LoopControl&) = delete;
    LoopControl& operator=(LoopControl&&) = default;
    LoopControl& operator=(LoopControl&&) = default;
+10 −0
Original line number Original line Diff line number Diff line
@@ -133,6 +133,16 @@ bool LoopControl::EnableDirectIo(int fd) {
    return true;
    return true;
}
}


bool LoopControl::SetAutoClearStatus(int fd) {
    struct loop_info64 info = {};

    info.lo_flags |= LO_FLAGS_AUTOCLEAR;
    if (ioctl(fd, LOOP_SET_STATUS64, &info)) {
        return false;
    }
    return true;
}

LoopDevice::LoopDevice(android::base::borrowed_fd fd, const std::chrono::milliseconds& timeout_ms,
LoopDevice::LoopDevice(android::base::borrowed_fd fd, const std::chrono::milliseconds& timeout_ms,
                       bool auto_close)
                       bool auto_close)
    : fd_(fd), owned_fd_(-1) {
    : fd_(fd), owned_fd_(-1) {