Sets the hypervisor uri in launch_avd
In stable OS versions libvirt connects to qemu:///system by default,
but in Debian testing the default is qemy:///session. This change
allows the selection of the uri in the cmd line and defaults to system
if it's not provided.
Test: run locally
Change-Id: I60d598439d5d8d0d64f3dbaa96bde773b61e5a95
diff --git a/host/commands/launch/main.cc b/host/commands/launch/main.cc
index dbcce2b..6eeb5f8 100644
--- a/host/commands/launch/main.cc
+++ b/host/commands/launch/main.cc
@@ -51,6 +51,8 @@
}
} // namespace
+#define VIRSH_OPTIONS_PLACEHOLDER "<virsh_options>"
+
using vsoc::GetPerInstanceDefault;
using vsoc::GetDefaultPerInstancePath;
@@ -74,8 +76,11 @@
DEFINE_string(kernel, "", "Location of cuttlefish kernel file.");
DEFINE_string(kernel_command_line, "",
"Location of a text file with the kernel command line.");
-DEFINE_string(launch_command, "virsh create /dev/fd/0",
- "Command to start an instance");
+DEFINE_string(hypervisor_uri, "qemu:///system", "Hypervisor cannonical uri.");
+DEFINE_string(launch_command,
+ "virsh " VIRSH_OPTIONS_PLACEHOLDER " create /dev/fd/0",
+ "Command to start an instance. If <virsh_options> is present it "
+ "will be replaced by options to the virsh command");
DEFINE_string(layout,
StringFromEnv("ANDROID_HOST_OUT", StringFromEnv("HOME", ".")) +
"/config/vsoc_mem.json",
@@ -112,6 +117,10 @@
const std::string kDataPolicyCreateIfMissing = "create_if_missing";
const std::string kDataPolicyAlwaysCreate = "always_create";
+std::string GetVirshOptions() {
+ return std::string("-c ").append(FLAGS_hypervisor_uri);
+}
+
Json::Value LoadLayoutFile(const std::string& file) {
char real_file_path[PATH_MAX];
if (realpath(file.c_str(), real_file_path) == nullptr) {
@@ -424,9 +433,16 @@
// Initialize the regions that require it before the VM starts.
PreLaunchInitializers::Initialize();
- FILE* launch = popen(FLAGS_launch_command.c_str(), "w");
+ std::string launch_command = FLAGS_launch_command;
+ auto pos = launch_command.find(VIRSH_OPTIONS_PLACEHOLDER);
+ if (pos != std::string::npos) {
+ launch_command.replace(
+ pos, sizeof(VIRSH_OPTIONS_PLACEHOLDER) - 1, GetVirshOptions());
+ }
+
+ FILE* launch = popen(launch_command.c_str(), "w");
if (!launch) {
- LOG(FATAL) << "Unable to execute " << FLAGS_launch_command;
+ LOG(FATAL) << "Unable to execute " << launch_command;
}
int rval = fputs(xml.c_str(), launch);
if (rval == EOF) {