Skip to content

lib: remove deprecated APIs and implicit resource creation#688

Draft
mtjhrc wants to merge 12 commits into
containers:mainfrom
mtjhrc:remove-deprecated-func
Draft

lib: remove deprecated APIs and implicit resource creation#688
mtjhrc wants to merge 12 commits into
containers:mainfrom
mtjhrc:remove-deprecated-func

Conversation

@mtjhrc
Copy link
Copy Markdown
Collaborator

@mtjhrc mtjhrc commented May 20, 2026

This PR is a preparatory cleanup before the full 2.0 API (#634).

Depends on
Depends on: #673 "Replace hardcoded init.krun with generic virtual file overlay"

New functionality introduced (replacing old way of doing this)

  • krun_set_oci_config_json(ctx, json) — set init config from OCI container-spec JSON (user shall no longer write it to disk)
  • krun_inject_init(ctx, fs_tag) — explicitly injects the init binary and json config for the init into the guest

Deprecated functions removed

  • krun_set_log_levelkrun_init_log
  • krun_set_root_diskkrun_add_disk3
  • krun_set_data_diskkrun_add_disk3
  • krun_set_passt_fdkrun_add_net_unixstream
  • krun_set_gvproxy_pathkrun_add_net_unixgram
  • krun_set_net_mac → mac parameter on krun_add_net_*
  • krun_set_mapped_volumes — was already returning -EINVAL
  • krun_set_console_outputkrun_add_virtio_console_default
  • krun_get_default_initkrun_inject_init

Old numbered API variants removed

  • krun_add_disk, krun_add_disk2krun_add_disk3
  • krun_add_virtiofs, krun_add_virtiofs2krun_add_virtiofs3
  • krun_add_vsock_portkrun_add_vsock_port2
  • krun_set_gpu_optionskrun_set_gpu_options2

Implicit resource creation removed

  • krun_disable_implicit_init + implicit init injection → krun_inject_init(ctx, fs_tag)
  • krun_disable_implicit_console + implicit console → krun_add_virtio_console_default(ctx, in, out, err)
  • krun_disable_implicit_vsock + implicit vsock with TSI heuristics → krun_add_vsock(ctx, tsi_features)

Init config delivery change

krun_set_exec/krun_set_env/krun_set_workdir/krun_set_rlimits no longer format config into kernel cmdline env vars (KRUN_INIT=, KRUN_WORKDIR=, -- args). Instead, they use newly introduced InitConfig /.krun_config.json on virtiofs.

The kernel cmdline no longer carries:

  • KRUN_INIT=...
  • KRUN_WORKDIR=...
  • KRUN_RLIMITS=... (now injected as an env var in the JSON Env array — see FIXME in code)
  • env vars
  • -- args epilog

Only KRUN_BLOCK_ROOT_DEVICE (+ fstype/options) remains on the cmdline when a block root is configured.

Init side follow-up: The C init (init/init.c) still supports both the cmdline and JSON paths. Eventually (maybe as part of #670), the legacy cmdline parsing can be dropped from init since libkrun will no longer use it.

@ggoodman
Copy link
Copy Markdown
Contributor

There's an interesting API design challenge here where krun_set_exec and some other methods are coupled to the specific init implementation. In other words, there's a contract with a pluggable init.

Another way to do this might be to explore passing the init-specific config when choosing the init binary. It's subtle but it makes it clear that the two things are coupled.

@mtjhrc
Copy link
Copy Markdown
Collaborator Author

mtjhrc commented May 21, 2026

There's an interesting API design challenge here where krun_set_exec and some other methods are coupled to the specific init implementation. In other words, there's a contract with a pluggable init.

This is not the final design, this is only the first step in untangling this, I'll decouple this more. The main motivation for this was to get rid of the buggy argv forwarding via the kernel command line and unify everything around our json config.

Currently the krun_set_exec and the other functions just forward to the init config builder methods defined in blob-init (this way, the output format produced by the builder and the format expected by the init binary stay in sync). In the future, you'll call the builder methods directly, but exposing them cleanly right now was complicated (you'd need something like a separate handle for the builder; a Rust/C bindings generator I'm working on should help with this).

If you wanted to use a different init, its configuration will be completely transparent to libkrun. I think the contract will simply be that you provide some virtual files (libkrun won't care if they are executables or configs or whatever) and add the appropriate kernel arguments (e.g. like set the init= kernel arg).

@mtjhrc mtjhrc force-pushed the remove-deprecated-func branch 3 times, most recently from a0af916 to 1da73b7 Compare June 2, 2026 11:30
@mtjhrc mtjhrc force-pushed the remove-deprecated-func branch from 1da73b7 to 9d9144c Compare June 4, 2026 10:50
mtjhrc added 12 commits June 4, 2026 12:51
…th krun_add_disk

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
These were replaced by krun_add_disk. Also remove the internal
root_block_cfg/data_block_cfg fields and their setters, and simplify
get_block_cfg() now that the legacy compat path is gone.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
…_set_net_mac

These were replaced by krun_add_net_unixstream, krun_add_net_unixgram,
and krun_add_net_tap (which take mac as a parameter directly).

Also remove the internal LegacyNetworkConfig enum, legacy_net_cfg and
legacy_mac fields, the compat path in krun_start_enter that converted
them to the new net backend, and the now-unused NET_COMPAT_FEATURES
constant.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
krun_set_log_level set KRUN_NITRO_DEBUG when level==4 (debug), but
krun_init_log did not. Fix the omission so removing krun_set_log_level
doesn't regress nitro debug logging.

Also fix the condition to level >= 4 so that trace (level 5) also
enables nitro debug.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
Superseded by krun_init_log which provides control over target fd,
log style, and env override options.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
This function has been returning -EINVAL unconditionally. Remove it.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
Replace implicit console creation with explicit
krun_add_virtio_console_default calls. Also replace
krun_set_console_output in nitro.c with
krun_add_virtio_console_default.

No test or example relies on implicit console injection anymore.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
…nd implicit console

Console creation is now fully explicit via krun_add_virtio_console_default
or krun_add_virtio_console_multiport. No console is created unless the
caller requests one.

Remove the disable_implicit_console field from VmResources, the implicit
console and serial device creation paths in builder.rs, the console_output
field and setter on VmResources, and krun_set_console_output (kept only
behind cfg(aws-nitro) where NitroEnclave still needs it).

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
- test_tsi_tcp_guest_connect: add krun_add_vsock(ctx, KRUN_TSI_HIJACK_INET)
- test_tsi_tcp_guest_listen: same
- test_vsock_guest_connect: add krun_add_vsock(ctx, 0)
- chroot_vm.c: replace krun_disable_implicit_vsock + vhost-user
  with explicit krun_add_vsock when not using vhost-user-vsock

No test or example relies on implicit vsock creation anymore.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
Vsock creation is now fully explicit via krun_add_vsock(). No vsock
device is created unless the caller requests one.

Remove the Implicit variant from VsockConfig, the implicit vsock
creation heuristics in krun_start_enter, and krun_disable_implicit_vsock.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
All krun_disable_implicit_* functions are gone. The 2.0 API requires
explicit resource creation.

Assisted-by: OpenCode:claude-opus-4.6
Signed-off-by: Matej Hrica <mhrica@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants