mirror of
https://github.com/systemd/systemd
synced 2024-07-21 18:24:38 +00:00
Merge pull request #31432 from poettering/vmspawn-qemu-rename
vmspawn: drop "qemu" word from most switches
This commit is contained in:
commit
a0d2c41ed6
|
@ -42,7 +42,8 @@
|
|||
file descriptors must be passed with the names <literal>kvm</literal> and <literal>vhost-vsock</literal>
|
||||
respectively.</para>
|
||||
|
||||
<para>Note: on Ubuntu/Debian derivatives systemd-vmspawn requires the user to be in the <literal>kvm</literal> group to use the VSock options.</para>
|
||||
<para>Note: on Ubuntu/Debian derivatives systemd-vmspawn requires the user to be in the
|
||||
<literal>kvm</literal> group to use the VSOCK options.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@ -103,7 +104,7 @@
|
|||
|
||||
<variablelist>
|
||||
<varlistentry>
|
||||
<term><option>--qemu-smp=</option><replaceable>SMP</replaceable></term>
|
||||
<term><option>--cpus=</option><replaceable>CPUS</replaceable></term>
|
||||
|
||||
<listitem><para>Configures the number of CPUs to start the virtual machine with.
|
||||
Defaults to 1.</para>
|
||||
|
@ -113,7 +114,7 @@
|
|||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--qemu-mem=</option><replaceable>MEM</replaceable></term>
|
||||
<term><option>--ram=</option><replaceable>BYTES</replaceable></term>
|
||||
|
||||
<listitem><para>Configures the amount of memory to start the virtual machine with.
|
||||
Defaults to 2G.</para>
|
||||
|
@ -123,7 +124,7 @@
|
|||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--qemu-kvm=</option><replaceable>BOOL</replaceable></term>
|
||||
<term><option>--kvm=</option><replaceable>BOOL</replaceable></term>
|
||||
|
||||
<listitem><para>Configures whether to use KVM. If the option is not specified KVM support will be
|
||||
detected automatically. If true, KVM is always used, and if false, KVM is never used.</para>
|
||||
|
@ -132,13 +133,13 @@
|
|||
</varlistentry>
|
||||
|
||||
<varlistentry>
|
||||
<term><option>--qemu-vsock=</option><replaceable>BOOL</replaceable></term>
|
||||
<term><option>--vsock=</option><replaceable>BOOL</replaceable></term>
|
||||
|
||||
<listitem>
|
||||
<para>Configure whether to use VSock networking.</para>
|
||||
<para>Configure whether to use VSOCK networking.</para>
|
||||
|
||||
<para>If the option is not specified VSock support will be detected automatically.
|
||||
If yes is specified VSocks are always used, and vice versa if no is set VSocks are never used.</para>
|
||||
<para>If the option is not specified VSOCK support will be detected automatically. If yes is
|
||||
specified VSOCK is always used, and vice versa if no is set VSOCK are never used.</para>
|
||||
<xi:include href="version-info.xml" xpointer="v255"/>
|
||||
</listitem>
|
||||
</varlistentry>
|
||||
|
@ -162,7 +163,7 @@
|
|||
<term><option>--tpm=</option><replaceable>BOOL</replaceable></term>
|
||||
|
||||
<listitem>
|
||||
<para>Configure whether to use qemu with a virtual TPM or not.</para>
|
||||
<para>Configure whether to use VM with a virtual TPM or not.</para>
|
||||
|
||||
<para>If the option is not specified vmspawn will detect the presence of <citerefentry project='man-pages'>
|
||||
<refentrytitle>swtpm</refentrytitle><manvolnum>8</manvolnum></citerefentry> and use it if available.
|
||||
|
@ -234,7 +235,7 @@
|
|||
<varlistentry>
|
||||
<term><option>--network-user-mode</option></term>
|
||||
|
||||
<listitem><para>Use user mode networking with QEMU.</para>
|
||||
<listitem><para>Use user mode networking.</para>
|
||||
|
||||
<xi:include href="version-info.xml" xpointer="v255"/></listitem>
|
||||
</varlistentry>
|
||||
|
|
|
@ -37,7 +37,7 @@ OvmfConfig* ovmf_config_free(OvmfConfig *config) {
|
|||
return mfree(config);
|
||||
}
|
||||
|
||||
DEFINE_STRING_TABLE_LOOKUP(qemu_network_stack, QemuNetworkStack);
|
||||
DEFINE_STRING_TABLE_LOOKUP(network_stack, NetworkStack);
|
||||
|
||||
int qemu_check_kvm_support(void) {
|
||||
if (access("/dev/kvm", F_OK) >= 0)
|
||||
|
|
|
@ -63,22 +63,22 @@ static inline const char *ovmf_config_vars_format(const OvmfConfig *c) {
|
|||
OvmfConfig* ovmf_config_free(OvmfConfig *ovmf_config);
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(OvmfConfig*, ovmf_config_free);
|
||||
|
||||
typedef enum QemuNetworkStack {
|
||||
QEMU_NET_TAP,
|
||||
QEMU_NET_USER,
|
||||
QEMU_NET_NONE,
|
||||
_QEMU_NET_MAX,
|
||||
_QEMU_NET_INVALID = -EINVAL,
|
||||
} QemuNetworkStack;
|
||||
typedef enum NetworkStack {
|
||||
NETWORK_STACK_TAP,
|
||||
NETWORK_STACK_USER,
|
||||
NETWORK_STACK_NONE,
|
||||
_NETWORK_STACK_MAX,
|
||||
_NETWORK_STACK_INVALID = -EINVAL,
|
||||
} NetworkStack;
|
||||
|
||||
static const char* const qemu_network_stack_table[_QEMU_NET_MAX] = {
|
||||
[QEMU_NET_TAP] = "tap",
|
||||
[QEMU_NET_USER] = "user",
|
||||
[QEMU_NET_NONE] = "none",
|
||||
static const char* const network_stack_table[_NETWORK_STACK_MAX] = {
|
||||
[NETWORK_STACK_TAP] = "tap",
|
||||
[NETWORK_STACK_USER] = "user",
|
||||
[NETWORK_STACK_NONE] = "none",
|
||||
};
|
||||
|
||||
const char* qemu_network_stack_to_string(QemuNetworkStack type) _const_;
|
||||
QemuNetworkStack qemu_network_stack_from_string(const char *s) _pure_;
|
||||
const char* network_stack_to_string(NetworkStack type) _const_;
|
||||
NetworkStack network_stack_from_string(const char *s) _pure_;
|
||||
|
||||
int qemu_check_kvm_support(void);
|
||||
int qemu_check_vsock_support(void);
|
||||
|
|
|
@ -65,16 +65,16 @@ static PagerFlags arg_pager_flags = 0;
|
|||
static char *arg_directory = NULL;
|
||||
static char *arg_image = NULL;
|
||||
static char *arg_machine = NULL;
|
||||
static char *arg_qemu_smp = NULL;
|
||||
static uint64_t arg_qemu_mem = UINT64_C(2) * U64_GB;
|
||||
static int arg_qemu_kvm = -1;
|
||||
static int arg_qemu_vsock = -1;
|
||||
static char *arg_cpus = NULL;
|
||||
static uint64_t arg_ram = UINT64_C(2) * U64_GB;
|
||||
static int arg_kvm = -1;
|
||||
static int arg_vsock = -1;
|
||||
static unsigned arg_vsock_cid = VMADDR_CID_ANY;
|
||||
static int arg_tpm = -1;
|
||||
static char *arg_linux = NULL;
|
||||
static char **arg_initrds = NULL;
|
||||
static bool arg_qemu_gui = false;
|
||||
static QemuNetworkStack arg_network_stack = QEMU_NET_NONE;
|
||||
static NetworkStack arg_network_stack = NETWORK_STACK_NONE;
|
||||
static int arg_secure_boot = -1;
|
||||
static MachineCredentialContext arg_credentials = {};
|
||||
static uid_t arg_uid_shift = UID_INVALID, arg_uid_range = 0x10000U;
|
||||
|
@ -91,7 +91,7 @@ static char **arg_extra_drives = NULL;
|
|||
STATIC_DESTRUCTOR_REGISTER(arg_directory, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_image, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_machine, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_qemu_smp, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_cpus, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_runtime_directory, freep);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_credentials, machine_credential_context_done);
|
||||
STATIC_DESTRUCTOR_REGISTER(arg_firmware, freep);
|
||||
|
@ -122,17 +122,17 @@ static int help(void) {
|
|||
" -D --directory=PATH Root directory for the VM\n"
|
||||
" -i --image=FILE|DEVICE Root file system disk image or device for the VM\n"
|
||||
"\n%3$sHost Configuration:%4$s\n"
|
||||
" --qemu-smp=SMP Configure guest's SMP settings\n"
|
||||
" --qemu-mem=MEM Configure guest's RAM size\n"
|
||||
" --qemu-kvm=BOOL Enable use of KVM\n"
|
||||
" --qemu-vsock=BOOL Override autodetection of VSock support in QEMU\n"
|
||||
" --vsock-cid=CID Specify the CID to use for the qemu guest's VSock\n"
|
||||
" --cpus=CPUS Configure number of CPUs in guest\n"
|
||||
" --ram=BYTES Configure guest's RAM size\n"
|
||||
" --kvm=BOOL Enable use of KVM\n"
|
||||
" --vsock=BOOL Override autodetection of VSOCK support\n"
|
||||
" --vsock-cid=CID Specify the CID to use for the guest's VSOCK support\n"
|
||||
" --tpm=BOOL Enable use of a virtual TPM\n"
|
||||
" --linux=PATH Specify the linux kernel for direct kernel boot\n"
|
||||
" --initrd=PATH Specify the initrd for direct kernel boot\n"
|
||||
" --qemu-gui Start QEMU in graphical mode\n"
|
||||
" -n --network-tap Create a TAP device for networking with QEMU\n"
|
||||
" --network-user-mode Use user mode networking with QEMU\n"
|
||||
" -n --network-tap Create a TAP device for networking\n"
|
||||
" --network-user-mode Use user mode networking\n"
|
||||
" --secure-boot=BOOL Enable searching for firmware supporting SecureBoot\n"
|
||||
" --firmware=PATH|list Select firmware definition file (or list available)\n"
|
||||
"\n%3$sSystem Identity:%4$s\n"
|
||||
|
@ -171,10 +171,10 @@ static int parse_argv(int argc, char *argv[]) {
|
|||
enum {
|
||||
ARG_VERSION = 0x100,
|
||||
ARG_NO_PAGER,
|
||||
ARG_QEMU_SMP,
|
||||
ARG_QEMU_MEM,
|
||||
ARG_QEMU_KVM,
|
||||
ARG_QEMU_VSOCK,
|
||||
ARG_CPUS,
|
||||
ARG_RAM,
|
||||
ARG_KVM,
|
||||
ARG_VSOCK,
|
||||
ARG_VSOCK_CID,
|
||||
ARG_TPM,
|
||||
ARG_LINUX,
|
||||
|
@ -200,10 +200,14 @@ static int parse_argv(int argc, char *argv[]) {
|
|||
{ "image", required_argument, NULL, 'i' },
|
||||
{ "directory", required_argument, NULL, 'D' },
|
||||
{ "machine", required_argument, NULL, 'M' },
|
||||
{ "qemu-smp", required_argument, NULL, ARG_QEMU_SMP },
|
||||
{ "qemu-mem", required_argument, NULL, ARG_QEMU_MEM },
|
||||
{ "qemu-kvm", required_argument, NULL, ARG_QEMU_KVM },
|
||||
{ "qemu-vsock", required_argument, NULL, ARG_QEMU_VSOCK },
|
||||
{ "cpus", required_argument, NULL, ARG_CPUS },
|
||||
{ "qemu-smp", required_argument, NULL, ARG_CPUS }, /* Compat alias */
|
||||
{ "ram", required_argument, NULL, ARG_RAM },
|
||||
{ "qemu-mem", required_argument, NULL, ARG_RAM }, /* Compat alias */
|
||||
{ "kvm", required_argument, NULL, ARG_KVM },
|
||||
{ "qemu-kvm", required_argument, NULL, ARG_KVM }, /* Compat alias */
|
||||
{ "vsock", required_argument, NULL, ARG_VSOCK },
|
||||
{ "qemu-vsock", required_argument, NULL, ARG_VSOCK }, /* Compat alias */
|
||||
{ "vsock-cid", required_argument, NULL, ARG_VSOCK_CID },
|
||||
{ "tpm", required_argument, NULL, ARG_TPM },
|
||||
{ "linux", required_argument, NULL, ARG_LINUX },
|
||||
|
@ -275,28 +279,28 @@ static int parse_argv(int argc, char *argv[]) {
|
|||
arg_pager_flags |= PAGER_DISABLE;
|
||||
break;
|
||||
|
||||
case ARG_QEMU_SMP:
|
||||
r = free_and_strdup_warn(&arg_qemu_smp, optarg);
|
||||
case ARG_CPUS:
|
||||
r = free_and_strdup_warn(&arg_cpus, optarg);
|
||||
if (r < 0)
|
||||
return r;
|
||||
break;
|
||||
|
||||
case ARG_QEMU_MEM:
|
||||
r = parse_size(optarg, 1024, &arg_qemu_mem);
|
||||
case ARG_RAM:
|
||||
r = parse_size(optarg, 1024, &arg_ram);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --qemu-mem=%s: %m", optarg);
|
||||
return log_error_errno(r, "Failed to parse --ram=%s: %m", optarg);
|
||||
break;
|
||||
|
||||
case ARG_QEMU_KVM:
|
||||
r = parse_tristate(optarg, &arg_qemu_kvm);
|
||||
case ARG_KVM:
|
||||
r = parse_tristate(optarg, &arg_kvm);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --qemu-kvm=%s: %m", optarg);
|
||||
return log_error_errno(r, "Failed to parse --kvm=%s: %m", optarg);
|
||||
break;
|
||||
|
||||
case ARG_QEMU_VSOCK:
|
||||
r = parse_tristate(optarg, &arg_qemu_vsock);
|
||||
case ARG_VSOCK:
|
||||
r = parse_tristate(optarg, &arg_vsock);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to parse --qemu-vsock=%s: %m", optarg);
|
||||
return log_error_errno(r, "Failed to parse --vsock=%s: %m", optarg);
|
||||
break;
|
||||
|
||||
case ARG_VSOCK_CID:
|
||||
|
@ -345,11 +349,11 @@ static int parse_argv(int argc, char *argv[]) {
|
|||
break;
|
||||
|
||||
case 'n':
|
||||
arg_network_stack = QEMU_NET_TAP;
|
||||
arg_network_stack = NETWORK_STACK_TAP;
|
||||
break;
|
||||
|
||||
case ARG_NETWORK_USER_MODE:
|
||||
arg_network_stack = QEMU_NET_USER;
|
||||
arg_network_stack = NETWORK_STACK_USER;
|
||||
break;
|
||||
|
||||
case ARG_BIND:
|
||||
|
@ -467,11 +471,11 @@ static int open_vsock(void) {
|
|||
|
||||
r = bind(vsock_fd, &bind_addr.sa, sizeof(bind_addr.vm));
|
||||
if (r < 0)
|
||||
return log_error_errno(errno, "Failed to bind to vsock to address %u:%u: %m", bind_addr.vm.svm_cid, bind_addr.vm.svm_port);
|
||||
return log_error_errno(errno, "Failed to bind to VSOCK address %u:%u: %m", bind_addr.vm.svm_cid, bind_addr.vm.svm_port);
|
||||
|
||||
r = listen(vsock_fd, SOMAXCONN_DELUXE);
|
||||
if (r < 0)
|
||||
return log_error_errno(errno, "Failed to listen on vsock: %m");
|
||||
return log_error_errno(errno, "Failed to listen on VSOCK: %m");
|
||||
|
||||
return TAKE_FD(vsock_fd);
|
||||
}
|
||||
|
@ -545,13 +549,13 @@ static int vmspawn_dispatch_vsock_connections(sd_event_source *source, int fd, u
|
|||
assert(userdata);
|
||||
|
||||
if (revents != EPOLLIN) {
|
||||
log_warning("Got unexpected poll event for vsock fd.");
|
||||
log_warning("Got unexpected poll event for VSOCK fd.");
|
||||
return 0;
|
||||
}
|
||||
|
||||
conn_fd = accept4(fd, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
|
||||
if (conn_fd < 0) {
|
||||
log_warning_errno(errno, "Failed to accept connection from vsock fd (%m), ignoring...");
|
||||
log_warning_errno(errno, "Failed to accept connection from VSOCK fd (%m), ignoring...");
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1035,8 +1039,8 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
if (r < 0)
|
||||
return r;
|
||||
|
||||
bool use_kvm = arg_qemu_kvm > 0;
|
||||
if (arg_qemu_kvm < 0) {
|
||||
bool use_kvm = arg_kvm > 0;
|
||||
if (arg_kvm < 0) {
|
||||
r = qemu_check_kvm_support();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to check for KVM support: %m");
|
||||
|
@ -1082,13 +1086,13 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to find QEMU binary: %m");
|
||||
|
||||
if (asprintf(&mem, "%" PRIu64 "M", DIV_ROUND_UP(arg_qemu_mem, U64_MB)) < 0)
|
||||
if (asprintf(&mem, "%" PRIu64 "M", DIV_ROUND_UP(arg_ram, U64_MB)) < 0)
|
||||
return log_oom();
|
||||
|
||||
cmdline = strv_new(
|
||||
qemu_binary,
|
||||
"-machine", machine,
|
||||
"-smp", arg_qemu_smp ?: "1",
|
||||
"-smp", arg_cpus ?: "1",
|
||||
"-m", mem,
|
||||
"-object", "rng-random,filename=/dev/urandom,id=rng0",
|
||||
"-device", "virtio-rng-pci,rng=rng0,id=rng-device0"
|
||||
|
@ -1110,9 +1114,9 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
}
|
||||
}
|
||||
|
||||
if (arg_network_stack == QEMU_NET_TAP)
|
||||
if (arg_network_stack == NETWORK_STACK_TAP)
|
||||
r = strv_extend_many(&cmdline, "-nic", "tap,script=no,model=virtio-net-pci");
|
||||
else if (arg_network_stack == QEMU_NET_USER)
|
||||
else if (arg_network_stack == NETWORK_STACK_USER)
|
||||
r = strv_extend_many(&cmdline, "-nic", "user,model=virtio-net-pci");
|
||||
else
|
||||
r = strv_extend_many(&cmdline, "-nic", "none");
|
||||
|
@ -1130,11 +1134,11 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
return log_oom();
|
||||
}
|
||||
|
||||
bool use_vsock = arg_qemu_vsock > 0 && ARCHITECTURE_SUPPORTS_SMBIOS;
|
||||
if (arg_qemu_vsock < 0) {
|
||||
bool use_vsock = arg_vsock > 0 && ARCHITECTURE_SUPPORTS_SMBIOS;
|
||||
if (arg_vsock < 0) {
|
||||
r = qemu_check_vsock_support();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to check for VSock support: %m");
|
||||
return log_error_errno(r, "Failed to check for VSOCK support: %m");
|
||||
|
||||
use_vsock = r;
|
||||
}
|
||||
|
@ -1185,7 +1189,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
|
||||
r = vsock_fix_child_cid(device_fd, &child_cid, arg_machine);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to fix CID for the guest vsock socket: %m");
|
||||
return log_error_errno(r, "Failed to fix CID for the guest VSOCK socket: %m");
|
||||
|
||||
r = strv_extend(&cmdline, "-device");
|
||||
if (r < 0)
|
||||
|
@ -1549,13 +1553,13 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
if (use_vsock) {
|
||||
notify_sock_fd = open_vsock();
|
||||
if (notify_sock_fd < 0)
|
||||
return log_error_errno(notify_sock_fd, "Failed to open vsock: %m");
|
||||
return log_error_errno(notify_sock_fd, "Failed to open VSOCK: %m");
|
||||
|
||||
r = cmdline_add_vsock(&cmdline, notify_sock_fd);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to call getsockname on vsock: %m");
|
||||
return log_error_errno(r, "Failed to call getsockname on VSOCK: %m");
|
||||
}
|
||||
|
||||
if (DEBUG_LOGGING) {
|
||||
|
@ -1606,7 +1610,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
if (use_vsock) {
|
||||
r = setup_notify_parent(event, notify_sock_fd, &exit_status, ¬ify_event_source);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to setup event loop to handle vsock notify events: %m");
|
||||
return log_error_errno(r, "Failed to setup event loop to handle VSOCK notify events: %m");
|
||||
}
|
||||
|
||||
/* shutdown qemu when we are shutdown */
|
||||
|
@ -1624,7 +1628,7 @@ static int run_virtual_machine(int kvm_device_fd, int vhost_device_fd) {
|
|||
|
||||
if (use_vsock) {
|
||||
if (exit_status == INT_MAX) {
|
||||
log_debug("Couldn't retrieve inner EXIT_STATUS from vsock");
|
||||
log_debug("Couldn't retrieve inner EXIT_STATUS from VSOCK");
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
if (exit_status != 0)
|
||||
|
@ -1694,7 +1698,7 @@ static int determine_names(void) {
|
|||
}
|
||||
|
||||
static int verify_arguments(void) {
|
||||
if (arg_network_stack == QEMU_NET_TAP && !arg_privileged)
|
||||
if (arg_network_stack == NETWORK_STACK_TAP && !arg_privileged)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EPERM), "--network-tap requires root privileges, refusing.");
|
||||
|
||||
if (!strv_isempty(arg_initrds) && !arg_linux)
|
||||
|
|
Loading…
Reference in a new issue