Repository navigation
feat(monitor): add hvi monitor implementation #1149
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Nachiket-Roy
wants to merge
3
commits into
urunc-dev:main
Choose a base branch
from
Nachiket-Roy:feat/hvi-vmm
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| // Copyright (c) 2023-2026, Nubificus LTD | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| package hypervisors | ||
|
|
||
| import ( | ||
| "errors" | ||
| "strconv" | ||
|
|
||
| "github.com/urunc-dev/urunc/pkg/unikontainers/types" | ||
| "golang.org/x/sys/unix" | ||
| ) | ||
|
|
||
| const ( | ||
| HviVmm VmmType = "hvi" | ||
| HviBinary string = "hvi" | ||
| ) | ||
|
|
||
| type HVI struct { | ||
| binaryPath string | ||
| binary string | ||
| } | ||
|
|
||
| func (h *HVI) Signal(pid int, signal unix.Signal) error { | ||
| return signalProcess(pid, signal) | ||
| } | ||
|
|
||
| func (h *HVI) Stop(pid int) error { | ||
| return killProcess(pid) | ||
| } | ||
|
|
||
| func (h *HVI) Ok() error { | ||
| return nil | ||
| } | ||
|
|
||
| // UsesKVM returns true as hvi is a KVM-based VMM on Linux | ||
| func (h *HVI) UsesKVM() bool { | ||
| return true | ||
| } | ||
|
|
||
| // UsesTUNTAP reports that the guest gets its network through a tap device. | ||
| func (h *HVI) UsesTUNTAP() bool { | ||
| return true | ||
| } | ||
|
|
||
| // SupportsControlSocket reports that hvi exposes no control/API socket. | ||
| func (h *HVI) SupportsControlSocket() bool { | ||
| return false | ||
| } | ||
|
|
||
| // SupportsSharedfs returns true as hvi supports vhost-user virtiofs on Linux | ||
| func (h *HVI) SupportsSharedfs(fsType string) bool { | ||
| switch fsType { | ||
| case "virtio": | ||
| return true | ||
| default: | ||
| return false | ||
| } | ||
| } | ||
|
|
||
| func (h *HVI) Path() string { | ||
| return h.binaryPath | ||
| } | ||
|
|
||
| // BuildExecCmd builds and validates the hvi command arguments without executing. | ||
| func (h *HVI) BuildExecCmd(args types.ExecArgs, ukernel types.Unikernel) ([]string, error) { | ||
| if args.UnikernelPath == "" { | ||
| return nil, errors.New("kernel path is required for hvi") | ||
| } | ||
|
|
||
| // hvi requires the "boot" subcommand | ||
| exArgs := []string{h.binaryPath, "boot", "--kernel", args.UnikernelPath} | ||
|
|
||
| // Memory configuration in MiB | ||
| if args.MemSizeB > 0 { | ||
| memMiB := bytesToMiB(args.MemSizeB) | ||
| if memMiB == 0 { | ||
| memMiB = DefaultMemory | ||
| } | ||
| exArgs = append(exArgs, "--mem-mib", strconv.FormatUint(memMiB, 10)) | ||
| } | ||
|
|
||
| // vCPU configuration | ||
| if args.VCPUs > 0 { | ||
| exArgs = append(exArgs, "--cpus", strconv.FormatUint(uint64(args.VCPUs), 10)) | ||
| } | ||
|
|
||
| // Network configuration (separate --net-tap and --net-mac flags) | ||
| if args.Net.TapDev != "" { | ||
| exArgs = append(exArgs, "--net-tap", args.Net.TapDev) | ||
| if args.Net.MAC != "" { | ||
| exArgs = append(exArgs, "--net-mac", args.Net.MAC) | ||
| } | ||
| } | ||
|
|
||
| // Block device configuration: --disk path=<path>[,serial=<id>] (max 4 block devices) | ||
| blockArgs := ukernel.MonitorBlockCli() | ||
| if len(blockArgs) > 4 { | ||
| return nil, errors.New("hvi supports at most 4 block devices") | ||
| } | ||
| for _, blockArg := range blockArgs { | ||
| if len(blockArg.ExactArgs) > 0 { | ||
| exArgs = append(exArgs, blockArg.ExactArgs...) | ||
| } else if blockArg.Path != "" { | ||
| diskArg := "path=" + blockArg.Path | ||
| if blockArg.ID != "" { | ||
| diskArg += ",serial=" + blockArg.ID | ||
| } | ||
| exArgs = append(exArgs, "--disk", diskArg) | ||
| } | ||
| } | ||
|
|
||
| // Initramfs configuration (hvi supports a single --initramfs flag) | ||
| extraMonArgs := ukernel.MonitorCli() | ||
| initrdPath := args.InitrdPath | ||
| if initrdPath == "" { | ||
| initrdPath = extraMonArgs.ExtraInitrd | ||
| } | ||
| if initrdPath != "" { | ||
| exArgs = append(exArgs, "--initramfs", initrdPath) | ||
| } | ||
|
|
||
| // Shared filesystem configuration (virtiofs over vhost-user) | ||
| switch args.Sharedfs.Type { | ||
| case "virtiofs": | ||
| exArgs = append(exArgs, "--fs", "tag=fs0,socket=/tmp/vhostqemu") | ||
| default: | ||
| // No shared filesystem | ||
| } | ||
|
|
||
| // Seccomp sandbox configuration (--no-sandbox when seccomp is disabled) | ||
| if !args.Seccomp { | ||
| exArgs = append(exArgs, "--no-sandbox") | ||
| } | ||
|
|
||
| if len(extraMonArgs.OtherArgs) > 0 { | ||
| exArgs = append(exArgs, extraMonArgs.OtherArgs...) | ||
| } | ||
|
|
||
| // Command line arguments for the guest kernel | ||
| if args.Command != "" { | ||
| exArgs = append(exArgs, "--cmdline", args.Command) | ||
| } | ||
|
|
||
| vmmLog.WithField("hvi command", exArgs).Debug("Ready to execve hvi") | ||
|
|
||
| return exArgs, nil | ||
| } | ||
|
|
||
| // PreExec performs pre-execution setup. hvi has no special pre-exec requirements. | ||
| func (h *HVI) PreExec(_ types.ExecArgs) error { | ||
| return nil | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.