aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTreehugger Robot <treehugger-gerrit@google.com>2022-08-09 19:40:09 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2022-08-09 19:40:09 +0000
commit16677403fb62b995784fbd8bf35aca643a01f0ba (patch)
tree985760886f95c17025a1cb927bbb3545ca938abc
parent7a68e6b20d92a0f6970621a1e6c51748157c25df (diff)
parented616b2743e4df71fa3246af1a39b0d8fef07cdb (diff)
downloadcuttlefish-16677403fb62b995784fbd8bf35aca643a01f0ba.tar.gz
Merge "Add a `--use_overlay` flag to allow disabling the overlay." am: ed616b2743
Original change: https://android-review.googlesource.com/c/device/google/cuttlefish/+/2175824 Change-Id: I82092601c57eaff7b8d12c5d4d6ed54973bc3ebb Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--host/commands/assemble_cvd/assemble_cvd.cc8
-rw-r--r--host/commands/assemble_cvd/disk_flags.cc35
-rw-r--r--host/commands/assemble_cvd/flags.cc8
-rw-r--r--host/commands/run_cvd/server_loop.cpp10
-rw-r--r--host/commands/start/main.cc19
-rw-r--r--host/libs/config/data_image.cpp9
6 files changed, 70 insertions, 19 deletions
diff --git a/host/commands/assemble_cvd/assemble_cvd.cc b/host/commands/assemble_cvd/assemble_cvd.cc
index d32751b8f..a0ce0e179 100644
--- a/host/commands/assemble_cvd/assemble_cvd.cc
+++ b/host/commands/assemble_cvd/assemble_cvd.cc
@@ -50,6 +50,8 @@ DEFINE_bool(resume, true, "Resume using the disk from the last session, if "
DEFINE_int32(modem_simulator_count, 1,
"Modem simulator count corresponding to maximum sim number");
+DECLARE_bool(use_overlay);
+
namespace cuttlefish {
namespace {
@@ -173,6 +175,12 @@ Result<const CuttlefishConfig*> InitFilesystemAndCreateConfig(
auto os_builder = OsCompositeDiskBuilder(config, instance);
creating_os_disk |= CF_EXPECT(os_builder.WillRebuildCompositeDisk());
}
+ // TODO(schuffelen): Add smarter decision for when to delete runtime files.
+ // Files like NVChip are tightly bound to Android keymint and should be
+ // deleted when userdata is reset. However if the user has ever run without
+ // the overlay, then we want to keep this until userdata.img was externally
+ // replaced.
+ creating_os_disk &= FLAGS_use_overlay;
if (FLAGS_resume && creating_os_disk) {
LOG(INFO) << "Requested resuming a previous session (the default behavior) "
<< "but the base images have changed under the overlay, making the "
diff --git a/host/commands/assemble_cvd/disk_flags.cc b/host/commands/assemble_cvd/disk_flags.cc
index a23633d61..46c4dcc09 100644
--- a/host/commands/assemble_cvd/disk_flags.cc
+++ b/host/commands/assemble_cvd/disk_flags.cc
@@ -93,6 +93,7 @@ DECLARE_string(initramfs_path);
DECLARE_string(kernel_path);
DECLARE_bool(resume);
DECLARE_bool(protected_vm);
+DECLARE_bool(use_overlay);
namespace cuttlefish {
@@ -149,91 +150,91 @@ std::vector<ImagePartition> GetOsCompositeDiskConfig() {
partitions.push_back(ImagePartition{
.label = "misc",
.image_file_path = AbsolutePath(FLAGS_misc_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "boot_a",
.image_file_path = AbsolutePath(FLAGS_boot_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "boot_b",
.image_file_path = AbsolutePath(FLAGS_boot_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "init_boot_a",
.image_file_path = AbsolutePath(FLAGS_init_boot_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "init_boot_b",
.image_file_path = AbsolutePath(FLAGS_init_boot_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "vendor_boot_a",
.image_file_path = AbsolutePath(FLAGS_vendor_boot_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "vendor_boot_b",
.image_file_path = AbsolutePath(FLAGS_vendor_boot_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "vbmeta_a",
.image_file_path = AbsolutePath(FLAGS_vbmeta_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "vbmeta_b",
.image_file_path = AbsolutePath(FLAGS_vbmeta_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "vbmeta_system_a",
.image_file_path = AbsolutePath(FLAGS_vbmeta_system_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "vbmeta_system_b",
.image_file_path = AbsolutePath(FLAGS_vbmeta_system_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "super",
.image_file_path = AbsolutePath(FLAGS_super_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "userdata",
.image_file_path = AbsolutePath(FLAGS_data_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "metadata",
.image_file_path = AbsolutePath(FLAGS_metadata_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
if (!FLAGS_otheros_root_image.empty()) {
partitions.push_back(ImagePartition{
.label = "otheros_esp",
.image_file_path = AbsolutePath(FLAGS_otheros_esp_image),
.type = kEfiSystemPartition,
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
partitions.push_back(ImagePartition{
.label = "otheros_root",
.image_file_path = AbsolutePath(FLAGS_otheros_root_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
}
if (!FLAGS_ap_rootfs_image.empty()) {
partitions.push_back(ImagePartition{
.label = "ap_rootfs",
.image_file_path = AbsolutePath(FLAGS_ap_rootfs_image),
- .read_only = true,
+ .read_only = FLAGS_use_overlay,
});
}
return partitions;
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc
index 4b4a30a61..1a74d83db 100644
--- a/host/commands/assemble_cvd/flags.cc
+++ b/host/commands/assemble_cvd/flags.cc
@@ -347,6 +347,10 @@ DEFINE_uint32(camera_server_port, 0, "camera vsock port");
DEFINE_string(userdata_format, "f2fs", "The userdata filesystem format");
+DEFINE_bool(use_overlay, true,
+ "Capture disk writes an overlay. This is a "
+ "prerequisite for powerwash_cvd or multiple instances.");
+
DECLARE_string(assembly_dir);
DECLARE_string(boot_image);
DECLARE_string(system_image_dir);
@@ -777,6 +781,9 @@ CuttlefishConfig InitializeCuttlefishConfiguration(
auto instance_nums = InstanceNumsCalculator().FromGlobalGflags().Calculate();
CHECK(instance_nums.ok()) << instance_nums.error();
+ CHECK(FLAGS_use_overlay || instance_nums->size() == 1)
+ << "`--use_overlay=false` is incompatible with multiple instances";
+
bool is_first_instance = true;
int instance_index = 0;
for (const auto& num : *instance_nums) {
@@ -872,6 +879,7 @@ CuttlefishConfig InitializeCuttlefishConfiguration(
os_overlay &= !FLAGS_protected_vm;
// Gem5 already uses CoW wrappers around disk images
os_overlay &= FLAGS_vm_manager != Gem5Manager::name();
+ os_overlay &= FLAGS_use_overlay;
if (os_overlay) {
auto path = const_instance.PerInstancePath("overlay.img");
virtual_disk_paths.push_back(path);
diff --git a/host/commands/run_cvd/server_loop.cpp b/host/commands/run_cvd/server_loop.cpp
index cbf8b1cbd..d67a72051 100644
--- a/host/commands/run_cvd/server_loop.cpp
+++ b/host/commands/run_cvd/server_loop.cpp
@@ -18,6 +18,7 @@
#include <unistd.h>
+#include <algorithm>
#include <string>
#include <fruit/fruit.h>
@@ -112,6 +113,15 @@ class ServerLoopImpl : public ServerLoop,
}
case LauncherAction::kPowerwash: {
LOG(INFO) << "Received a Powerwash request from the monitor socket";
+ const auto& disks = instance_.virtual_disk_paths();
+ auto overlay = instance_.PerInstancePath("overlay.img");
+ if (std::find(disks.begin(), disks.end(), overlay) == disks.end()) {
+ LOG(ERROR) << "Powerwash unsupported with --use_overlay=false";
+ auto response = LauncherResponse::kError;
+ client->Write(&response, sizeof(response));
+ break;
+ }
+
auto stop = process_monitor.StopMonitoredProcesses();
if (!stop.ok()) {
LOG(ERROR) << "Stopping processes failed:\n" << stop.error();
diff --git a/host/commands/start/main.cc b/host/commands/start/main.cc
index 4317effb0..ea49ab056 100644
--- a/host/commands/start/main.cc
+++ b/host/commands/start/main.cc
@@ -58,6 +58,9 @@ DEFINE_string(verbosity, "INFO", "Console logging verbosity. Options are VERBOSE
DEFINE_string(file_verbosity, "DEBUG",
"Log file logging verbosity. Options are VERBOSE,DEBUG,INFO,"
"WARNING,ERROR");
+DEFINE_bool(use_overlay, true,
+ "Capture disk writes an overlay. This is a "
+ "prerequisite for powerwash_cvd or multiple instances.");
namespace {
@@ -200,6 +203,22 @@ int main(int argc, char** argv) {
cuttlefish::InstanceNumsCalculator().FromGlobalGflags().Calculate();
CHECK(instance_nums.ok()) << instance_nums.error();
+ if (cuttlefish::CuttlefishConfig::ConfigExists()) {
+ auto previous_config = cuttlefish::CuttlefishConfig::Get();
+ CHECK(previous_config);
+ CHECK(previous_config->Instances().size() > 0);
+ auto previous_instance = previous_config->Instances()[0];
+ const auto& disks = previous_instance.virtual_disk_paths();
+ auto overlay = previous_instance.PerInstancePath("overlay.img");
+ auto used_overlay =
+ std::find(disks.begin(), disks.end(), overlay) != disks.end();
+ CHECK(used_overlay == FLAGS_use_overlay)
+ << "Cannot transition between different values of --use_overlay "
+ << "(Previous = " << used_overlay << ", current = " << FLAGS_use_overlay
+ << "). To fix this, delete \"" << previous_config->root_dir()
+ << "\" and any image files.";
+ }
+
CHECK(instance_nums->size() > 0) << "Expected at least one instance";
auto instance_num_str = std::to_string(*instance_nums->begin());
setenv("CUTTLEFISH_INSTANCE", instance_num_str.c_str(), /* overwrite */ 1);
diff --git a/host/libs/config/data_image.cpp b/host/libs/config/data_image.cpp
index 8932c7c6a..f93c375cc 100644
--- a/host/libs/config/data_image.cpp
+++ b/host/libs/config/data_image.cpp
@@ -282,10 +282,15 @@ class InitializeDataImageImpl : public InitializeDataImage {
}
return DataImageAction::kCreateImage;
}
- if (GetFsType(data_path_.Path()) != config_.userdata_format()) {
+ if (config_.data_policy() == kDataPolicyUseExisting) {
+ return DataImageAction::kNoAction;
+ }
+ auto current_fs_type = GetFsType(data_path_.Path());
+ if (current_fs_type != config_.userdata_format()) {
CF_EXPECT(config_.data_policy() == kDataPolicyResizeUpTo,
"Changing the fs format is incompatible with -data_policy="
- << kDataPolicyResizeUpTo);
+ << kDataPolicyResizeUpTo << " (\"" << current_fs_type
+ << "\" != \"" << config_.userdata_format() << "\")");
return DataImageAction::kCreateImage;
}
if (config_.data_policy() == kDataPolicyResizeUpTo) {