Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ cf_cc_library(
deps = [
"//cuttlefish/common/libs/utils:files",
"//cuttlefish/files:file_exists",
"//cuttlefish/host/commands/assemble_cvd:assemble_cvd_flags",
"//cuttlefish/host/commands/assemble_cvd:boot_config",
"//cuttlefish/host/commands/assemble_cvd:boot_image_utils",
"//cuttlefish/host/commands/assemble_cvd:disk_builder",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "cuttlefish/common/libs/utils/files.h"
#include "cuttlefish/files/file_exists.h"
#include "cuttlefish/host/commands/assemble_cvd/android_build/android_builds.h"
#include "cuttlefish/host/commands/assemble_cvd/assemble_cvd_flags.h"
#include "cuttlefish/host/commands/assemble_cvd/boot_config.h"
#include "cuttlefish/host/commands/assemble_cvd/boot_image_utils.h"
#include "cuttlefish/host/commands/assemble_cvd/disk/access_kregistry.h"
Expand Down Expand Up @@ -83,6 +84,43 @@ uint64_t AvailableSpaceAtPath(const std::string& path) {
return static_cast<uint64_t>(vfs.f_frsize) * vfs.f_bavail;
}

Result<void> CheckDataImageSpace(
const CuttlefishConfig::InstanceSpecific& instance) {
if (FLAGS_use_overlay) {
return {};
}

// Check if filling in the sparse image would run out of disk space.
std::string data_image = instance.data_image();
auto existing_sizes = SparseFileSizes(data_image);
if (existing_sizes.sparse_size == 0 && existing_sizes.disk_size == 0) {
data_image = instance.new_data_image();
existing_sizes = SparseFileSizes(data_image);
CF_EXPECT(existing_sizes.sparse_size > 0 || existing_sizes.disk_size > 0,
"Unable to determine size of \"" << data_image
<< "\". Does this file exist?");
}
if (existing_sizes.sparse_size > 0 || existing_sizes.disk_size > 0) {
auto available_space = AvailableSpaceAtPath(data_image);
if (available_space <
existing_sizes.sparse_size - existing_sizes.disk_size) {
// TODO(schuffelen): Duplicate this check in run_cvd when it can run on
// a separate machine
return CF_ERR("Not enough space remaining in fs containing \""
<< data_image << "\", wanted "
<< (existing_sizes.sparse_size - existing_sizes.disk_size)
<< ", got " << available_space);
} else {
VLOG(0) << "Available space: " << available_space;
VLOG(0) << "Sparse size of \"" << data_image
<< "\": " << existing_sizes.sparse_size;
VLOG(0) << "Disk size of \"" << data_image
<< "\": " << existing_sizes.disk_size;
}
}
return {};
}

Result<BuildArchive> FindImgZip(const FetcherConfig& fetcher_config,
std::string_view system_image_dir) {
for (const auto& [member_name, member] : fetcher_config.get_cvd_files()) {
Expand Down Expand Up @@ -139,35 +177,7 @@ Result<void> CreateDynamicDiskFiles(
CF_EXPECT(InitializeSdCard(config, instance));
CF_EXPECT(InitializeDataImage(instance));
CF_EXPECT(InitializePflash(instance));

// Check if filling in the sparse image would run out of disk space.
std::string data_image = instance.data_image();
auto existing_sizes = SparseFileSizes(data_image);
if (existing_sizes.sparse_size == 0 && existing_sizes.disk_size == 0) {
data_image = instance.new_data_image();
existing_sizes = SparseFileSizes(data_image);
CF_EXPECT(existing_sizes.sparse_size > 0 || existing_sizes.disk_size > 0,
"Unable to determine size of \""
<< data_image << "\". Does this file exist?");
}
if (existing_sizes.sparse_size > 0 || existing_sizes.disk_size > 0) {
auto available_space = AvailableSpaceAtPath(data_image);
if (available_space <
existing_sizes.sparse_size - existing_sizes.disk_size) {
// TODO(schuffelen): Duplicate this check in run_cvd when it can run on
// a separate machine
return CF_ERR("Not enough space remaining in fs containing \""
<< data_image << "\", wanted "
<< (existing_sizes.sparse_size - existing_sizes.disk_size)
<< ", got " << available_space);
} else {
VLOG(0) << "Available space: " << available_space;
VLOG(0) << "Sparse size of \"" << data_image
<< "\": " << existing_sizes.sparse_size;
VLOG(0) << "Disk size of \"" << data_image
<< "\": " << existing_sizes.disk_size;
}
}
CF_EXPECT(CheckDataImageSpace(instance));

CF_EXPECT_LE(instance_index, image_files.size());
const std::vector<std::unique_ptr<ImageFile>>& instance_image_files =
Expand Down
Loading