diff options
author | Yi-Yo Chiang <yochiang@google.com> | 2021-11-04 10:32:45 +0000 |
---|---|---|
committer | Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com> | 2021-11-04 10:32:45 +0000 |
commit | a6e80aec961631453531bd42f9442c308eb23d8a (patch) | |
tree | ba8f6a6a2885ce495a5c0dc2b10e7ca19100de06 | |
parent | de292556d5ade1d6d98f26e0a7a209236640bdb0 (diff) | |
parent | 53b1040fc2d31d67ec45a4ffaa914598b3713b21 (diff) | |
download | gsid-a6e80aec961631453531bd42f9442c308eb23d8a.tar.gz |
gsid: Increase image allocation size limit am: 81af6b2313 am: 53b1040fc2
Original change: https://android-review.googlesource.com/c/platform/system/gsid/+/1879338
Change-Id: Ie6544b83abea3babbe98a6226988f4521f3a7e33
-rw-r--r-- | gsi_service.cpp | 12 | ||||
-rw-r--r-- | libgsi_private.h | 3 | ||||
-rw-r--r-- | partition_installer.cpp | 35 | ||||
-rw-r--r-- | partition_installer.h | 3 |
4 files changed, 37 insertions, 16 deletions
diff --git a/gsi_service.cpp b/gsi_service.cpp index 939f603..2e1de14 100644 --- a/gsi_service.cpp +++ b/gsi_service.cpp @@ -515,12 +515,12 @@ binder::Status GsiService::suggestScratchSize(int64_t* _aidl_return) { if (statvfs(install_dir_.c_str(), &info)) { PLOG(ERROR) << "Could not statvfs(" << install_dir_ << ")"; } else { - // 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; + uint64_t free_space = static_cast<uint64_t>(info.f_bavail) * info.f_frsize; + const auto free_space_threshold = + PartitionInstaller::GetMinimumFreeSpaceThreshold(install_dir_); + if (free_space_threshold.has_value() && free_space > *free_space_threshold) { + // Round down to multiples of filesystem block size. + size = (free_space - *free_space_threshold) / info.f_frsize * info.f_frsize; } } diff --git a/libgsi_private.h b/libgsi_private.h index 82814a9..51c7915 100644 --- a/libgsi_private.h +++ b/libgsi_private.h @@ -28,8 +28,5 @@ 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 79af71a..5450169 100644 --- a/partition_installer.cpp +++ b/partition_installer.cpp @@ -22,9 +22,11 @@ #include <android-base/logging.h> #include <android-base/unique_fd.h> #include <ext4_utils/ext4_utils.h> +#include <fs_mgr.h> #include <fs_mgr_dm_linear.h> #include <libdm/dm.h> #include <libgsi/libgsi.h> +#include <liblp/partition_opener.h> #include "file_paths.h" #include "gsi_service.h" @@ -127,17 +129,18 @@ 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 = 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; } - // We are asking for 40% of the /data to be empty. - // TODO: may be not hard code it like this - double free_space_percent = ((1.0 * free_space) / fs_size) * 100; - if (free_space_percent < kMinimumFreeSpaceThreshold) { - LOG(ERROR) << "free space " << static_cast<uint64_t>(free_space_percent) - << "% is below the minimum threshold of " << kMinimumFreeSpaceThreshold << "%"; + + const auto free_space_threshold = GetMinimumFreeSpaceThreshold(install_dir_); + if (!free_space_threshold.has_value()) { + return IGsiService::INSTALL_ERROR_GENERIC; + } + if (free_space < size_ + *free_space_threshold) { + LOG(ERROR) << "post-installation free space (" << free_space << " - " << size_ + << ") would be below the minimum threshold of " << *free_space_threshold; return IGsiService::INSTALL_ERROR_FILE_SYSTEM_CLUTTERED; } return IGsiService::INSTALL_OK; @@ -345,5 +348,23 @@ int PartitionInstaller::WipeWritable(const std::string& active_dsu, const std::s return IGsiService::INSTALL_OK; } +std::optional<uint64_t> PartitionInstaller::GetMinimumFreeSpaceThreshold( + const std::string& install_dir) { + // No need to retain any space if we were not installing to the internal storage. + if (!android::base::StartsWith(install_dir, "/data"s)) { + return 0; + } + // Dynamic Partitions device must have a "super" block device. + BlockDeviceInfo info; + PartitionOpener opener; + if (!opener.GetInfo(fs_mgr_get_super_partition_name(), &info)) { + // We shouldn't reach here, but handle it just in case. + LOG(ERROR) << "could not get block device info of super"; + return std::nullopt; + } + // Reserve |super partition| of storage space so we don't disable VAB. + return info.size; +} + } // namespace gsi } // namespace android diff --git a/partition_installer.h b/partition_installer.h index 920af47..1cb9535 100644 --- a/partition_installer.h +++ b/partition_installer.h @@ -53,6 +53,9 @@ class PartitionInstaller final { static int WipeWritable(const std::string& active_dsu, const std::string& install_dir, const std::string& name); + // Returns the minimum free space to reserve for /data. + static std::optional<uint64_t> GetMinimumFreeSpaceThreshold(const std::string& install_dir); + // Finish a partition installation and release resources. // If the installation is incomplete or corrupted, the backing image would // be cleaned up and an error code is returned. |