• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include "host/libs/vm_manager/vm_manager.h"
18 
19 #include <android-base/logging.h>
20 
21 #include <iomanip>
22 #include <memory>
23 
24 #include "host/libs/config/cuttlefish_config.h"
25 #include "host/libs/vm_manager/crosvm_manager.h"
26 #include "host/libs/vm_manager/qemu_manager.h"
27 
28 namespace cuttlefish {
29 namespace vm_manager {
30 
GetVmManager(const std::string & name,Arch arch)31 std::unique_ptr<VmManager> GetVmManager(const std::string& name, Arch arch) {
32   std::unique_ptr<VmManager> vmm;
33   if (name == QemuManager::name()) {
34     vmm.reset(new QemuManager(arch));
35   } else if (name == CrosvmManager::name()) {
36     vmm.reset(new CrosvmManager(arch));
37   }
38   if (!vmm) {
39     LOG(ERROR) << "Invalid VM manager: " << name;
40     return {};
41   }
42   if (!vmm->IsSupported()) {
43     LOG(ERROR) << "VM manager " << name << " is not supported on this machine.";
44     return {};
45   }
46   return vmm;
47 }
48 
ConfigureMultipleBootDevices(const std::string & pci_path,int pci_offset,int num_disks)49 std::string ConfigureMultipleBootDevices(const std::string& pci_path,
50                                          int pci_offset, int num_disks) {
51   int num_boot_devices =
52       (num_disks < VmManager::kDefaultNumBootDevices) ? num_disks : VmManager::kDefaultNumBootDevices;
53   std::string boot_devices_prop = "androidboot.boot_devices=";
54   for (int i = 0; i < num_boot_devices; i++) {
55     std::stringstream stream;
56     stream << std::setfill('0') << std::setw(2) << std::hex
57            << pci_offset + i + VmManager::kDefaultNumHvcs + VmManager::kMaxDisks - num_disks;
58     boot_devices_prop += pci_path + stream.str() + ".0,";
59   }
60   boot_devices_prop.pop_back();
61   return {boot_devices_prop};
62 }
63 
64 } // namespace vm_manager
65 } // namespace cuttlefish
66 
67