summaryrefslogtreecommitdiff
path: root/services/incremental/IncrementalService.cpp
diff options
context:
space:
mode:
authorYurii Zubrytskyi <zyy@google.com>2021-03-24 00:46:29 -0700
committerAlex Buynytskyy <alexbuy@google.com>2021-03-24 15:05:17 +0000
commit4cd249257638993be352ba607f8a81a534ddb199 (patch)
treec18a347aaf7c440db6022ab49c5e36f9b2f3cb89 /services/incremental/IncrementalService.cpp
parent16828074ec56fe8a2393bfcbf341cbdbaddd07cf (diff)
[incfs] Space trimming for IncFS v1
Run a manual timed job that trims all files one by one on the old version of IncFS, where it didn't do it automatically. Bug: 183435580 Fixes: 183436717 Test: atest libincfs-test service.incremental_test Change-Id: I57885b2826e383814822c767802f837135fd8464
Diffstat (limited to 'services/incremental/IncrementalService.cpp')
-rw-r--r--services/incremental/IncrementalService.cpp44
1 files changed, 33 insertions, 11 deletions
diff --git a/services/incremental/IncrementalService.cpp b/services/incremental/IncrementalService.cpp
index 9bb2f041556a..94f8e59c6057 100644
--- a/services/incremental/IncrementalService.cpp
+++ b/services/incremental/IncrementalService.cpp
@@ -1086,17 +1086,14 @@ int IncrementalService::makeFile(StorageId storage, std::string_view path, int m
return err;
}
if (params.size > 0) {
- // Only v2+ incfs supports automatically trimming file over-reserved sizes
- if (mIncFs->features() & incfs::Features::v2) {
- if (auto err = mIncFs->reserveSpace(ifs->control, normPath, params.size)) {
- if (err != -EOPNOTSUPP) {
- LOG(ERROR) << "Failed to reserve space for a new file: " << err;
- (void)mIncFs->unlink(ifs->control, normPath);
- return err;
- } else {
- LOG(WARNING) << "Reserving space for backing file isn't supported, "
- "may run out of disk later";
- }
+ if (auto err = mIncFs->reserveSpace(ifs->control, id, params.size)) {
+ if (err != -EOPNOTSUPP) {
+ LOG(ERROR) << "Failed to reserve space for a new file: " << err;
+ (void)mIncFs->unlink(ifs->control, normPath);
+ return err;
+ } else {
+ LOG(WARNING) << "Reserving space for backing file isn't supported, "
+ "may run out of disk later";
}
}
if (!data.empty()) {
@@ -1680,6 +1677,15 @@ void IncrementalService::runCmdLooper() {
}
}
+void IncrementalService::trimReservedSpaceV1(const IncFsMount& ifs) {
+ mIncFs->forEachFile(ifs.control, [this](auto&& control, auto&& fileId) {
+ if (mIncFs->isFileFullyLoaded(control, fileId) == incfs::LoadingState::Full) {
+ mIncFs->reserveSpace(control, fileId, -1);
+ }
+ return true;
+ });
+}
+
void IncrementalService::prepareDataLoaderLocked(IncFsMount& ifs, DataLoaderParamsParcel&& params,
DataLoaderStatusListener&& statusListener,
const StorageHealthCheckParams& healthCheckParams,
@@ -1699,6 +1705,22 @@ void IncrementalService::prepareDataLoaderLocked(IncFsMount& ifs, DataLoaderPara
std::move(statusListener), healthCheckParams,
std::move(healthListener), path::join(ifs.root, constants().mount));
+ // pre-v2 IncFS doesn't do automatic reserved space trimming - need to run it manually
+ if (!(mIncFs->features() & incfs::Features::v2)) {
+ addIfsStateCallback(ifs.mountId, [this](StorageId storageId, IfsState state) -> bool {
+ if (!state.fullyLoaded) {
+ return true;
+ }
+
+ const auto ifs = getIfs(storageId);
+ if (!ifs) {
+ return false;
+ }
+ trimReservedSpaceV1(*ifs);
+ return false;
+ });
+ }
+
addIfsStateCallback(ifs.mountId, [this](StorageId storageId, IfsState state) -> bool {
if (!state.fullyLoaded || state.readLogsEnabled) {
return true;