No longer include libvirt as a supported VMM
Bug: 123551778
Test: build & run locally
Change-Id: Id7c9c48fc251cc61ec3b1fedaacc8d16685ab357
diff --git a/host/commands/launch/main.cc b/host/commands/launch/main.cc
index ee2c051..95cc7b2 100644
--- a/host/commands/launch/main.cc
+++ b/host/commands/launch/main.cc
@@ -57,7 +57,6 @@
#include "host/libs/config/cuttlefish_config.h"
#include "host/commands/kernel_log_monitor/kernel_log_server.h"
#include "host/libs/vm_manager/vm_manager.h"
-#include "host/libs/vm_manager/libvirt_manager.h"
#include "host/libs/vm_manager/qemu_manager.h"
using vsoc::GetPerInstanceDefault;
@@ -85,11 +84,6 @@
DEFINE_int32(dpi, 160, "Pixels per inch for the screen");
DEFINE_int32(refresh_rate_hz, 60, "Screen refresh rate in Hertz");
DEFINE_int32(num_screen_buffers, 3, "The number of screen buffers");
-
-DEFINE_bool(disable_app_armor_security, false,
- "Disable AppArmor security in libvirt. For debug only.");
-DEFINE_bool(disable_dac_security, false,
- "Disable DAC security in libvirt. For debug only.");
DEFINE_string(kernel_path, "",
"Path to the kernel. Overrides the one from the boot image");
DEFINE_string(extra_kernel_cmdline, "",
@@ -123,10 +117,8 @@
DEFINE_string(instance_dir, "", // default handled on ParseCommandLine
"A directory to put all instance specific files");
DEFINE_string(
- vm_manager,
- vsoc::HostSupportsQemuCli() ? vm_manager::QemuManager::name()
- : vm_manager::LibvirtManager::name(),
- "What virtual machine manager to use, one of libvirt or qemu_cli");
+ vm_manager, vm_manager::QemuManager::name(),
+ "What virtual machine manager to use, one of {qemu_cli}");
DEFINE_string(system_image_dir, vsoc::DefaultGuestImagePath(""),
"Location of the system partition images.");
DEFINE_string(vendor_image, "", "Location of the vendor partition image.");
@@ -205,8 +197,6 @@
DEFINE_string(qemu_binary,
"/usr/bin/qemu-system-x86_64",
"The qemu binary to use");
-DEFINE_string(hypervisor_uri, "qemu:///system", "Hypervisor cannonical uri.");
-DEFINE_bool(log_xml, false, "Log the XML machine configuration");
DEFINE_bool(restart_subprocesses, true, "Restart any crashed host process");
DEFINE_bool(run_e2e_test, true, "Run e2e test after device launches");
DEFINE_string(e2e_test_binary,
@@ -655,14 +645,9 @@
tmp_config_obj.set_entropy_source("/dev/urandom");
tmp_config_obj.set_uuid(FLAGS_uuid);
- tmp_config_obj.set_disable_dac_security(FLAGS_disable_dac_security);
- tmp_config_obj.set_disable_app_armor_security(FLAGS_disable_app_armor_security);
-
tmp_config_obj.set_qemu_binary(FLAGS_qemu_binary);
tmp_config_obj.set_ivserver_binary(FLAGS_ivserver_binary);
tmp_config_obj.set_kernel_log_monitor_binary(FLAGS_kernel_log_monitor_binary);
- tmp_config_obj.set_hypervisor_uri(FLAGS_hypervisor_uri);
- tmp_config_obj.set_log_xml(FLAGS_log_xml);
tmp_config_obj.set_enable_vnc_server(FLAGS_start_vnc_server);
tmp_config_obj.set_vnc_server_binary(FLAGS_vnc_server_binary);
@@ -719,31 +704,6 @@
google::FlagSettingMode::SET_FLAGS_DEFAULT);
}
-void SetDefaultFlagsForLibvirt() {
- auto default_mobile_interface = GetPerInstanceDefault("cvd-mobile-");
- SetCommandLineOptionWithMode("mobile_interface",
- default_mobile_interface.c_str(),
- google::FlagSettingMode::SET_FLAGS_DEFAULT);
- auto default_mobile_tap_name = GetPerInstanceDefault("amobile");
- SetCommandLineOptionWithMode("mobile_tap_name",
- default_mobile_tap_name.c_str(),
- google::FlagSettingMode::SET_FLAGS_DEFAULT);
- auto default_wifi_interface = GetPerInstanceDefault("cvd-wifi-");
- SetCommandLineOptionWithMode("wifi_interface",
- default_wifi_interface.c_str(),
- google::FlagSettingMode::SET_FLAGS_DEFAULT);
- auto default_wifi_tap_name = GetPerInstanceDefault("awifi");
- SetCommandLineOptionWithMode("wifi_tap_name",
- default_wifi_tap_name.c_str(),
- google::FlagSettingMode::SET_FLAGS_DEFAULT);
- auto default_instance_dir =
- "/var/run/libvirt-" +
- vsoc::GetPerInstanceDefault(vsoc::kDefaultUuidPrefix);
- SetCommandLineOptionWithMode("instance_dir",
- default_instance_dir.c_str(),
- google::FlagSettingMode::SET_FLAGS_DEFAULT);
-}
-
bool ParseCommandLineFlags(int* argc, char*** argv) {
// The config_file is created by the launcher, so the launcher is the only
// host process that doesn't use the flag.
@@ -752,9 +712,7 @@
gflags::SET_FLAGS_DEFAULT);
google::ParseCommandLineNonHelpFlags(argc, argv, true);
bool invalid_manager = false;
- if (FLAGS_vm_manager == vm_manager::LibvirtManager::name()) {
- SetDefaultFlagsForLibvirt();
- } else if (FLAGS_vm_manager == vm_manager::QemuManager::name()) {
+ if (FLAGS_vm_manager == vm_manager::QemuManager::name()) {
SetDefaultFlagsForQemu();
} else {
std::cerr << "Unknown Virtual Machine Manager: " << FLAGS_vm_manager
@@ -791,11 +749,6 @@
return false;
}
std::string clean_command = "rm -rf " + prior_files;
- if (FLAGS_vm_manager == vm_manager::LibvirtManager::name()) {
- // Libvirt runs as libvirt-qemu so we need sudo to delete the files it
- // creates
- clean_command = "sudo " + clean_command;
- }
rval = std::system(clean_command.c_str());
if (WEXITSTATUS(rval) != 0) {
LOG(ERROR) << "Remove of files failed";
@@ -966,13 +919,14 @@
LOG(ERROR) << "Failed to clean prior files";
return LauncherExitCodes::kPrioFilesCleanupError;
}
- // For now it has to be the vm manager who ensures the instance dir exists
- // because in the case of the libvirt manager root privileges are required to
- // create and set acls on the directory
- if (!vm_manager::VmManager::EnsureInstanceDirExists(FLAGS_vm_manager,
- FLAGS_instance_dir)) {
- LOG(ERROR) << "Failed to create instance directory";
- return LauncherExitCodes::kInstanceDirCreationError;
+ // Create instance directory if it doesn't exist.
+ if (!cvd::DirectoryExists(FLAGS_instance_dir.c_str())) {
+ LOG(INFO) << "Setting up " << FLAGS_instance_dir;
+ if (mkdir(FLAGS_instance_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
+ LOG(ERROR) << "Failed to create instance directory: "
+ << FLAGS_instance_dir << ". Error: " << errno;
+ return LauncherExitCodes::kInstanceDirCreationError;
+ }
}
auto boot_img_unpacker = cvd::BootImageUnpacker::FromImage(FLAGS_boot_image);
@@ -1003,12 +957,6 @@
return LauncherExitCodes::kInvalidHostConfiguration;
}
- if (!vm_manager->EnsureInstanceDirExists(FLAGS_vm_manager,
- FLAGS_instance_dir)) {
- LOG(ERROR) << "Failed to create instance directory: " << FLAGS_instance_dir;
- return LauncherExitCodes::kInstanceDirCreationError;
- }
-
if (!UnpackBootImage(*boot_img_unpacker, *config)) {
LOG(ERROR) << "Failed to unpack boot image";
return LauncherExitCodes::kBootImageUnpackError;
diff --git a/host/commands/stop_cvd/main.cc b/host/commands/stop_cvd/main.cc
index e537314..b631d75 100644
--- a/host/commands/stop_cvd/main.cc
+++ b/host/commands/stop_cvd/main.cc
@@ -44,7 +44,6 @@
#include "host/commands/launch/launcher_defs.h"
#include "host/libs/config/cuttlefish_config.h"
#include "host/libs/vm_manager/vm_manager.h"
-#include "host/libs/vm_manager/libvirt_manager.h"
DEFINE_int32(wait_for_launcher, 5,
"How many seconds to wait for the launcher to respond to the stop "
@@ -54,12 +53,9 @@
// Gets a set of the possible process groups of a previous launch
std::set<pid_t> GetCandidateProcessGroups() {
std::string cmd = "fuser";
- // Add the instance directory for qemu
+ // Add the instance directory
cmd += " " + cvd::StringFromEnv("HOME", ".") + "/cuttlefish_runtime/*";
- // Add the instance directory for libvirt
- auto libvirt_instance_dir =
- std::string("/var/run/libvirt-") + vsoc::kDefaultUuidPrefix;
- cmd += " " + vsoc::GetPerInstanceDefault(libvirt_instance_dir.c_str()) + "/*";
+ // Add the shared memory file
cmd += " " + vsoc::GetPerInstanceDefault("/dev/shm/cvd-");
std::shared_ptr<FILE> cmd_out(popen(cmd.c_str(), "r"), pclose);
if (!cmd_out) {
@@ -84,22 +80,6 @@
int FallBackStop() {
auto exit_code = 1; // Having to fallback is an error
- if (vm_manager::VmManager::IsVmManagerSupported(
- vm_manager::LibvirtManager::name())) {
- // Libvirt doesn't run as the same user as stop_cvd, so we must stop it
- // through the manager. Qemu on the other hand would get killed by the
- // commands below.
- vsoc::CuttlefishConfig config;
- config.set_instance_dir(std::string("/var/run/libvirt-") +
- vsoc::kDefaultUuidPrefix);
- auto vm_manager =
- vm_manager::VmManager::Get(vm_manager::LibvirtManager::name(), &config);
- if (!vm_manager->Stop()) {
- LOG(WARNING) << "Failed to stop the libvirt domain: Is it still running? "
- "Is it using qemu_cli?";
- exit_code |= 2;
- }
- }
auto process_groups = GetCandidateProcessGroups();
for (auto pgid: process_groups) {
diff --git a/host/libs/config/cuttlefish_config.cpp b/host/libs/config/cuttlefish_config.cpp
index 75f9788..ec6e588 100644
--- a/host/libs/config/cuttlefish_config.cpp
+++ b/host/libs/config/cuttlefish_config.cpp
@@ -112,16 +112,12 @@
const char* kVsockGuestCid = "vsock_guest_cid";
const char* kUuid = "uuid";
-const char* kDisableDacSecurity = "disable_dac_security";
-const char* kDisableAppArmorSecurity = "disable_app_armor_security";
const char* kCuttlefishEnvPath = "cuttlefish_env_path";
const char* kAdbMode = "adb_mode";
const char* kAdbIPAndPort = "adb_ip_and_port";
const char* kSetupWizardMode = "setupwizard_mode";
-const char* kLogXml = "log_xml";
-const char* kHypervisorUri = "hypervisor_uri";
const char* kQemuBinary = "qemu_binary";
const char* kIvServerBinary = "ivserver_binary";
const char* kKernelLogMonitorBinary = "kernel_log_monitor_binary";
@@ -471,13 +467,6 @@
(*dictionary_)[kUuid] = uuid;
}
-bool CuttlefishConfig::disable_dac_security() const {
- return (*dictionary_)[kDisableDacSecurity].asBool();
-}
-void CuttlefishConfig::set_disable_dac_security(bool disable_dac_security) {
- (*dictionary_)[kDisableDacSecurity] = disable_dac_security;
-}
-
void CuttlefishConfig::set_cuttlefish_env_path(const std::string& path) {
SetPath(kCuttlefishEnvPath, path);
}
@@ -485,14 +474,6 @@
return (*dictionary_)[kCuttlefishEnvPath].asString();
}
-bool CuttlefishConfig::disable_app_armor_security() const {
- return (*dictionary_)[kDisableAppArmorSecurity].asBool();
-}
-void CuttlefishConfig::set_disable_app_armor_security(
- bool disable_app_armor_security) {
- (*dictionary_)[kDisableAppArmorSecurity] = disable_app_armor_security;
-}
-
std::string CuttlefishConfig::adb_mode() const {
return (*dictionary_)[kAdbMode].asString();
}
@@ -535,22 +516,6 @@
(*dictionary_)[kSetupWizardMode] = mode;
}
-bool CuttlefishConfig::log_xml() const {
- return (*dictionary_)[kLogXml].asBool();
-}
-
-void CuttlefishConfig::set_log_xml(bool log_xml) {
- (*dictionary_)[kLogXml] = log_xml;
-}
-
-std::string CuttlefishConfig::hypervisor_uri() const {
- return (*dictionary_)[kHypervisorUri].asString();
-}
-
-void CuttlefishConfig::set_hypervisor_uri(const std::string& hypervisor_uri) {
- (*dictionary_)[kHypervisorUri] = hypervisor_uri;
-}
-
std::string CuttlefishConfig::qemu_binary() const {
return (*dictionary_)[kQemuBinary].asString();
}
@@ -708,12 +673,7 @@
std::string GetDefaultPerInstanceDir() {
std::ostringstream stream;
- if (HostSupportsQemuCli()) {
- stream << std::getenv("HOME") << "/cuttlefish_runtime";
- } else {
- stream << "/var/run/libvirt-" << kDefaultUuidPrefix << std::setfill('0')
- << std::setw(2) << GetInstance();
- }
+ stream << std::getenv("HOME") << "/cuttlefish_runtime";
return stream.str();
}
diff --git a/host/libs/config/cuttlefish_config.h b/host/libs/config/cuttlefish_config.h
index 1fefea8..9a9fa53 100644
--- a/host/libs/config/cuttlefish_config.h
+++ b/host/libs/config/cuttlefish_config.h
@@ -182,12 +182,6 @@
std::string uuid() const;
void set_uuid(const std::string& uuid);
- bool disable_dac_security() const;
- void set_disable_dac_security(bool disable_dac_security);
-
- bool disable_app_armor_security() const;
- void set_disable_app_armor_security(bool disable_app_armor_security);
-
void set_cuttlefish_env_path(const std::string& path);
std::string cuttlefish_env_path() const;
@@ -205,12 +199,6 @@
void set_setupwizard_mode(const std::string& title);
std::string setupwizard_mode() const;
- void set_log_xml(bool log_xml);
- bool log_xml() const;
-
- void set_hypervisor_uri(const std::string& hypervisor_uri);
- std::string hypervisor_uri() const;
-
void set_qemu_binary(const std::string& qemu_binary);
std::string qemu_binary() const;
@@ -273,8 +261,7 @@
std::string DefaultHostArtifactsPath(const std::string& file);
std::string DefaultGuestImagePath(const std::string& file);
-// Whether the installed host packages support calling qemu directly instead of
-// through libvirt
+// Whether the host supports qemu
bool HostSupportsQemuCli();
bool HostSupportsVsock();
} // namespace vsoc
diff --git a/host/libs/vm_manager/Android.bp b/host/libs/vm_manager/Android.bp
index 0d077ea..8a1f1c8 100644
--- a/host/libs/vm_manager/Android.bp
+++ b/host/libs/vm_manager/Android.bp
@@ -16,7 +16,6 @@
cc_library_host_static {
name: "libcuttlefish_vm_manager",
srcs: [
- "libvirt_manager.cpp",
"qemu_manager.cpp",
"vm_manager.cpp",
],
diff --git a/host/libs/vm_manager/libvirt_manager.cpp b/host/libs/vm_manager/libvirt_manager.cpp
deleted file mode 100644
index 24ff33b..0000000
--- a/host/libs/vm_manager/libvirt_manager.cpp
+++ /dev/null
@@ -1,397 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "host/libs/vm_manager/libvirt_manager.h"
-
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <cstdlib>
-#include <iomanip>
-#include <sstream>
-#include <string>
-
-#include <glog/logging.h>
-#include <libxml/tree.h>
-
-#include "common/libs/utils/files.h"
-#include "common/libs/utils/subprocess.h"
-#include "common/libs/utils/users.h"
-#include "host/libs/config/cuttlefish_config.h"
-
-// A lot of useful information about the document created here can be found on
-// these websites:
-// - https://libvirt.org/formatdomain.html
-// - https://wiki.libvirt.org/page/Virtio
-namespace vm_manager {
-
-namespace {
-// This trivial no-op helper function serves purpose of making libxml2 happy.
-// Apparently, *most* (not all!) string literals in libxml2 have to be of
-// unsigned char* (aka xmlChar*) type.
-inline const xmlChar* xc(const char* str) {
- return reinterpret_cast<const xmlChar*>(str);
-}
-
-// Helper functions that allow us to combine any set of arguments to a single
-// string.
-// Example:
-// concat("Answer", ' ', "is: ", 42);
-// will produce string "Answer is: 42"
-template <typename Arg>
-inline std::ostream& concat_helper(std::ostream& o, Arg a) {
- o << a;
- return o;
-}
-
-template <typename Arg, typename... Args>
-inline std::ostream& concat_helper(std::ostream& o, Arg a, Args... args) {
- o << a;
- concat_helper(o, args...);
- return o;
-}
-
-template <typename... Args>
-inline std::string concat(Args... args) {
- std::ostringstream str;
- concat_helper(str, args...);
- return str.str();
-}
-
-enum class DeviceSourceType {
- kFile,
- kUnixSocketClient,
- kUnixSocketServer,
-};
-
-// Basic VM configuration.
-// This section configures name, basic resource allocation and response to
-// events.
-void ConfigureVM(xmlNode* root, const std::string& instance_name, int cpus,
- int mem_mb, const std::string& uuid) {
- xmlNewChild(root, nullptr, xc("name"), xc(instance_name.c_str()));
-
- // TODO(ender): should this all be 'restart'?
- xmlNewChild(root, nullptr, xc("on_poweroff"), xc("destroy"));
- xmlNewChild(root, nullptr, xc("on_reboot"), xc("restart"));
- xmlNewChild(root, nullptr, xc("on_crash"), xc("restart"));
- xmlNewChild(root, nullptr, xc("vcpu"), xc(concat(cpus).c_str()));
- xmlNewChild(root, nullptr, xc("memory"), xc(concat(mem_mb << 10).c_str()));
- if (uuid.size()) {
- xmlNewChild(root, nullptr, xc("uuid"), xc(uuid.c_str()));
- }
-}
-
-// Configure VM features.
-// This section takes care of the <features> section of the target XML file.
-void ConfigureVMFeatures(xmlNode* root,
- const std::initializer_list<std::string>& features) {
- auto ch = xmlNewChild(root, nullptr, xc("features"), nullptr);
- for (const auto& str : features) {
- xmlNewChild(ch, nullptr, xc(str.c_str()), nullptr);
- }
-}
-
-// Configure VM OS.
-// This section configures target os (<os>).
-void ConfigureOperatingSystem(xmlNode* root, const std::string& kernel,
- const std::string& initrd,
- const std::string& args, const std::string& dtb) {
- auto os = xmlNewChild(root, nullptr, xc("os"), nullptr);
-
- auto type = xmlNewChild(os, nullptr, xc("type"), xc("hvm"));
- xmlNewProp(type, xc("arch"), xc("x86_64"));
- xmlNewProp(type, xc("machine"), xc("pc"));
-
- xmlNewChild(os, nullptr, xc("kernel"), xc(kernel.c_str()));
- if (!initrd.empty()) {
- xmlNewChild(os, nullptr, xc("initrd"), xc(initrd.c_str()));
- }
- xmlNewChild(os, nullptr, xc("cmdline"), xc(args.c_str()));
- xmlNewChild(os, nullptr, xc("dtb"), xc(dtb.c_str()));
-}
-
-// Configure QEmu specific arguments.
-// This section adds the <qemu:commandline> node.
-xmlNodePtr ConfigureQEmuSpecificOptions(
- xmlNode* root, std::initializer_list<std::string> qemu_args,
- xmlNode* existing_options = nullptr) {
- xmlNs* qemu_ns{xmlNewNs(
- root, xc("http://libvirt.org/schemas/domain/qemu/1.0"), xc("qemu"))};
-
- xmlNode* cmd;
- if (existing_options) {
- cmd = existing_options;
- } else {
- cmd = xmlNewChild(root, qemu_ns, xc("commandline"), nullptr);
- }
-
- for (const auto& str : qemu_args) {
- auto arg = xmlNewChild(cmd, qemu_ns, xc("arg"), nullptr);
- xmlNewProp(arg, xc("value"), xc(str.c_str()));
- }
- return cmd;
-}
-
-void ConfigureDeviceSource(xmlNode* device, DeviceSourceType type,
- const std::string& path) {
- auto source = xmlNewChild(device, nullptr, xc("source"), nullptr);
- xmlNewProp(source, xc("path"), xc(path.c_str()));
-
- switch (type) {
- case DeviceSourceType::kFile:
- xmlNewProp(device, xc("type"), xc("file"));
- break;
-
- case DeviceSourceType::kUnixSocketClient:
- xmlNewProp(device, xc("type"), xc("unix"));
- xmlNewProp(source, xc("mode"), xc("connect"));
- break;
-
- case DeviceSourceType::kUnixSocketServer:
- xmlNewProp(device, xc("type"), xc("unix"));
- xmlNewProp(source, xc("mode"), xc("bind"));
- break;
- }
-}
-
-// Configure serial port.
-// This section adds <serial> elements to <device> node.
-void ConfigureSerialPort(xmlNode* devices, int port, DeviceSourceType type,
- const std::string& path) {
- auto tty = xmlNewChild(devices, nullptr, xc("serial"), nullptr);
- ConfigureDeviceSource(tty, type, path);
-
- auto tgt = xmlNewChild(tty, nullptr, xc("target"), nullptr);
- xmlNewProp(tgt, xc("port"), xc(concat(port).c_str()));
-}
-
-// Configure disk partition.
-// This section adds <disk> elements to <devices> node.
-void ConfigureDisk(xmlNode* devices, const std::string& name,
- const std::string& path) {
- auto ch = xmlNewChild(devices, nullptr, xc("disk"), nullptr);
- xmlNewProp(ch, xc("type"), xc("file"));
-
- auto dr = xmlNewChild(ch, nullptr, xc("driver"), nullptr);
- xmlNewProp(dr, xc("name"), xc("qemu"));
- xmlNewProp(dr, xc("type"), xc("raw"));
- xmlNewProp(dr, xc("io"), xc("threads"));
-
- auto tg = xmlNewChild(ch, nullptr, xc("target"), nullptr);
- xmlNewProp(tg, xc("dev"), xc(name.c_str()));
- xmlNewProp(tg, xc("bus"), xc("virtio"));
-
- auto sr = xmlNewChild(ch, nullptr, xc("source"), nullptr);
- xmlNewProp(sr, xc("file"), xc(path.c_str()));
-}
-
-// Configure virtio channel.
-// This section adds <channel> elements to <devices> node.
-void ConfigureVirtioChannel(xmlNode* devices, int port, const std::string& name,
- DeviceSourceType type, const std::string& path) {
- if (path.empty()) {
- return;
- }
- auto vch = xmlNewChild(devices, nullptr, xc("channel"), nullptr);
- ConfigureDeviceSource(vch, type, path);
-
- auto tgt = xmlNewChild(vch, nullptr, xc("target"), nullptr);
- xmlNewProp(tgt, xc("type"), xc("virtio"));
- xmlNewProp(tgt, xc("name"), xc(name.c_str()));
-
- auto adr = xmlNewChild(vch, nullptr, xc("address"), nullptr);
- xmlNewProp(adr, xc("type"), xc("virtio-serial"));
- xmlNewProp(adr, xc("controller"), xc("0"));
- xmlNewProp(adr, xc("bus"), xc("0"));
- xmlNewProp(adr, xc("port"), xc(concat(port).c_str()));
-}
-
-// Configure network interface.
-// This section adds <interface> elements to <devices> node.
-void ConfigureNIC(xmlNode* devices, const std::string& name,
- const std::string& bridge, int guest_id, int nic_id) {
- auto nic = xmlNewChild(devices, nullptr, xc("interface"), nullptr);
- xmlNewProp(nic, xc("type"), xc("bridge"));
-
- auto brg = xmlNewChild(nic, nullptr, xc("source"), nullptr);
- xmlNewProp(brg, xc("bridge"), xc(bridge.c_str()));
-
- auto mac = xmlNewChild(nic, nullptr, xc("mac"), nullptr);
- xmlNewProp(mac, xc("address"),
- xc(concat("00:43:56:44:", std::setfill('0'), std::hex,
- std::setw(2), guest_id, ':', std::setw(2), nic_id)
- .c_str()));
-
- auto mdl = xmlNewChild(nic, nullptr, xc("model"), nullptr);
- xmlNewProp(mdl, xc("type"), xc("virtio"));
-
- auto tgt = xmlNewChild(nic, nullptr, xc("target"), nullptr);
- xmlNewProp(tgt, xc("dev"), xc(name.c_str()));
-}
-
-// Configure Harwdare Random Number Generator.
-// This section adds <rng> element to <devices> node.
-void ConfigureHWRNG(xmlNode* devices, const std::string& entsrc) {
- auto rng = xmlNewChild(devices, nullptr, xc("rng"), nullptr);
- xmlNewProp(rng, xc("model"), xc("virtio"));
-
- auto rate = xmlNewChild(rng, nullptr, xc("rate"), nullptr);
- xmlNewProp(rate, xc("period"), xc("2000"));
- xmlNewProp(rate, xc("bytes"), xc("1024"));
-
- auto bend = xmlNewChild(rng, nullptr, xc("backend"), xc(entsrc.c_str()));
- xmlNewProp(bend, xc("model"), xc("random"));
-}
-
-static std::string GetLibvirtCommand(const vsoc::CuttlefishConfig* config) {
- std::string cmd = "virsh";
- if (!config->hypervisor_uri().empty()) {
- cmd += " -c " + config->hypervisor_uri();
- }
- return cmd;
-}
-
-std::string BuildXmlConfig(const vsoc::CuttlefishConfig* config) {
- std::string instance_name = config->instance_name();
-
- std::unique_ptr<xmlDoc, void (*)(xmlDocPtr)> xml{xmlNewDoc(xc("1.0")),
- xmlFreeDoc};
- auto root{xmlNewNode(nullptr, xc("domain"))};
- xmlDocSetRootElement(xml.get(), root);
- xmlNewProp(root, xc("type"), xc("kvm"));
-
- ConfigureVM(root, instance_name, config->cpus(), config->memory_mb(),
- config->uuid());
- ConfigureVMFeatures(root, {"acpi", "apic", "hap"});
- ConfigureOperatingSystem(root, config->kernel_image_path(),
- config->ramdisk_image_path(),
- config->kernel_cmdline_as_string(),
- config->dtb_path());
- auto qemu_options = ConfigureQEmuSpecificOptions(
- root, {"-chardev",
- concat("socket,path=", config->ivshmem_qemu_socket_path(),
- ",id=ivsocket"),
- "-device",
- concat("ivshmem-doorbell,chardev=ivsocket,vectors=",
- config->ivshmem_vector_count()),
- "-cpu", "host"});
- if (config->gdb_flag().size()) {
- ConfigureQEmuSpecificOptions(root, {"-gdb", config->gdb_flag().c_str(),
- "-S"},
- qemu_options);
- }
-
- if (config->disable_app_armor_security()) {
- auto seclabel = xmlNewChild(root, nullptr, xc("seclabel"), nullptr);
- xmlNewProp(seclabel, xc("type"), xc("none"));
- xmlNewProp(seclabel, xc("model"), xc("apparmor"));
- }
- if (config->disable_dac_security()) {
- auto seclabel = xmlNewChild(root, nullptr, xc("seclabel"), nullptr);
- xmlNewProp(seclabel, xc("type"), xc("none"));
- xmlNewProp(seclabel, xc("model"), xc("dac"));
- }
-
- auto devices = xmlNewChild(root, nullptr, xc("devices"), nullptr);
-
- ConfigureSerialPort(devices, 0, DeviceSourceType::kUnixSocketClient,
- config->kernel_log_socket_name());
- ConfigureSerialPort(devices, 1, DeviceSourceType::kUnixSocketServer,
- config->console_path());
- ConfigureVirtioChannel(devices, 1, "cf-logcat", DeviceSourceType::kFile,
- config->logcat_path());
- ConfigureVirtioChannel(devices, 2, "cf-gadget-usb-v1",
- DeviceSourceType::kUnixSocketClient,
- config->usb_v1_socket_name());
-
- ConfigureDisk(devices, "vda", config->system_image_path());
- ConfigureDisk(devices, "vdb", config->data_image_path());
- ConfigureDisk(devices, "vdc", config->cache_image_path());
- ConfigureDisk(devices, "vdd", config->vendor_image_path());
-
- ConfigureNIC(devices, config->wifi_tap_name(), config->wifi_bridge_name(),
- vsoc::GetInstance(), 1);
- ConfigureNIC(devices, config->mobile_tap_name(), config->mobile_bridge_name(),
- vsoc::GetInstance(), 2);
- ConfigureHWRNG(devices, config->entropy_source());
-
- xmlChar* tgt;
- int tgt_len;
-
- xmlDocDumpFormatMemoryEnc(xml.get(), &tgt, &tgt_len, "utf-8", true);
- std::string out((const char*)(tgt), tgt_len);
- xmlFree(tgt);
- return out;
-}
-} // namespace
-
-const std::string LibvirtManager::name() { return "libvirt"; }
-
-LibvirtManager::LibvirtManager(const vsoc::CuttlefishConfig* config)
- : VmManager(config) {}
-
-bool LibvirtManager::Start() {
- std::string start_command = GetLibvirtCommand(config_);
- start_command += " create /dev/fd/0";
-
- std::string xml = BuildXmlConfig(config_);
- if (config_->log_xml()) {
- LOG(INFO) << "Using XML:\n" << xml;
- }
-
- FILE* launch = popen(start_command.c_str(), "w");
- if (!launch) {
- LOG(ERROR) << "Unable to execute " << start_command;
- return false;
- }
- int rval = fputs(xml.c_str(), launch);
- if (rval == EOF) {
- LOG(ERROR) << "Launch command exited while accepting XML";
- return false;
- }
- int exit_code = pclose(launch);
- if (exit_code != 0) {
- LOG(ERROR) << "Launch command exited with status " << exit_code;
- return false;
- }
- return true;
-}
-
-bool LibvirtManager::Stop() {
- auto stop_command = GetLibvirtCommand(config_);
- stop_command += " destroy " + config_->instance_name();
- return std::system(stop_command.c_str()) == 0;
-}
-
-bool LibvirtManager::EnsureInstanceDirExists(const std::string& instance_dir) {
- if (!cvd::DirectoryExists(instance_dir)) {
- LOG(INFO) << "Setting up " << instance_dir;
- cvd::execute({"/usr/bin/sudo", "/bin/mkdir", "-m", "0775", instance_dir});
-
- // When created with sudo the owner and group is root.
- std::string user_group = getenv("USER");
- user_group += ":libvirt-qemu";
- cvd::execute({"/usr/bin/sudo", "/bin/chown", user_group, instance_dir});
- }
- return true;
-}
-
-bool LibvirtManager::ValidateHostConfiguration(
- std::vector<std::string>* config_commands) const {
- return VmManager::UserInGroup("libvirt", config_commands);
-}
-} // namespace vm_manager
diff --git a/host/libs/vm_manager/libvirt_manager.h b/host/libs/vm_manager/libvirt_manager.h
deleted file mode 100644
index 6bb99d1..0000000
--- a/host/libs/vm_manager/libvirt_manager.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * Copyright (C) 2017 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#pragma once
-
-#include <string>
-
-#include "host/libs/vm_manager/vm_manager.h"
-
-namespace vm_manager {
-
-class LibvirtManager : public VmManager {
- public:
- static const std::string name();
- static bool EnsureInstanceDirExists(const std::string& instance_dir);
-
- LibvirtManager(const vsoc::CuttlefishConfig* config);
- virtual ~LibvirtManager() = default;
-
- bool Start() override;
- bool Stop() override;
-
- bool ValidateHostConfiguration(
- std::vector<std::string>* config_commands) const override;
-};
-
-} // namespace vm_manager
diff --git a/host/libs/vm_manager/qemu_manager.cpp b/host/libs/vm_manager/qemu_manager.cpp
index a1db7f3..af6be88 100644
--- a/host/libs/vm_manager/qemu_manager.cpp
+++ b/host/libs/vm_manager/qemu_manager.cpp
@@ -144,18 +144,6 @@
return true;
}
-bool QemuManager::EnsureInstanceDirExists(const std::string& instance_dir) {
- if (!cvd::DirectoryExists(instance_dir.c_str())) {
- LOG(INFO) << "Setting up " << instance_dir;
- if (mkdir(instance_dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) < 0) {
- LOG(ERROR) << "Unable to create " << instance_dir << ". Error: " << errno;
- return false;
- }
- }
- return true;
-
-}
-
bool QemuManager::ValidateHostConfiguration(
std::vector<std::string>* config_commands) const {
// the check for cvdnetwork needs to happen even if the user is not in kvm, so
diff --git a/host/libs/vm_manager/qemu_manager.h b/host/libs/vm_manager/qemu_manager.h
index 6ae1926..42038ba 100644
--- a/host/libs/vm_manager/qemu_manager.h
+++ b/host/libs/vm_manager/qemu_manager.h
@@ -26,7 +26,6 @@
class QemuManager : public VmManager {
public:
static const std::string name();
- static bool EnsureInstanceDirExists(const std::string& instance_dir);
QemuManager(const vsoc::CuttlefishConfig* config);
virtual ~QemuManager() = default;
diff --git a/host/libs/vm_manager/vm_manager.cpp b/host/libs/vm_manager/vm_manager.cpp
index 39122f1..8811902 100644
--- a/host/libs/vm_manager/vm_manager.cpp
+++ b/host/libs/vm_manager/vm_manager.cpp
@@ -22,7 +22,6 @@
#include "common/libs/utils/users.h"
#include "host/libs/config/cuttlefish_config.h"
-#include "host/libs/vm_manager/libvirt_manager.h"
#include "host/libs/vm_manager/qemu_manager.h"
namespace vm_manager {
@@ -40,22 +39,11 @@
std::map<std::string, VmManager::VmManagerHelper>
VmManager::vm_manager_helpers_ = {
- {LibvirtManager::name(),
- {[](const vsoc::CuttlefishConfig* config) {
- return GetManagerSingleton<LibvirtManager>(config);
- },
- []() { return true; },
- [](const std::string& dir_path) {
- return LibvirtManager::EnsureInstanceDirExists(dir_path);
- }}},
{QemuManager::name(),
{[](const vsoc::CuttlefishConfig* config) {
return GetManagerSingleton<QemuManager>(config);
},
- []() { return vsoc::HostSupportsQemuCli(); },
- [](const std::string& dir_path) {
- return QemuManager::EnsureInstanceDirExists(dir_path);
- }}}};
+ []() { return vsoc::HostSupportsQemuCli(); }}}};
VmManager* VmManager::Get(const std::string& vm_manager_name,
const vsoc::CuttlefishConfig* config) {
@@ -93,10 +81,4 @@
}
return true;
}
-
-bool VmManager::EnsureInstanceDirExists(const std::string& vm_manager_name,
- const std::string& instance_dir_path) {
- return vm_manager_helpers_[vm_manager_name].instance_dir_creator(
- instance_dir_path);
-}
} // namespace vm_manager
diff --git a/host/libs/vm_manager/vm_manager.h b/host/libs/vm_manager/vm_manager.h
index 98dd1d3..ca5ed59 100644
--- a/host/libs/vm_manager/vm_manager.h
+++ b/host/libs/vm_manager/vm_manager.h
@@ -36,8 +36,6 @@
static bool IsValidName(const std::string& name);
static bool IsVmManagerSupported(const std::string& name);
static std::vector<std::string> GetValidNames();
- static bool EnsureInstanceDirExists(const std::string& vm_manager_name,
- const std::string& instance_dir_path);
virtual ~VmManager() = default;
@@ -59,8 +57,6 @@
std::function<VmManager*(const vsoc::CuttlefishConfig*)> builder;
// Whether the host packages support this vm manager
std::function<bool()> support_checker;
- // Creates the instance directory if it doesn't exist
- std::function<bool(const std::string&)> instance_dir_creator;
};
// Asociates a vm manager helper to every valid vm manager name
static std::map<std::string, VmManagerHelper> vm_manager_helpers_;