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

Commit cf6c68cd authored by Jeff Sharkey's avatar Jeff Sharkey Committed by Android (Google) Code Review
Browse files

Merge "Skip hard quotas when reserved has our back."

parents bdae91fd f29a3bc7
Loading
Loading
Loading
Loading
+17 −8
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@
#include <unistd.h>

#include <android-base/logging.h>
#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <android-base/strings.h>
#include <android-base/unique_fd.h>
@@ -71,6 +72,7 @@ namespace installd {

static constexpr const char* kCpPath = "/system/bin/cp";
static constexpr const char* kXattrDefault = "user.default";
static constexpr const char* kPropHasReserved = "vold.has_reserved";

static constexpr const int MIN_RESTRICTED_HOME_SDK_VERSION = 24; // > M

@@ -302,6 +304,9 @@ static int prepare_app_dir(const std::string& path, mode_t target_mode, uid_t ui
 */
static int prepare_app_quota(const std::unique_ptr<std::string>& uuid, const std::string& device,
        uid_t uid) {
    // Skip when reserved blocks are protecting us against abusive apps
    if (android::base::GetBoolProperty(kPropHasReserved, false)) return 0;
    // Skip when device no quotas present
    if (device.empty()) return 0;

    struct dqblk dq;
@@ -2417,17 +2422,21 @@ binder::Status InstalldNativeService::invalidateMounts() {
                mQuotaReverseMounts[target] = source;

                // ext4 only enables DQUOT_USAGE_ENABLED by default, so we
                // need to kick it again to enable DQUOT_LIMITS_ENABLED.
                if (quotactl(QCMD(Q_QUOTAON, USRQUOTA), source.c_str(), QFMT_VFS_V1, nullptr) != 0
                        && errno != EBUSY) {
                // need to kick it again to enable DQUOT_LIMITS_ENABLED. We
                // only need hard limits enabled when we're not being protected
                // by reserved blocks.
                if (!android::base::GetBoolProperty(kPropHasReserved, false)) {
                    if (quotactl(QCMD(Q_QUOTAON, USRQUOTA), source.c_str(), QFMT_VFS_V1,
                            nullptr) != 0 && errno != EBUSY) {
                        PLOG(ERROR) << "Failed to enable USRQUOTA on " << source;
                    }
                if (quotactl(QCMD(Q_QUOTAON, GRPQUOTA), source.c_str(), QFMT_VFS_V1, nullptr) != 0
                        && errno != EBUSY) {
                    if (quotactl(QCMD(Q_QUOTAON, GRPQUOTA), source.c_str(), QFMT_VFS_V1,
                            nullptr) != 0 && errno != EBUSY) {
                        PLOG(ERROR) << "Failed to enable GRPQUOTA on " << source;
                    }
                }
            }
        }
#endif
    }
    return ok();