diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel b/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel index 4a9aa985da3..0d855b2258f 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/BUILD.bazel @@ -179,7 +179,6 @@ cf_cc_library( "//cuttlefish/host/libs/config:fetcher_config", "//cuttlefish/host/libs/config:file_source", "//cuttlefish/host/libs/config:instance_nums", - "//cuttlefish/host/libs/config:vmm_mode", "//cuttlefish/host/libs/feature:inject", "//libbase", "@abseil-cpp//absl/strings", @@ -220,7 +219,6 @@ cf_cc_library( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:fetcher_config", "//cuttlefish/host/libs/config:instance_nums", - "//cuttlefish/host/libs/config:vmm_mode", "//libbase", ], ) diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp index 9614106ff11..5c9fd58bee1 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/bootconfig_args.cpp @@ -115,9 +115,8 @@ Result> BootconfigArgsFromConfig( std::to_string(instance.openthread_node_id()); } - const auto enable_confui = (config.vm_manager() == VmmMode::kQemu ? 0 : 1); bootconfig_args["androidboot.enable_confirmationui"] = - std::to_string(enable_confui); + std::to_string(!VmManagerIsQemu(config)); if (instance.audiocontrol_server_port()) { bootconfig_args["androidboot.vendor.audiocontrol.server.cid"] = diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/create_dynamic_disk_files.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/create_dynamic_disk_files.cc index bcebcfbe1f0..ab6dffb45d0 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/create_dynamic_disk_files.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/create_dynamic_disk_files.cc @@ -59,7 +59,6 @@ #include "cuttlefish/host/libs/config/fetched_archive.h" #include "cuttlefish/host/libs/config/fetcher_config.h" #include "cuttlefish/host/libs/config/file_source.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" namespace cuttlefish { namespace { @@ -234,7 +233,7 @@ Result CreateDynamicDiskFiles( // Gem5 Simulate per-instance what the bootloader would usually do // Since on other devices this runs every time, just do it here every time - if (config.vm_manager() == VmmMode::kGem5) { + if (VmManagerIsGem5(config)) { RepackGem5BootImage(instance.PerInstancePath("initrd.img"), boot_config, config.assembly_dir(), instance.initramfs_path()); } diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel index fe0b804808f..4c873078083 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/BUILD.bazel @@ -199,7 +199,6 @@ cf_cc_library( "//cuttlefish/host/commands/assemble_cvd/disk:generate_persistent_vbmeta", "//cuttlefish/host/libs/config:ap_boot_flow", "//cuttlefish/host/libs/config:cuttlefish_config", - "//cuttlefish/host/libs/config:vmm_mode", "//cuttlefish/host/libs/image_aggregator", "//cuttlefish/host/libs/vm_manager", "@gflags", @@ -315,7 +314,6 @@ cf_cc_library( "//cuttlefish/common/libs/utils:result", "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:data_image", - "//cuttlefish/host/libs/config:vmm_mode", "//cuttlefish/host/libs/image_aggregator:qcow2", ], ) diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/gem5_image_unpacker.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/gem5_image_unpacker.cpp index abd606c08c6..a510a55dd10 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/gem5_image_unpacker.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/gem5_image_unpacker.cpp @@ -27,7 +27,7 @@ namespace cuttlefish { Result Gem5ImageUnpacker(const CuttlefishConfig& config) { - if (config.vm_manager() != VmmMode::kGem5) { + if (!VmManagerIsGem5(config)) { return {}; } // TODO: b/281130788 - This should accept InstanceSpecific as an argument diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp index 431cf5cc133..cb4f0ff43ae 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.cpp @@ -16,7 +16,6 @@ #include "cuttlefish/host/commands/assemble_cvd/disk/generate_persistent_bootconfig.h" -#include #include #include @@ -74,7 +73,7 @@ Result> BootConfigPartition::CreateIfNeeded( << bootconfig_path << "` failed:" << bootconfig_fd->StrError()); - if (config.vm_manager() == VmmMode::kGem5) { + if (VmManagerIsGem5(config)) { const off_t bootconfig_size_bytes_gem5 = AlignToPowerOf2(bytesWritten, PARTITION_SIZE_SHIFT); CF_EXPECT(bootconfig_fd->Truncate(bootconfig_size_bytes_gem5) == 0); diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/initialize_instance_composite_disk.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/initialize_instance_composite_disk.cc index 675ef08859c..01256e92a13 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/initialize_instance_composite_disk.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/initialize_instance_composite_disk.cc @@ -26,7 +26,6 @@ #include "cuttlefish/host/commands/assemble_cvd/disk_builder.h" #include "cuttlefish/host/libs/config/ap_boot_flow.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" #include "cuttlefish/host/libs/image_aggregator/image_aggregator.h" namespace cuttlefish { @@ -71,10 +70,6 @@ std::vector PersistentAPCompositeDiskConfig( return partitions; } -bool IsVmManagerQemu(const CuttlefishConfig& config) { - return config.vm_manager() == VmmMode::kQemu; -} - } // namespace Result InstanceCompositeDisk::Create( @@ -104,7 +99,7 @@ Result InstanceCompositeDisk::Create( std::string overlay_path = instance.PerInstancePath("persistent_composite_overlay.img"); persistent_disk_builder.OverlayPath(overlay_path); - if (IsVmManagerQemu(config)) { + if (VmManagerIsQemu(config)) { CF_EXPECT(persistent_disk_builder.BuildOverlayIfNecessary()); } return InstanceCompositeDisk(); @@ -136,7 +131,7 @@ Result> ApCompositeDisk::Create( CF_EXPECT(persistent_ap_disk_builder.BuildCompositeDiskIfNecessary()); persistent_ap_disk_builder.OverlayPath( instance.PerInstancePath("ap_persistent_composite_overlay.img")); - if (IsVmManagerQemu(config)) { + if (VmManagerIsQemu(config)) { CF_EXPECT(persistent_ap_disk_builder.BuildOverlayIfNecessary()); } return ApCompositeDisk(); diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/kernel_ramdisk_repacker.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/kernel_ramdisk_repacker.cpp index ac6bd59beb9..8e58754142e 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/kernel_ramdisk_repacker.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/kernel_ramdisk_repacker.cpp @@ -109,7 +109,7 @@ Result RepackKernelRamdisk( // large to be repacked. Skip repack of boot.img on Gem5, as we need to be // able to extract the ramdisk.img in a later stage and so this step must // not fail (..and the repacked kernel wouldn't be used anyway). - if (!instance.kernel_path().empty() && config.vm_manager() != VmmMode::kGem5) { + if (!instance.kernel_path().empty() && !VmManagerIsGem5(config)) { CF_EXPECT( RepackBootImage(avb, instance.kernel_path(), instance.boot_image(), instance.new_boot_image(), instance.instance_dir()), diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/sd_card.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/sd_card.cc index 2b62f631dd7..2f7fa8938aa 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/sd_card.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk/sd_card.cc @@ -20,7 +20,6 @@ #include "cuttlefish/common/libs/utils/result.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/data_image.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" #include "cuttlefish/host/libs/image_aggregator/qcow2.h" namespace cuttlefish { @@ -37,7 +36,7 @@ Result InitializeSdCard( CF_EXPECT(CreateBlankImage(instance.sdcard_path(), instance.blank_sdcard_image_mb(), "sdcard"), "Failed to create \"" << instance.sdcard_path() << "\""); - if (config.vm_manager() == VmmMode::kQemu) { + if (VmManagerIsQemu(config)) { const std::string crosvm_path = instance.crosvm_binary(); CF_EXPECT(Qcow2Image::Create(crosvm_path, instance.sdcard_path(), instance.sdcard_overlay_path())); diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_builder.cpp b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_builder.cpp index 53938e4b6bc..ae22b9068c3 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_builder.cpp +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_builder.cpp @@ -208,7 +208,7 @@ Result DiskBuilder::BuildCompositeDiskIfNecessary() { CF_EXPECT(vm_manager_ != VmmMode::kUnknown); // TODO: b/346855591 - run with QEMU when crosvm block device is integrated - if (vm_manager_ == VmmMode::kCrosvm) { + if (VmManagerIsCrosvm(vm_manager_)) { CF_EXPECT(!header_path_.empty(), "No header path"); CF_EXPECT(!footer_path_.empty(), "No footer path"); CF_EXPECT(CreateOrUpdateCompositeDisk( diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.cc index b5d49a678ac..83696bfdc03 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/disk_image_flags_vectorization.cc @@ -38,7 +38,6 @@ #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/fetcher_config.h" #include "cuttlefish/host/libs/config/instance_nums.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" namespace cuttlefish { @@ -214,7 +213,7 @@ Result DiskImageFlagsVectorization( const CuttlefishConfig::InstanceSpecific const_instance = const_config.ForInstance(num); if (!kernel_path.KernelPathForIndex(instance_index).empty() && - config.vm_manager() != VmmMode::kGem5) { + !VmManagerIsGem5(config)) { const std::string new_boot_image_path = const_instance.PerInstancePath("boot_repacked.img"); // change the new flag value to corresponding instance diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc index bc2a5a48ec4..4452e6f96de 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags.cc @@ -850,7 +850,7 @@ Result InitializeCuttlefishConfiguration( std::set default_on_arch = {Arch::Arm64}; if (guest_configs[instance_index].vhost_user_vsock) { instance.set_vhost_user_vsock(true); - } else if (tmp_config_obj.vm_manager() == VmmMode::kCrosvm && + } else if (VmManagerIsCrosvm(tmp_config_obj) && default_on_arch.find( guest_configs[instance_index].target_arch) != default_on_arch.end()) { @@ -1150,28 +1150,23 @@ Result InitializeCuttlefishConfiguration( std::vector virtual_disk_paths; - bool os_overlay = true; // Gem5 already uses CoW wrappers around disk images - os_overlay &= vm_manager_flag.Mode() != VmmMode::kGem5; - os_overlay &= FLAGS_use_overlay; - if (os_overlay) { + if (FLAGS_use_overlay && !VmManagerIsGem5(vm_manager_flag)) { auto path = const_instance.PerInstancePath("overlay.img"); virtual_disk_paths.push_back(path); } else { virtual_disk_paths.push_back(const_instance.os_composite_disk_path()); } - bool persistent_disk = vm_manager_flag.Mode() != VmmMode::kGem5; + bool persistent_disk = !VmManagerIsGem5(vm_manager_flag); if (persistent_disk) { #ifdef __APPLE__ const std::string persistent_composite_img_base = "persistent_composite.img"; #else - const bool is_vm_qemu_cli = - (tmp_config_obj.vm_manager() == VmmMode::kQemu); const std::string persistent_composite_img_base = - is_vm_qemu_cli ? "persistent_composite_overlay.img" - : "persistent_composite.img"; + VmManagerIsQemu(tmp_config_obj) ? "persistent_composite_overlay.img" + : "persistent_composite.img"; #endif auto path = const_instance.PerInstancePath(persistent_composite_img_base.data()); @@ -1182,7 +1177,7 @@ Result InitializeCuttlefishConfiguration( bool sdcard = use_sdcard_vec[instance_index]; if (sdcard) { - if (tmp_config_obj.vm_manager() == VmmMode::kQemu) { + if (VmManagerIsQemu(tmp_config_obj)) { virtual_disk_paths.push_back(const_instance.sdcard_overlay_path()); } else { virtual_disk_paths.push_back(const_instance.sdcard_path()); @@ -1269,7 +1264,7 @@ Result InitializeCuttlefishConfiguration( auto external_network_mode = CF_EXPECT( ParseExternalNetworkMode(device_external_network_vec[instance_index])); CF_EXPECT(external_network_mode == ExternalNetworkMode::kTap || - vm_manager_flag.Mode() == VmmMode::kQemu, + VmManagerIsQemu(vm_manager_flag), "TODO(b/286284441): slirp only works on QEMU"); instance.set_external_network_mode(external_network_mode); @@ -1333,11 +1328,10 @@ Result InitializeCuttlefishConfiguration( const auto& environment_specific = (static_cast(tmp_config_obj)) .ForEnvironment(environment_name); - CF_EXPECT(CheckSnapshotCompatible( - FLAGS_snapshot_compatible && - (tmp_config_obj.vm_manager() == VmmMode::kCrosvm) && - instance_nums.size() == 1, - calculated_gpu_mode_vec), + CF_EXPECT(CheckSnapshotCompatible(FLAGS_snapshot_compatible && + VmManagerIsCrosvm(tmp_config_obj) && + instance_nums.size() == 1, + calculated_gpu_mode_vec), "The set of flags is incompatible with snapshot"); AndroidEfiLoaderFlag efi_loader = diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.cc index e713bbe53b6..4255c5fbf57 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.cc @@ -66,4 +66,16 @@ VmManagerFlag::VmManagerFlag(VmmMode mode) : mode_(mode) {} VmmMode VmManagerFlag::Mode() const { return mode_; } +bool VmManagerIsCrosvm(const VmManagerFlag& vmm) { + return VmManagerIsCrosvm(vmm.Mode()); +} + +bool VmManagerIsQemu(const VmManagerFlag& vmm) { + return VmManagerIsQemu(vmm.Mode()); +} + +bool VmManagerIsGem5(const VmManagerFlag& vmm) { + return VmManagerIsGem5(vmm.Mode()); +} + } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h index b7ae8a6ce6b..4c3762b9e12 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/flags/vm_manager.h @@ -36,4 +36,8 @@ class VmManagerFlag { VmmMode mode_; }; +bool VmManagerIsCrosvm(const VmManagerFlag&); +bool VmManagerIsQemu(const VmManagerFlag&); +bool VmManagerIsGem5(const VmManagerFlag&); + } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc b/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc index 5cdcc1a0d42..b136f8f19ae 100644 --- a/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc +++ b/base/cvd/cuttlefish/host/commands/assemble_cvd/graphics_flags.cc @@ -292,7 +292,7 @@ Result SelectGpuMode( LOG(INFO) << "GPU auto mode: detected prerequisites for accelerated " << "rendering support."; - if (vmm == VmmMode::kQemu && !UseQemuPrebuilt()) { + if (VmManagerIsQemu(vmm) && !UseQemuPrebuilt()) { LOG(INFO) << "Not using QEMU prebuilt (QEMU 8+): selecting guest swiftshader"; return kGpuModeGuestSwiftshader; } else if (guest_config.prefer_drm_virgl_when_supported) { @@ -325,7 +325,7 @@ Result SelectGpuMode( "--gpu_mode=auto or --gpu_mode=guest_swiftshader."; } - if (vmm == VmmMode::kQemu && !UseQemuPrebuilt()) { + if (VmManagerIsQemu(vmm) && !UseQemuPrebuilt()) { LOG(INFO) << "Not using QEMU prebuilt (QEMU 8+): selecting guest swiftshader"; return kGpuModeGuestSwiftshader; } @@ -347,7 +347,7 @@ Result SelectGpuVhostUserMode(const std::string& gpu_mode, return false; } - if (vmm != VmmMode::kCrosvm) { + if (!VmManagerIsCrosvm(vmm)) { LOG(INFO) << "GPU vhost user auto mode: not yet supported with " << vmm << ". Not enabling vhost user gpu."; return false; diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel b/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel index 1eb935ea554..74456f5c557 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel +++ b/base/cvd/cuttlefish/host/commands/run_cvd/launch/BUILD.bazel @@ -307,7 +307,6 @@ cf_cc_library( "//cuttlefish/host/libs/config:ap_boot_flow", "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:openwrt_args", - "//cuttlefish/host/libs/config:vmm_mode", "//cuttlefish/host/libs/feature", "//cuttlefish/host/libs/vm_manager", "//libbase", @@ -447,7 +446,6 @@ cf_cc_library( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:guest_os", "//cuttlefish/host/libs/config:known_paths", - "//cuttlefish/host/libs/config:vmm_mode", "//cuttlefish/host/libs/feature", "//libbase", "@fmt", diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/open_wrt.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/launch/open_wrt.cpp index e35be7dc171..c2e9e93d17d 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/open_wrt.cpp +++ b/base/cvd/cuttlefish/host/commands/run_cvd/launch/open_wrt.cpp @@ -34,7 +34,6 @@ #include "cuttlefish/host/libs/config/ap_boot_flow.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/openwrt_args.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" #include "cuttlefish/host/libs/feature/command_source.h" #include "cuttlefish/host/libs/feature/feature.h" #include "cuttlefish/host/libs/vm_manager/crosvm_builder.h" @@ -146,7 +145,7 @@ class OpenWrt : public CommandSource { auto openwrt_args = OpenwrtArgsFromConfig(instance_); switch (instance_.ap_boot_flow()) { case APBootFlow::Grub: - if (config_.vm_manager() == VmmMode::kQemu) { + if (VmManagerIsQemu(config_)) { ap_cmd.AddReadWriteDisk( instance_.persistent_ap_composite_overlay_path()); } else { @@ -179,7 +178,7 @@ class OpenWrt : public CommandSource { std::string Name() const override { return "OpenWrt"; } bool Enabled() const override { return instance_.ap_boot_flow() != APBootFlow::None && - config_.vm_manager() == VmmMode::kCrosvm; + VmManagerIsCrosvm(config_); } private: diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/launch/streamer.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/launch/streamer.cpp index 4eeadfee155..3f274fa27b1 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/launch/streamer.cpp +++ b/base/cvd/cuttlefish/host/commands/run_cvd/launch/streamer.cpp @@ -44,7 +44,6 @@ #include "cuttlefish/host/libs/config/custom_actions.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/known_paths.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" #include "cuttlefish/host/libs/feature/command_source.h" #include "cuttlefish/host/libs/feature/feature.h" #include "cuttlefish/host/libs/feature/kernel_log_pipe_provider.h" @@ -151,9 +150,8 @@ class StreamerSockets : public virtual SetupFeature { // SetupFeature std::string Name() const override { return "StreamerSockets"; } bool Enabled() const override { - bool is_qemu = config_.vm_manager() == VmmMode::kQemu; bool is_accelerated = instance_.gpu_mode() != kGpuModeGuestSwiftshader; - return !(is_qemu && is_accelerated); + return !(VmManagerIsQemu(config_) && is_accelerated); } private: @@ -270,17 +268,8 @@ class WebRtcServer : public virtual CommandSource, // SetupFeature bool Enabled() const override { - if (!sockets_.Enabled()) { - return false; - } - switch (config_.vm_manager()) { - case VmmMode::kCrosvm: - case VmmMode::kQemu: - return true; - case VmmMode::kGem5: - case VmmMode::kUnknown: - return false; - } + return sockets_.Enabled() && + (VmManagerIsCrosvm(config_) || VmManagerIsQemu(config_)); } private: diff --git a/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl_snapshot.cpp b/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl_snapshot.cpp index ca3b7a8074c..db50bb387f5 100644 --- a/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl_snapshot.cpp +++ b/base/cvd/cuttlefish/host/commands/run_cvd/server_loop_impl_snapshot.cpp @@ -27,13 +27,9 @@ #include "cuttlefish/common/libs/utils/files.h" #include "cuttlefish/common/libs/utils/json.h" #include "cuttlefish/common/libs/utils/result.h" -#include "cuttlefish/host/libs/command_util/runner/defs.h" #include "cuttlefish/host/libs/command_util/runner/run_cvd.pb.h" #include "cuttlefish/host/libs/command_util/snapshot_utils.h" -#include "cuttlefish/host/libs/command_util/util.h" #include "cuttlefish/host/libs/config/ap_boot_flow.h" -#include "cuttlefish/host/libs/vm_manager/crosvm_manager.h" -#include "cuttlefish/host/libs/vm_manager/qemu_manager.h" namespace cuttlefish { namespace run_cvd_impl { @@ -106,7 +102,7 @@ Result ServerLoopImpl::SuspendGuest() { "failed to suspend openwrt crosvm instance."); } const auto main_vmm = config_.vm_manager(); - if (main_vmm == VmmMode::kCrosvm) { + if (VmManagerIsCrosvm(main_vmm)) { const auto& vm_sock = GetSocketPath(ToString(main_vmm), vm_name_to_control_sock_); if (vm_sock.empty()) { @@ -132,7 +128,7 @@ Result ServerLoopImpl::ResumeGuest() { "failed to resume openwrt crosvm instance."); } const auto main_vmm = config_.vm_manager(); - if (main_vmm == VmmMode::kCrosvm) { + if (VmManagerIsCrosvm(main_vmm)) { const auto& vm_sock = GetSocketPath(ToString(main_vmm), vm_name_to_control_sock_); if (vm_sock.empty()) { @@ -256,7 +252,7 @@ Result ServerLoopImpl::TakeGuestSnapshot(VmmMode vm_manager, std::string("Failed to read from ") + json_path); Json::Value meta_json = CF_EXPECTF( ParseJson(json_contents), "Failed to parse json: \n{}", json_contents); - CF_EXPECTF(vm_manager == VmmMode::kCrosvm, + CF_EXPECTF(VmManagerIsCrosvm(vm_manager), "{}, which is not crosvm, is not yet supported.", vm_manager); CF_EXPECT(TakeCrosvmGuestSnapshot(meta_json), "TakeCrosvmGuestSnapshot() failed."); diff --git a/base/cvd/cuttlefish/host/libs/config/BUILD.bazel b/base/cvd/cuttlefish/host/libs/config/BUILD.bazel index d32b99fcd9d..b73095f189b 100644 --- a/base/cvd/cuttlefish/host/libs/config/BUILD.bazel +++ b/base/cvd/cuttlefish/host/libs/config/BUILD.bazel @@ -138,7 +138,6 @@ cf_cc_library( "//cuttlefish/host/libs/config:cuttlefish_config", "//cuttlefish/host/libs/config:esp", "//cuttlefish/host/libs/config:openwrt_args", - "//cuttlefish/host/libs/config:vmm_mode", "//cuttlefish/host/libs/image_aggregator:mbr", "//libbase", ], @@ -288,7 +287,6 @@ cf_cc_library( deps = [ "//cuttlefish/common/libs/utils:host_info", "//cuttlefish/host/libs/config:cuttlefish_config", - "//cuttlefish/host/libs/config:vmm_mode", ], ) diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp index c688ad4b358..65f8a9e74db 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.cpp @@ -126,10 +126,6 @@ void CuttlefishConfig::set_crosvm_binary(const std::string& crosvm_binary) { (*dictionary_)[kCrosvmBinary] = crosvm_binary; } -bool CuttlefishConfig::IsCrosvm() const { - return vm_manager() == VmmMode::kCrosvm; -} - static constexpr char kGem5DebugFlags[] = "gem5_debug_flags"; std::string CuttlefishConfig::gem5_debug_flags() const { return (*dictionary_)[kGem5DebugFlags].asString(); @@ -718,4 +714,16 @@ std::vector CuttlefishConfig::environment_dirs() const { return result; } +bool VmManagerIsCrosvm(const CuttlefishConfig& config) { + return VmManagerIsCrosvm(config.vm_manager()); +} + +bool VmManagerIsQemu(const CuttlefishConfig& config) { + return VmManagerIsQemu(config.vm_manager()); +} + +bool VmManagerIsGem5(const CuttlefishConfig& config) { + return VmManagerIsGem5(config.vm_manager()); +} + } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h index cec20d62678..a46b8d0dd95 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config.h @@ -239,8 +239,6 @@ class CuttlefishConfig { std::string vhost_vsock_path() const; void set_vhost_vsock_path(const std::string&); - bool IsCrosvm() const; - class InstanceSpecific; class MutableInstanceSpecific; @@ -967,5 +965,9 @@ class CuttlefishConfig { // device would actually perform a restore instead of their respective actions. bool IsRestoring(const CuttlefishConfig&); +bool VmManagerIsCrosvm(const CuttlefishConfig&); +bool VmManagerIsQemu(const CuttlefishConfig&); +bool VmManagerIsGem5(const CuttlefishConfig&); + } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp index e2bdfe8cfdc..c5da81c48ff 100644 --- a/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp +++ b/base/cvd/cuttlefish/host/libs/config/cuttlefish_config_instance.cpp @@ -45,7 +45,6 @@ #include "cuttlefish/host/libs/config/external_network_mode.h" #include "cuttlefish/host/libs/config/guest_hwui_renderer.h" #include "cuttlefish/host/libs/config/guest_renderer_preload.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" namespace cuttlefish { namespace { @@ -1328,7 +1327,7 @@ bool CuttlefishConfig::InstanceSpecific::console() const { std::string CuttlefishConfig::InstanceSpecific::console_dev() const { auto can_use_virtio_console = !kgdb() && !use_bootloader(); std::string console_dev; - if (can_use_virtio_console || config_->vm_manager() == VmmMode::kGem5) { + if (can_use_virtio_console || VmManagerIsGem5(*config_)) { // If kgdb and the bootloader are disabled, the Android serial console // spawns on a virtio-console port. If the bootloader is enabled, virtio // console can't be used since uboot doesn't support it. @@ -1338,7 +1337,7 @@ std::string CuttlefishConfig::InstanceSpecific::console_dev() const { // architectures emulate ns16550a/uart8250 instead. Arch target = target_arch(); if ((target == Arch::Arm64 || target == Arch::Arm) && - config_->vm_manager() != VmmMode::kCrosvm) { + !VmManagerIsCrosvm(*config_)) { console_dev = "ttyAMA0"; } else { console_dev = "ttyS0"; diff --git a/base/cvd/cuttlefish/host/libs/config/data_image.cpp b/base/cvd/cuttlefish/host/libs/config/data_image.cpp index 5f2a6564b1d..ccdf1d2f444 100644 --- a/base/cvd/cuttlefish/host/libs/config/data_image.cpp +++ b/base/cvd/cuttlefish/host/libs/config/data_image.cpp @@ -39,7 +39,6 @@ #include "cuttlefish/host/libs/config/cuttlefish_config.h" #include "cuttlefish/host/libs/config/esp.h" #include "cuttlefish/host/libs/config/openwrt_args.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" #include "cuttlefish/host/libs/image_aggregator/mbr.h" // https://cs.android.com/android/platform/superproject/main/+/main:device/google/cuttlefish/Android.bp;l=127;drc=6f7d6a4db58efcc2ddd09eda07e009c6329414cd @@ -372,10 +371,8 @@ Result InitializeEspImage( LOG(DEBUG) << "creating esp_image: " << instance.ap_esp_image_path(); CF_EXPECT(BuildAPImage(config, instance)); } - const auto is_not_gem5 = config.vm_manager() != VmmMode::kGem5; - const auto esp_required_for_boot_flow = - EspRequiredForBootFlow(instance.boot_flow()); - if (is_not_gem5 && esp_required_for_boot_flow) { + if (EspRequiredForBootFlow(instance.boot_flow()) && + !VmManagerIsGem5(config)) { LOG(DEBUG) << "creating esp_image: " << instance.esp_image_path(); CF_EXPECT(BuildOSImage(instance)); } diff --git a/base/cvd/cuttlefish/host/libs/config/kernel_args.cpp b/base/cvd/cuttlefish/host/libs/config/kernel_args.cpp index c2b45bfd11b..729462e36f4 100644 --- a/base/cvd/cuttlefish/host/libs/config/kernel_args.cpp +++ b/base/cvd/cuttlefish/host/libs/config/kernel_args.cpp @@ -21,7 +21,6 @@ #include "cuttlefish/common/libs/utils/host_info.h" #include "cuttlefish/host/libs/config/cuttlefish_config.h" -#include "cuttlefish/host/libs/config/vmm_mode.h" namespace cuttlefish { namespace { @@ -37,7 +36,7 @@ std::vector VmManagerKernelCmdline( const CuttlefishConfig& config, const CuttlefishConfig::InstanceSpecific& instance) { std::vector vm_manager_cmdline; - if (config.vm_manager() == VmmMode::kQemu) { + if (VmManagerIsQemu(config)) { Arch target_arch = instance.target_arch(); if (target_arch == Arch::Arm64 || target_arch == Arch::Arm) { if (instance.enable_kernel_log()) { diff --git a/base/cvd/cuttlefish/host/libs/config/vmm_mode.cc b/base/cvd/cuttlefish/host/libs/config/vmm_mode.cc index 8fe73712322..1dbff0e8672 100644 --- a/base/cvd/cuttlefish/host/libs/config/vmm_mode.cc +++ b/base/cvd/cuttlefish/host/libs/config/vmm_mode.cc @@ -58,4 +58,10 @@ Result ParseVmm(std::string_view str) { } } +bool VmManagerIsCrosvm(VmmMode mode) { return mode == VmmMode::kCrosvm; } + +bool VmManagerIsQemu(VmmMode mode) { return mode == VmmMode::kQemu; } + +bool VmManagerIsGem5(VmmMode mode) { return mode == VmmMode::kGem5; } + } // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/libs/config/vmm_mode.h b/base/cvd/cuttlefish/host/libs/config/vmm_mode.h index 34ace725cb1..51620b63905 100644 --- a/base/cvd/cuttlefish/host/libs/config/vmm_mode.h +++ b/base/cvd/cuttlefish/host/libs/config/vmm_mode.h @@ -36,6 +36,10 @@ std::ostream& operator<<(std::ostream&, VmmMode); std::string ToString(VmmMode mode); Result ParseVmm(std::string_view); +bool VmManagerIsCrosvm(VmmMode); +bool VmManagerIsQemu(VmmMode); +bool VmManagerIsGem5(VmmMode); + } // namespace cuttlefish template <> diff --git a/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_display_controller.cpp b/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_display_controller.cpp index a538447695b..403992f8769 100644 --- a/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_display_controller.cpp +++ b/base/cvd/cuttlefish/host/libs/vm_manager/crosvm_display_controller.cpp @@ -32,16 +32,11 @@ namespace cuttlefish { namespace vm_manager { Result GetCrosvmDisplayController() { - auto config = CuttlefishConfig::Get(); - if (!config) { - return CF_ERR("Failed to get Cuttlefish config."); - } - auto vm_manager = config->vm_manager(); - if (vm_manager != VmmMode::kCrosvm) { - LOG(ERROR) << "Expected vm_manager is kCrosvm but " << vm_manager; - return CF_ERR( - "CrosvmDisplayController is only available when VmmMode is kCrosvm"); - } + const CuttlefishConfig* config = CF_EXPECT(CuttlefishConfig::Get()); + + CF_EXPECT(VmManagerIsCrosvm(*config), + "CrosvmDisplayController is only for crosvm"); + return CrosvmDisplayController(config); } diff --git a/base/cvd/cuttlefish/host/libs/vm_manager/vm_manager.cpp b/base/cvd/cuttlefish/host/libs/vm_manager/vm_manager.cpp index fa613832cc7..8de3d05206a 100644 --- a/base/cvd/cuttlefish/host/libs/vm_manager/vm_manager.cpp +++ b/base/cvd/cuttlefish/host/libs/vm_manager/vm_manager.cpp @@ -37,20 +37,23 @@ namespace cuttlefish { namespace vm_manager { -std::unique_ptr GetVmManager(VmmMode vmm_mode, Arch arch) { - std::unique_ptr vmm; - if (vmm_mode == VmmMode::kQemu) { - vmm.reset(new QemuManager(arch)); - } else if (vmm_mode == VmmMode::kGem5) { - vmm.reset(new Gem5Manager(arch)); - } else if (vmm_mode == VmmMode::kCrosvm) { - vmm.reset(new CrosvmManager()); - } - if (!vmm) { - LOG(ERROR) << "Invalid VM manager: " << vmm_mode; - return {}; +static std::unique_ptr Allocate(VmmMode mode, Arch arch) { + switch (mode) { + case VmmMode::kCrosvm: + return std::make_unique(); + case VmmMode::kQemu: + return std::make_unique(arch); + case VmmMode::kGem5: + return std::make_unique(arch); + case VmmMode::kUnknown: + LOG(ERROR) << "Invalid VM manager: " << mode; + return {}; } - if (!vmm->IsSupported()) { +} + +std::unique_ptr GetVmManager(VmmMode vmm_mode, Arch arch) { + std::unique_ptr vmm = Allocate(vmm_mode, arch); + if (vmm.get() != nullptr && !vmm->IsSupported()) { LOG(ERROR) << "VM manager " << vmm_mode << " is not supported on this machine."; return {};