• 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 #pragma once
17 
18 #include <string>
19 #include <vector>
20 
21 #include <common/libs/utils/subprocess.h>
22 #include <host/libs/config/cuttlefish_config.h>
23 
24 namespace cuttlefish {
25 namespace vm_manager {
26 
27 // Superclass of every guest VM manager.
28 class VmManager {
29  protected:
30   const Arch arch_;
31 
32  public:
33   // This is the number of HVC virtual console ports that should be configured
34   // by the VmManager. Because crosvm currently allocates these ports as the
35   // first PCI devices, and it does not control the allocation of PCI ID
36   // assignments, the number of these ports affects the PCI paths for
37   // subsequent PCI devices, and these paths are hard-coded in SEPolicy.
38   // Fortunately, HVC virtual console ports can be set up to be "sink" devices,
39   // so even if they are disabled and the guest isn't using them, they don't
40   // need to consume host resources, except for the PCI ID. Use this trick to
41   // keep the number of PCI IDs assigned constant for all flags/vm manager
42   // combinations
43   static const int kDefaultNumHvcs = 6;
44 
45   // This is the number of virtual disks (block devices) that should be
46   // configured by the VmManager. Related to the description above regarding
47   // HVC ports, this problem can also affect block devices (which are
48   // enumerated second) if not all of the block devices are available. Unlike
49   // HVC virtual console ports, block devices cannot be configured to be sinks,
50   // so we once again leverage HVC virtual console ports to "bump up" the last
51   // assigned virtual disk PCI ID (i.e. 2 disks = 7 hvcs, 1 disks = 8 hvcs)
52   static const int kMaxDisks = 3;
53 
54   // This is the number of virtual disks that contribute to the named partition
55   // list (/dev/block/by-name/*) under Android. The partitions names from
56   // multiple disks *must not* collide. Normally we have one set of partitions
57   // from the powerwashed disk (operating system disk) and another set from
58   // the persistent disk
59   static const int kDefaultNumBootDevices = 2;
60 
VmManager(Arch arch)61   VmManager(Arch arch) : arch_(arch) {}
62   virtual ~VmManager() = default;
63 
64   virtual bool IsSupported() = 0;
65   virtual std::vector<std::string> ConfigureGpuMode(const std::string&) = 0;
66   virtual std::string ConfigureBootDevices(int num_disks) = 0;
67 
68   // Starts the VMM. It will usually build a command and pass it to the
69   // command_starter function, although it may start more than one. The
70   // command_starter function allows to customize the way vmm commands are
71   // started/tracked/etc.
72   virtual std::vector<cuttlefish::Command> StartCommands(
73       const CuttlefishConfig& config) = 0;
74 };
75 
76 std::unique_ptr<VmManager> GetVmManager(const std::string&, Arch arch);
77 
78 std::string ConfigureMultipleBootDevices(const std::string& pci_path, int pci_offset,
79                                          int num_disks);
80 
81 } // namespace vm_manager
82 } // namespace cuttlefish
83 
84