Android-cuttlefish cvd tool
crosvm_builder.h
Go to the documentation of this file.
1//
2// Copyright (C) 2021 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 <optional>
19#include <string>
20
21#include "json/value.h"
22
26
27namespace cuttlefish {
28
30 public:
31 static std::string FormatPciArgument(std::optional<pci::Address> pci);
32
34
35 void ApplyProcessRestarter(const std::string& crosvm_binary,
36 const std::string& first_time_argument,
37 int exit_code);
38 void AddControlSocket(const std::string&, const std::string&);
39
40 Result<void> AddCpus(size_t cpus, const std::string& vcpu_config_path);
41 Result<void> AddCpus(const Json::Value&);
42 void AddCpus(size_t cpus);
43
44 void AddHvcSink();
45 void AddHvcReadOnly(const std::string& output, bool console = false);
46 void AddHvcReadWrite(const std::string& output, const std::string& input);
47 void AddHvcSocket(const std::string& socket);
48
49 void AddKvmPath(const std::string& path);
50
51 void AddReadOnlyDisk(const std::string& path,
52 std::optional<pci::Address> pci = std::nullopt);
53 void AddReadWriteDisk(const std::string& path,
54 std::optional<pci::Address> pci = std::nullopt);
55
56 void AddSerialSink();
57 void AddSerialConsoleReadOnly(const std::string& output);
58 void AddSerialConsoleReadWrite(const std::string& output,
59 const std::string& input, bool earlycon);
60 // [[deprecated("do not add any more users")]]
61 void AddSerial(const std::string& output, const std::string& input);
62
63#ifdef __linux__
64 void AddTap(const std::string& tap_name,
65 std::optional<std::string_view> mac = std::nullopt,
66 const std::optional<pci::Address>& pci = std::nullopt);
67#endif
68 // Adds a vhost-user device to the crosvm command.
69 // The max_queue_size parameter represents the maximum number of buffers the
70 // virtqueues can hold at a given time and must be a power of 2. It must be
71 // large enough to avoid dropping buffers during peak usage but not so large
72 // that it consumes excesive amounts of guest RAM. Most sources recommend a
73 // value between 256 and 1024, suggesting to start with 256 when in doubt and
74 // increase as needed for performance.
75 void AddVhostUser(const std::string& type, const std::string& socket_path,
76 int max_queue_size = 256);
77
78 int HvcNum();
79
80 Command& Cmd();
81
82 private:
84 int hvc_num_ = 0;
85 int serial_num_ = 0;
86};
87
88} // namespace cuttlefish
Definition: command.h:38
Definition: crosvm_builder.h:29
void AddHvcSink()
Definition: crosvm_builder.cpp:99
int serial_num_
Definition: crosvm_builder.h:85
void AddSerialConsoleReadOnly(const std::string &output)
Definition: crosvm_builder.cpp:138
void AddSerialSink()
Definition: crosvm_builder.cpp:134
void AddKvmPath(const std::string &path)
Definition: crosvm_builder.cpp:119
void AddHvcReadWrite(const std::string &output, const std::string &input)
Definition: crosvm_builder.cpp:108
void AddReadOnlyDisk(const std::string &path, std::optional< pci::Address > pci=std::nullopt)
Definition: crosvm_builder.cpp:123
void AddVhostUser(const std::string &type, const std::string &socket_path, int max_queue_size=256)
Definition: crosvm_builder.cpp:164
Command & Cmd()
Definition: crosvm_builder.cpp:173
int HvcNum()
Definition: crosvm_builder.cpp:171
void AddHvcReadOnly(const std::string &output, bool console=false)
Definition: crosvm_builder.cpp:103
Result< void > AddCpus(size_t cpus, const std::string &vcpu_config_path)
Definition: crosvm_builder.cpp:73
Command command_
Definition: crosvm_builder.h:83
void AddSerial(const std::string &output, const std::string &input)
Definition: crosvm_builder.cpp:149
CrosvmBuilder()
Definition: crosvm_builder.cpp:43
void AddControlSocket(const std::string &, const std::string &)
Definition: crosvm_builder.cpp:60
static std::string FormatPciArgument(std::optional< pci::Address > pci)
Definition: crosvm_builder.cpp:38
void AddReadWriteDisk(const std::string &path, std::optional< pci::Address > pci=std::nullopt)
Definition: crosvm_builder.cpp:129
void AddSerialConsoleReadWrite(const std::string &output, const std::string &input, bool earlycon)
Definition: crosvm_builder.cpp:142
void AddHvcSocket(const std::string &socket)
Definition: crosvm_builder.cpp:113
int hvc_num_
Definition: crosvm_builder.h:84
void ApplyProcessRestarter(const std::string &crosvm_binary, const std::string &first_time_argument, int exit_code)
Definition: crosvm_builder.cpp:45
Definition: alloc_driver.h:20
tl::expected< T, StackTraceError > Result
Definition: result_type.h:30
uint8_t type
Definition: pairing_connection.h:0