Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions examples/boot_efi.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ int main(int argc, char *const argv[])
}

// Set the log level to "off".
err = krun_set_log_level(0);
err = krun_init_log(KRUN_LOG_TARGET_DEFAULT, KRUN_LOG_LEVEL_OFF, KRUN_LOG_STYLE_AUTO, 0);
if (err) {
errno = -err;
perror("Error configuring log level");
Expand All @@ -191,13 +191,19 @@ int main(int argc, char *const argv[])
return -1;
}

if (err = krun_add_virtio_console_default(ctx_id, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO)) {
errno = -err;
perror("Error configuring console");
return -1;
}

if (err = krun_set_firmware(ctx_id, cmdline.efi_fw)) {
errno = -err;
perror("Error configuring EFI FW path");
return -1;
}

if (err = krun_set_root_disk(ctx_id, cmdline.disk_image)) {
if (err = krun_add_disk(ctx_id, "root", cmdline.disk_image, false)) {
errno = -err;
perror("Error configuring disk image");
return -1;
Expand Down
24 changes: 16 additions & 8 deletions examples/chroot_vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,12 @@ int main(int argc, char *const argv[])
return -1;
}

if (err = krun_add_virtio_console_default(ctx_id, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO)) {
errno = -err;
perror("Error configuring console");
return -1;
}

// Configure vhost-user RNG if requested
if (cmdline.vhost_user_rng_socket != NULL) {
// Test sentinel-terminated array: auto-detect queue count, use custom size
Expand Down Expand Up @@ -357,14 +363,8 @@ int main(int argc, char *const argv[])
printf("Using vhost-user sound backend at %s\n", cmdline.vhost_user_snd_socket);
}

// Configure vhost-user vsock if requested
// Configure vsock: either vhost-user or built-in with TSI
if (cmdline.vhost_user_vsock_socket != NULL) {
// Disable the implicit vsock device to avoid conflict
if (!check_krun_error(krun_disable_implicit_vsock(ctx_id),
"Error disabling implicit vsock")) {
return -1;
}

if (!check_krun_error(krun_add_vhost_user_device(ctx_id, KRUN_VIRTIO_DEVICE_VSOCK,
cmdline.vhost_user_vsock_socket, NULL,
KRUN_VHOST_USER_VSOCK_NUM_QUEUES,
Expand Down Expand Up @@ -419,8 +419,16 @@ int main(int argc, char *const argv[])
return -1;
}

// Add built-in vsock with TSI when not using vhost-user-vsock
if (cmdline.vhost_user_vsock_socket == NULL) {
if (err = krun_add_vsock(ctx_id, KRUN_TSI_HIJACK_INET)) {
errno = -err;
perror("Error configuring vsock");
return -1;
}
}

// Map port 18000 in the host to 8000 in the guest (if networking uses TSI)
// Skip port mapping when using vhost-user-vsock (TSI requires built-in vsock)
if (cmdline.net_mode == NET_MODE_TSI && cmdline.vhost_user_vsock_socket == NULL) {
if (err = krun_set_port_map(ctx_id, &port_map[0])) {
errno = -err;
Expand Down
8 changes: 1 addition & 7 deletions examples/consoles.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,12 @@ int main(int argc, char *const argv[])
const char *const *command_args = (argc > 3) ? (const char *const *)&argv[3] : NULL;
const char *const envp[] = { 0 };

krun_set_log_level(KRUN_LOG_LEVEL_WARN);
krun_init_log(KRUN_LOG_TARGET_DEFAULT, KRUN_LOG_LEVEL_WARN, KRUN_LOG_STYLE_AUTO, 0);

int err;
int ctx_id = krun_create_ctx();
if (ctx_id < 0) { errno = -ctx_id; perror("krun_create_ctx"); return 1; }

if ((err = krun_disable_implicit_console(ctx_id))) {
errno = -err;
perror("krun_disable_implicit_console");
return 1;
}

int console_id = krun_add_virtio_console_multiport(ctx_id);
if (console_id < 0) {
errno = -console_id;
Expand Down
9 changes: 8 additions & 1 deletion examples/external_kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ int main(int argc, char *const argv[])
}

// Set the log level to "off".
err = krun_set_log_level(0);
err = krun_init_log(KRUN_LOG_TARGET_DEFAULT, KRUN_LOG_LEVEL_OFF, KRUN_LOG_STYLE_AUTO, 0);
if (err)
{
errno = -err;
Expand All @@ -243,6 +243,13 @@ int main(int argc, char *const argv[])
return -1;
}

if (err = krun_add_virtio_console_default(ctx_id, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO))
{
errno = -err;
perror("Error configuring console");
return -1;
}

if (cmdline.boot_disk)
{
if (err = krun_add_disk(ctx_id, "boot", cmdline.boot_disk, 0))
Expand Down
15 changes: 11 additions & 4 deletions examples/gui_vm/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use krun_sys::{
KRUN_LOG_LEVEL_TRACE, KRUN_LOG_LEVEL_WARN, KRUN_LOG_STYLE_ALWAYS, KRUN_LOG_TARGET_DEFAULT,
VIRGLRENDERER_RENDER_SERVER, VIRGLRENDERER_THREAD_SYNC, VIRGLRENDERER_USE_ASYNC_FENCE_CB,
VIRGLRENDERER_USE_EGL, VIRGLRENDERER_VENUS, krun_add_display, krun_add_input_device,
krun_add_input_device_fd, krun_create_ctx, krun_display_set_dpi,
krun_display_set_physical_size, krun_display_set_refresh_rate, krun_init_log,
krun_set_display_backend, krun_set_exec, krun_set_gpu_options2, krun_set_root,
krun_add_input_device_fd, krun_add_virtio_console_default, krun_create_ctx,
krun_display_set_dpi, krun_display_set_physical_size, krun_display_set_refresh_rate,
krun_init_log, krun_set_display_backend, krun_set_exec, krun_set_gpu_options2, krun_set_root,
krun_set_vm_config, krun_start_enter,
};
use log::LevelFilter;
Expand All @@ -22,7 +22,7 @@ use std::fs::{File, OpenOptions};
use std::mem::size_of_val;

use anyhow::Context;
use std::os::fd::IntoRawFd;
use std::os::fd::{AsRawFd, IntoRawFd};
use std::path::PathBuf;
use std::process::exit;
use std::ptr::null;
Expand Down Expand Up @@ -150,6 +150,13 @@ fn krun_thread(

krun_call!(krun_set_vm_config(ctx, 4, 4096))?;

krun_call!(krun_add_virtio_console_default(
ctx,
std::io::stdin().as_raw_fd(),
std::io::stdout().as_raw_fd(),
std::io::stderr().as_raw_fd(),
))?;

krun_call!(krun_set_gpu_options2(
ctx,
VIRGLRENDERER_USE_EGL
Expand Down
12 changes: 9 additions & 3 deletions examples/launch-tee.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ int main(int argc, char *const argv[])
}

// Set the log level to "error".
err = krun_set_log_level(1);
err = krun_init_log(KRUN_LOG_TARGET_DEFAULT, KRUN_LOG_LEVEL_ERROR, KRUN_LOG_STYLE_AUTO, 0);
if (err) {
errno = -err;
perror("Error configuring log level");
Expand All @@ -67,8 +67,14 @@ int main(int argc, char *const argv[])
return -1;
}

if (err = krun_add_virtio_console_default(ctx_id, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO)) {
errno = -err;
perror("Error configuring console");
return -1;
}

// Use the first command line argument as the disk image containing the root fs.
if (err = krun_set_root_disk(ctx_id, argv[1])) {
if (err = krun_add_disk(ctx_id, "root", argv[1], false)) {
errno = -err;
perror("Error configuring root disk image");
return -1;
Expand Down Expand Up @@ -114,7 +120,7 @@ int main(int argc, char *const argv[])
return -1;
}

if (err = krun_set_data_disk(ctx_id, argv[3])) {
if (err = krun_add_disk(ctx_id, "data", argv[3], false)) {
errno = -err;
perror("Error configuring the TEE config data disk");
return -1;
Expand Down
6 changes: 3 additions & 3 deletions examples/nitro.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int main(int argc, char *const argv[])

// Enable debug output if configured.
log_level = (cmdline.debug) ? KRUN_LOG_LEVEL_DEBUG : KRUN_LOG_LEVEL_OFF;
err = krun_set_log_level(log_level);
err = krun_init_log(KRUN_LOG_TARGET_DEFAULT, log_level, KRUN_LOG_STYLE_AUTO, 0);
if (err) {
errno = -err;
perror("Error configuring log level");
Expand All @@ -203,9 +203,9 @@ int main(int argc, char *const argv[])
return -1;
}

if (err = krun_set_console_output(ctx_id, "/dev/stdout")) {
if (err = krun_add_virtio_console_default(ctx_id, -1, STDOUT_FILENO, -1)) {
errno = -err;
perror("Error configuring the console output");
perror("Error configuring the console");
return -1;
}

Expand Down
Loading
Loading