diff options
author | Elie Kheirallah <khei@google.com> | 2024-04-17 23:56:07 +0000 |
---|---|---|
committer | Elie Kheirallah <khei@google.com> | 2024-04-21 01:45:46 +0000 |
commit | 32e01973ecb13b1e41916fbcdf674ba06faffc88 (patch) | |
tree | 712b37fb8288b602c92e813b09eaf209d034738d | |
parent | 6ec513b15cbd6bf3b9a8e5774903780140b0066d (diff) | |
download | cuttlefish-32e01973ecb13b1e41916fbcdf674ba06faffc88.tar.gz |
add flag to enable usb passthrough
add enable_usb_passthrough with default value FALSE.
Bug: 335492801
Test: cvd start --enable_usb=true
Test: cvd start --enable_usb
Test: cvd start --enable_usb=true --enable_virtiofs=false && try to snapshot the VM.
Change-Id: I50c716c37bc21f661640fcde2ac92c8c87e4abe1
-rw-r--r-- | host/commands/assemble_cvd/flags.cc | 16 | ||||
-rw-r--r-- | host/commands/assemble_cvd/flags_defaults.h | 3 | ||||
-rw-r--r-- | host/commands/start/main.cc | 1 | ||||
-rw-r--r-- | host/libs/config/cuttlefish_config.h | 2 | ||||
-rw-r--r-- | host/libs/config/cuttlefish_config_instance.cpp | 8 | ||||
-rw-r--r-- | host/libs/vm_manager/crosvm_manager.cpp | 6 |
6 files changed, 33 insertions, 3 deletions
diff --git a/host/commands/assemble_cvd/flags.cc b/host/commands/assemble_cvd/flags.cc index c1e8b8767..9efeb43ee 100644 --- a/host/commands/assemble_cvd/flags.cc +++ b/host/commands/assemble_cvd/flags.cc @@ -435,6 +435,9 @@ DEFINE_vec(mte, fmt::format("{}", CF_DEFAULTS_MTE), "Enable MTE"); DEFINE_vec(enable_audio, fmt::format("{}", CF_DEFAULTS_ENABLE_AUDIO), "Whether to play or capture audio"); +DEFINE_vec(enable_usb, fmt::format("{}", CF_DEFAULTS_ENABLE_USB), + "Whether to allow USB passthrough on the device"); + DEFINE_vec(camera_server_port, std::to_string(CF_DEFAULTS_CAMERA_SERVER_PORT), "camera vsock port"); @@ -885,6 +888,14 @@ Result<void> CheckSnapshotCompatible( "--enable_virtiofs=false"); /* + * TODO(khei@): delete this block once usb is supported + */ + CF_EXPECTF(gflags::GetCommandLineFlagInfoOrDie("enable_usb").current_value == + "false", + "--enable_usb should be false for snapshot, consider \"{}\"", + "--enable_usb=false"); + + /* * TODO(kwstephenkim@): delete this block once 3D gpu mode snapshots are * supported */ @@ -1076,6 +1087,7 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration( modem_simulator_sim_type)); std::vector<bool> console_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(console)); std::vector<bool> enable_audio_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(enable_audio)); + std::vector<bool> enable_usb_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE(enable_usb)); std::vector<bool> start_gnss_proxy_vec = CF_EXPECT(GET_FLAG_BOOL_VALUE( start_gnss_proxy)); std::vector<bool> enable_bootanimation_vec = @@ -1301,6 +1313,7 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration( guest_configs[instance_index].hctr2_supported ? "hctr2" : "cts"); instance.set_use_allocd(use_allocd_vec[instance_index]); instance.set_enable_audio(enable_audio_vec[instance_index]); + instance.set_enable_usb(enable_usb_vec[instance_index]); instance.set_enable_gnss_grpc_proxy(start_gnss_proxy_vec[instance_index]); instance.set_enable_bootanimation(enable_bootanimation_vec[instance_index]); @@ -1775,7 +1788,8 @@ Result<CuttlefishConfig> InitializeCuttlefishConfiguration( .ForEnvironment(environment_name); CF_EXPECT(CheckSnapshotCompatible( FLAGS_snapshot_compatible && - (tmp_config_obj.vm_manager() == CrosvmManager::name()), + (tmp_config_obj.vm_manager() == CrosvmManager::name()) && + instance_nums.size() == 1, calculated_gpu_mode_vec), "The set of flags is incompatible with snapshot"); diff --git a/host/commands/assemble_cvd/flags_defaults.h b/host/commands/assemble_cvd/flags_defaults.h index 1fd1b168a..289b1e8d9 100644 --- a/host/commands/assemble_cvd/flags_defaults.h +++ b/host/commands/assemble_cvd/flags_defaults.h @@ -196,6 +196,9 @@ // Audio default parameters #define CF_DEFAULTS_ENABLE_AUDIO true +// USB Passhtrough default parameters +#define CF_DEFAULTS_ENABLE_USB false + // Streaming default parameters #define CF_DEFAULTS_START_WEBRTC false #define CF_DEFAULTS_START_WEBRTC_SIG_SERVER true diff --git a/host/commands/start/main.cc b/host/commands/start/main.cc index 1f5ca8d07..e0c035f9c 100644 --- a/host/commands/start/main.cc +++ b/host/commands/start/main.cc @@ -250,6 +250,7 @@ std::unordered_set<std::string> kBoolFlags = { "console", "enable_sandbox", "enable_virtiofs", + "enable_usb", "restart_subprocesses", "enable_gpu_udmabuf", "enable_gpu_vhost_user", diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h index e4a924806..e24939e15 100644 --- a/host/libs/config/cuttlefish_config.h +++ b/host/libs/config/cuttlefish_config.h @@ -559,6 +559,7 @@ class CuttlefishConfig { bool enable_audio() const; bool enable_gnss_grpc_proxy() const; bool enable_bootanimation() const; + bool enable_usb() const; std::vector<std::string> extra_bootconfig_args() const; bool record_screen() const; std::string gem5_debug_file() const; @@ -761,6 +762,7 @@ class CuttlefishConfig { void set_pause_in_bootloader(bool pause_in_bootloader); void set_run_as_daemon(bool run_as_daemon); void set_enable_audio(bool enable); + void set_enable_usb(bool enable); void set_enable_gnss_grpc_proxy(const bool enable_gnss_grpc_proxy); void set_enable_bootanimation(const bool enable_bootanimation); void set_extra_bootconfig_args(const std::string& extra_bootconfig_args); diff --git a/host/libs/config/cuttlefish_config_instance.cpp b/host/libs/config/cuttlefish_config_instance.cpp index 335c0621a..927ba9082 100644 --- a/host/libs/config/cuttlefish_config_instance.cpp +++ b/host/libs/config/cuttlefish_config_instance.cpp @@ -816,6 +816,14 @@ void CuttlefishConfig::MutableInstanceSpecific::set_enable_bootanimation( (*Dictionary())[kEnableBootAnimation] = enable_bootanimation; } +static constexpr char kEnableUsb[] = "enable_usb"; +void CuttlefishConfig::MutableInstanceSpecific::set_enable_usb(bool enable) { + (*Dictionary())[kEnableUsb] = enable; +} +bool CuttlefishConfig::InstanceSpecific::enable_usb() const { + return (*Dictionary())[kEnableUsb].asBool(); +} + static constexpr char kExtraBootconfigArgsInstanced[] = "extra_bootconfig_args"; std::vector<std::string> CuttlefishConfig::InstanceSpecific::extra_bootconfig_args() const { diff --git a/host/libs/vm_manager/crosvm_manager.cpp b/host/libs/vm_manager/crosvm_manager.cpp index 162219baa..c52b649b2 100644 --- a/host/libs/vm_manager/crosvm_manager.cpp +++ b/host/libs/vm_manager/crosvm_manager.cpp @@ -1,4 +1,4 @@ -/* +/*crosvm * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -456,7 +456,9 @@ Result<std::vector<MonitorCommand>> CrosvmManager::StartCommands( // Disable USB passthrough. It isn't needed for any key use cases and it is // not compatible with crosvm suspend-resume support yet (b/266622743). // TODO: Allow it to be turned back on using a flag. - crosvm_cmd.Cmd().AddParameter("--no-usb"); + if (!instance.enable_usb()) { + crosvm_cmd.Cmd().AddParameter("--no-usb"); + } crosvm_cmd.Cmd().AddParameter("--core-scheduling=false"); |