Loading cmds/installd/CacheItem.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ int CacheItem::purge() { FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(WARNING) << "Failed to fts_open " << path; return -1; } Loading cmds/installd/CacheTracker.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ void CacheTracker::loadItemsFrom(const std::string& path) { FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(WARNING) << "Failed to fts_open " << path; return; } Loading cmds/installd/InstalldNativeService.cpp +28 −18 Original line number Diff line number Diff line Loading @@ -203,15 +203,21 @@ status_t InstalldNativeService::dump(int fd, const Vector<String16> & /* args */ out << "installd is happy!" << endl; { std::lock_guard<std::recursive_mutex> lock(mQuotaDevicesLock); out << endl << "Devices with quota support:" << endl; for (const auto& n : mQuotaDevices) { out << " " << n.first << " = " << n.second << endl; } } { std::lock_guard<std::recursive_mutex> lock(mCacheQuotasLock); out << endl << "Per-UID cache quotas:" << endl; for (const auto& n : mCacheQuotas) { out << " " << n.first << " = " << n.second << endl; } } out << endl; out.flush(); Loading Loading @@ -753,9 +759,6 @@ binder::Status InstalldNativeService::freeCache(const std::unique_ptr<std::strin CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); // TODO: remove this once framework is more robust invalidateMounts(); const char* uuid_ = uuid ? uuid->c_str() : nullptr; auto data_path = create_data_path(uuid_); auto device = findQuotaDeviceForUuid(uuid); Loading Loading @@ -787,7 +790,7 @@ binder::Status InstalldNativeService::freeCache(const std::unique_ptr<std::strin (char*) create_data_user_de_path(uuid_, user).c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { return error("Failed to fts_open"); } while ((p = fts_read(fts)) != NULL) { Loading @@ -800,7 +803,10 @@ binder::Status InstalldNativeService::freeCache(const std::unique_ptr<std::strin auto tracker = std::shared_ptr<CacheTracker>(new CacheTracker( multiuser_get_user_id(uid), multiuser_get_app_id(uid), device)); tracker->addDataPath(p->fts_path); { std::lock_guard<std::recursive_mutex> lock(mCacheQuotasLock); tracker->cacheQuota = mCacheQuotas[uid]; } if (tracker->cacheQuota == 0) { LOG(WARNING) << "UID " << uid << " has no cache quota; assuming 64MB"; tracker->cacheQuota = 67108864; Loading Loading @@ -1120,7 +1126,7 @@ static void collectManualExternalStatsForUser(const std::string& path, struct st FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(ERROR) << "Failed to fts_open " << path; return; } Loading Loading @@ -1159,7 +1165,8 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri for (auto packageName : packageNames) { CHECK_ARGUMENT_PACKAGE_NAME(packageName); } std::lock_guard<std::recursive_mutex> lock(mLock); // NOTE: Locking is relaxed on this method, since it's limited to // read-only measurements without mutation. // When modifying this logic, always verify using tests: // runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java -m testGetAppSize Loading Loading @@ -1274,7 +1281,8 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptr<std::str std::vector<int64_t>* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); // NOTE: Locking is relaxed on this method, since it's limited to // read-only measurements without mutation. // When modifying this logic, always verify using tests: // runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java -m testGetUserSize Loading Loading @@ -1420,7 +1428,8 @@ binder::Status InstalldNativeService::getExternalSize(const std::unique_ptr<std: int32_t userId, int32_t flags, std::vector<int64_t>* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); // NOTE: Locking is relaxed on this method, since it's limited to // read-only measurements without mutation. // When modifying this logic, always verify using tests: // runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java -m testGetExternalSize Loading Loading @@ -1486,7 +1495,7 @@ binder::Status InstalldNativeService::getExternalSize(const std::unique_ptr<std: FTSENT *p; auto path = create_data_media_path(uuid_, userId); char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { return error("Failed to fts_open " + path); } while ((p = fts_read(fts)) != NULL) { Loading Loading @@ -1533,7 +1542,7 @@ binder::Status InstalldNativeService::setAppQuota(const std::unique_ptr<std::str int32_t userId, int32_t appId, int64_t cacheQuota) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mCacheQuotasLock); int32_t uid = multiuser_get_uid(userId, appId); mCacheQuotas[uid] = cacheQuota; Loading Loading @@ -1986,7 +1995,7 @@ binder::Status InstalldNativeService::reconcileSecondaryDexFile( binder::Status InstalldNativeService::invalidateMounts() { ENFORCE_UID(AID_SYSTEM); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mQuotaDevicesLock); mQuotaDevices.clear(); Loading Loading @@ -2017,6 +2026,7 @@ binder::Status InstalldNativeService::invalidateMounts() { std::string InstalldNativeService::findQuotaDeviceForUuid( const std::unique_ptr<std::string>& uuid) { std::lock_guard<std::recursive_mutex> lock(mQuotaDevicesLock); auto path = create_data_path(uuid ? uuid->c_str() : nullptr); return mQuotaDevices[path]; } Loading cmds/installd/InstalldNativeService.h +3 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,9 @@ public: private: std::recursive_mutex mLock; std::recursive_mutex mQuotaDevicesLock; std::recursive_mutex mCacheQuotasLock; /* Map from mount point to underlying device node */ std::unordered_map<std::string, std::string> mQuotaDevices; /* Map from UID to cache quota size */ Loading cmds/installd/utils.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -284,7 +284,7 @@ int calculate_tree_size(const std::string& path, int64_t* size, FTSENT *p; int64_t matchedSize = 0; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { if (errno != ENOENT) { PLOG(ERROR) << "Failed to fts_open " << path; } Loading Loading @@ -1440,7 +1440,7 @@ int prepare_app_cache_dir(const std::string& parent, const char* name, mode_t ta FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(ERROR) << "Failed to fts_open " << path; return -1; } Loading Loading
cmds/installd/CacheItem.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -72,7 +72,7 @@ int CacheItem::purge() { FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(WARNING) << "Failed to fts_open " << path; return -1; } Loading
cmds/installd/CacheTracker.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -83,7 +83,7 @@ void CacheTracker::loadItemsFrom(const std::string& path) { FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(WARNING) << "Failed to fts_open " << path; return; } Loading
cmds/installd/InstalldNativeService.cpp +28 −18 Original line number Diff line number Diff line Loading @@ -203,15 +203,21 @@ status_t InstalldNativeService::dump(int fd, const Vector<String16> & /* args */ out << "installd is happy!" << endl; { std::lock_guard<std::recursive_mutex> lock(mQuotaDevicesLock); out << endl << "Devices with quota support:" << endl; for (const auto& n : mQuotaDevices) { out << " " << n.first << " = " << n.second << endl; } } { std::lock_guard<std::recursive_mutex> lock(mCacheQuotasLock); out << endl << "Per-UID cache quotas:" << endl; for (const auto& n : mCacheQuotas) { out << " " << n.first << " = " << n.second << endl; } } out << endl; out.flush(); Loading Loading @@ -753,9 +759,6 @@ binder::Status InstalldNativeService::freeCache(const std::unique_ptr<std::strin CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); // TODO: remove this once framework is more robust invalidateMounts(); const char* uuid_ = uuid ? uuid->c_str() : nullptr; auto data_path = create_data_path(uuid_); auto device = findQuotaDeviceForUuid(uuid); Loading Loading @@ -787,7 +790,7 @@ binder::Status InstalldNativeService::freeCache(const std::unique_ptr<std::strin (char*) create_data_user_de_path(uuid_, user).c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { return error("Failed to fts_open"); } while ((p = fts_read(fts)) != NULL) { Loading @@ -800,7 +803,10 @@ binder::Status InstalldNativeService::freeCache(const std::unique_ptr<std::strin auto tracker = std::shared_ptr<CacheTracker>(new CacheTracker( multiuser_get_user_id(uid), multiuser_get_app_id(uid), device)); tracker->addDataPath(p->fts_path); { std::lock_guard<std::recursive_mutex> lock(mCacheQuotasLock); tracker->cacheQuota = mCacheQuotas[uid]; } if (tracker->cacheQuota == 0) { LOG(WARNING) << "UID " << uid << " has no cache quota; assuming 64MB"; tracker->cacheQuota = 67108864; Loading Loading @@ -1120,7 +1126,7 @@ static void collectManualExternalStatsForUser(const std::string& path, struct st FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(ERROR) << "Failed to fts_open " << path; return; } Loading Loading @@ -1159,7 +1165,8 @@ binder::Status InstalldNativeService::getAppSize(const std::unique_ptr<std::stri for (auto packageName : packageNames) { CHECK_ARGUMENT_PACKAGE_NAME(packageName); } std::lock_guard<std::recursive_mutex> lock(mLock); // NOTE: Locking is relaxed on this method, since it's limited to // read-only measurements without mutation. // When modifying this logic, always verify using tests: // runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java -m testGetAppSize Loading Loading @@ -1274,7 +1281,8 @@ binder::Status InstalldNativeService::getUserSize(const std::unique_ptr<std::str std::vector<int64_t>* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); // NOTE: Locking is relaxed on this method, since it's limited to // read-only measurements without mutation. // When modifying this logic, always verify using tests: // runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java -m testGetUserSize Loading Loading @@ -1420,7 +1428,8 @@ binder::Status InstalldNativeService::getExternalSize(const std::unique_ptr<std: int32_t userId, int32_t flags, std::vector<int64_t>* _aidl_return) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); // NOTE: Locking is relaxed on this method, since it's limited to // read-only measurements without mutation. // When modifying this logic, always verify using tests: // runtest -x frameworks/base/services/tests/servicestests/src/com/android/server/pm/InstallerTest.java -m testGetExternalSize Loading Loading @@ -1486,7 +1495,7 @@ binder::Status InstalldNativeService::getExternalSize(const std::unique_ptr<std: FTSENT *p; auto path = create_data_media_path(uuid_, userId); char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { return error("Failed to fts_open " + path); } while ((p = fts_read(fts)) != NULL) { Loading Loading @@ -1533,7 +1542,7 @@ binder::Status InstalldNativeService::setAppQuota(const std::unique_ptr<std::str int32_t userId, int32_t appId, int64_t cacheQuota) { ENFORCE_UID(AID_SYSTEM); CHECK_ARGUMENT_UUID(uuid); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mCacheQuotasLock); int32_t uid = multiuser_get_uid(userId, appId); mCacheQuotas[uid] = cacheQuota; Loading Loading @@ -1986,7 +1995,7 @@ binder::Status InstalldNativeService::reconcileSecondaryDexFile( binder::Status InstalldNativeService::invalidateMounts() { ENFORCE_UID(AID_SYSTEM); std::lock_guard<std::recursive_mutex> lock(mLock); std::lock_guard<std::recursive_mutex> lock(mQuotaDevicesLock); mQuotaDevices.clear(); Loading Loading @@ -2017,6 +2026,7 @@ binder::Status InstalldNativeService::invalidateMounts() { std::string InstalldNativeService::findQuotaDeviceForUuid( const std::unique_ptr<std::string>& uuid) { std::lock_guard<std::recursive_mutex> lock(mQuotaDevicesLock); auto path = create_data_path(uuid ? uuid->c_str() : nullptr); return mQuotaDevices[path]; } Loading
cmds/installd/InstalldNativeService.h +3 −0 Original line number Diff line number Diff line Loading @@ -117,6 +117,9 @@ public: private: std::recursive_mutex mLock; std::recursive_mutex mQuotaDevicesLock; std::recursive_mutex mCacheQuotasLock; /* Map from mount point to underlying device node */ std::unordered_map<std::string, std::string> mQuotaDevices; /* Map from UID to cache quota size */ Loading
cmds/installd/utils.cpp +2 −2 Original line number Diff line number Diff line Loading @@ -284,7 +284,7 @@ int calculate_tree_size(const std::string& path, int64_t* size, FTSENT *p; int64_t matchedSize = 0; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { if (errno != ENOENT) { PLOG(ERROR) << "Failed to fts_open " << path; } Loading Loading @@ -1440,7 +1440,7 @@ int prepare_app_cache_dir(const std::string& parent, const char* name, mode_t ta FTS *fts; FTSENT *p; char *argv[] = { (char*) path.c_str(), nullptr }; if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_XDEV, NULL))) { if (!(fts = fts_open(argv, FTS_PHYSICAL | FTS_NOCHDIR | FTS_XDEV, NULL))) { PLOG(ERROR) << "Failed to fts_open " << path; return -1; } Loading