Merge "Reduce ifs lock scope." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
fef3257d39
@@ -323,6 +323,14 @@ void IncrementalService::IncFsMount::setReadLogsEnabled(bool value) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void IncrementalService::IncFsMount::setReadLogsRequested(bool value) {
|
||||||
|
if (value) {
|
||||||
|
flags |= StorageFlags::ReadLogsRequested;
|
||||||
|
} else {
|
||||||
|
flags &= ~StorageFlags::ReadLogsRequested;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir)
|
IncrementalService::IncrementalService(ServiceManagerWrapper&& sm, std::string_view rootDir)
|
||||||
: mVold(sm.getVoldService()),
|
: mVold(sm.getVoldService()),
|
||||||
mDataLoaderManager(sm.getDataLoaderManager()),
|
mDataLoaderManager(sm.getDataLoaderManager()),
|
||||||
@@ -804,32 +812,38 @@ int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLog
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_lock l(ifs->lock);
|
std::string packageName;
|
||||||
if (!enableReadLogs) {
|
|
||||||
return disableReadLogsLocked(*ifs);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!ifs->readLogsAllowed()) {
|
{
|
||||||
LOG(ERROR) << "enableReadLogs failed, readlogs disallowed for storageId: " << storageId;
|
std::unique_lock l(ifs->lock);
|
||||||
return -EPERM;
|
if (!enableReadLogs) {
|
||||||
}
|
return disableReadLogsLocked(*ifs);
|
||||||
|
}
|
||||||
|
|
||||||
if (!ifs->dataLoaderStub) {
|
if (!ifs->readLogsAllowed()) {
|
||||||
// This should never happen - only DL can call enableReadLogs.
|
LOG(ERROR) << "enableReadLogs failed, readlogs disallowed for storageId: " << storageId;
|
||||||
LOG(ERROR) << "enableReadLogs failed: invalid state";
|
return -EPERM;
|
||||||
return -EPERM;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Check installation time.
|
if (!ifs->dataLoaderStub) {
|
||||||
const auto now = mClock->now();
|
// This should never happen - only DL can call enableReadLogs.
|
||||||
const auto startLoadingTs = ifs->startLoadingTs;
|
LOG(ERROR) << "enableReadLogs failed: invalid state";
|
||||||
if (startLoadingTs <= now && now - startLoadingTs > getReadLogsMaxInterval()) {
|
return -EPERM;
|
||||||
LOG(ERROR) << "enableReadLogs failed, readlogs can't be enabled at this time, storageId: "
|
}
|
||||||
<< storageId;
|
|
||||||
return -EPERM;
|
|
||||||
}
|
|
||||||
|
|
||||||
const auto& packageName = ifs->dataLoaderStub->params().packageName;
|
// Check installation time.
|
||||||
|
const auto now = mClock->now();
|
||||||
|
const auto startLoadingTs = ifs->startLoadingTs;
|
||||||
|
if (startLoadingTs <= now && now - startLoadingTs > getReadLogsMaxInterval()) {
|
||||||
|
LOG(ERROR)
|
||||||
|
<< "enableReadLogs failed, readlogs can't be enabled at this time, storageId: "
|
||||||
|
<< storageId;
|
||||||
|
return -EPERM;
|
||||||
|
}
|
||||||
|
|
||||||
|
packageName = ifs->dataLoaderStub->params().packageName;
|
||||||
|
ifs->setReadLogsRequested(true);
|
||||||
|
}
|
||||||
|
|
||||||
// Check loader usage stats permission and apop.
|
// Check loader usage stats permission and apop.
|
||||||
if (auto status =
|
if (auto status =
|
||||||
@@ -849,8 +863,14 @@ int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLog
|
|||||||
return fromBinderStatus(status);
|
return fromBinderStatus(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (auto status = applyStorageParamsLocked(*ifs, /*enableReadLogs=*/true); status != 0) {
|
{
|
||||||
return status;
|
std::unique_lock l(ifs->lock);
|
||||||
|
if (!ifs->readLogsRequested()) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if (auto status = applyStorageParamsLocked(*ifs, /*enableReadLogs=*/true); status != 0) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
registerAppOpsCallback(packageName);
|
registerAppOpsCallback(packageName);
|
||||||
@@ -859,6 +879,7 @@ int IncrementalService::setStorageParams(StorageId storageId, bool enableReadLog
|
|||||||
}
|
}
|
||||||
|
|
||||||
int IncrementalService::disableReadLogsLocked(IncFsMount& ifs) {
|
int IncrementalService::disableReadLogsLocked(IncFsMount& ifs) {
|
||||||
|
ifs.setReadLogsRequested(false);
|
||||||
return applyStorageParamsLocked(ifs, /*enableReadLogs=*/false);
|
return applyStorageParamsLocked(ifs, /*enableReadLogs=*/false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2214,7 +2235,6 @@ void IncrementalService::onAppOpChanged(const std::string& packageName) {
|
|||||||
affected.reserve(mMounts.size());
|
affected.reserve(mMounts.size());
|
||||||
for (auto&& [id, ifs] : mMounts) {
|
for (auto&& [id, ifs] : mMounts) {
|
||||||
std::unique_lock ll(ifs->lock);
|
std::unique_lock ll(ifs->lock);
|
||||||
|
|
||||||
if (ifs->mountId == id && ifs->dataLoaderStub &&
|
if (ifs->mountId == id && ifs->dataLoaderStub &&
|
||||||
ifs->dataLoaderStub->params().packageName == packageName) {
|
ifs->dataLoaderStub->params().packageName == packageName) {
|
||||||
affected.push_back(ifs);
|
affected.push_back(ifs);
|
||||||
@@ -2222,7 +2242,8 @@ void IncrementalService::onAppOpChanged(const std::string& packageName) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (auto&& ifs : affected) {
|
for (auto&& ifs : affected) {
|
||||||
applyStorageParamsLocked(*ifs, /*enableReadLogs=*/false);
|
std::unique_lock ll(ifs->lock);
|
||||||
|
disableReadLogsLocked(*ifs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -116,6 +116,7 @@ public:
|
|||||||
enum StorageFlags {
|
enum StorageFlags {
|
||||||
ReadLogsAllowed = 1 << 0,
|
ReadLogsAllowed = 1 << 0,
|
||||||
ReadLogsEnabled = 1 << 1,
|
ReadLogsEnabled = 1 << 1,
|
||||||
|
ReadLogsRequested = 1 << 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LoadingProgress {
|
struct LoadingProgress {
|
||||||
@@ -365,6 +366,9 @@ private:
|
|||||||
void setReadLogsEnabled(bool value);
|
void setReadLogsEnabled(bool value);
|
||||||
int32_t readLogsEnabled() const { return (flags & StorageFlags::ReadLogsEnabled); }
|
int32_t readLogsEnabled() const { return (flags & StorageFlags::ReadLogsEnabled); }
|
||||||
|
|
||||||
|
void setReadLogsRequested(bool value);
|
||||||
|
int32_t readLogsRequested() const { return (flags & StorageFlags::ReadLogsRequested); }
|
||||||
|
|
||||||
static void cleanupFilesystem(std::string_view root);
|
static void cleanupFilesystem(std::string_view root);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user