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

Commit 0fa49253 authored by Priyanka Advani (xWF)'s avatar Priyanka Advani (xWF) Committed by Gerrit Code Review
Browse files

Revert "libprocessgroup: Combine all 3 ActivateControllers imple..."

Revert submission 3212512

Reason for revert: Droidmonitor created revert due to b/372273614. Will be verifying through ABTD before submission.

Reverted changes: /q/submissionid:3212512

Change-Id: I3dadc0b7bccfe28bb067a93df2acf2c3ea0f9920
parent 5161033f
Loading
Loading
Loading
Loading
+20 −2
Original line number Diff line number Diff line
@@ -194,6 +194,24 @@ CgroupControllerWrapper CgroupMap::FindControllerByPath(const std::string& path)
    return CgroupControllerWrapper(nullptr);
}

bool CgroupMap::ActivateControllers(const std::string& path) const {
    return ::ActivateControllers(path, descriptors_);
int CgroupMap::ActivateControllers(const std::string& path) const {
    for (const auto& [name, descriptor] : descriptors_) {
        const uint32_t flags = descriptor.controller()->flags();
        const uint32_t max_activation_depth = descriptor.controller()->max_activation_depth();
        const int depth = GetCgroupDepth(descriptor.controller()->path(), path);

        if (flags & CGROUPRC_CONTROLLER_FLAG_NEEDS_ACTIVATION && depth < max_activation_depth) {
            std::string str("+");
            str.append(descriptor.controller()->name());
            if (!WriteStringToFile(str, path + "/cgroup.subtree_control")) {
                if (flags & CGROUPRC_CONTROLLER_FLAG_OPTIONAL) {
                    PLOG(WARNING) << "Activation of cgroup controller " << str
                                  << " failed in path " << path;
                } else {
                    return -errno;
                }
            }
        }
    }
    return 0;
}
+1 −1
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ class CgroupMap {
    static CgroupMap& GetInstance();
    CgroupControllerWrapper FindController(const std::string& name) const;
    CgroupControllerWrapper FindControllerByPath(const std::string& path) const;
    bool ActivateControllers(const std::string& path) const;
    int ActivateControllers(const std::string& path) const;

  private:
    bool loaded_ = false;
+4 −3
Original line number Diff line number Diff line
@@ -662,9 +662,10 @@ static int createProcessGroupInternal(uid_t uid, pid_t initialPid, std::string c
        return -errno;
    }
    if (activate_controllers) {
        if (!CgroupMap::GetInstance().ActivateControllers(uid_path)) {
            PLOG(ERROR) << "Failed to activate controllers in " << uid_path;
            return -errno;
        ret = CgroupMap::GetInstance().ActivateControllers(uid_path);
        if (ret) {
            LOG(ERROR) << "Failed to activate controllers in " << uid_path;
            return ret;
        }
    }

+40 −2
Original line number Diff line number Diff line
@@ -180,7 +180,25 @@ static bool ActivateV2CgroupController(const CgroupDescriptor& descriptor) {
        return false;
    }

    return ::ActivateControllers(controller->path(), {{controller->name(), descriptor}});
    if (controller->flags() & CGROUPRC_CONTROLLER_FLAG_NEEDS_ACTIVATION &&
        controller->max_activation_depth() > 0) {
        std::string str = "+";
        str += controller->name();
        std::string path = controller->path();
        path += "/cgroup.subtree_control";

        if (!android::base::WriteStringToFile(str, path)) {
            if (IsOptionalController(controller)) {
                PLOG(INFO) << "Failed to activate optional controller " << controller->name()
                           << " at " << path;
                return true;
            }
            PLOG(ERROR) << "Failed to activate controller " << controller->name();
            return false;
        }
    }

    return true;
}

static bool MountV1CgroupController(const CgroupDescriptor& descriptor) {
@@ -305,7 +323,27 @@ static bool CreateV2SubHierarchy(const std::string& path, const CgroupDescriptor

    // Activate all v2 controllers in path so they can be activated in
    // children as they are created.
    return ::ActivateControllers(path, descriptors);
    for (const auto& [name, descriptor] : descriptors) {
        const CgroupController* controller = descriptor.controller();
        std::uint32_t flags = controller->flags();
        std::uint32_t max_activation_depth = controller->max_activation_depth();
        const int depth = GetCgroupDepth(controller->path(), path);

        if (controller->version() == 2 && name != CGROUPV2_HIERARCHY_NAME &&
            flags & CGROUPRC_CONTROLLER_FLAG_NEEDS_ACTIVATION && depth < max_activation_depth) {
            std::string str("+");
            str += controller->name();
            if (!android::base::WriteStringToFile(str, path + "/cgroup.subtree_control")) {
                if (flags & CGROUPRC_CONTROLLER_FLAG_OPTIONAL) {
                    PLOG(WARNING) << "Activation of cgroup controller " << str << " failed in path "
                                  << path;
                } else {
                    return false;
                }
            }
        }
    }
    return true;
}

bool CgroupSetup() {
+0 −2
Original line number Diff line number Diff line
@@ -31,5 +31,3 @@ unsigned int GetCgroupDepth(const std::string& controller_root, const std::strin
using CgroupControllerName = std::string;
using CgroupDescriptorMap = std::map<CgroupControllerName, CgroupDescriptor>;
bool ReadDescriptors(CgroupDescriptorMap* descriptors);

bool ActivateControllers(const std::string& path, const CgroupDescriptorMap& descriptors);
Loading