summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2021-02-18 02:08:11 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2021-02-18 02:08:11 +0000
commit56dc8b54aee74e7575edd002bdce2b6fea39b1ad (patch)
tree6c4b0a188949657ddaed694ea4262d72deaeec63
parentd8c502a8a97286747b50659b0d3a5161d820ff78 (diff)
parent70f53ee4523964834e3e5be00d812ae991e978df (diff)
downloadgsid-56dc8b54aee74e7575edd002bdce2b6fea39b1ad.tar.gz
Snap for 7152399 from 70f53ee4523964834e3e5be00d812ae991e978df to sc-d1-release
Change-Id: I57f4354d612bcaae3b8193b44e91f45918a44edd
-rw-r--r--gsi_service.cpp18
-rw-r--r--libgsi_private.h3
-rw-r--r--partition_installer.cpp8
3 files changed, 16 insertions, 13 deletions
diff --git a/gsi_service.cpp b/gsi_service.cpp
index cc6497a..66e01ee 100644
--- a/gsi_service.cpp
+++ b/gsi_service.cpp
@@ -510,20 +510,24 @@ binder::Status GsiService::getAvbPublicKey(AvbPublicKey* dst, int32_t* _aidl_ret
binder::Status GsiService::suggestScratchSize(int64_t* _aidl_return) {
ENFORCE_SYSTEM;
- static constexpr int64_t kMinScratchSize = 512_MiB;
- static constexpr int64_t kMaxScratchSize = 2_GiB;
+ static constexpr uint64_t kMinScratchSize = 512_MiB;
+ static constexpr uint64_t kMaxScratchSize = 2_GiB;
- int64_t size = 0;
+ uint64_t size = 0;
struct statvfs info;
if (statvfs(install_dir_.c_str(), &info)) {
PLOG(ERROR) << "Could not statvfs(" << install_dir_ << ")";
} else {
- const int64_t available_space = static_cast<int64_t>(info.f_bavail) * info.f_frsize;
- LOG(INFO) << "Available space of " << install_dir_ << ": " << available_space;
- // Use up to half of free space. Don't exhaust the storage device with scratch partition.
- size = available_space / 2;
+ // Keep the storage device at least 40% free, plus 1% for jitter.
+ constexpr int jitter = 1;
+ const uint64_t reserved_blocks =
+ static_cast<uint64_t>(info.f_blocks) * (kMinimumFreeSpaceThreshold + jitter) / 100;
+ if (info.f_bavail > reserved_blocks) {
+ size = (info.f_bavail - reserved_blocks) * info.f_frsize;
+ }
}
+ // We can safely downcast the result here, since we clamped the result within int64_t range.
*_aidl_return = std::clamp(size, kMinScratchSize, kMaxScratchSize);
return binder::Status::ok();
}
diff --git a/libgsi_private.h b/libgsi_private.h
index 51c7915..82814a9 100644
--- a/libgsi_private.h
+++ b/libgsi_private.h
@@ -28,5 +28,8 @@ static constexpr char kInstallStatusOk[] = "ok";
static constexpr char kInstallStatusWipe[] = "wipe";
static constexpr char kInstallStatusDisabled[] = "disabled";
+// We are looking for /data to have at least 40% free space.
+static constexpr uint32_t kMinimumFreeSpaceThreshold = 40;
+
} // namespace gsi
} // namespace android
diff --git a/partition_installer.cpp b/partition_installer.cpp
index 35ac884..79af71a 100644
--- a/partition_installer.cpp
+++ b/partition_installer.cpp
@@ -39,10 +39,6 @@ using namespace android::fiemap;
using namespace android::fs_mgr;
using android::base::unique_fd;
-// The default size of userdata.img for GSI.
-// We are looking for /data to have atleast 40% free space
-static constexpr uint32_t kMinimumFreeSpaceThreshold = 40;
-
PartitionInstaller::PartitionInstaller(GsiService* service, const std::string& install_dir,
const std::string& name, const std::string& active_dsu,
int64_t size, bool read_only)
@@ -130,8 +126,8 @@ int PartitionInstaller::PerformSanityChecks() {
// This is the same as android::vold::GetFreebytes() but we also
// need the total file system size so we open code it here.
- uint64_t free_space = 1ULL * sb.f_bavail * sb.f_frsize;
- uint64_t fs_size = sb.f_blocks * sb.f_frsize;
+ uint64_t free_space = static_cast<uint64_t>(sb.f_bavail) * sb.f_frsize;
+ uint64_t fs_size = static_cast<uint64_t>(sb.f_blocks) * sb.f_frsize;
if (free_space <= (size_)) {
LOG(ERROR) << "not enough free space (only " << free_space << " bytes available)";
return IGsiService::INSTALL_ERROR_NO_SPACE;